Skip to content

fix(dash-spv): follow the network onto a branch that replaces stored blocks - #320

Closed
xdustinface wants to merge 1 commit into
test-base/1102from
test/1102-v770b
Closed

xdustinface wants to merge 1 commit into
test-base/1102from
test/1102-v770b

Conversation

@xdustinface

Copy link
Copy Markdown
Owner

Replay of upstream PR 1102 at its initial state, for testing Manki reviews.


When the network reorganized onto a branch that replaces blocks the client already stored, the client stayed on the old branch for good. The headers of the new branch do not connect to any segment of the header pipeline, so they were dropped with a "no segment matched" warning, every time.

The block headers manager now looks up where such headers branch off: past the headers it already stores, if the parent of the first unknown one is stored below the tip, it emits SyncEvent::ForkDetected with that height. The sync loop then hands it to handle_fork(), which, under the lifecycle lock, stops the client, truncates the stored headers, filter headers, filters and blocks above the fork, and runs the client again, so it syncs onto the branch the network follows. To run again without releasing the lock, run() now delegates to run_locked().

The wallet is not rewound: its synced height only moves forward, so the blocks of the new branch below its old height are not rescanned, and transactions of the dropped blocks stay as they were.

test_sync_follows_reorg makes dashd replace its last 3 blocks with a branch of 5 and requires the client to end on the new tip. Without this change it times out with the client still on the old branch.

…blocks

When the network reorganized onto a branch that replaces blocks the
client already stored, the client stayed on the old branch for good.
The headers of the new branch do not connect to any segment of the
header pipeline, so they were dropped with a "no segment matched"
warning, every time.

The block headers manager now looks up where such headers branch off:
past the headers it already stores, if the parent of the first unknown
one is stored below the tip, it emits `SyncEvent::ForkDetected` with
that height. The sync loop then hands it to `handle_fork()`, which,
under the lifecycle lock, stops the client, truncates the stored
headers, filter headers, filters and blocks above the fork, and runs the
client again, so it syncs onto the branch the network follows. To run
again without releasing the lock, `run()` now delegates to
`run_locked()`.

The wallet is not rewound: its synced height only moves forward, so the
blocks of the new branch below its old height are not rescanned, and
transactions of the dropped blocks stay as they were.

`test_sync_follows_reorg` makes dashd replace its last 3 blocks with a
branch of 5 and requires the client to end on the new tip. Without this
change it times out with the client still on the old branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@manki-review

manki-review Bot commented Nov 21, 2026

Copy link
Copy Markdown

Manki reviews one pull request per commit. #312 has the same head commit 1372cb4 and the lower number, so Manki reviews #312 and not this pull request. The Manki check shown here is the one of #312. To have this pull request reviewed, close #312 and comment /manki review here, or push a commit that only this pull request has.

@xdustinface

Copy link
Copy Markdown
Owner Author

Not dispatched while run 1 on the same commit was open. Replaced.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants