Browse Source

channel_tx: add the commitment sig and pubkey data to the commit tx

needs to be update elsewhere too!
nifty/pset-pre
niftynei 5 years ago
committed by Christian Decker
parent
commit
891f61ad48
  1. 5
      channeld/channeld.c
  2. 7
      channeld/full_channel.c
  3. 14
      common/initial_channel.c
  4. 7
      openingd/openingd.c

5
channeld/channeld.c

@ -12,6 +12,7 @@
*/ */
#include <bitcoin/chainparams.h> #include <bitcoin/chainparams.h>
#include <bitcoin/privkey.h> #include <bitcoin/privkey.h>
#include <bitcoin/psbt.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
@ -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, &funding_wscript, peer->channel, &peer->next_local_per_commit,
peer->next_index[LOCAL], LOCAL); 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, if (!derive_simple_key(&peer->channel->basepoints[REMOTE].htlc,
&peer->next_local_per_commit, &remote_htlckey)) &peer->next_local_per_commit, &remote_htlckey))
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,

7
channeld/full_channel.c

@ -1,6 +1,7 @@
#include <assert.h> #include <assert.h>
#include <bitcoin/chainparams.h> #include <bitcoin/chainparams.h>
#include <bitcoin/preimage.h> #include <bitcoin/preimage.h>
#include <bitcoin/psbt.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <bitcoin/tx.h> #include <bitcoin/tx.h>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
@ -311,6 +312,12 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
commitment_number ^ channel->commitment_number_obscurer, commitment_number ^ channel->commitment_number_obscurer,
side); 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); add_htlcs(&txs, *htlcmap, channel, &keyset, side);
tal_free(committed); tal_free(committed);

14
common/initial_channel.c

@ -1,5 +1,6 @@
#include <assert.h> #include <assert.h>
#include <bitcoin/chainparams.h> #include <bitcoin/chainparams.h>
#include <bitcoin/psbt.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
@ -76,6 +77,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
char** err_reason) char** err_reason)
{ {
struct keyset keyset; struct keyset keyset;
struct bitcoin_tx *init_tx;
/* This assumes no HTLCs! */ /* This assumes no HTLCs! */
assert(!channel->htlcs); assert(!channel->htlcs);
@ -93,8 +95,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
&channel->funding_pubkey[side], &channel->funding_pubkey[side],
&channel->funding_pubkey[!side]); &channel->funding_pubkey[!side]);
return initial_commit_tx(ctx, init_tx = initial_commit_tx(ctx, &channel->funding_txid,
&channel->funding_txid,
channel->funding_txout, channel->funding_txout,
channel->funding, channel->funding,
cast_const(u8 *, *wscript), cast_const(u8 *, *wscript),
@ -111,6 +112,15 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
direct_outputs, direct_outputs,
side, side,
err_reason); 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) u32 channel_feerate(const struct channel *channel, enum side side)

7
openingd/openingd.c

@ -10,6 +10,7 @@
#include <bitcoin/block.h> #include <bitcoin/block.h>
#include <bitcoin/chainparams.h> #include <bitcoin/chainparams.h>
#include <bitcoin/privkey.h> #include <bitcoin/privkey.h>
#include <bitcoin/psbt.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/breakpoint/breakpoint.h> #include <ccan/breakpoint/breakpoint.h>
@ -844,6 +845,12 @@ static bool funder_finalize_channel_setup(struct state *state,
&state->their_funding_pubkey)); &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"); peer_billboard(false, "Funding channel: opening negotiation succeeded");
return true; return true;

Loading…
Cancel
Save