-
Notifications
You must be signed in to change notification settings - Fork 2.3k
sweep: roll back wallet inputs on all AddWalletInputs error paths #10723
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
50a74b7
01d69f9
976196f
1c35f4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -367,10 +367,14 @@ func (b *BudgetInputSet) AddWalletInputs(wallet Wallet) error { | |||||||
| return utxos[i].Value < utxos[j].Value | ||||||||
| }) | ||||||||
|
|
||||||||
| // Save the current number of inputs so we can roll back on error. | ||||||||
| inputsBefore := len(b.inputs) | ||||||||
|
|
||||||||
| // Add wallet inputs to the set until the specified budget is covered. | ||||||||
| for _, utxo := range utxos { | ||||||||
| err := b.addWalletInput(utxo) | ||||||||
| if err != nil { | ||||||||
| b.inputs = b.inputs[:inputsBefore] | ||||||||
| return err | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -382,6 +386,7 @@ func (b *BudgetInputSet) AddWalletInputs(wallet Wallet) error { | |||||||
|
|
||||||||
| // Exit if there are no inputs can contribute to the fees. | ||||||||
| if !b.hasNormalInput() { | ||||||||
| b.inputs = b.inputs[:inputsBefore] | ||||||||
| return ErrNotEnoughInputs | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rollback operation is redundant in this specific error path. If the loop at line 374 successfully added any wallet inputs,
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment partially restates the code (1:1 explanation), which is discouraged by the repository's style guide. It should instead focus on the intention or the "why" behind the logic, providing more context for the rollback mechanism.
References