Skip to content

refactor(starknet): replace BlockStatus string with typed enum#3779

Open
0xsamalt wants to merge 1 commit into
NethermindEth:mainfrom
0xsamalt:refactor/block-status-type
Open

refactor(starknet): replace BlockStatus string with typed enum#3779
0xsamalt wants to merge 1 commit into
NethermindEth:mainfrom
0xsamalt:refactor/block-status-type

Conversation

@0xsamalt

@0xsamalt 0xsamalt commented Jul 1, 2026

Copy link
Copy Markdown
  • Introduces BlockStatus as a typed uint8 enum in starknet/block.go with constants BlockPending, BlockAcceptedOnL1, BlockAcceptedOnL2, BlockRejected, and BlockPreConfirmed
  • Adds UnmarshalText so the feeder JSON response deserialises directly into the enum and invalid status strings now return an error
  • Updates all comparison sites and test assertions to use the typed constants

@Ehsan-saradar

Copy link
Copy Markdown
Contributor

Nice one, typed status is much better than a bare string 👍

One thing I'd double-check first though: UnmarshalText now errors on any status that isn't one of the five, and since blocks are decoded straight through json.Unmarshal, an unknown status fails the whole block decode — not just that field. With the old string we accepted anything and only really cared about PENDING / PRE_CONFIRMED.

So if the feeder ever sends something not in the list (pretty sure ABORTED / REVERTED can show up on blocks), we'd fail to read that block and sync would get stuck on it.

Wdyt about mapping unknown values to a BlockUnknown instead of erroring? Keeps it harmless like before, since we only check for PENDING / PRE_CONFIRMED anyway. Or if we'd rather keep it strict, probably worth confirming the list covers everything the gateway can actually send.

@0xsamalt

0xsamalt commented Jul 7, 2026

Copy link
Copy Markdown
Author

Checked this against both the spec and Juno's own fixtures. BLOCK_STATUS is a closed enum (PENDING / ACCEPTED_ON_L2 / ACCEPTED_ON_L1 / REJECTED, plus PRE_CONFIRMED since RPC 0.9) and ABORTED/REVERTED aren't block statuses, they're TXN_EXECUTION_STATUS values scoped to individual transaction receipts.

Grepped our own feeder testdata to be sure this isn't just spec theory: REVERTED shows up in exactly one fixture, and it's a transaction file, never a block file. Across every block and state-update fixture we've captured from the real feeder gateway, block-level status has only ever been PENDING/ACCEPTED_ON_L2/ACCEPTED_ON_L1/REJECTED/PRE_CONFIRMED, no evidence the feeder has ever sent anything else at the block level.

So I don't think there's a real path that hits the default error case. Given that, I'd rather keep it strict if the feeder ever does send something unexpected here, that's a signal of an actual protocol change we want to know about loudly, not something we want to silently coerce into a BlockUnknown fallback and risk masking. Happy to add the fallback anyway if you'd still prefer defensive handling, but wanted to share what I found first.

@Ehsan-saradar

Copy link
Copy Markdown
Contributor

Fair enough — the fixture check convinced me, let's keep it strict. Only nit: could the UnmarshalText error include the offending value (e.g. unknown block status %q)? Makes a future protocol change point straight at itself. 👍

@0xsamalt

0xsamalt commented Jul 8, 2026

Copy link
Copy Markdown
Author

Already included... the default case returns fmt.Errorf("unknown BlockStatus %q", str), so the error message carries the offending value.

@0xsamalt 0xsamalt force-pushed the refactor/block-status-type branch from f3415d0 to 6ce228b Compare July 15, 2026 07:33
@0xsamalt

Copy link
Copy Markdown
Author

Rebased onto main to resolve conflicts. A few refactors landed on main since this opened (subscription-cache→deduper, feeder client value-return change, pending-endpoint removal) that touched the same code paths.

No change to the BlockStatus type or its logic; the rebase also required updating a handful of test call sites (clients/feeder/feeder_test.go, sync/preconfirmed/chain_storage,poller_test.go, rpc/v9|v10/transaction_test.go) that still used the raw "PRE_CONFIRMED" string instead of the typed constant, since those tests were touched by other PRs after this one opened.

Verified with go build/go vet/go test across the affected packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants