Conversation
This branch has not been deployed
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.
A one-shot accessor for the current best block, next to the finalized one. Defaults stay on finalized; this is an opt-in for callers that want the newest view and accept that it can be reorged or pruned.
Motivation
#1126 added
Backend::latest_best_block_ref; #1161 moved every default to the finalized block because the best block "might actually be pruned in the near future" (#1161 (comment)) and dropped the method as unused, noting a user "can still provide a block hash that they prefer" (#1161 (comment)). There is no direct way to get that hash with a pin from a chainHead-backed client:stream_best_blocks()replays the finalized hashes, bufferedNewBlocks and the latestBestBlockChangedwith no end marker, each item behind achainHead_v1_headerround trip (the integration tests use a 200 ms timer,consume_initial_blocks, for the same problem on the finalized stream);LegacyRpcMethods::chain_get_block_hash(None)is legacy-only and unpinned.Use case: a server authorising requests against chain state wants to read at its newest block instead of making a client that already saw finality wait for the server's (paritytech/web3-storage#384).
Changes
Backend::latest_best_block_ref; the trait is sealed, all four in-tree backends implement it.FollowStreamDriverSubscription::latest_best_blockawaitsInitialized, drains the already-queued events withnow_or_never, returns the lastBestBlockChangedelse the last finalized hash. A queuedStoprestarts the wait (those blocks are unpinned). TheBlockRefkeeps the block pinned likelatest_finalized_block_ref. Right after a (re)subscription, before the node reports a best block, it returns the finalized head.chain_getBlockHash(None)inretry(), as in Introduce Backend trait to allow different RPC (or other) backends to be implemented #1126. archive: error. combined: chainHead, then legacy.OnlineClient::at_current_best_block(), plus a mention in the introduction docs.No existing behaviour changes.
Tests
follow_stream_driver.rs: replayedBestBlockChangedwins over the finalized head; empty replay falls back to it;Stopin the replay restarts and returns the new finalized head (fails without the restart). Integration:best_block_is_at_or_ahead_of_finalized_block(full client, all backend/rpc combinations) andbest_block_lookup(light client).