Repository navigation
Fix reorg recovery erasing the whole DB to genesis - #7
Open
thomas-kroes wants to merge 2 commits into
Open
thomas-kroes wants to merge 2 commits into
thomas-kroes wants to merge 2 commits into
Conversation
The elders peek returns the height of the *oldest* entry with ids ordered newest -> oldest, but chain_reorged_impl anchored the local comparison window at that height, so every zip pair was offset by (len - 1) blocks and a common ancestor could never match. On top of that, `break` on a match only exited the inner loop, so the walk always continued to genesis and reverted the entire database. Since every elder id is a block on the node's canonical chain and block ids are unique, the highest local block appearing among the elders is the common ancestor: find it with an indexed id lookup and revert to just above it. Bail out on empty or non-descending elders responses instead of walking forever. Fixes #5
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
Summary
Fixes #5 — any real reorg caused
chain_reorged_implto walk%eldersall the way down and revert the DB to height 0, as seen on the height-112,500 mainnet fork.Two defects combined (both confirmed against
+get-eldersin dumbnet'sconsensus.hoon):len − 1blocks and a match was essentially impossible.breakonly exited the innerfor; the outerwhilekept walking to genesis and the fall-throughrevert_to(0)wiped the database.Fix
Every elder id is a block on the node's canonical chain, and block ids are unique hashes — so no height alignment is needed at all: the highest local block whose id appears in the elders batch is the common ancestor. Each batch is now checked with a single indexed
id IN (...)lookup (primary key), and on a match we immediatelyrevert_to(ancestor.height + 1). If a batch has no overlap, the walk continues from the oldest elder; empty or non-descending responses error out (UnableToPullElders) instead of looping forever. Reverting to genesis now only happens when the chains genuinely share no blocks.Test plan
Scryablethat mirrors+get-elderssemantics (newest → oldest ids, oldest height returned, 24-entry cap, genesis stop):cargo test --features binary --all-targets(31 passed)cargo clippy --features binary --all-targets(no new warnings),cargo fmt --check