diff options
author | S3RK <1466284+S3RK@users.noreply.github.com> | 2022-08-15 09:30:31 +0200 |
---|---|---|
committer | S3RK <1466284+S3RK@users.noreply.github.com> | 2022-08-15 09:34:26 +0200 |
commit | c8cf08ea743e430c2bf3fe46439594257b0937e5 (patch) | |
tree | 81f06a202081dd8c4402d524b70ad359d8ac7af6 /src/wallet/coinselection.cpp | |
parent | dc9d6626835ec2864dfa747c12071dabdc95b919 (diff) | |
download | bitcoin-c8cf08ea743e430c2bf3fe46439594257b0937e5.tar.xz |
wallet: ensure m_min_change_target always covers change fee
Diffstat (limited to 'src/wallet/coinselection.cpp')
-rw-r--r-- | src/wallet/coinselection.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index 49e6bac462..37cc7e37c8 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -389,14 +389,14 @@ CAmount GetSelectionWaste(const std::set<COutput>& inputs, CAmount change_cost, return waste; } -CAmount GenerateChangeTarget(CAmount payment_value, FastRandomContext& rng) +CAmount GenerateChangeTarget(const CAmount payment_value, const CAmount change_fee, FastRandomContext& rng) { if (payment_value <= CHANGE_LOWER / 2) { - return CHANGE_LOWER; + return change_fee + CHANGE_LOWER; } else { // random value between 50ksat and min (payment_value * 2, 1milsat) const auto upper_bound = std::min(payment_value * 2, CHANGE_UPPER); - return rng.randrange(upper_bound - CHANGE_LOWER) + CHANGE_LOWER; + return change_fee + rng.randrange(upper_bound - CHANGE_LOWER) + CHANGE_LOWER; } } |