diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 474384c1d..2e919a10b 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -1916,6 +1916,27 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) handle_send_tx_sigs(state, msg); } +static void add_funding_output(struct tx_state *tx_state, + struct state *state, + struct amount_sat total) +{ + const u8 *wscript; + struct wally_psbt_output *funding_out; + + wscript = bitcoin_redeem_2of2(tmpctx, &state->our_funding_pubkey, + &state->their_funding_pubkey); + funding_out = psbt_append_output(tx_state->psbt, + scriptpubkey_p2wsh(tmpctx, wscript), + total); + + /* Add a serial_id for this output */ + tx_state->funding_serial = psbt_new_input_serial(tx_state->psbt, + TX_INITIATOR); + psbt_output_set_serial_id(tx_state->psbt, + funding_out, + tx_state->funding_serial); +} + static void opener_start(struct state *state, u8 *msg) { struct tlv_opening_tlvs *open_tlv; @@ -1924,7 +1945,6 @@ static void opener_start(struct state *state, u8 *msg) char *err_reason; struct amount_sat total; struct amount_msat our_msats; - struct wally_psbt_output *funding_out; struct sha256 podle; struct wally_tx_output *direct_outputs[NUM_SIDES]; struct penalty_base *pbase; @@ -2121,21 +2141,7 @@ static void opener_start(struct state *state, u8 *msg) * - MUST send at least one `tx_add_output`, the channel * funding output. */ - /* If fails before returning from `send_next`, this will - * be marked as a memleak */ - wscript = notleak(bitcoin_redeem_2of2(state, - &state->our_funding_pubkey, - &state->their_funding_pubkey)); - funding_out = psbt_append_output(tx_state->psbt, - scriptpubkey_p2wsh(tmpctx, - wscript), - total); - /* Add a serial_id for this output */ - tx_state->funding_serial = psbt_new_input_serial(tx_state->psbt, - TX_INITIATOR); - psbt_output_set_serial_id(tx_state->psbt, - funding_out, - tx_state->funding_serial); + add_funding_output(tx_state, state, total); /* Add all of our inputs/outputs to the changeset */ init_changeset(tx_state, tx_state->psbt);