Skip to content

wallet: Sweep function and deprecating subtractFeeFromOutputs #23787

@achow101

Description

@achow101

The subtractFeeFromOutputs function has long been the cause of many issues in coin selection. It is unclear whether it is being used for things other than sweeping the entire wallet balance, and sweeping specific inputs (i.e. spending inputs without creating change and without figuring out the feerate manually). Many issues opened about subtractFeeFromOutputs indicate that users are using it for sweeping, and the linked issue in the PR that adds it also discusses sweeping as the intended feature. Instead of using subtractFeeFromOutputs in order to implement this feature, it makes more sense to me to add specific functionality for sweeping. This would allow us to de-complicate our coin selection code by removing subtractFeeFromOutputs.


There are a few specific things that I would want to see in a sweep function, besides the obvious spending all UTXOs with one destination.

It is possible that users will want to sweep to multiple destinations, so the sweep function should optionally allow users to specify amounts with addresses. If no amount is provided for an address, then the remaining value being swept will be sent to that address. Furthermore, multiple addresses may have no amount specified, in which case the remainder is split equally among the addresses, much in the same way that subtractFeeFromOutputs currently distributes the fee among the outputs.

Additionally, sweeping may be used to sweep only specific inputs. So this sweep function should be able to allow users to specify which inputs to use. All specified inputs should be spent. If no inputs are provided, then the entire wallet will be spent.


There are a few ways this could be implemented. The obvious is a new RPC with an API similar to send so that all of the relevant options can be provided. This would allow for a psbt to be returned in the case that the wallet does not have private keys, or if the user requests it. Another way would be to add it as an option to send, however I don't think that the API for using it would be easy to understand. For the GUI, there should be a dedicated button.

Internally, it should be completely separate from existing coin selection (i.e. not in CreateTransaction, SelectCoins, or AttemptSelection).

Lastly, when sweep is implemented, subtractFeeFromOutputs should be added to -deprecatedrpc and the option removed from the GUI. Users should be informed that they can use the sweep function if that is what they are doing. Otherwise they can open an issue to discuss their use case. After one (or two) major release with -deprecatedrpc and no users complaining about a use case for subtractFeeFromOutputs that was not sweeping, then the subtractFeeFromOutputs option can be removed and the code for handling it removed from coin selection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions