mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
4fef534428wallet: use GetChange() when computing waste (S3RK)87e0ef9031wallet: use GetChange() in tx building (S3RK)15e97a6886wallet: add SelectionResult::GetChange (S3RK)72cad28da0wallet: calculate and store min_viable_change (S3RK)e3210a7225wallet: account for preselected inputs in target (S3RK)f8e796348bwallet: add SelectionResult::Merge (S3RK)06f558e4e2wallet: accurate SelectionResult::m_target (S3RK)c8cf08ea74wallet: ensure m_min_change_target always covers change fee (S3RK) Pull request description: Benefits: 1. more accurate waste calculation for knapsack. Waste calculation is now consistent with tx building code. Before we always assumed change for knapsack even when the solution is changeless4. 2. simpler tx building code. Only create change output when it's needed 3. makes it easier to correctly account for fees for CPFP inputs (should be done in a follow up) In the first three commits we fix the code to accurately track selection target in `SelectionResult::m_target` Then we introduce new variable `min_change` that represents the minimum viable change amount Then we introduce `SelectionResult::GetChange()` which incapsulates dropping change for fee logic and uses correct values of `SelectionResult::m_target` Then we use `SelectionResult::GetChange()` in both tx building and waste calculation code This PR is a refactoring and shouldn't change the behaviour. There is only one known small change (arguably a bug fix). Before we dropped change output if it's smaller than `cost_of_change` after paying change fees. This is incorrect as `cost_of_change` already includes `change_fee`. ACKs for top commit: achow101: ACK4fef534428Xekyo: crACK4fef534428furszy: Code review ACK4fef5344w0xlt: ACK4fef534428Tree-SHA512: 31a7455d4129bc39a444da0f16ad478d690d4d9627b2b8fdb5605facc6488171926bf02f5d7d9a545b2b59efafcf5bb3d404005e4da15c7b44b3f7d441afb941