Repository navigation
fix(aztec-listener): follow the L2 chain by block hash through the SDK block stream - #112
Draft
alejoamiras wants to merge 31 commits into
Draft
alejoamiras wants to merge 31 commits into
alejoamiras wants to merge 31 commits into
Conversation
ChainPublisher handles the block stream's events. It checks each one against the store and the pass's tips, and a rejected event sets the pinned node aside and ends the pass: - a batch must carry the stream's rollup version, link block to block, and extend the stored block below it, read again from the node; - a prune must land on a block the store holds, with a stored block above it, and stay within AZTEC_MAX_PRUNE_DEPTH; - a tier event needs ordered tips and the stored hash at its height. It sends a batch's blocks one by one, each with the pass's proposed tip, and stores the blocks that went out, so a failed send goes out again on the next pass. A prune, or a proven tip that moves back, lowers the proven side work's cursor in the store's transaction. A node with only a shorter copy of the stored chain ends the pass without a prune: the handler warns when that wait starts and alerts while it lasts. The source gains reads of the pinned node outside the walk bound and checks the block 0 a pass serves against the store's genesis block. Blocks go out keyed by the network id, so the topic keeps their order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each tick of the block poller now runs one pass of the SDK block stream over the elected node, through ChainPublisher, in place of the proposed and proven height loops. After the pass: - tips go out only when the store reached the pass's snapshot, taken from that snapshot, when they changed or the heartbeat is due; the separate tips timer is gone; - heights.processedProposedBlockHeight follows the store's tip; - after such a pass the fee juice balance work runs on the proven blocks above its cursor, at most AZTEC_PROVEN_SIDE_WORK_MAX of them, read from the pinned node, with balances read at each block's hash. A block that fails stops the run and goes again on the next pass. It covers every stored tx of the block, whatever its state, and the cursor drops to the store's proven tip when it is above it, as the heights of a new rollup version start over; - an empty store starts at the elected node's finalized block. The rollup version comes from the nodes' node info, read again every CHAIN_INFO_POLL_INTERVAL_MS. A new version starts a new store from the reporting node's block 0; a node without block 0 stops the listener at start, and a pass that serves another block 0 alerts. Range requests and the full sweep read one node per request, its tips and version first, and mark a block final at or below that node's finalized tip on the stream's rollup version. The sweep stays at or below the store's tip. The stream's own logs go through the listener's logger: a failed send shows only there. AZTEC_BLOCK_STREAM_BATCH_SIZE (10, at most 50) and AZTEC_PROVEN_SIDE_WORK_MAX (200) are new; L2_TIPS_POLL_INTERVAL_MS and CATCHUP_POLL_WAIT_TIME_MS are gone. AZTEC_DISABLE_LISTEN_FOR_PROPOSED_BLOCKS now stops the whole stream, with its tips and its proven work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing calls storeBlockHeights, storeChainProposedBlockHeight or storeChainProvenBlockHeight since the block stream replaced the height loops. heights.chainProvenBlockHeight now keeps the old listener's last value, which the stream's first start reads as its floor, so no writer of it stays behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every URL in a line the SDK block stream logs, in its message, an error or its data, is replaced with <url> before the line reaches the listener's logger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The store lowers the checkpointed and proven tips to the ones a prune carries and writes their hashes over the stored ones at those heights. At or below the prune target no block of the pass writes them back, so a wrong hash there stayed, the finalized block's included. ChainPublisher now checks a prune as it checks a tier event before the store sees it: the pass's tips must be in order, and each tier at or below the target must name the block the store holds at its height. Otherwise the node is set aside and nothing is stored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On an empty store the stream started at the election probe's finalized block. When the pass's own snapshot then showed a lower tip, the stream downloaded nothing, still reported that tip, and the store recorded it although no block up to it had been sent; later passes resumed above it. The start now comes from the snapshot the stream itself read, which it reads before it plans the downloads. ChainPublisher also ends the pass on a proposed tip the store does not hold with that hash, so a tip is stored only once its block was sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The side work reads proven blocks from the pinned node by height after the pass settled, and the node can serve another block at a height by then. Before a block's balances and tx states, the side work now requires the stream's rollup version and the hash the store holds at that height; below the store's finalized tip, where it keeps no hashes and a block cannot change, the version alone. Any other block ends the side work for the pass, which the next pass retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK block stream catches a handler's error, logs it and resolves, so a pass whose send or store write failed went on to publish tips and run the proven side work. ChainPublisher now keeps the first such error of a pass, ends the pass quietly for the stream, and rethrows the error from finishPass(), after sync() and before any post-pass work. A pass that ends on the prefix rule, or on a rejected event, stays quiet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing in this listener reads heights.processedProposedBlockHeight; the listener's previous version resumes from it after a rollback. It was written only by a pass that moved the store's tip, so a pass that failed after storing blocks left it behind for good. Each pass now writes the store's proposed tip whenever the stored height differs, before it publishes tips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ChainPublisher's doc keeps its one invariant, the prefix wait and the tips publisher lose comments that narrate their code, and the stream logger's names only bigints, since field elements implement toJSON. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The listener's block stream starts an empty store at the finalized block, so a fresh explorer-api gets the blocks below it only through its block reconciliation. When the API's startup reconciliation runs before any block has arrived it has no upper bound and skips, and the next request came on the 120 s default cadence, at the edge of the 120 s wait for block 1. The run's explorer-api now reconciles every 5 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A handler failure from a node read reaches the poll loop through finishPass(), which logged its stack raw. The loop now logs the error through inspect(), so its cause is included, and through the stream logger's URL redaction. File URLs are left alone, as Node prints an ES module's stack frames as file URLs. The loop's pass is exported as pollOnce() to test that path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The handler accepted the stream's proposed tip when the store held the same hash at that height. A prune writes each tier it lowers, hash included, before any block of the pass is sent, so after an interrupted prune that hash can sit above the stored tip; a later pass that downloads nothing would then move the tip over unsent blocks. The handler now requires the store's tip to already equal the event, which every valid pass has reached through its blocks, and writes nothing. The tier-order check moves from the handler to the stream source's snapshot checks, so the election and every pass refuse tips out of order before any block is read. The handler's check could no longer fire. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Below the store's finalized tip there is no stored hash to compare, so the proven side work takes the pinned node's block as it is served. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The handler and the poll loop took any error named AbortError for an intentional end of the pass. One from a dependency, such as the send, was rethrown unrecorded; the stream dropped it, and the pass went on to write the legacy height and sweep as if it had succeeded. The stream source and the handler now throw PassExit, an AbortError subclass, so the SDK's stream still ends the pass without logging. Only that type is an exit: any other error, an AbortError included, is recorded, rethrown after the pass and logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…has a block A pass that elects no node, or follows one at block 0, leaves the new store empty, and the listener wrote its tip, 0, over the previous version's proposed height. After a rollback that version lifts a 0 to the chain's proven height and sends again the blocks it had sent above it. The height is now written only once the store holds a block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A store started at the snapshot's finalized block whenever its proposed tip was 0. A prune to block 0 leaves the tip at 0 over the hashes above it, so after such a prune whose first send failed, the next pass skipped the new chain's blocks below its finalized block. A store is now empty only when it holds no block hash at or above 1, and the next pass starts at block 1. The legacy proposed height waits on the same predicate, so a store pruned to block 0 writes its tip there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK's fetch names the node's URL in the errors it throws, and the listener logs those errors from many places: the poll loop, the stream source's election, node info, validator stats and the RPC-node error event. The pool's client now wraps the fetch so that every error it throws has its URLs redacted, in place, before the SDK client or any caller sees it. The offline markers that callNodeFunction looks for name no URL and stay. The redaction moves to network-client/redact-urls.ts, and the rollup version and proven side work warnings go through it too. The RPC-node error event's message, cause and stack are now redacted as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…attern The generic URL pattern stops at an apostrophe, which a path can hold, so the rest of such a URL stayed in the text. The redactor now first replaces each AZTEC_RPC_URLS entry and its parts, longest first: the URL as configured and its href, host, hostname, path, query, user and password, raw and decoded, and each path segment and query value of 8 characters or more. The generic pattern then runs as before, and file URLs still stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The redactor replaced each part of the pool's URLs ignoring case, so a host named `gateway` turned "Bad Gateway" into "Bad <url>" in every node's errors, and callNodeFunction no longer set a node offline on that answer. The parts now match as written: an error names a part as configured or as the URL parser normalized it, and the redactor lists both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node's fetch refuses a URL with userinfo and names the whole URL in its error, and the election logs that error's message when a probe fails. Such a URL never works, but it can be configured by mistake. The probe's client now wraps its fetch like the pool's, so its errors have their URLs redacted before the SDK client or the election sees them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The startup config printed each pool entry's URL whole. It now prints the entry's name and the URL's scheme, host and port, with "/…" when the URL has a path or query, and never its userinfo, path or query. The print predates the block stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r holds The stream emits each batch before it checks the snapshot's tip, so blocks went out with a tip the node had since dropped, and the API kept dead blocks below that tip canonical. Each batch now first confirms that tip against the pinned node, and the pass ends, sending nothing, when the node no longer holds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ound AZTEC_MAX_PRUNE_DEPTH had no maximum, so a deeper prune could leave more canonical blocks above an ordered block's tip than the API demotes, halting its ordered topic. The bound now lives in @chicmoz-pkg/message-registry as CHAIN_WALK_BOUND, and the listener's env takes it as both its maximum and its default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A range request read up to 200 blocks serially without a heartbeat, so a slow one outlasted the Kafka session and was redelivered and rerun, delaying later repairs. The handler now awaits the bus's heartbeat before each block read, and a failed heartbeat stops the request and rejects it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A normal pass of 15 blocks at batch size 10 sends every block once, each with the pass's tip, and stores the pass's tip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Storing the sent part of a batch let the next pass skip those blocks, so a tip the node had dropped since stayed theirs. A failed send now stores nothing, and the next pass sends the whole batch again with its own tip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… serve The pass ended, yet the node kept its pin: the sticky election keeps it while no node leads it by more than two blocks. It is now benched until its tip changes, through the prefix rule's bench, renamed benchPinnedUntilNewTip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and before each publish The reader's tips and node-info reads ran back to back before the first heartbeat, and a slow block read was followed by its publish with none between; either pair can outlast the Kafka session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… next election A tip mismatch benched the node only until its tip changed. A node that kept advancing cleared that bench at its next probe and, still the most advanced, won every election while each of its passes failed the check, so a healthy node never got the pin. The mismatch now also costs the node the next election, which hands the pin to any other eligible node; the sticky election then keeps that node while the benched one leads it by no more than the pin's lead. A single node still runs every pass, since a bench holding every eligible node clears. The tip check still reads the tip's block through the checked block read, but without that read's own bench, which had already unpinned a node with no block at its tip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the proven batch setting
Ordered blocks go out with `ordered: { proposedTip }`, and catch-up
blocks a node's reader attests with `finalized: true`, the registry's
new field names. The attested reader's flag is `finalized` too.
AZTEC_PROVEN_SIDE_WORK_MAX becomes AZTEC_PROVEN_BLOCKS_PER_PASS, and
the prefix wait and the rollup version read use the renamed stall
alert and node probe settings. Defaults are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3 of 6 of the stack that makes the explorer follow the L2 chain by block hash. Closes #97.
The block poller followed the chain by height, so after a prune it skipped the replacing block (#97). It now runs the SDK's
L2BlockStreamon the store and source from part 2. The stream follows the chain by hash and emits prunes. Each block goes out on one ordered, keyed stream with its pass's proposed tip, from which the API (parts 4 and 5) decides the canonical chain.What changed
src/svcs/poller/pollers/block_poller/index.ts: each poll runs one pass (runPass).currentChainfollows the highest rollup version the nodes report (network-client/rollup-version.ts), read everyCHAIN_INFO_POLL_INTERVAL_MS. A new version starts a new store from the reporting node's block 0.init()), and fails if no node reports its rollup version in time, or the reporting node does not serve block 0.L2BlockStream.sync()runs in batches ofAZTEC_BLOCK_STREAM_BATCH_SIZE(default 10, at most the SDK'sMAX_RPC_BLOCKS_LEN). An empty store starts at the snapshot's finalized block, inclusive. No history is replayed: the API's reconciliation fills the heights below.processedProposedBlockHeightkeeps following the store's tip once the store holds a block, so the previous listener version can resume from it.AZTEC_ENABLE_FULL_SWEEP_CATCHUP) reads one block per idle pass, bounded by the store's tip.block_poller/chain-publisher.ts:ChainPublisher, the stream's event handler.onOrderedBlock, then stores the batch.AZTEC_STREAM_STALL_ALERT_MS.AZTEC_MAX_PRUNE_DEPTH. It stores a prune, or a proven tip that moves back, and moves the proven cursor back in one listener transaction.src/events/emitted/index.ts:onOrderedBlock(block, proposedTip)replacesonBlock. It publishesNEW_BLOCK_EVENTkeyed by the network id, withordered: { proposedTip }, and promotes the block's pending txs to proposed. A block is no longer sent a second time once proven, as block statuses come from the tips.src/svcs/message-bus/index.tsadds a typedpublishKeyedMessage.network-client/attested-reads.ts:openAttestedReaderreads one node's tips and rollup version before its blocks, and marks a blockfinalizedonly at or below that node's finalized tip, on the stream's version. Block range requests (on-l2-block-range-request.ts) and the full sweep answer from one node through it, and their catch-up blocks carryfinalized.block_poller/proven-side-work.tsandhandle-proven-block-txs.ts: the proven side work (fee juice balances, then proven tx states) runs on at mostAZTEC_PROVEN_BLOCKS_PER_PASS(default 200) blocks per pass, read from the pinned node, and only on blocks of the stored chain. A failed block stops the run, and the next pass retries it. A prune, or a proven tip that moves back, moves the cursor back (lowerProcessedProvenBlockHeight, withLEAST).pollers/l2-tips-poller.ts: tips are published from the pass's snapshot (publishTipsIfDue) instead of a separate timer.svcs/database/heights.controller.ts: the chain height writers are removed.txs.controller.tsaddsgetTxsByHashes.network-client/block-stream-source.ts: a pass ends on its own exit type (PassExit); a snapshot whose tiers are out of order fails the checks; block-0 reads check the genesis hash;pinnedBlockDataandpinnedReadread from the pinned node.withRedactedErrorsinpool.ts,network-client/redact-urls.ts), in the stream's logs (block_poller/stream-logger.ts), and in the logs of a failed pass, the proven side work and the rollup version read. The startup config print shows only each pool URL's origin.AZTEC_BLOCK_STREAM_BATCH_SIZEandAZTEC_PROVEN_BLOCKS_PER_PASSare new.CATCHUP_POLL_WAIT_TIME_MSandL2_TIPS_POLL_INTERVAL_MSare no longer read.AZTEC_DISABLE_LISTEN_FOR_PROPOSED_BLOCKSnow stops the whole stream, its tips and proven side work included; before, proven blocks and tips still went out.network-smokeruns the API's block reconciliation every 5 s.Also: before each batch goes out, the pass's tip is confirmed on the node. A node whose blocks do not match its own tip ends the pass there, sits out the next election, and then stays benched until its tip changes. A batch is stored only once every block in it is sent; after a failed send, the next pass sends the whole batch again, with its own tip.
AZTEC_MAX_PRUNE_DEPTHis capped atCHAIN_WALK_BOUND(10,000), new in@chicmoz-pkg/message-registry, which the API's chain walk takes in part 5; a larger value fails at start. Block range repairs heartbeat before each read and each publish, and the attested reader heartbeats between its two setup reads.How it was tested
tests/unit/chain-publisher.test.ts(new, 24 tests), on the SDK's ownL2BlockStream:tests/integration/chain-publisher.integration.test.ts(new, 3 tests, real Postgres): a prune and the proven cursor's move back commit in one transaction, and a prune or a proof that moves back rolls back with the cursor when a later write fails.tests/unit/block-poller.test.ts(new, 12 tests): where an empty store starts; URLs redacted in a failed pass's log; tips and side work only after a settled pass, and none after a failed send; the legacy proposed height follows the store's tip; a new rollup version starts a new store from block 0.tests/unit/block-poller-cursor.test.ts(rewritten for the proven side work): a 201-block advance over two passes, a failed block retried, side work only on blocks of the stored chain, the cursor moved down to a lower proven tip, and the same updates sent when it moves back.tests/unit/block-processing.test.ts:onOrderedBlocksends the block under the network's key with its pass's tip, and promotes its pending txs.tests/unit/attested-reads.test.ts(new),l2-block-range-request.test.tsandfull-sweep-catchup.test.ts: one node answers, its tips are read first, andfinalizedis set only on blocks it attests. The reader heartbeats between its two setup reads; a range repair heartbeats before each read and each publish, and stops on a failed heartbeat.node-client.test.ts,stream-logger.test.tsandconfig-print.test.ts(new).rollup-version.test.ts(new): the highest version a node reports in time.max-prune-depth.test.ts(new): the depth defaults toCHAIN_WALK_BOUNDand refuses a larger one.block-stream-source.test.tsgains 2 cases: tips out of order, and a block 0 other than the store's genesis.tests/characterization/producer-payloads.corpus.test.tsis updated for the ordered payload.yarn lintis clean.yarn testpasses 464 tests, with 1 skipped, andyarn test:integrationpasses 139.Migration and rollout
0005_l2_block_stream.sqlfrom part 2.orderedand applies its height rules, so until the API is upgraded a stale catch-up block can still move its head back. The next ordered block restores the head. The previous listener also sent each block again once it was proven, and that second copy replaced the stale block; this listener does not. The stale block then stays canonical at its height, under the new API as well, until a reorg or prune reaches that height.chainProvenBlockHeight). It then starts at the elected node's finalized block.ordered, so its head would stall behind the previous listener. The previous listener resumes fromprocessedProposedBlockHeight, which this version keeps at the store's tip. Thel2_block_stream_*tables can stay.🤖 Generated with Claude Code