lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.58k stars 2.06k forks source link

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

Open morehouse opened 2 months ago

morehouse commented 2 months ago

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

https://github.com/lightningnetwork/lnd/blob/9d358bc64934caef724108fc9704097db31658c4/sweep/tx_input_set.go#L297-L327

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.