feat(rpc): add reth_subscribeLatestPersistedBlock subscription
#20616
+127
−31
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.
When using direct database access
(examples/db-access)and subscribing to new header events, it is currently necessary to add a delay to wait for persistence. This happens because the new header event over WebSockets is triggered before persistence. Even when using--engine.persistence-threshold 0, the event is emitted before persistence is triggered (and this is totally fine).This PR adds a WebSocket subscription that emits notifications when blocks are persisted to disk, allowing external services to know when database reads reflect the latest canonical state. This can also be used when
--engine.persistence-threshold 0is not provided, to determine when the state has been written.Usage:
{"jsonrpc":"2.0","method":"reth_subscribeLatestPersistedBlock","params":[],"id":1}PS: I am currently investigating whether #7836 is still an issue. You can find a test repo here: https://github.com/cakevm/reth-stale-direct-db. This also allows you to test this feature. I tested it with and without
--engine.persistence-threshold 0.I can downgrade this to
debugbut thought it may be useful:Looks like: