Skip to content

Conversation

@cakevm
Copy link
Contributor

@cakevm cakevm commented Dec 23, 2025

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 0 is 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 debug but thought it may be useful:

ConsensusEngineEvent::LatestPersistedBlock(num_hash) => {
   info!(number=num_hash.number, hash=?num_hash.hash, "Latest persisted block");
}

Looks like:

2025-12-23T16:26:02.298841Z  INFO Received block from consensus engine number=24076495 hash=0xba428297deae3da18ba9b1731e141283c189daccce1050bb25213f8e185a08a1
2025-12-23T16:26:02.333813Z  INFO State root task finished state_root=0x80fd2171cd0728134f98ac7e2d83d3e28817f517168d00c52a1aa565f6c756fe elapsed=7.41032ms
2025-12-23T16:26:02.333914Z  INFO Block added to canonical chain number=24076495 hash=0xba428297deae3da18ba9b1731e141283c189daccce1050bb25213f8e185a08a1 peers=4 txs=307 gas_used=21.73Mgas gas_throughput=707.14Mgas/second gas_limit=60.00Mgas full=36.2% base_fee=0.10Gwei blobs=8 excess_blobs=998 elapsed=30.722264ms
2025-12-23T16:26:02.447327Z  INFO Canonical chain committed number=24076495 hash=0xba428297deae3da18ba9b1731e141283c189daccce1050bb25213f8e185a08a1 elapsed=354.086µs
2025-12-23T16:26:02.448215Z  INFO New payload job created id=0x028ee883bdbafbdc parent=0xba428297deae3da18ba9b1731e141283c189daccce1050bb25213f8e185a08a1
2025-12-23T16:26:02.949877Z  INFO Latest persisted block number=24076495 hash=0xba428297deae3da18ba9b1731e141283c189daccce1050bb25213f8e185a08a1 <-- NEW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant