change fees: more accurate rounding for change amount

We were getting off-by-one for the total amount that the change is for,
since it rounds the fee *down*, independent of the total weight of the
entire tx.

We fix this by using the diff btw the fee of the total weight (w/ and
w/o the change output)
This commit is contained in:
niftynei
2021-07-12 12:06:29 -05:00
committed by neil saitug
parent 914e3dd082
commit 04b6ad06cb
5 changed files with 29 additions and 7 deletions

View File

@@ -474,7 +474,8 @@ mw_after_fundpsbt(struct command *cmd,
}
/* Handle any change output. */
mw->change_amount = change_amount(excess_sat, feerate_per_kw);
mw->change_amount = change_amount(excess_sat, feerate_per_kw,
estimated_final_weight);
mw->change_needed = !amount_sat_eq(mw->change_amount, AMOUNT_SAT(0));
if (mw->change_needed)