mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
initial_commit_tx.h: extract base-weight calculation.
This avoids reproducing it inside full_channel.c. Not sure it does elements correctly though. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3ff8311b40
commit
f0afd060db
3 changed files with 19 additions and 33 deletions
|
@ -1015,28 +1015,7 @@ u32 approx_max_feerate(const struct channel *channel)
|
|||
/* Assume none are trimmed; this gives lower bound on feerate. */
|
||||
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* commitment_transaction: 125 + 43 * num-htlc-outputs bytes
|
||||
* - version: 4 bytes
|
||||
* - witness_header <---- part of the witness data
|
||||
* - count_tx_in: 1 byte
|
||||
* - tx_in: 41 bytes
|
||||
* funding_input
|
||||
* - count_tx_out: 1 byte
|
||||
* - tx_out: 74 + 43 * num-htlc-outputs bytes
|
||||
* output_paying_to_remote,
|
||||
* output_paying_to_local,
|
||||
* ....htlc_output's...
|
||||
* - lock_time: 4 bytes
|
||||
*/
|
||||
/* Those 74 bytes static output are effectively 2 outputs, one
|
||||
* `output_paying_to_local` and one `output_paying_to_remote`. So when
|
||||
* adding the elements overhead we need to add 2 + num htlcs
|
||||
* outputs. */
|
||||
|
||||
weight = 724 + 172 * num;
|
||||
weight = elements_add_overhead(weight, 1, num + 2);
|
||||
weight = commit_tx_base_weight(num, false /* FIXME-anchor */);
|
||||
|
||||
/* Available is their view */
|
||||
avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]);
|
||||
|
|
|
@ -19,6 +19,8 @@ struct ripemd160;
|
|||
* proofs per input and 35 bytes per output. In addition the explicit fee
|
||||
* output will add 9 bytes and the per output overhead as well.
|
||||
*/
|
||||
/* FIXME: This seems to be a generalization of the logic in initial_commit_tx.h
|
||||
* and should be in bitcoin/tx.h */
|
||||
static inline size_t elements_add_overhead(size_t weight, size_t incount,
|
||||
size_t outcount)
|
||||
{
|
||||
|
|
|
@ -21,12 +21,12 @@ struct keyset;
|
|||
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 struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
|
||||
size_t num_untrimmed_htlcs,
|
||||
bool option_anchor_outputs)
|
||||
|
||||
/* The base weight of a commitment tx */
|
||||
static inline size_t commit_tx_base_weight(size_t num_untrimmed_htlcs,
|
||||
bool option_anchor_outputs)
|
||||
{
|
||||
u64 weight;
|
||||
size_t weight;
|
||||
|
||||
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
|
||||
*
|
||||
|
@ -68,12 +68,17 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
|
|||
weight += (32 + 1 + 1 + 1) * 4; /* Elements added fields */
|
||||
}
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* 3. Multiply `feerate_per_kw` by `weight`, divide by 1000 (rounding
|
||||
* down).
|
||||
*/
|
||||
return amount_tx_fee(feerate_per_kw, weight);
|
||||
return weight;
|
||||
}
|
||||
|
||||
/* Helper to calculate the base fee if we have this many htlc outputs */
|
||||
static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
|
||||
size_t num_untrimmed_htlcs,
|
||||
bool option_anchor_outputs)
|
||||
{
|
||||
return amount_tx_fee(feerate_per_kw,
|
||||
commit_tx_base_weight(num_untrimmed_htlcs,
|
||||
option_anchor_outputs));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue