Skip to content

Commit

Permalink
splice: Add check for correct txid in splice_locked
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
ddustin committed Feb 4, 2025
1 parent b385150 commit e117ec4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
31 changes: 27 additions & 4 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,20 @@ 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",
fmt_bitcoin_txid(tmpctx,
peer->splice_state->remote_locked_txid),
fmt_bitcoin_txid(tmpctx,
&peer->splice_state->locked_txid));

peer->splice_state->await_commitment_succcess = true;

Expand Down Expand Up @@ -473,7 +485,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),
Expand All @@ -487,7 +499,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);

Expand All @@ -508,6 +520,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`.
Expand All @@ -522,6 +535,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 "
Expand Down
1 change: 1 addition & 0 deletions channeld/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions channeld/splice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit e117ec4

Please sign in to comment.