diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index ca41d7220..575fbb47e 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -125,7 +125,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * 2. Calculate the base [commitment transaction * fee](#fee-calculation). */ - base_fee_msat = commit_tx_base_fee(feerate_per_kw, untrimmed) * 1000; + base_fee_msat = commit_tx_base_fee_msat(feerate_per_kw, untrimmed); SUPERVERBOSE("# base commitment transaction fee = %"PRIu64"\n", base_fee_msat / 1000); diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 4a7879d65..cffada329 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -414,7 +414,7 @@ static enum channel_add_err add_htlc(struct channel *channel, - commit_tx_num_untrimmed(removing, feerate, dust, recipient); - fee_msat = commit_tx_base_fee(feerate, untrimmed) * 1000; + fee_msat = commit_tx_base_fee_msat(feerate, untrimmed); } else fee_msat = 0; @@ -718,7 +718,7 @@ bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw - commit_tx_num_untrimmed(removing, feerate_per_kw, dust, !channel->funder); - fee_msat = commit_tx_base_fee(feerate_per_kw, untrimmed) * 1000; + fee_msat = commit_tx_base_fee_msat(feerate_per_kw, untrimmed); /* BOLT #2: * diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index 5df146654..1e0e7c006 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -916,8 +916,7 @@ int main(void) /* Now make sure we cover case where funder can't afford the fee; * its output cannot go negative! */ for (;;) { - u64 base_fee_msat = commit_tx_base_fee(feerate_per_kw, 0) - * 1000; + u64 base_fee_msat = commit_tx_base_fee_msat(feerate_per_kw, 0); if (base_fee_msat <= to_local_msat) { feerate_per_kw++; diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index a64b044a4..2d3aadb0d 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -92,7 +92,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, * 2. Calculate the base [commitment transaction * fee](#fee-calculation). */ - base_fee_msat = commit_tx_base_fee(feerate_per_kw, untrimmed) * 1000; + base_fee_msat = commit_tx_base_fee_msat(feerate_per_kw, untrimmed); /* BOLT #3: * diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h index 6710b550c..bb31afabf 100644 --- a/common/initial_commit_tx.h +++ b/common/initial_commit_tx.h @@ -18,8 +18,8 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint, const struct pubkey *accepter_payment_basepoint); /* Helper to calculate the base fee if we have this many htlc outputs */ -static inline u64 commit_tx_base_fee(u32 feerate_per_kw, - size_t num_untrimmed_htlcs) +static inline u64 commit_tx_base_fee_sat(u32 feerate_per_kw, + size_t num_untrimmed_htlcs) { u64 weight; @@ -44,7 +44,14 @@ static inline u64 commit_tx_base_fee(u32 feerate_per_kw, * 3. Multiply `feerate_per_kw` by `weight`, divide by 1000 (rounding * down). */ - return feerate_per_kw * weight / 1000; + return (feerate_per_kw * weight / 1000); +} + +static inline u64 commit_tx_base_fee_msat(u32 feerate_per_kw, + size_t num_untrimmed_htlcs) +{ + return commit_tx_base_fee_sat(feerate_per_kw, num_untrimmed_htlcs) + * 1000; } /** diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 32d6aea0f..ad3a50fa2 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -184,11 +184,11 @@ void peer_start_closingd(struct channel *channel, * fee of the final commitment transaction, as calculated in * [BOLT #3](03-transactions.md#fee-calculation). */ - feelimit = commit_tx_base_fee(channel->channel_info.feerate_per_kw[LOCAL], - 0); + feelimit = commit_tx_base_fee_sat(channel->channel_info.feerate_per_kw[LOCAL], + 0); /* Pick some value above slow feerate (or min possible if unknown) */ - minfee = commit_tx_base_fee(feerate_min(ld, NULL), 0); + minfee = commit_tx_base_fee_sat(feerate_min(ld, NULL), 0); /* If we can't determine feerate, start at half unilateral feerate. */ feerate = mutual_close_feerate(ld->topology); @@ -197,7 +197,7 @@ void peer_start_closingd(struct channel *channel, if (feerate < feerate_floor()) feerate = feerate_floor(); } - startfee = commit_tx_base_fee(feerate, 0); + startfee = commit_tx_base_fee_sat(feerate, 0); if (startfee > feelimit) startfee = feelimit;