wallet: Fix off-by-one in addr discovery#2319
Merged
jrick merged 1 commit intodecred:masterfrom Dec 21, 2023
Merged
Conversation
This fixes an off-by-one in sizing the backing array for cfilter data during address discovery. During address discovery, the GetMainChainCFilters call to fetch cfilters from the DB uses an array sized by the caller to put the data. However, due to being an inclusive fetch, the call in the address finder is not correctly sized, missing one (i.e. the last) block. This could cause an issue when the wallet had a single address used and that address was used on a transaction on the wallet's tip, causing the wallet to miss that address being used.
Contributor
|
It seems like this is such a rare edge case. Am I correct in understanding that in order for this bug to occur:
And if any other blocks were mined, it would be fine? |
Member
Author
|
Your example should trigger the issue, but a simpler one is just:
A rescan would indeed fix the issue and having more blocks would also prevent the issue from being hit. This is an issue that would likely only affect automated tests that have precise control over the entire situation (which is indeed how I found it). |
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.
This fixes an off-by-one in sizing the backing array for cfilter data during address discovery.
During address discovery, the GetMainChainCFilters call to fetch cfilters from the DB uses an array sized by the caller to put the data. However, due to being an inclusive fetch, the call in the address finder is not correctly sized, missing one (i.e. the last) block.
This could cause an issue when the wallet had a single address used and that address was used on a transaction on the wallet's tip, causing the wallet to miss that address being used.
Required by #2318.
This was uncovered while debugging this test