Skip to content

Commit 8de1741

Browse files
committed
channeld: detect splice on reestablish via funding_tx_index, not txid
is_splice_active compared the peer's my_current_funding_locked txid against peer->channel->funding.txid, which is wrong: once a splice locks, funding.txid becomes the splice txid, both sides agree on it, the check falls through, and channel_ready is incorrectly retransmitted on reconnect. Resolve the txid to its funding_tx_index (the current channel funding or a pending splice inflight) and treat > 0 as a splice. Changelog-Fixed: channeld: correctly detect splice transactions when deciding whether to retransmit `channel_ready` on reconnect.
1 parent 03a3d78 commit 8de1741

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

channeld/channeld.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,6 +5645,23 @@ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg)
56455645
return true;
56465646
}
56475647

5648+
/* Returns the funding_tx_index of the funding tx with this txid: the current
5649+
* channel funding, or a pending splice inflight. Returns 0 (the original
5650+
* funding) if unknown.
5651+
*/
5652+
static u32 funding_tx_index_for_txid(const struct peer *peer,
5653+
const struct bitcoin_txid *txid)
5654+
{
5655+
if (bitcoin_txid_eq(txid, &peer->channel->funding.txid))
5656+
return peer->channel->funding_tx_index;
5657+
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5658+
const struct inflight *inf = peer->splice_state->inflights[i];
5659+
if (bitcoin_txid_eq(txid, &inf->outpoint.txid))
5660+
return inf->funding_tx_index;
5661+
}
5662+
return 0;
5663+
}
5664+
56485665
static void peer_reconnect(struct peer *peer,
56495666
const struct secret *last_remote_per_commit_secret)
56505667
{
@@ -5967,17 +5984,6 @@ static void peer_reconnect(struct peer *peer,
59675984
"next_funding_txid not recognized.");
59685985
}
59695986

5970-
/* "none of those channel_reestablish messages contain
5971-
* my_current_funding_locked or next_funding for a splice transaction" */
5972-
bool is_splice_active = local_next_funding
5973-
|| peer->splice_state->locked_ready[LOCAL]
5974-
|| remote_next_funding
5975-
|| (recv_tlvs
5976-
&& recv_tlvs->my_current_funding_locked
5977-
&& !bitcoin_txid_eq(
5978-
&recv_tlvs->my_current_funding_locked->my_current_funding_locked_txid,
5979-
&peer->channel->funding.txid));
5980-
59815987
/* BOLT #2:
59825988
*
59835989
* A node:
@@ -5996,7 +6002,17 @@ static void peer_reconnect(struct peer *peer,
59966002
if (peer->channel_ready[LOCAL]
59976003
&& peer->next_index[LOCAL] == 1
59986004
&& next_commitment_number == 1
5999-
&& !is_splice_active) {
6005+
/* "none of those channel_reestablish messages contain
6006+
* my_current_funding_locked or next_funding for a splice
6007+
* transaction": a funding_tx_index of 1 or more means the txid came
6008+
* from a splice (0 is the original funding). */
6009+
&& !local_next_funding
6010+
&& !peer->splice_state->locked_ready[LOCAL]
6011+
&& !remote_next_funding
6012+
&& !(recv_tlvs
6013+
&& recv_tlvs->my_current_funding_locked
6014+
&& funding_tx_index_for_txid(peer,
6015+
&recv_tlvs->my_current_funding_locked->my_current_funding_locked_txid) > 0)) {
60006016
struct tlv_channel_ready_tlvs *tlvs = tlv_channel_ready_tlvs_new(tmpctx);
60016017

60026018
tlvs->short_channel_id = &peer->local_alias;

tests/test_splicing_disconnect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def test_splice_disconnect_sig(node_factory, bitcoind):
6969
@pytest.mark.openchannel('v1')
7070
@pytest.mark.openchannel('v2')
7171
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
72-
@pytest.mark.xfail(strict=True, reason="channel_ready wrongly retransmitted after splice until funding_tx_index detection")
7372
def test_splice_reconnect_after_lock_no_channel_ready(node_factory, bitcoind):
7473
# Once a splice locks, channel funding txid is updated to the splice txid.
7574
# On reconnect we must still recognise the peer's `my_current_funding_locked`

0 commit comments

Comments
 (0)