Skip to content

Commit

Permalink
channeld-df: actually check serial_id of input when setting sigs
Browse files Browse the repository at this point in the history
We're about to totally upset the order that sigs are set on our PSBTs
for new channel opens, making it such that our peer's sigs may arrive
before ours do.

We can no longer rely on the 'set witness means this is our input' since
there's no guarantee that our input sigs have been added yet, so we
check the serial_id and only set the stack on their (odd) inputs.
  • Loading branch information
niftynei authored and rustyrussell committed Oct 20, 2020
1 parent f3bd57a commit d1c7c78
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,9 @@ static void handle_tx_sigs(struct peer *peer, const u8 *msg)
const struct witness_stack **ws;
const struct wally_tx *wtx;
size_t j = 0;
enum tx_role role = peer->channel->opener == REMOTE
? TX_INITIATOR : TX_ACCEPTER;


if (!fromwire_tx_signatures(tmpctx, msg, &cid, &txid,
cast_const3(
Expand Down Expand Up @@ -2047,11 +2050,17 @@ static void handle_tx_sigs(struct peer *peer, const u8 *msg)
for (size_t i = 0; i < peer->psbt->num_inputs; i++) {
struct wally_psbt_input *in =
&peer->psbt->inputs[i];
u16 in_serial;
const struct witness_element **elem;
/* Really we should check serial parity, but we can
* cheat and only check that the final witness
* stack hasn't been set yet */
if (in->final_witness)

if (!psbt_get_serial_id(&in->unknowns, &in_serial)) {
status_broken("PSBT input %zu missing serial_id %s",
i, type_to_string(tmpctx,
struct wally_psbt,
peer->psbt));
return;
}
if (in_serial % 2 != role)
continue;

if (j == tal_count(ws))
Expand Down

0 comments on commit d1c7c78

Please sign in to comment.