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

Function initial_commit_tx

common/initial_commit_tx.c:73–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
74 const struct bitcoin_outpoint *funding,
75 struct amount_sat funding_sats,
76 const struct pubkey funding_key[NUM_SIDES],
77 enum side opener,
78 u16 to_self_delay,
79 const struct keyset *keyset,
80 u32 feerate_per_kw,
81 struct amount_sat dust_limit,
82 struct amount_msat self_pay,
83 struct amount_msat other_pay,
84 struct amount_sat self_reserve,
85 u64 obscured_commitment_number,
86 struct wally_tx_output *direct_outputs[NUM_SIDES],
87 enum side side,
88 u32 csv_lock,
89 bool option_anchor_outputs,
90 bool option_anchors_zero_fee_htlc_tx,
91 char** err_reason)
92{
93 struct amount_sat base_fee;
94 struct bitcoin_tx *tx;
95 size_t n, untrimmed;
96 bool to_local, to_remote;
97 struct amount_msat total_pay;
98 struct amount_sat amount;
99 enum side lessor = !opener;
100 u32 sequence;
101 void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE;
102 /* There is a direct, and possibly an anchor output for each side. */
103 const void *output_order[2 * NUM_SIDES];
104 const u8 *funding_wscript = bitcoin_redeem_2of2(tmpctx,
105 &funding_key[LOCAL],
106 &funding_key[REMOTE]);
107
108 if (!amount_msat_add(&total_pay, self_pay, other_pay))
109 abort();
110 assert(!amount_msat_greater_sat(total_pay, funding_sats));
111
112 /* BOLT #3:
113 *
114 * 1. Calculate which committed HTLCs need to be trimmed (see
115 * [Trimmed Outputs](#trimmed-outputs)).
116 */
117 untrimmed = 0;
118
119 /* BOLT #3:
120 *
121 * 2. Calculate the base [commitment transaction
122 * fee](#fee-calculation).
123 */
124 base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
125 option_anchor_outputs,
126 option_anchors_zero_fee_htlc_tx);
127
128 /* BOLT #3:
129 * If `option_anchors` applies to the commitment
130 * transaction, also subtract two times the fixed anchor size

Callers 1

initial_channel_txFunction · 0.85

Calls 15

bitcoin_redeem_2of2Function · 0.85
amount_msat_addFunction · 0.85
abortFunction · 0.85
amount_msat_greater_satFunction · 0.85
commit_tx_base_feeFunction · 0.85
try_subtract_feeFunction · 0.85
bitcoin_tx_add_outputFunction · 0.85
scriptpubkey_p2wshFunction · 0.85
scriptpubkey_p2wpkhFunction · 0.85

Tested by

no test coverage detected