MCPcopy Create free account
hub / github.com/ElementsProject/lightning / commit_tx_base_weight

Function commit_tx_base_weight

common/initial_commit_tx.h:26–59  ·  view source on GitHub ↗

The base weight of a commitment tx */

Source from the content-addressed store, hash-verified

24
25/* The base weight of a commitment tx */
26static inline size_t commit_tx_base_weight(size_t num_untrimmed_htlcs,
27 bool option_anchor_outputs,
28 bool option_anchors_zero_fee_htlc_tx)
29{
30 size_t weight;
31 size_t num_outputs;
32
33 /* BOLT #3:
34 *
35 * The base fee for a commitment transaction:
36 * - MUST be calculated to match:
37 * 1. Start with `weight` = 724 (1124 if `option_anchors` applies).
38 */
39 if (option_anchor_outputs || option_anchors_zero_fee_htlc_tx) {
40 weight = 1124;
41 num_outputs = 4;
42 } else {
43 weight = 724;
44 num_outputs = 2;
45 }
46 /* BOLT #3:
47 *
48 * 2. For each committed HTLC, if that output is not trimmed as
49 * specified in [Trimmed Outputs](#trimmed-outputs), add 172
50 * to `weight`.
51 */
52 weight += 172 * num_untrimmed_htlcs;
53 num_outputs += num_untrimmed_htlcs;
54
55 /* Extra fields for Elements */
56 weight += elements_tx_overhead(chainparams, 1, num_outputs);
57
58 return weight;
59}
60
61/* Helper to calculate the base fee if we have this many htlc outputs */
62static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,

Callers 2

approx_max_feerateFunction · 0.85
commit_tx_base_feeFunction · 0.85

Calls 1

elements_tx_overheadFunction · 0.85

Tested by

no test coverage detected