forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move output reductions for fee to after coin selection
Simplifies CreateTransactionInternal without changing behavior. Removes the pick_new_inputs variable by moving the subtract fee from amount implementation to later in the loop to where it is possible to calculate the fee for the transaction. This allows the fee to be subtracted from the outputs within a single iteration, instead of calculating the fee in the first iteration, and subtracting the fee in the second. This also removes another scenario where a second iteration of the loop finds a smaller input set (and thus smaller fees than the first iteration) with no change and so a third iteration of the loop is done in order to make a change output that contains the excess fees. To handle these cases, we always create a change output which contains the difference between selected input values and the recipient amounts. Once the transaction fee is calculated, the change output is reduced (in the normal case) or the recipient amounts are reduced (in the subtract fee from amount case). All of this is done in a single iteration of the loop.
- Loading branch information
Showing
1 changed file
with
94 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters