refactor(safedb): move L1AtSafeHead lookup into SafeDB#20845
Merged
Conversation
The walkback that resolves "earliest L1 at which an L2 block became safe" previously lived in op-supernode/virtual_node and went through the SafeHeadAtL1 point-query interface, requiring repeated SeekLT lookups and a special case for the earliest recorded entry (the cursorL2 == target exact-BlockID branch). That special case is unreachable from callers that only know the target L2 number, which is why FirstProvableSafeHeadNumber in #20833 has to advance the target by +1. Push the lookup into SafeDB itself: it iterates with a single Pebble cursor (Last + Prev) and returns the first entry meeting target directly. SafeDB only writes entries when the deriver actually advances the safe head, so an entry's L1 is the canonical L1 at which that L2 became safe; the new method can therefore answer target == firstL2 without any +1 gymnastics. The two error semantics live in the safedb package now: - ErrL1AtSafeHeadNotFound (transient: empty DB or target > latestL2) - ErrL1AtSafeHeadUnavailable (permanent: target < firstL2, predates records) simpleVirtualNode.L1AtSafeHead now delegates to db.L1AtSafeHead and keeps only the rollup-genesis special case (which SafeDB can't know about). Replaces the walkback in #20833 / #20581 with a single iterator pass.
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.
Pushes the "earliest L1 at which an L2 block became safe" walkback out of
op-supernode/virtual_nodeand into SafeDB itself. SafeDB now does a single Pebble cursor pass (Last+Prev) instead of repeatedSafeHeadAtL1point queries, and it can answertarget == firstL2directly — no morecursorL2 == targetexact-BlockID special case, and no morefirstL2 + 1workaround on the caller side (seeFirstProvableSafeHeadNumberin #20833).ErrL1AtSafeHeadNotFound(transient) andErrL1AtSafeHeadUnavailable(permanent) move to thesafedbpackage.simpleVirtualNode.L1AtSafeHeadkeeps only the rollup-genesis special case and delegates the rest. Same end-to-end semantics; cleaner contract.Related: #20833, #20581.