Skip to content

Commit 52bd2db

Browse files
committed
splice: Sign shared output early
When doing a multi channel splice, we need to break the deadlock by signing the shared output early (even though it is not sent to the peer until later).
1 parent c6fc74f commit 52bd2db

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

channeld/channeld.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,6 +4315,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
43154315
u8 *outmsg;
43164316
struct interactivetx_context *ictx;
43174317
struct bitcoin_tx *prev_tx;
4318+
struct bitcoin_tx *bitcoin_tx;
4319+
struct bitcoin_signature splice_sig;
43184320
bool sign_first;
43194321
char *error;
43204322
u32 chan_output_index, splice_funding_index;
@@ -4326,6 +4328,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
43264328
struct amount_msat current_push_val;
43274329
const enum tx_role our_role = TX_INITIATOR;
43284330
u8 *abort_msg;
4331+
const u8* msg;
43294332

43304333
/* We must loading the funding tx as our previous utxo */
43314334
prev_tx = bitcoin_tx_from_txid(peer, peer->channel->funding.txid);
@@ -4374,6 +4377,44 @@ static void splice_initiator_user_finalized(struct peer *peer)
43744377

43754378
psbt_elements_normalize_fees(ictx->current_psbt);
43764379

4380+
/* We have to sign the shared output early (here) for cases where we are
4381+
* splicing between multiple channels simultaneously. This is so the
4382+
* we can build a complete `tx_signatures` message when there are two
4383+
* or more shared outputs between mulitple peers */
4384+
4385+
splice_sig.sighash_type = SIGHASH_ALL;
4386+
4387+
bitcoin_tx = bitcoin_tx_with_psbt(tmpctx, ictx->current_psbt);
4388+
4389+
status_info("Splice pre-signing tx: %s",
4390+
tal_hex(tmpctx, linearize_tx(tmpctx, bitcoin_tx)));
4391+
4392+
msg = towire_hsmd_sign_splice_tx(tmpctx, bitcoin_tx,
4393+
&peer->channel->funding_pubkey[REMOTE],
4394+
splice_funding_index);
4395+
4396+
msg = hsm_req(tmpctx, take(msg));
4397+
if (!fromwire_hsmd_sign_tx_reply(msg, &splice_sig))
4398+
status_failed(STATUS_FAIL_HSM_IO,
4399+
"Reading sign_splice_tx reply: %s",
4400+
tal_hex(tmpctx, msg));
4401+
4402+
/* Set the splice_sig on the splice funding tx psbt */
4403+
if (!psbt_input_set_signature(ictx->current_psbt, splice_funding_index,
4404+
&peer->channel->funding_pubkey[LOCAL],
4405+
&splice_sig))
4406+
status_failed(STATUS_FAIL_INTERNAL_ERROR,
4407+
"Unable to pre-set signature internally "
4408+
"funding_index: %d "
4409+
"my pubkey: %s "
4410+
"my signature: %s "
4411+
"psbt: %s",
4412+
splice_funding_index,
4413+
fmt_pubkey(tmpctx,
4414+
&peer->channel->funding_pubkey[LOCAL]),
4415+
fmt_bitcoin_signature(tmpctx, &splice_sig),
4416+
fmt_wally_psbt(tmpctx, ictx->current_psbt));
4417+
43774418
status_debug("Splice adding inflight: %s",
43784419
fmt_wally_psbt(tmpctx, ictx->current_psbt));
43794420

0 commit comments

Comments
 (0)