splice: Add check for correct txid in splice_locked

Check that the peer sent the correct txid in their `splice_locked` message.

We have to check this later on in `check_mutal_splice_locked` so we store the value in `splice_state`
This commit is contained in:
Dusty Daemon
2025-02-04 15:23:31 -05:00
committed by Rusty Russell
parent 940b6a3af2
commit 721f36831e
3 changed files with 32 additions and 4 deletions

View File

@@ -444,8 +444,22 @@ static void check_mutual_splice_locked(struct peer *peer)
if (short_channel_id_eq(peer->short_channel_ids[LOCAL],
peer->splice_state->short_channel_id))
peer_failed_warn(peer->pps, &peer->channel_id,
"Duplicate splice_locked events detected");
peer_failed_err(peer->pps, &peer->channel_id,
"Duplicate splice_locked events detected"
" by scid check");
if (!peer->splice_state->remote_locked_txid
|| !bitcoin_txid_eq(peer->splice_state->remote_locked_txid,
&peer->splice_state->locked_txid))
peer_failed_err(peer->pps, &peer->channel_id,
"splice_locked message txid %s does not match"
" our locked txid %s",
peer->splice_state->remote_locked_txid
? fmt_bitcoin_txid(tmpctx,
peer->splice_state->remote_locked_txid)
: "NULL",
fmt_bitcoin_txid(tmpctx,
&peer->splice_state->locked_txid));
peer->splice_state->await_commitment_succcess = true;
@@ -473,7 +487,7 @@ static void check_mutual_splice_locked(struct peer *peer)
inflight = peer->splice_state->inflights[i];
if (!inflight)
peer_failed_warn(peer->pps, &peer->channel_id,
peer_failed_err(peer->pps, &peer->channel_id,
"Unable to find inflight txid amoung %zu"
" inflights. new funding txid: %s",
tal_count(peer->splice_state->inflights),
@@ -487,7 +501,7 @@ static void check_mutual_splice_locked(struct peer *peer)
inflight->amnt,
inflight->splice_amnt);
if (error)
peer_failed_warn(peer->pps, &peer->channel_id,
peer_failed_err(peer->pps, &peer->channel_id,
"Splice lock unable to update funding. %s",
error);
@@ -508,6 +522,7 @@ static void check_mutual_splice_locked(struct peer *peer)
peer->splice_state->inflights = tal_free(peer->splice_state->inflights);
peer->splice_state->count = 0;
peer->splice_state->remote_locked_txid = tal_free(peer->splice_state->remote_locked_txid);
}
/* Our peer told us they saw our splice confirm on chain with `splice_locked`.
@@ -522,6 +537,16 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad splice_locked %s", tal_hex(msg, msg));
if (peer->splice_state->remote_locked_txid)
peer_failed_err(peer->pps, &chanid,
"Peer sent duplicate splice_locked message %s",
tal_hex(tmpctx, msg));
peer->splice_state->remote_locked_txid = tal(peer->splice_state,
struct bitcoin_txid);
*peer->splice_state->remote_locked_txid = splice_txid;
if (!channel_id_eq(&chanid, &peer->channel_id))
peer_failed_err(peer->pps, &chanid,
"Wrong splice lock channel id in %s "

View File

@@ -11,6 +11,7 @@ struct splice_state *splice_state_new(const tal_t *ctx)
splice_state->locked_ready[REMOTE] = false;
splice_state->await_commitment_succcess = false;
splice_state->inflights = NULL;
splice_state->remote_locked_txid = NULL;
return splice_state;
}

View File

@@ -21,6 +21,8 @@ struct splice_state {
bool await_commitment_succcess;
/* The txid of which splice inflight was confirmed */
struct bitcoin_txid locked_txid;
/* The txid our peer locked their splice on */
struct bitcoin_txid *remote_locked_txid;
/* The number of splices that are active (awaiting confirmation) */
u32 count;
};