Browse Source

commit_tx: make fee msat vs sat explicit.

Suggested-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
plugin-7
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
72b68845ca
  1. 2
      channeld/commit_tx.c
  2. 4
      channeld/full_channel.c
  3. 3
      channeld/test/run-commit_tx.c
  4. 2
      common/initial_commit_tx.c
  5. 11
      common/initial_commit_tx.h
  6. 6
      lightningd/closing_control.c

2
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);

4
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:
*

3
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++;

2
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:
*

11
common/initial_commit_tx.h

@ -18,7 +18,7 @@ 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,
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;
}
/**

6
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],
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;

Loading…
Cancel
Save