Skip to content

Commit e91b6b7

Browse files
committed
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`
1 parent 366cacb commit e91b6b7

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

channeld/channeld.c

+27-4
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,20 @@ static void check_mutual_splice_locked(struct peer *peer)
444444

445445
if (short_channel_id_eq(peer->short_channel_ids[LOCAL],
446446
peer->splice_state->short_channel_id))
447-
peer_failed_warn(peer->pps, &peer->channel_id,
448-
"Duplicate splice_locked events detected");
447+
peer_failed_err(peer->pps, &peer->channel_id,
448+
"Duplicate splice_locked events detected"
449+
" by scid check");
450+
451+
if (!peer->splice_state->remote_locked_txid
452+
|| !bitcoin_txid_eq(peer->splice_state->remote_locked_txid,
453+
&peer->splice_state->locked_txid))
454+
peer_failed_err(peer->pps, &peer->channel_id,
455+
"splice_locked message txid %s does not match"
456+
" our locked txid %s",
457+
fmt_bitcoin_txid(tmpctx,
458+
peer->splice_state->remote_locked_txid),
459+
fmt_bitcoin_txid(tmpctx,
460+
&peer->splice_state->locked_txid));
449461

450462
peer->splice_state->await_commitment_succcess = true;
451463

@@ -473,7 +485,7 @@ static void check_mutual_splice_locked(struct peer *peer)
473485
inflight = peer->splice_state->inflights[i];
474486

475487
if (!inflight)
476-
peer_failed_warn(peer->pps, &peer->channel_id,
488+
peer_failed_err(peer->pps, &peer->channel_id,
477489
"Unable to find inflight txid amoung %zu"
478490
" inflights. new funding txid: %s",
479491
tal_count(peer->splice_state->inflights),
@@ -487,7 +499,7 @@ static void check_mutual_splice_locked(struct peer *peer)
487499
inflight->amnt,
488500
inflight->splice_amnt);
489501
if (error)
490-
peer_failed_warn(peer->pps, &peer->channel_id,
502+
peer_failed_err(peer->pps, &peer->channel_id,
491503
"Splice lock unable to update funding. %s",
492504
error);
493505

@@ -508,6 +520,7 @@ static void check_mutual_splice_locked(struct peer *peer)
508520

509521
peer->splice_state->inflights = tal_free(peer->splice_state->inflights);
510522
peer->splice_state->count = 0;
523+
peer->splice_state->remote_locked_txid = tal_free(peer->splice_state->remote_locked_txid);
511524
}
512525

513526
/* Our peer told us they saw our splice confirm on chain with `splice_locked`.
@@ -522,6 +535,16 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
522535
peer_failed_warn(peer->pps, &peer->channel_id,
523536
"Bad splice_locked %s", tal_hex(msg, msg));
524537

538+
if (peer->splice_state->remote_locked_txid)
539+
peer_failed_err(peer->pps, &chanid,
540+
"Peer sent duplicate splice_locked message %s",
541+
tal_hex(tmpctx, msg));
542+
543+
peer->splice_state->remote_locked_txid = tal(peer->splice_state,
544+
struct bitcoin_txid);
545+
546+
*peer->splice_state->remote_locked_txid = splice_txid;
547+
525548
if (!channel_id_eq(&chanid, &peer->channel_id))
526549
peer_failed_err(peer->pps, &chanid,
527550
"Wrong splice lock channel id in %s "

channeld/splice.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct splice_state *splice_state_new(const tal_t *ctx)
1111
splice_state->locked_ready[REMOTE] = false;
1212
splice_state->await_commitment_succcess = false;
1313
splice_state->inflights = NULL;
14+
splice_state->remote_locked_txid = NULL;
1415

1516
return splice_state;
1617
}

channeld/splice.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct splice_state {
2121
bool await_commitment_succcess;
2222
/* The txid of which splice inflight was confirmed */
2323
struct bitcoin_txid locked_txid;
24+
/* The txid our peer locked their splice on */
25+
struct bitcoin_txid *remote_locked_txid;
2426
/* The number of splices that are active (awaiting confirmation) */
2527
u32 count;
2628
};

0 commit comments

Comments
 (0)