From 9b3965c8059a28f9c12e106f0c70c01e3e9a1955 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 26 Oct 2023 13:02:55 +1030 Subject: [PATCH] channeld: rename channel_splice_txs to channel_txs. channel_txs was a thin wrapper around channel_splice_txs, but that's just confusing. Rename channel_splice_txs to channel_txs, and just call it everywhere. Signed-off-by: Rusty Russell --- channeld/channeld.c | 20 ++++++++--------- channeld/full_channel.c | 25 +++++---------------- channeld/full_channel.h | 28 +++++++++-------------- channeld/test/run-full_channel.c | 38 ++++++++++++++++++-------------- devtools/mkcommit.c | 10 +++++---- 5 files changed, 53 insertions(+), 68 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index df4cf3641..137f359d6 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1533,11 +1533,11 @@ static u8 *send_commit_part(struct peer *peer, derive_channel_id(cs_tlv->splice_info, funding); } - txs = channel_splice_txs(tmpctx, funding, funding_sats, &htlc_map, - direct_outputs, &funding_wscript, - peer->channel, &peer->remote_per_commit, - remote_index, REMOTE, - splice_amnt, remote_splice_amnt); + txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map, + direct_outputs, &funding_wscript, + peer->channel, &peer->remote_per_commit, + remote_index, REMOTE, + splice_amnt, remote_splice_amnt); htlc_sigs = calc_commitsigs(tmpctx, peer, txs, funding_wscript, htlc_map, remote_index, &commit_sig); @@ -2047,11 +2047,11 @@ static struct commitsig *handle_peer_commit_sig(struct peer *peer, funding_sats = peer->channel->funding_sats; } - txs = channel_splice_txs(tmpctx, &outpoint, funding_sats, &htlc_map, - NULL, &funding_wscript, peer->channel, - &peer->next_local_per_commit, - peer->next_index[LOCAL], LOCAL, splice_amnt, - remote_splice_amnt); + txs = channel_txs(tmpctx, &outpoint, funding_sats, &htlc_map, + NULL, &funding_wscript, peer->channel, + &peer->next_local_per_commit, + peer->next_index[LOCAL], LOCAL, splice_amnt, + remote_splice_amnt); /* 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 57115c7a3..197a4639c 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -299,32 +299,17 @@ static void add_htlcs(struct bitcoin_tx ***txs, /* FIXME: We could cache these. */ struct bitcoin_tx **channel_txs(const tal_t *ctx, + const struct bitcoin_outpoint *funding, + struct amount_sat funding_sats, const struct htlc ***htlcmap, struct wally_tx_output *direct_outputs[NUM_SIDES], const u8 **funding_wscript, const struct channel *channel, const struct pubkey *per_commitment_point, u64 commitment_number, - enum side side) -{ - return channel_splice_txs(ctx, &channel->funding, channel->funding_sats, - htlcmap, direct_outputs, funding_wscript, - channel, per_commitment_point, - commitment_number, side, 0, 0); -} - -struct bitcoin_tx **channel_splice_txs(const tal_t *ctx, - const struct bitcoin_outpoint *funding, - struct amount_sat funding_sats, - const struct htlc ***htlcmap, - struct wally_tx_output *direct_outputs[NUM_SIDES], - const u8 **funding_wscript, - const struct channel *channel, - const struct pubkey *per_commitment_point, - u64 commitment_number, - enum side side, - s64 splice_amnt, - s64 remote_splice_amnt) + enum side side, + s64 splice_amnt, + s64 remote_splice_amnt) { struct bitcoin_tx **txs; const struct htlc **committed; diff --git a/channeld/full_channel.h b/channeld/full_channel.h index c0fbe6b7d..66f467e5c 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -55,42 +55,34 @@ struct channel *new_full_channel(const tal_t *ctx, /** * channel_txs: Get the current commitment and htlc txs for the channel. * @ctx: tal context to allocate return value from. - * @channel: The channel to evaluate + * @funding: the outpoint we're spending + * @funding_sats: the amount of @funding * @htlc_map: Pointer to htlcs for each tx output (allocated off @ctx). * @direct_outputs: If non-NULL, fill with pointers to the direct (non-HTLC) outputs (or NULL if none). * @funding_wscript: Pointer to wscript for the funding tx output + * @channel: The channel to evaluate * @per_commitment_point: Per-commitment point to determine keys * @commitment_number: The index of this commitment. * @side: which side to get the commitment transaction for + * @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. * * Returns the unsigned commitment transaction for the committed state * for @side, followed by the htlc transactions in output order and * fills in @htlc_map, or NULL on key derivation failure. */ struct bitcoin_tx **channel_txs(const tal_t *ctx, + const struct bitcoin_outpoint *funding, + struct amount_sat funding_sats, const struct htlc ***htlcmap, struct wally_tx_output *direct_outputs[NUM_SIDES], const u8 **funding_wscript, const struct channel *channel, const struct pubkey *per_commitment_point, u64 commitment_number, - enum side side); - -/* Version of `channel_txs` that lets you specify a custom funding outpoint - * and funding_sats. - */ -struct bitcoin_tx **channel_splice_txs(const tal_t *ctx, - const struct bitcoin_outpoint *funding, - struct amount_sat funding_sats, - const struct htlc ***htlcmap, - struct wally_tx_output *direct_outputs[NUM_SIDES], - const u8 **funding_wscript, - const struct channel *channel, - const struct pubkey *per_commitment_point, - u64 commitment_number, - enum side side, - s64 splice_amnt, - s64 remote_splice_amnt); + enum side side, + s64 local_splice_amnt, + s64 remote_splice_amnt); /** * 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 3c42a3a9d..6d123c129 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -537,17 +537,17 @@ int main(int argc, const char *argv[]) NULL, &htlc_map, NULL, 0x2bb038521914 ^ 42, option_anchor_outputs, option_anchors_zero_fee_htlc_tx, LOCAL); - txs = channel_txs(tmpctx, + txs = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript_alt, - lchannel, &local_per_commitment_point, 42, LOCAL); + lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0); assert(tal_count(txs) == 1); assert(tal_count(htlc_map) == 2); assert(scripteq(funding_wscript_alt, funding_wscript)); tx_must_be_eq(txs[0], raw_tx); - txs2 = channel_txs(tmpctx, + txs2 = channel_txs(tmpctx, &funding, funding_amount, &htlc_map, NULL, &funding_wscript, - rchannel, &local_per_commitment_point, 42, REMOTE); + rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0); txs_must_be_eq(txs, txs2); /* BOLT #3: @@ -573,11 +573,13 @@ int main(int argc, const char *argv[]) assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis == rchannel->view[LOCAL].owed[LOCAL].millisatoshis); - txs = channel_txs(tmpctx, &htlc_map, NULL, &funding_wscript, - lchannel, &local_per_commitment_point, 42, LOCAL); + txs = channel_txs(tmpctx, &funding, funding_amount, + &htlc_map, NULL, &funding_wscript, + lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0); assert(tal_count(txs) == 1); - txs2 = channel_txs(tmpctx, &htlc_map, NULL, &funding_wscript, - rchannel, &local_per_commitment_point, 42, REMOTE); + txs2 = channel_txs(tmpctx, &funding, funding_amount, + &htlc_map, NULL, &funding_wscript, + rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0); txs_must_be_eq(txs, txs2); update_feerate(lchannel, feerate_per_kw[LOCAL]); @@ -591,11 +593,13 @@ int main(int argc, const char *argv[]) assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis == rchannel->view[LOCAL].owed[LOCAL].millisatoshis); - txs = channel_txs(tmpctx, &htlc_map, NULL, &funding_wscript, - lchannel, &local_per_commitment_point, 42, LOCAL); + txs = channel_txs(tmpctx, &funding, funding_amount, + &htlc_map, NULL, &funding_wscript, + lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0); assert(tal_count(txs) == 6); - txs2 = channel_txs(tmpctx, &htlc_map, NULL, &funding_wscript, - rchannel, &local_per_commitment_point, 42, REMOTE); + txs2 = channel_txs(tmpctx, &funding, funding_amount, + &htlc_map, NULL, &funding_wscript, + rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0); txs_must_be_eq(txs, txs2); /* FIXME: Compare signatures! */ @@ -665,14 +669,16 @@ int main(int argc, const char *argv[]) 0x2bb038521914 ^ 42, option_anchor_outputs, option_anchors_zero_fee_htlc_tx, LOCAL); - txs = channel_txs(tmpctx, &htlc_map, NULL, &funding_wscript, + txs = channel_txs(tmpctx, &funding, funding_amount, + &htlc_map, NULL, &funding_wscript, lchannel, &local_per_commitment_point, 42, - LOCAL); + LOCAL, 0, 0); tx_must_be_eq(txs[0], raw_tx); - txs2 = channel_txs(tmpctx, &htlc_map, NULL, &funding_wscript, + txs2 = channel_txs(tmpctx, &funding, funding_amount, + &htlc_map, NULL, &funding_wscript, rchannel, &local_per_commitment_point, - 42, REMOTE); + 42, REMOTE, 0, 0); txs_must_be_eq(txs, txs2); } diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index 288cae118..cc460b36e 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -422,9 +422,10 @@ int main(int argc, char *argv[]) if (!per_commit_point(&localseed, &local_per_commit_point, commitnum)) errx(1, "Bad deriving local per-commitment-point"); - local_txs = channel_txs(NULL, &htlcmap, NULL, &funding_wscript, channel, + local_txs = channel_txs(NULL, &channel->funding, channel->funding_sats, + &htlcmap, NULL, &funding_wscript, channel, &local_per_commit_point, commitnum, - LOCAL); + LOCAL, 0, 0); printf("## local_commitment\n" "# input amount %s, funding_wscript %s, pubkey %s\n", @@ -532,9 +533,10 @@ int main(int argc, char *argv[]) /* Create the remote commitment tx */ if (!per_commit_point(&remoteseed, &remote_per_commit_point, commitnum)) errx(1, "Bad deriving remote per-commitment-point"); - remote_txs = channel_txs(NULL, &htlcmap, NULL, &funding_wscript, channel, + remote_txs = channel_txs(NULL, &channel->funding, channel->funding_sats, + &htlcmap, NULL, &funding_wscript, channel, &remote_per_commit_point, commitnum, - REMOTE); + REMOTE, 0, 0); printf("## remote_commitment\n" "# input amount %s, funding_wscript %s, key %s\n",