Skip to content

feat: world-state per-block message insertion (A-1380)#24785

Open
spalladino wants to merge 2 commits into
spl/a-1379-archiver-bucketsfrom
spl/a-1380-world-state-per-block
Open

feat: world-state per-block message insertion (A-1380)#24785
spalladino wants to merge 2 commits into
spl/a-1379-archiver-bucketsfrom
spl/a-1380-world-state-per-block

Conversation

@spalladino

@spalladino spalladino commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Part of the Fast Inbox stack (AZIP-22, FI-10 / A-1380). Base: `spl/a-1379-archiver-buckets`.

What this changes

  • `NativeWorldStateService.handleL2BlockAndMessages` no longer throws when a non-first block carries an L1-to-L2 message bundle. Any block may now transition the L1-to-L2 message tree.
  • First-in-checkpoint bundles are still padded to `NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP` (so the legacy call shape produces bit-identical trees); non-first bundles are appended exactly as given (the post-flip compact append the circuits perform). Padding stays in this method as a transitional concern and moves to the caller at the flip.
  • The legacy "non-first blocks carry no messages" rule moves from a throw inside world-state to a transitional assertion owned by the synchronizer call site (`handleL2Block`). The synchronizer's per-checkpoint message fetch is unchanged pre-flip.
  • `MerkleTreeAdminDatabase.handleL2BlockAndMessages` JSDoc updated to document the per-block semantics.

C++ investigation outcome (no barretenberg change needed)

Investigated the native sync/unwind paths under `barretenberg/cpp/src/barretenberg/world_state/`. Per-block message insertion and per-block unwind already work with no C++ change:

  • The L1-to-L2 message tree is the same append-only `FrTree`/`FrStore` as the note-hash tree, which already varies its leaf count per block and unwinds per block.
  • `commit_block` increments the tree's block height and writes a per-block `BlockPayload` (`{size, root}`) on every `sync_block`, even when zero leaves are appended, so the message tree's per-block history stays in lockstep with the other trees.
  • `unwind_block` reverts exactly one block's appended leaves from that stored per-block metadata, generic over leaf count. C++ has no concept of an L2 checkpoint or "first block" — that is a TS-only invariant — so a mid-checkpoint block that appended message leaves unwinds correctly.

The TS-side pending-chain rollback (`handleChainPruned` -> `unwindBlocks`) just unwinds to a block number and carries no checkpoint assumption about the message tree either.

Tests

  • Every-block equivalence: a legacy-shaped multi-block checkpoint leaves the message tree byte-identical (root + size) on every non-first block, while the archive advances per block — proving the degenerate path is a no-op at every block, not just at checkpoint ends.
  • Per-block appends: a checkpoint whose blocks advance the message tree by exactly their (unpadded) bundle size on non-first blocks; forks opened mid-chain see exactly the bundles up to that block.
  • Per-block unwind: unwinding a message-carrying non-first block reverts exactly its appended leaves back to the pre-block state, and re-syncing afterwards reconverges.
  • Synchronizer guard: a non-first block carrying messages is rejected by the call-site assertion.

world-state type-checks clean and all world-state unit tests pass (76 across the two modified suites). The full `yarn build` still fails only in the pre-existing stale-artifact packages (noir-protocol-circuits-types, simulator, prover-client), unrelated to this change.

Review follow-up

Codex (routine review) confirmed the C++ no-change conclusion and the pre-flip synchronizer soundness, and flagged that the TXE world-state caller (txe/src/state_machine/synchronizer.ts) padded the bundle unconditionally. TXE mines one block per checkpoint (always the first block), so this was a no-op in practice, but the second commit makes its padding conditional on indexWithinCheckpoint === 0 to keep the caller aligned with the new per-block semantics.

Lift the non-first-block guard out of NativeWorldStateService.handleL2BlockAndMessages
so any block may carry an L1-to-L2 message bundle and transition the message tree.
First-in-checkpoint bundles are still padded to NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP
(bit-identical trees for the legacy call shape); non-first bundles are appended
unpadded (post-flip compact-append semantics). The transitional non-first-blocks-
carry-no-messages invariant now lives at the synchronizer call site as an assertion.

Per-block unwind already works natively: the append-only message tree commits a
per-block snapshot on every sync_block (like the note-hash tree) and unwinds per
block regardless of leaf count, with no C++ change required.
…kpoint blocks (A-1380)

Align the TXE world-state caller with the per-block message-insertion semantics of
handleL2BlockAndMessages: pad the bundle only when the block is first in its checkpoint,
matching native world state. TXE mines one block per checkpoint (always the first block),
so this is a no-op for current behaviour but keeps the caller consistent with the new
per-block shape.
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.

1 participant