mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-27 07:18:33 +02:00
wallet: ensure m_min_change_target always covers change fee
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user