From 79bf18b4704e4e493f2c45896d10cffebbe59f28 Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Tue, 21 Jan 2025 10:32:07 -0500 Subject: [PATCH 1/3] Splice: Rotating funding pubkey fix Interop testing with Eclair revealed an issue with remote funding key rotation. This searches for the funding output using the rotated remote funding pubkey instead of the furrent funding pubkey. Also update the variable name to be more clear which this represents. Changelog-Changed: Interop fixes for compatability with Eclair --- channeld/channeld.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index c00081a78e0e..f7f81d44dbdf 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3306,7 +3306,7 @@ static void resume_splice_negotiation(struct peer *peer, struct bitcoin_tx *bitcoin_tx; u32 splice_funding_index; const u8 *msg, *sigmsg; - u32 chan_output_index; + u32 new_output_index; struct pubkey *their_pubkey; struct bitcoin_tx *final_tx; struct bitcoin_txid final_txid; @@ -3337,8 +3337,8 @@ static void resume_splice_negotiation(struct peer *peer, &peer->channel->funding_pubkey[LOCAL], &peer->channel->funding_pubkey[REMOTE]); - find_channel_output(peer, current_psbt, &chan_output_index, - &peer->channel->funding_pubkey[REMOTE]); + find_channel_output(peer, current_psbt, &new_output_index, + &inflight->remote_funding); splice_funding_index = find_channel_funding_input(current_psbt, &peer->channel->funding); @@ -3622,7 +3622,7 @@ static void resume_splice_negotiation(struct peer *peer, final_tx = bitcoin_tx_with_psbt(tmpctx, current_psbt); msg = towire_channeld_splice_confirmed_signed(tmpctx, final_tx, - chan_output_index); + new_output_index); wire_sync_write(MASTER_FD, take(msg)); } } From 1d98b891ab38db10f25ad3687bcdef3d24280dcb Mon Sep 17 00:00:00 2001 From: Richard Myers Date: Wed, 22 Jan 2025 15:42:39 +0100 Subject: [PATCH 2/3] Fixed splice_locked messgae to include splice_txid field --- channeld/channeld.c | 11 ++++++----- wire/peer_wire.csv | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index f7f81d44dbdf..61d8272bb630 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -511,13 +511,14 @@ static void check_mutual_splice_locked(struct peer *peer) } /* Our peer told us they saw our splice confirm on chain with `splice_locked`. - * If we see it to we jump into tansitioning to post-splice, otherwise we mark + * If we see it to we jump into transitioning to post-splice, otherwise we mark * a flag and wait until we see it on chain too. */ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg) { struct channel_id chanid; + struct bitcoin_txid splice_txid; - if (!fromwire_splice_locked(msg, &chanid)) + if (!fromwire_splice_locked(msg, &chanid, &splice_txid)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad splice_locked %s", tal_hex(msg, msg)); @@ -5214,7 +5215,7 @@ static void peer_reconnect(struct peer *peer, status_info("We have no pending splice but peer" " expects one; resending splice_lock"); peer_write(peer->pps, - take(towire_splice_locked(NULL, &peer->channel_id))); + take(towire_splice_locked(NULL, &peer->channel_id, &peer->channel->funding.txid))); } else { splice_abort(peer, "next_funding_txid not recognized." @@ -5593,10 +5594,10 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg) } else if(splicing && !peer->splice_state->locked_ready[LOCAL]) { assert(scid); - msg = towire_splice_locked(NULL, &peer->channel_id); - peer->splice_state->locked_txid = txid; + msg = towire_splice_locked(NULL, &peer->channel_id, &peer->splice_state->locked_txid); + peer_write(peer->pps, take(msg)); peer->splice_state->locked_ready[LOCAL] = true; diff --git a/wire/peer_wire.csv b/wire/peer_wire.csv index c36d90807b08..183a2c143cc4 100644 --- a/wire/peer_wire.csv +++ b/wire/peer_wire.csv @@ -223,6 +223,7 @@ msgdata,splice_ack,relative_satoshis,s64, msgdata,splice_ack,funding_pubkey,point, msgtype,splice_locked,77, msgdata,splice_locked,channel_id,channel_id, +msgdata,splice_locked,splice_txid,sha256, msgtype,shutdown,38 msgdata,shutdown,channel_id,channel_id, msgdata,shutdown,len,u16, From dc3ae192d0e9fcea373ce1420246edd9e762defe Mon Sep 17 00:00:00 2001 From: Richard Myers Date: Mon, 27 Jan 2025 14:39:36 +0100 Subject: [PATCH 3/3] Add debug outputs and fix prevtx issue --- channeld/channeld.c | 6 ++++++ common/interactivetx.c | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 61d8272bb630..c9ed41d7b2b3 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3945,6 +3945,7 @@ static void splice_initiator(struct peer *peer, const u8 *inmsg) ictx->shared_outpoint = tal(ictx, struct bitcoin_outpoint); *ictx->shared_outpoint = peer->channel->funding; ictx->funding_tx = prev_tx; + status_info("splice_initiator ictx->shared_outpoint = %s",(ictx->shared_outpoint?"defined":"null")); peer->splicing->tx_add_input_count = 0; peer->splicing->tx_add_output_count = 0; @@ -3996,6 +3997,7 @@ static void splice_initiator_user_finalized(struct peer *peer) ictx->shared_outpoint = tal(ictx, struct bitcoin_outpoint); *ictx->shared_outpoint = peer->channel->funding; + status_info("splice_initiator_user_finalized: ictx->shared_outpoint = %s",(ictx->shared_outpoint?"defined":"null")); ictx->funding_tx = prev_tx; error = process_interactivetx_updates(tmpctx, ictx, @@ -4144,6 +4146,10 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg) ictx->tx_add_input_count = peer->splicing->tx_add_input_count; ictx->tx_add_output_count = peer->splicing->tx_add_output_count; + ictx->shared_outpoint = tal(ictx, struct bitcoin_outpoint); + *ictx->shared_outpoint = peer->channel->funding; + ictx->funding_tx = bitcoin_tx_from_txid(peer, peer->channel->funding.txid); + /* If there no are no changes, we consider the splice user finalized */ if (!interactivetx_has_changes(ictx, ictx->desired_psbt)) { splice_initiator_user_finalized(peer); diff --git a/common/interactivetx.c b/common/interactivetx.c index a9163a7dcf1c..ef8763e8e3a0 100644 --- a/common/interactivetx.c +++ b/common/interactivetx.c @@ -227,12 +227,22 @@ static char *send_next(const tal_t *ctx, /* If this the shared channel input, we send funding txid in * in tlvs and do not send prevtx */ + status_info("ictx->shared_outpoint = %s",(ictx->shared_outpoint?"defined":"null")); + char txid_hex[65]; + if (ictx->shared_outpoint && bitcoin_txid_to_hex(&(ictx->shared_outpoint->txid), txid_hex, sizeof(txid_hex))) { + status_info("ictx->shared_outpoint->txid=%s, ictx->shared_outpoint->n=%d", txid_hex, ictx->shared_outpoint->n); + } + if (bitcoin_txid_to_hex(&(point.txid), txid_hex, sizeof(txid_hex))) { + status_info("point.txid=%s, point.n=%d", txid_hex, point.n); + } + status_info("here2"); if (ictx->shared_outpoint && bitcoin_outpoint_eq(&point, ictx->shared_outpoint)) { - struct tlv_tx_add_input_tlvs *tlvs = tal(tmpctx, struct tlv_tx_add_input_tlvs); + struct tlv_tx_add_input_tlvs *tlvs = tlv_tx_add_input_tlvs_new(tmpctx); tlvs->shared_input_txid = tal_dup(tlvs, struct bitcoin_txid, &point.txid); + status_info("Adding shared input %s", tal_hexstr(ctx, &serial_id, sizeof(serial_id))); msg = towire_tx_add_input(NULL, cid, serial_id, NULL, in->input.index, in->input.sequence, tlvs); @@ -240,6 +250,7 @@ static char *send_next(const tal_t *ctx, msg = towire_tx_add_input(NULL, cid, serial_id, prevtx, in->input.index, in->input.sequence, NULL); + status_info("Adding splice input %s", tal_hexstr(ctx, &serial_id, sizeof(serial_id))); } tal_arr_remove(&set->added_ins, 0);