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

Function initial_channel_tx

common/initial_channel.c:83–147  ·  view source on GitHub ↗

FIXME: We could cache this. */

Source from the content-addressed store, hash-verified

81
82/* FIXME: We could cache this. */
83struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
84 const u8 **wscript,
85 const struct channel *channel,
86 const struct pubkey *per_commitment_point,
87 enum side side,
88 struct wally_tx_output *direct_outputs[NUM_SIDES],
89 char** err_reason)
90{
91 struct keyset keyset;
92 struct bitcoin_tx *init_tx;
93 u32 csv_lock;
94
95 /* This assumes no HTLCs! */
96 assert(!channel->htlcs);
97
98 if (!derive_keyset(per_commitment_point,
99 &channel->basepoints[side],
100 &channel->basepoints[!side],
101 channel_has(channel, OPT_STATIC_REMOTEKEY),
102 &keyset)) {
103 *err_reason = "Cannot derive keyset";
104 return NULL;
105 }
106
107 /* Figure out the csv_lock (if there's a lease) */
108 if (channel->lease_expiry == 0)
109 csv_lock = 1;
110 else
111 /* For the initial commitment, starts max lease */
112 csv_lock = channel->lease_expiry
113 - get_blockheight(channel->blockheight_states,
114 channel->opener,
115 side);
116
117 *wscript = bitcoin_redeem_2of2(ctx,
118 &channel->funding_pubkey[side],
119 &channel->funding_pubkey[!side]);
120
121 init_tx = initial_commit_tx(ctx, &channel->funding,
122 channel->funding_sats,
123 channel->funding_pubkey,
124 channel->opener,
125 /* They specify our to_self_delay and v.v. */
126 channel->config[!side].to_self_delay,
127 &keyset,
128 channel_feerate(channel, side),
129 channel->config[side].dust_limit,
130 channel->view[side].owed[side],
131 channel->view[side].owed[!side],
132 channel->config[!side].channel_reserve,
133 0 ^ channel->commitment_number_obscurer,
134 direct_outputs,
135 side, csv_lock,
136 channel_has(channel, OPT_ANCHOR_OUTPUTS),
137 err_reason);
138
139 if (init_tx) {
140 psbt_input_add_pubkey(init_tx->psbt, 0,

Callers 4

fundee_channelFunction · 0.85
accepter_commitsFunction · 0.85
opener_commitsFunction · 0.85

Calls 7

get_blockheightFunction · 0.85
bitcoin_redeem_2of2Function · 0.85
initial_commit_txFunction · 0.85
channel_feerateFunction · 0.85
psbt_input_add_pubkeyFunction · 0.85
derive_keysetFunction · 0.70
channel_hasFunction · 0.70

Tested by

no test coverage detected