From b01145313ebfcd1dbaf71bf603f29966f0389d9f Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Wed, 24 Jan 2024 16:37:23 -0500 Subject: [PATCH] splice: Add support for out-of-bound tx_sig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the peer isn’t required to send signatures first but does while we are awaiting the next user RPC action — we should be caching the message and using it later. Before we would leave the message cached in the socket itself, but tx_abort semantics require us to check the socket more often. --- channeld/channeld.c | 26 ++++++++++++++++++++++---- channeld/splice.c | 1 + channeld/splice.h | 2 ++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 95c3a35cc8ba..1ad0ef110f11 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3363,6 +3363,13 @@ static void resume_splice_negotiation(struct peer *peer, their_pubkey = &peer->channel->funding_pubkey[REMOTE]; if (recv_signature) { + if (peer->splicing && peer->splicing->tx_sig_msg) { + msg_received = tal_steal(tmpctx, + peer->splicing->tx_sig_msg); + peer->splicing->tx_sig_msg = NULL; + status_debug("Splice is using cached tx_sig_msg"); + } + if (fromwire_peektype(msg_received) == WIRE_TX_SIGNATURES) msg = msg_received; else @@ -4229,10 +4236,21 @@ static void peer_in(struct peer *peer, const u8 *msg) /* If we're in STFU mode and aren't waiting for a STFU mode * specific message, the only valid message was tx_abort */ - if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) - peer_failed_warn(peer->pps, &peer->channel_id, - "Received message %s when only TX_ABORT was" - " valid", peer_wire_name(type)); + if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) { + if (peer->splicing && type == WIRE_TX_SIGNATURES) { + if (peer->splicing->tx_sig_msg) + peer_failed_warn(peer->pps, &peer->channel_id, + "Received TX_SIGNATURES while" + " we already have one cached"); + peer->splicing->tx_sig_msg = tal_steal(peer->splicing, + msg); + return; + } else { + peer_failed_warn(peer->pps, &peer->channel_id, + "Received message %s when only TX_ABORT was" + " valid", peer_wire_name(type)); + } + } /* Must get channel_ready before almost anything. */ if (!peer->channel_ready[REMOTE]) { diff --git a/channeld/splice.c b/channeld/splice.c index 473159614f09..ffb3d5877390 100644 --- a/channeld/splice.c +++ b/channeld/splice.c @@ -30,6 +30,7 @@ struct splicing *splicing_new(const tal_t *ctx) splicing->current_psbt = NULL; splicing->received_tx_complete = false; splicing->sent_tx_complete = false; + splicing->tx_sig_msg = NULL; return splicing; } diff --git a/channeld/splice.h b/channeld/splice.h index 267fddbac679..04b62cbb9485 100644 --- a/channeld/splice.h +++ b/channeld/splice.h @@ -51,6 +51,8 @@ struct splicing { bool received_tx_complete; /* If, in the last splice_update, we sent tx_complete */ bool sent_tx_complete; + /* If our peer signs early, we allow that and cache it here */ + const u8 *tx_sig_msg; }; /* Sets `splice` items to default values */