BudgetInputSet.AddWalletInputs
currently restores the original inputs if there aren't enough wallet inputs to meet the budget.
|
// 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.