txdb: fix lockedUnconfirmed if FINALIZE is inserted with block#512
Merged
chjj merged 1 commit intohandshake-org:masterfrom Nov 22, 2020
Merged
txdb: fix lockedUnconfirmed if FINALIZE is inserted with block#512chjj merged 1 commit intohandshake-org:masterfrom
chjj merged 1 commit intohandshake-org:masterfrom
Conversation
Pull Request Test Coverage Report for Build 250320504
💛 - Coveralls |
tynes
reviewed
Sep 8, 2020
tynes
reviewed
Sep 8, 2020
15a105a to
0e7865c
Compare
Member
Author
|
rebase to 0e7865c: |
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 is an edge case we should have addressed in #464 especially after dealing with basically the same behavior in #387. And actually if I'd written better test coverage in #387 to actually include TRANSFER and FINALIZE, we probably would've fixed all the bugs six months ago 🤷♂️ 😬
The issue is that in bcoin and hsd,
unconfirmedincludes all confirmed amounts in addition to unconfirmed amounts, they are not mutually exclusive. Normally when we send a TX, it is inserted into the database as unconfirmed. Then when we see it in a block, we update the confirmed balance but we leave the unconfirmed balance alone (it was already updated when the TX was first seen in the mempool).During a rescan (or more explicitly, an import-from-seed or deep rescan) we never see the TX as unconfirmed -- it is inserted into the database with the block that confirms it. So to keep the
unconfirmedbalance in sync, we need to update that value first, and then continue with the confirmation process that updates the confirmed balance.