feat: optimistic block notifications#798
Open
pauldelucia wants to merge 1 commit into
Open
Conversation
Follow-up to a16z#738 (checkpoint notifications). Exposes the latest optimistic-header-derived block via a `tokio::sync::watch::Receiver` on the same shape as `finalized_block_recv`: - `Consensus::optimistic_block_recv() -> Option<watch::Receiver<Option<B>>>` - `HeliosApi::current_optimistic_block() -> Result<Option<N::BlockResponse>>` - `HeliosApi::new_optimistic_blocks_recv() -> Result<watch::Receiver<Option<N::BlockResponse>>>` Use case: external consumers (e.g. data indexers, dashboards) that need to react to chain-tip advances under sync-committee attestation without waiting for full finality. `block_recv` already streams the same blocks via mpsc, but the watch variant lets multiple subscribers each see the latest value without coordinating a single consumer. `ConsensusClient` for Ethereum publishes on `optimistic_block_send` in both branches of `send_blocks` so the receiver always reflects the most recent optimistic execution block. opstack and linea return `None` from the trait method, matching their existing handling of light-client features they don't implement. Closes the gap noted in a16z#302 between checkpoint notifications and arbitrary-update notifications for light-client consumers.
Author
|
Hi @ncitron could you have a look at this one please? |
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.
Summary
Adds a
watch-channel notification path for the latest optimistic-header-derived block, mirroring the shape of #738's checkpoint notifications. Builds on the consensus client's already-trackedoptimistic_headerstate — no new sync logic, just exposes data that the light client already maintains.Motivation
#302 originally asked for "tracking and getting notified when a new update is applied" with a concrete use case of "setting a hook on new optimistic update, to do some action (e.g. re-check a list of balances)". #738 addressed the checkpoint half of that — the finalized side. This addresses the optimistic side.
block_recvalready streams the same blocks via mpsc, but the watch variant lets multiple subscribers each see the latest value without coordinating a single consumer. Concrete external use cases:watch::Receiverclone of the same channel.For comparison:
block_recv(mpsc) is a stream meant for a single consumer; the new watch channel is meant for many lightweight observers that only care about the latest value.Changes
core/src/consensus.rs— addoptimistic_block_recvto theConsensustraitcore/src/client/api.rs— addcurrent_optimistic_block+new_optimistic_blocks_recvtoHeliosApicore/src/client/node.rs— implement the newHeliosApimethods (delegate toConsensus::optimistic_block_recv)ethereum/src/consensus.rs— wireoptimistic_block_sendintoConsensusClient+Inner, publish in both branches ofsend_blocks(matching howblock_sendwas already invoked)opstack/src/consensus.rs,linea/src/consensus.rs— implement the trait method returningNone, matching how they already handlecheckpoint_recv44 lines added across 6 files.
cargo test --workspace --libclean (23 tests passing),cargo clippy --workspace --libclean,cargo fmt --checkclean.What's deliberately NOT in this PR
helios_getCurrentCheckpoint/helios_subscribeNewCheckpointsfrom feat: checkpoint notifications #738, but doing so cleanly requires making theHeliosRpctrait generic overN::BlockResponse(the current shape returns concreteOption<B256>for checkpoints, which works because B256 is concrete; blocks are network-specific). That's a bigger trait-surface change that the maintainers may prefer to design themselves. Happy to follow up in a separate PR if you want this — the Rust-API additions in this PR work standalone for crate consumers.helios-tsbindings. Depend on the JSON-RPC layer, so deferred along with that.Note on tests
There's no test directly observing the new channel — there's no analogous test for
finalized_block_sendeither, since exercisingsend_blocksend-to-end needs richer mock-RPC fixture work than the existing tests do. The channel wiring is mechanical (mirrorsfinalized_block_sendexactly). Happy to add a test if reviewers prefer — pointer to the right test pattern would help.