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

[bug]: sweep: AddWalletInputs modifies BudgetInputSet when error occurs #8757

Open
morehouse opened this issue May 14, 2024 · 0 comments
Open
Labels
bug Unintended code behaviour P1 MUST be fixed or reviewed utxo sweeping

Comments

@morehouse
Copy link
Collaborator

BudgetInputSet.AddWalletInputs currently restores the original inputs if there aren't enough wallet inputs to meet the budget.

lnd/sweep/tx_input_set.go

Lines 297 to 327 in 9d358bc

// Make a copy of the current inputs. If the wallet doesn't have enough
// utxos to cover the budget, we will revert the current set to its
// original state by removing the added wallet inputs.
originalInputs := b.copyInputs()
// Add wallet inputs to the set until the specified budget is covered.
for _, utxo := range utxos {
input, err := createWalletTxInput(utxo)
if err != nil {
return err
}
pi := SweeperInput{
Input: input,
params: Params{
DeadlineHeight: fn.Some(b.deadlineHeight),
},
}
b.addInput(pi)
// Return if we've reached the minimum output amount.
if !b.NeedWalletInput() {
return nil
}
}
// The wallet doesn't have enough utxos to cover the budget. Revert the
// input set to its original state.
b.inputs = originalInputs
return ErrNotEnoughInputs

But if createWalletTxInput returns an error, the original inputs are not restored.

Solution

Today createWalletTxInput shouldn't ever return an error, though it may in the future if a new witness type is added. We should unify all error paths in AddWalletInputs to ensure inputs are restored.

@morehouse morehouse added bug Unintended code behaviour utxo sweeping needs triage labels May 14, 2024
@saubyk saubyk added P1 MUST be fixed or reviewed and removed needs triage labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unintended code behaviour P1 MUST be fixed or reviewed utxo sweeping
Projects
None yet
Development

No branches or pull requests

2 participants