Fix electrum do_reorganized: reset() (not flush()) the status accumulator#786
Open
echennells wants to merge 1 commit into
Open
Fix electrum do_reorganized: reset() (not flush()) the status accumulator#786echennells wants to merge 1 commit into
echennells wants to merge 1 commit into
Conversation
…ator On a chain regression, protocol_electrum::do_reorganized clears each address subscription's Electrum status-hash cursor and calls accumulator.flush() to clear the persistent midstate. But flush() finalizes the digest in place (non-idempotent, non-destructive) and does not reset the midstate; reset() is the operation intended to reuse the accumulator. Because do_reorganized also clears the cursor, the next confirmed-history scan rebuilds the midstate from height 0 on top of that non-reset state, so the recomputed status hash no longer equals sha256 of the intended "<tx>:<height>:" history string. Electrum clients key history re-fetch on status equality, so a wrong-but-stable status silently diverges a wallet's view from the chain. Call reset() instead, which restores the accumulator to its initial state for reuse, so re-accumulation reproduces the correct status. Adds a regression test (electrum__blockchain_scripthash_subscribe__reorganized_notify__status_recomputed_clean) mirroring the progressive_notify case: it subscribes over a confirmed history, fires reorganized then organized, and asserts the recomputed pushed status equals the golden hash. Pre-fix it fails (stale midstate); post-fix it passes. The full electrum_tests suite passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #785
On a chain regression, protocol_electrum::do_reorganized clears each address subscription's Electrum status-hash cursor and calls accumulator.flush() to clear the persistent midstate. But flush() finalizes the digest in place (non-idempotent, non-destructive) and does not reset the midstate; reset() is the operation intended to reuse the accumulator. Because do_reorganized also clears the cursor, the next confirmed-history scan rebuilds the midstate from height 0 on top of that non-reset state, so the recomputed status hash no longer equals sha256 of the intended "::" history string.
Electrum clients key history re-fetch on status equality, so a wrong-but-stable status silently diverges a wallet's view from the chain.
Call reset() instead, which restores the accumulator to its initial state for reuse, so re-accumulation reproduces the correct status.
Adds a regression test
(electrum__blockchain_scripthash_subscribe__reorganized_notify__status_recomputed_clean) mirroring the progressive_notify case: it subscribes over a confirmed history, fires reorganized then organized, and asserts the recomputed pushed status equals the golden hash. Pre-fix it fails (stale midstate); post-fix it passes. The full electrum_tests suite passes.