Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: Fix off-by-one in addr discovery #2319

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

matheusd
Copy link
Member

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

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.
@matheusd matheusd marked this pull request as ready for review December 21, 2023 17:56
Copy link
Member

@jrick jrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find

@jrick jrick merged commit 3c1d19e into decred:master Dec 21, 2023
2 checks passed
@matheusd matheusd deleted the discovery-off-by-one branch December 21, 2023 18:04
@matthawkins90
Copy link
Contributor

matthawkins90 commented Jan 5, 2024

It seems like this is such a rare edge case. Am I correct in understanding that in order for this bug to occur:

  • Wallet A would need to generate an address
  • Wallet B would need to send it a tx
  • Wallet A would be deleted
  • The tx would be mined into the tip block
  • Wallet A would be restored--syncing with the tip block, but prior to any other blocks being mined
  • Wallet A would miss the transaction in the tip block?

And if any other blocks were mined, it would be fine?
I'm just trying to clarify for DJ how rare this situation might've been.
I'm also curious if, when more blocks are mined, if a rescan would've fixed this for users.

@matheusd
Copy link
Member Author

matheusd commented Jan 5, 2024

Your example should trigger the issue, but a simpler one is just:

  • Empty wallet generates an address
  • Wallet is shutdown
  • Some other wallet (or miner reward) is sent to the address and the tx is mined
  • Wallet is restored from seed and misses the tx

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).

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.

3 participants