mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
commit_tx: make fee msat vs sat explicit.
Suggested-by: @niftynei Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
a8e0e1709a
commit
72b68845ca
@@ -125,7 +125,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
* 2. Calculate the base [commitment transaction
|
* 2. Calculate the base [commitment transaction
|
||||||
* fee](#fee-calculation).
|
* 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",
|
SUPERVERBOSE("# base commitment transaction fee = %"PRIu64"\n",
|
||||||
base_fee_msat / 1000);
|
base_fee_msat / 1000);
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
- commit_tx_num_untrimmed(removing, feerate, dust,
|
- commit_tx_num_untrimmed(removing, feerate, dust,
|
||||||
recipient);
|
recipient);
|
||||||
|
|
||||||
fee_msat = commit_tx_base_fee(feerate, untrimmed) * 1000;
|
fee_msat = commit_tx_base_fee_msat(feerate, untrimmed);
|
||||||
} else
|
} else
|
||||||
fee_msat = 0;
|
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,
|
- commit_tx_num_untrimmed(removing, feerate_per_kw, dust,
|
||||||
!channel->funder);
|
!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:
|
/* BOLT #2:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -916,8 +916,7 @@ int main(void)
|
|||||||
/* Now make sure we cover case where funder can't afford the fee;
|
/* Now make sure we cover case where funder can't afford the fee;
|
||||||
* its output cannot go negative! */
|
* its output cannot go negative! */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
u64 base_fee_msat = commit_tx_base_fee(feerate_per_kw, 0)
|
u64 base_fee_msat = commit_tx_base_fee_msat(feerate_per_kw, 0);
|
||||||
* 1000;
|
|
||||||
|
|
||||||
if (base_fee_msat <= to_local_msat) {
|
if (base_fee_msat <= to_local_msat) {
|
||||||
feerate_per_kw++;
|
feerate_per_kw++;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
* 2. Calculate the base [commitment transaction
|
* 2. Calculate the base [commitment transaction
|
||||||
* fee](#fee-calculation).
|
* 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:
|
/* BOLT #3:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
|
|||||||
const struct pubkey *accepter_payment_basepoint);
|
const struct pubkey *accepter_payment_basepoint);
|
||||||
|
|
||||||
/* Helper to calculate the base fee if we have this many htlc outputs */
|
/* 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)
|
size_t num_untrimmed_htlcs)
|
||||||
{
|
{
|
||||||
u64 weight;
|
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
|
* 3. Multiply `feerate_per_kw` by `weight`, divide by 1000 (rounding
|
||||||
* down).
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -184,11 +184,11 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
* fee of the final commitment transaction, as calculated in
|
* fee of the final commitment transaction, as calculated in
|
||||||
* [BOLT #3](03-transactions.md#fee-calculation).
|
* [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);
|
0);
|
||||||
|
|
||||||
/* Pick some value above slow feerate (or min possible if unknown) */
|
/* 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. */
|
/* If we can't determine feerate, start at half unilateral feerate. */
|
||||||
feerate = mutual_close_feerate(ld->topology);
|
feerate = mutual_close_feerate(ld->topology);
|
||||||
@@ -197,7 +197,7 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
if (feerate < feerate_floor())
|
if (feerate < feerate_floor())
|
||||||
feerate = feerate_floor();
|
feerate = feerate_floor();
|
||||||
}
|
}
|
||||||
startfee = commit_tx_base_fee(feerate, 0);
|
startfee = commit_tx_base_fee_sat(feerate, 0);
|
||||||
|
|
||||||
if (startfee > feelimit)
|
if (startfee > feelimit)
|
||||||
startfee = feelimit;
|
startfee = feelimit;
|
||||||
|
|||||||
Reference in New Issue
Block a user