From a21ae33b2d3072d42ccc6d88132f5156ffa04772 Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Fri, 4 Oct 2024 15:49:56 -0400 Subject: [PATCH] channeld: Add dynamic funding_pubkeys to channel_txs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In anticipation of adding support for rotating funding pubkeys during a splice, `channel_txs` is updated to support specifying these manually instead of using the channel’s funding pubkeys. Changelog-None --- channeld/channeld.c | 6 ++++-- channeld/full_channel.c | 18 +++++++++++------- channeld/full_channel.h | 4 +++- channeld/test/run-full_channel.c | 16 ++++++++-------- devtools/mkcommit.c | 4 ++-- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 76c591e3d..85a5862e6 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1166,7 +1166,8 @@ static u8 *send_commit_part(const tal_t *ctx, direct_outputs, &funding_wscript, peer->channel, remote_per_commit, remote_index, REMOTE, - splice_amnt, remote_splice_amnt, &local_anchor_outnum); + splice_amnt, remote_splice_amnt, &local_anchor_outnum, + NULL); htlc_sigs = calc_commitsigs(tmpctx, peer, txs, funding_wscript, htlc_map, remote_index, remote_per_commit, &commit_sig); @@ -1935,7 +1936,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, NULL, &funding_wscript, peer->channel, local_per_commit, local_index, LOCAL, splice_amnt, - remote_splice_amnt, &remote_anchor_outnum); + remote_splice_amnt, &remote_anchor_outnum, + NULL); /* Set the commit_sig on the commitment tx psbt */ if (!psbt_input_set_signature(txs[0]->psbt, 0, diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 9cea66567..79c0b2da3 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -309,13 +309,17 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, enum side side, s64 splice_amnt, s64 remote_splice_amnt, - int *other_anchor_outnum) + int *other_anchor_outnum, + const struct pubkey funding_pubkeys[NUM_SIDES]) { struct bitcoin_tx **txs; const struct htlc **committed; struct keyset keyset; struct amount_msat side_pay, other_side_pay; + if (!funding_pubkeys) + funding_pubkeys = channel->funding_pubkey; + if (!derive_keyset(per_commitment_point, &channel->basepoints[side], &channel->basepoints[!side], @@ -329,8 +333,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, /* Generating and saving witness script required to spend * the funding output */ *funding_wscript = bitcoin_redeem_2of2(ctx, - &channel->funding_pubkey[side], - &channel->funding_pubkey[!side]); + &funding_pubkeys[side], + &funding_pubkeys[!side]); side_pay = channel->view[side].owed[side]; other_side_pay = channel->view[side].owed[!side]; @@ -351,8 +355,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, txs[0] = commit_tx( txs, funding, funding_sats, - &channel->funding_pubkey[side], - &channel->funding_pubkey[!side], + &funding_pubkeys[side], + &funding_pubkeys[!side], channel->opener, channel->config[!side].to_self_delay, channel->lease_expiry, @@ -367,9 +371,9 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, /* Set the remote/local pubkeys on the commitment tx psbt */ psbt_input_add_pubkey(txs[0]->psbt, 0, - &channel->funding_pubkey[side], false /* is_taproot */); + &funding_pubkeys[side], false /* is_taproot */); psbt_input_add_pubkey(txs[0]->psbt, 0, - &channel->funding_pubkey[!side], false /* is_taproot */); + &funding_pubkeys[!side], false /* is_taproot */); add_htlcs(&txs, *htlcmap, channel, &keyset, side); diff --git a/channeld/full_channel.h b/channeld/full_channel.h index 05ebf8da0..3eaba5086 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -67,6 +67,7 @@ struct channel *new_full_channel(const tal_t *ctx, * @local_splice_amnt: how much is being spliced in (or out, if -ve) of local side. * @remote_splice_amnt: how much is being spliced in (or out, if -ve) of remote side. * @other_anchor_outnum: which output (-1 if none) is the !!side anchor + * @funding_pubkeys: The funding pubkeys (specify NULL to use channel's value). * * Returns the unsigned commitment transaction for the committed state * for @side, followed by the htlc transactions in output order and @@ -84,7 +85,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, enum side side, s64 local_splice_amnt, s64 remote_splice_amnt, - int *local_anchor_outnum); + int *local_anchor_outnum, + const struct pubkey funding_pubkeys[NUM_SIDES]); /** * actual_feerate: what is the actual feerate for the local side. diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 95757e8de..c0d41ab79 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -555,7 +555,7 @@ int main(int argc, const char *argv[]) txs = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript_alt, lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0, - &local_anchor); + &local_anchor, NULL); assert(tal_count(txs) == 1); assert(tal_count(htlc_map) == 2); assert(scripteq(funding_wscript_alt, funding_wscript)); @@ -564,7 +564,7 @@ int main(int argc, const char *argv[]) txs2 = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0, - &local_anchor); + &local_anchor, NULL); txs_must_be_eq(txs, txs2); /* BOLT #3: @@ -593,12 +593,12 @@ int main(int argc, const char *argv[]) txs = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0, - &local_anchor); + &local_anchor, NULL); assert(tal_count(txs) == 1); txs2 = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0, - &local_anchor); + &local_anchor, NULL); txs_must_be_eq(txs, txs2); update_feerate(lchannel, feerate_per_kw[LOCAL]); @@ -615,12 +615,12 @@ int main(int argc, const char *argv[]) txs = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0, - &local_anchor); + &local_anchor, NULL); assert(tal_count(txs) == 6); txs2 = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0, - &local_anchor); + &local_anchor, NULL); txs_must_be_eq(txs, txs2); /* FIXME: Compare signatures! */ @@ -695,14 +695,14 @@ int main(int argc, const char *argv[]) &htlc_map, NULL, &funding_wscript, lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0, - &local_anchor); + &local_anchor, NULL); tx_must_be_eq(txs[0], raw_tx); txs2 = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0, - &local_anchor); + &local_anchor, NULL); txs_must_be_eq(txs, txs2); } diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index 93d3b470d..069282b2f 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -425,7 +425,7 @@ int main(int argc, char *argv[]) local_txs = channel_txs(NULL, &channel->funding, channel->funding_sats, &htlcmap, NULL, &funding_wscript, channel, &local_per_commit_point, commitnum, - LOCAL, 0, 0, &local_anchor_outnum); + LOCAL, 0, 0, &local_anchor_outnum, NULL); printf("## local_commitment\n" "# input amount %s, funding_wscript %s, pubkey %s\n", @@ -536,7 +536,7 @@ int main(int argc, char *argv[]) remote_txs = channel_txs(NULL, &channel->funding, channel->funding_sats, &htlcmap, NULL, &funding_wscript, channel, &remote_per_commit_point, commitnum, - REMOTE, 0, 0, &local_anchor_outnum); + REMOTE, 0, 0, &local_anchor_outnum, NULL); printf("## remote_commitment\n" "# input amount %s, funding_wscript %s, key %s\n",