wallet: shortchain history should include base block #9601
+2
−0
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.
ELI5: The Problem
Your wallet keeps track of part of the blockchain, starting from a specific point (called the "offset"). Sometimes, the wallet might only have one block stored (the "base block") or no blocks at all.
The bug is that when the wallet has just the "base block" (and no newer ones), this block wasn't being included in the list of blocks that the wallet sends to check its history with the blockchain. This makes the wallet’s history incomplete and can break synchronization.
Example
Buggy Code:
ids = [block_0]
Missing block 1000!
Fixed Code:
ids = [block_1000, block_0]
Now both blocks are included, and the history is accurate!
Short Summary of the Fix
The original get_short_chain_history method in the wallet2 class contained a bug where the base block (the block at m_blockchain.offset()) was not included in the ids list when sz == 0 (i.e., no blocks exist beyond the offset). This caused an incomplete short chain history in edge cases where the wallet had a minimal or empty blockchain view.
The fixed code ensures the correct behavior by:
Impact of the Fix
The updated code properly includes the base block when sz == 0, ensuring the short chain history is accurate and complete in all scenarios. This fix resolves potential synchronization issues, particularly for wallets with minimal or partially synced blockchain data. It improves reliability during wallet synchronization and avoids missing critical blocks.