Skip to content

Commit

Permalink
dual_open: correct silent enum conversions
Browse files Browse the repository at this point in the history
We were silently converting a side enum (3 variants) to a tx_role enum
(2 variants).

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
  • Loading branch information
darosior authored and niftynei committed Oct 27, 2020
1 parent 01dfd8a commit aec52a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,16 @@ static enum tx_role their_tx_role(const struct peer *peer)
}

static const u8 *psbt_to_tx_sigs_msg(const tal_t *ctx,
struct channel *channel,
const struct peer *peer,
const struct wally_psbt *psbt)
{
const struct witness_stack **ws =
psbt_to_witness_stacks(tmpctx, psbt,
channel->opener);
const struct witness_stack **ws;

ws = psbt_to_witness_stacks(tmpctx, psbt,
our_tx_role(peer));

return towire_tx_signatures(ctx, &channel->cid,
&channel->funding_txid,
return towire_tx_signatures(ctx, &peer->channel->cid,
&peer->channel->funding_txid,
ws);
}
#endif /* EXPERIMENTAL_FEATURES */
Expand Down Expand Up @@ -2051,8 +2052,7 @@ static void handle_send_tx_sigs(struct peer *peer, const u8 *msg)
tal_wally_end(tal_steal(peer, peer->psbt));
#if EXPERIMENTAL_FEATURES
sync_crypto_write(peer->pps,
take(psbt_to_tx_sigs_msg(NULL, peer->channel,
psbt)));
take(psbt_to_tx_sigs_msg(NULL, peer, psbt)));
#endif /* EXPERIMENTAL_FEATURES */
}

Expand Down Expand Up @@ -2803,8 +2803,7 @@ static void peer_reconnect(struct peer *peer,
our_tx_role(peer))
&& !peer->funding_locked[REMOTE])
sync_crypto_write(peer->pps,
take(psbt_to_tx_sigs_msg(NULL, peer->channel,
peer->psbt)));
take(psbt_to_tx_sigs_msg(NULL, peer, peer->psbt)));
#endif /* EXPERIMENTAL_FEATURES */

/* BOLT #2:
Expand Down Expand Up @@ -3605,8 +3604,7 @@ static void init_channel(struct peer *peer)
if (!reconnected && peer->psbt &&
psbt_side_finalized(peer->psbt, our_tx_role(peer)))
sync_crypto_write(peer->pps,
take(psbt_to_tx_sigs_msg(NULL, peer->channel,
peer->psbt)));
take(psbt_to_tx_sigs_msg(NULL, peer, peer->psbt)));
#endif /* EXPERIMENTAL_FEATURES */

/* Reenable channel */
Expand Down
2 changes: 1 addition & 1 deletion lightningd/dual_open_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ openchannel2_changed_deserialize(struct openchannel2_psbt_payload *payload,
return false;

/* Add serials to PSBT, before checking for required fields */
psbt_add_serials(psbt, REMOTE);
psbt_add_serials(psbt, TX_ACCEPTER);

if (!psbt_has_required_fields(psbt))
fatal("Plugin supplied PSBT that's missing required fields. %s",
Expand Down

0 comments on commit aec52a2

Please sign in to comment.