feat(op-bridge): persist last processed block and resume via set_with_head#59
feat(op-bridge): persist last processed block and resume via set_with_head#59temrjan wants to merge 1 commit into
Conversation
…_head Add a key/value `state` table that records the latest block fully processed by the ExEx (number + hash). On init, read this state and, if present, configure the notifications stream via `ExExNotificationsStream::set_with_head` so the ExEx resumes from the next block, letting reth backfill any blocks committed while the ExEx was offline. Updates run atomically inside a SQLite transaction so an interrupted process can never leave the state table with mismatched number/hash. Refs: paradigmxyz#25 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This PR adds block persistence and resume support to the op-bridge ExEx — after a node restart, it picks up from the last processed block instead of replaying from the current tip and missing events committed while it was offline. Based on top of @mattsse would appreciate your feedback on the approach — happy to adjust the A follow-up PR will handle the rollup half of #25 (it also needs a small fix — |
What
Adds a key/value
statetable to op-bridge that records the latest block fully processed by the ExEx (number + hash). On init, the notifications stream is configured viaExExNotificationsStream::set_with_headso the ExEx resumes from the next block on restart, letting reth backfill any blocks committed while the ExEx was offline.Updates run atomically inside a SQLite transaction so an interrupted process can never leave the state table with mismatched number/hash.
Why
Currently, on restart, op-bridge starts processing from the node's current tip and skips any blocks committed while it was offline, losing deposit/withdrawal events. With
set_with_head, reth runs a backfill from the persisted head, ensuring no events are missed.This addresses the op-bridge half of #25. A follow-up PR will handle the rollup example, which requires a heavier schema change (adding a
hashcolumn to the existingblocktable).Implementation
statetable (key/value, idempotentCREATE TABLE IF NOT EXISTS)read_last_processed_block/update_last_processed_blockhelpers (private, doc-commented)set_with_headonly called if state is present, preserving current first-run behaviourTesting
Local baseline — all green:
+ '' +cargo build -p op-bridge+ '' ++ '' +cargo test -p op-bridge+ '' +— 4 passed (was 1, added 3 unit tests: empty state, roundtrip, partial state)+ '' +cargo clippy -p op-bridge --all-targets --all-features -- -Dwarnings+ '' ++ '' +cargo +nightly fmt --all --check+ '' ++ '' +cargo +nightly doc -p op-bridge --all-features --no-deps --document-private-items+ '' +with+ '' +RUSTDOCFLAGS=\"-D warnings\"+ '' +Notes
Refs: #25