From 891f61ad4874d4e2c92abd4c82eb9b3454e9aa4c Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 27 May 2020 18:09:39 -0500 Subject: [PATCH] channel_tx: add the commitment sig and pubkey data to the commit tx needs to be update elsewhere too! --- channeld/channeld.c | 5 +++++ channeld/full_channel.c | 7 ++++++ common/initial_channel.c | 46 ++++++++++++++++++++++++---------------- openingd/openingd.c | 7 ++++++ 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index d1470ea14..99aba4523 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -12,6 +12,7 @@ */ #include #include +#include #include #include #include @@ -1289,6 +1290,10 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg) &funding_wscript, peer->channel, &peer->next_local_per_commit, peer->next_index[LOCAL], LOCAL); + /* Set the commit_sig on the commitment tx psbt */ + psbt_input_set_partial_sig(txs[0]->psbt, 0, + &peer->channel->funding_pubkey[REMOTE], &commit_sig); + if (!derive_simple_key(&peer->channel->basepoints[REMOTE].htlc, &peer->next_local_per_commit, &remote_htlckey)) status_failed(STATUS_FAIL_INTERNAL_ERROR, diff --git a/channeld/full_channel.c b/channeld/full_channel.c index f67ea35b2..38fd1602b 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,12 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, commitment_number ^ channel->commitment_number_obscurer, side); + /* Set the remote/local pubkeys on the commitment tx psbt */ + psbt_input_add_pubkey(txs[0]->psbt, 0, + &channel->funding_pubkey[side]); + psbt_input_add_pubkey(txs[0]->psbt, 0, + &channel->funding_pubkey[!side]); + add_htlcs(&txs, *htlcmap, channel, &keyset, side); tal_free(committed); diff --git a/common/initial_channel.c b/common/initial_channel.c index be0426670..2508969a5 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -76,6 +77,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, char** err_reason) { struct keyset keyset; + struct bitcoin_tx *init_tx; /* This assumes no HTLCs! */ assert(!channel->htlcs); @@ -93,24 +95,32 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, &channel->funding_pubkey[side], &channel->funding_pubkey[!side]); - return initial_commit_tx(ctx, - &channel->funding_txid, - channel->funding_txout, - channel->funding, - cast_const(u8 *, *wscript), - channel->opener, - /* They specify our to_self_delay and v.v. */ - channel->config[!side].to_self_delay, - &keyset, - channel_feerate(channel, side), - channel->config[side].dust_limit, - channel->view[side].owed[side], - channel->view[side].owed[!side], - channel->config[!side].channel_reserve, - 0 ^ channel->commitment_number_obscurer, - direct_outputs, - side, - err_reason); + init_tx = initial_commit_tx(ctx, &channel->funding_txid, + channel->funding_txout, + channel->funding, + cast_const(u8 *, *wscript), + channel->opener, + /* They specify our to_self_delay and v.v. */ + channel->config[!side].to_self_delay, + &keyset, + channel_feerate(channel, side), + channel->config[side].dust_limit, + channel->view[side].owed[side], + channel->view[side].owed[!side], + channel->config[!side].channel_reserve, + 0 ^ channel->commitment_number_obscurer, + direct_outputs, + side, + err_reason); + + if (init_tx) { + psbt_input_add_pubkey(init_tx->psbt, 0, + &channel->funding_pubkey[side]); + psbt_input_add_pubkey(init_tx->psbt, 0, + &channel->funding_pubkey[!side]); + } + + return init_tx; } u32 channel_feerate(const struct channel *channel, enum side side) diff --git a/openingd/openingd.c b/openingd/openingd.c index 739171892..b72be7cda 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -844,6 +845,12 @@ static bool funder_finalize_channel_setup(struct state *state, &state->their_funding_pubkey)); } + /* We save their sig to our first commitment tx */ + psbt_input_set_partial_sig((*tx)->psbt, 0, + &state->their_funding_pubkey, + sig); + + peer_billboard(false, "Funding channel: opening negotiation succeeded"); return true;