fix(wallet): only mark change address used if create_tx succeeds#1579
Merged
notmandatory merged 3 commits intobitcoindevkit:masterfrom Sep 9, 2024
Merged
Conversation
699a6bb to
b15c97c
Compare
Collaborator
Author
|
This might also be related to bitcoindevkit/bdk_wallet#74 |
evanlinjin
reviewed
Aug 28, 2024
Member
evanlinjin
left a comment
There was a problem hiding this comment.
Thanks for taking this forward. Let me know what you think about the next_unused_spk_without_revealing idea.
evanlinjin
reviewed
Sep 3, 2024
9341041 to
18ecd06
Compare
evanlinjin
approved these changes
Sep 5, 2024
18ecd06 to
004b0ca
Compare
Collaborator
oleonardolima
left a comment
There was a problem hiding this comment.
utACK 004b0ca
It looks good! Thanks for addressing this issue.
I left some suggestions and nit below.
51fe144 to
849e136
Compare
If no drain script is specified in tx params then we get it from the change keychain by looking at the next unused address. We want to mark the change address used so that other callers won't attempt to use the same address between the time we create the tx and when it appears on chain. Before, we marked the index used regardless of whether a change output is finally added. Then if creating a PSBT failed, we never restored the unused status of the change address, so creating the next tx would have revealed an extra one. Now we only mark the change address used if we successfully create a PSBT and the drain script is used in the change output.
849e136 to
75989d8
Compare
Collaborator
Author
|
Made last minute changes @notmandatory |
This was referenced Sep 13, 2024
Closed
Closed
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.
If no drain script is specified in tx params then we get it from the change keychain by looking at the next unused address. Before this PR we marked the index used regardless of whether a change output is finally added. Then if creating a psbt failed, we never restored the unused status of the change address, so creating the next tx would have revealed an extra one.
We want to mark the change address used so that other callers won't attempt to use the same address between the time we create the tx and when it appears on chain. With this PR we only mark the change address used if we successfully create a psbt and the drain script is used in the change output.
fixes #1578
Notes to the reviewers
An early idea was to unmark the change address used if we fail to create a tx due to
InsufficientFunds, but after looking into it I figure it doesn't totally make sense to mark the address used before we've determined that a change output is necessary. Further,create_txcan fail in other ways besides running coin selection, so I moved themark_usedlogic to the end of the function.Changelog notice
Fixed an issue that caused an unused internal address to be skipped when creating transactions (#1578)
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingBugfixes: