dualfund: Pass in expected remote's serial parity

Now that we've got the opener in progress, we need to be able to toggle
which parity to check a remote's serial_ids for
This commit is contained in:
niftynei 2020-09-03 14:12:56 -05:00 committed by Rusty Russell
parent 06c41a0547
commit 3a405c33e6
1 changed files with 11 additions and 9 deletions

View File

@ -231,7 +231,7 @@ static bool is_openers(const struct wally_map *unknowns)
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"PSBTs must have serial_ids set"); "PSBTs must have serial_ids set");
return serial_id % 2 == 0; return serial_id % 2 == TX_INITIATOR;
} }
static size_t psbt_input_weight(struct wally_psbt *psbt, static size_t psbt_input_weight(struct wally_psbt *psbt,
@ -560,7 +560,8 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
} }
} }
static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psbt) static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psbt,
enum tx_role our_role)
{ {
/* Opener always sends the first utxo info */ /* Opener always sends the first utxo info */
bool we_complete = false, they_complete = false; bool we_complete = false, they_complete = false;
@ -576,7 +577,8 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
* they have to re-affirm every time */ * they have to re-affirm every time */
they_complete = false; they_complete = false;
msg = opening_negotiate_msg(tmpctx, state, false); msg = opening_negotiate_msg(tmpctx, state,
our_role == TX_INITIATOR);
if (!msg) if (!msg)
return false; return false;
t = fromwire_peektype(msg); t = fromwire_peektype(msg);
@ -611,7 +613,7 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
* - it receives a `serial_id` from the peer * - it receives a `serial_id` from the peer
* with the incorrect parity * with the incorrect parity
*/ */
if (serial_id % 2 != 0) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", serial_id); "Invalid serial_id rcvd. %u", serial_id);
/* /*
@ -706,7 +708,7 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
* The sending node: * The sending node:
* - MUST NOT send a `tx_remove_input` for an * - MUST NOT send a `tx_remove_input` for an
* input which is not theirs */ * input which is not theirs */
if (serial_id % 2 != 0) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", serial_id); "Invalid serial_id rcvd. %u", serial_id);
@ -739,7 +741,7 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
* ... * ...
* - it receives a `serial_id` from the peer with the * - it receives a `serial_id` from the peer with the
* incorrect parity */ * incorrect parity */
if (serial_id % 2 != 0) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", serial_id); "Invalid serial_id rcvd. %u", serial_id);
@ -765,7 +767,7 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
* The sending node: * The sending node:
* - MUST NOT send a `tx_remove_ouput` for an * - MUST NOT send a `tx_remove_ouput` for an
* input which is not theirs */ * input which is not theirs */
if (serial_id % 2 != 0) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", serial_id); "Invalid serial_id rcvd. %u", serial_id);
@ -1057,7 +1059,7 @@ static u8 *accepter_start(struct state *state, const u8 *oc2_msg)
peer_billboard(false, "channel open: accept sent, waiting for reply"); peer_billboard(false, "channel open: accept sent, waiting for reply");
/* Figure out what the funding transaction looks like! */ /* Figure out what the funding transaction looks like! */
if (!run_tx_interactive(state, &psbt)) if (!run_tx_interactive(state, &psbt, TX_ACCEPTER))
return NULL; return NULL;
/* Find the funding transaction txid */ /* Find the funding transaction txid */
@ -1409,7 +1411,7 @@ static u8 *opener_start(struct state *state, u8 *msg)
"Must have at least one update to send"); "Must have at least one update to send");
/* Figure out what the funding transaction looks like! */ /* Figure out what the funding transaction looks like! */
if (!run_tx_interactive(state, &psbt)) if (!run_tx_interactive(state, &psbt, TX_INITIATOR))
return NULL; return NULL;
/* FIXME! */ /* FIXME! */