Skip to content

Commit 537cfdf

Browse files
committed
splice: Changing encoding of TLV funding_txid
Using the wrong encoding flips the bytes. We have to use sha256 as the spec says to prevent them from flipping.
1 parent 98f6370 commit 537cfdf

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

channeld/channeld.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ static u8 *send_commit_part(const tal_t *ctx,
12011201
struct tlv_commitment_signed_tlvs_splice_info);
12021202

12031203
cs_tlv->splice_info->batch_size = batch_size;
1204-
derive_channel_id(&cs_tlv->splice_info->funding_txid, funding);
1204+
cs_tlv->splice_info->funding_txid = funding->txid;
12051205
}
12061206

12071207
txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map,
@@ -1934,7 +1934,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19341934
const u8 * msg2;
19351935
struct bitcoin_outpoint outpoint;
19361936
struct amount_sat funding_sats;
1937-
struct channel_id active_id;
19381937
const struct commitsig **commitsigs;
19391938
int remote_anchor_outnum;
19401939
struct pubkey funding_pubkeys[NUM_SIDES] =
@@ -1960,16 +1959,16 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19601959
* ...
19611960
* - MUST ignore `commitment_signed` messages where `splice_channel_id`
19621961
* does not match the `channel_id` of the confirmed splice. */
1963-
derive_channel_id(&active_id, &peer->channel->funding);
19641962
if (peer->splice_state->await_commitment_succcess
19651963
&& !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) {
1966-
if (!channel_id_eq(&active_id,
1967-
&cs_tlv->splice_info->funding_txid)) {
1964+
if (!bitcoin_txid_eq(&peer->channel->funding.txid,
1965+
&cs_tlv->splice_info->funding_txid)) {
19681966
status_info("Ignoring stale commit_sig for channel_id"
19691967
" %s, as %s is locked in now.",
1970-
fmt_channel_id(tmpctx,
1971-
&cs_tlv->splice_info->funding_txid),
1972-
fmt_channel_id(tmpctx, &active_id));
1968+
fmt_bitcoin_txid(tmpctx,
1969+
&cs_tlv->splice_info->funding_txid),
1970+
fmt_bitcoin_txid(tmpctx,
1971+
&peer->channel->funding.txid));
19731972
return NULL;
19741973
}
19751974
}
@@ -2071,8 +2070,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20712070
fmt_bitcoin_outpoint(tmpctx, &outpoint),
20722071
fmt_amount_sat(tmpctx, funding_sats),
20732072
cs_tlv && cs_tlv->splice_info
2074-
? fmt_channel_id(tmpctx,
2075-
&cs_tlv->splice_info->funding_txid)
2073+
? fmt_bitcoin_txid(tmpctx,
2074+
&cs_tlv->splice_info->funding_txid)
20762075
: "N/A",
20772076
peer->splice_state->await_commitment_succcess ? "yes"
20782077
: "no",

wire/peer_wire.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ msgdata,commitment_signed,htlc_signature,signature,num_htlcs
301301
msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
302302
tlvtype,commitment_signed_tlvs,splice_info,0
303303
tlvdata,commitment_signed_tlvs,splice_info,batch_size,u16,
304-
tlvdata,commitment_signed_tlvs,splice_info,funding_txid,channel_id,
304+
tlvdata,commitment_signed_tlvs,splice_info,funding_txid,sha256,
305305
msgtype,revoke_and_ack,133
306306
msgdata,revoke_and_ack,channel_id,channel_id,
307307
msgdata,revoke_and_ack,per_commitment_secret,byte,32

wire/test/run-peer-wire.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ static void set_scid(struct short_channel_id *scid)
4040
memset(scid, 2, sizeof(struct short_channel_id));
4141
}
4242

43-
static void set_cid(struct channel_id *cid)
43+
static void set_bitcoin_txid(struct bitcoin_txid *cid)
4444
{
45-
memset(cid, 2, sizeof(struct channel_id));
45+
memset(cid, 2, sizeof(struct bitcoin_txid));
4646
}
4747

4848
/* Size up to field. */
@@ -1028,7 +1028,7 @@ int main(int argc, char *argv[])
10281028
cs.tlvs = tlv_commitment_signed_tlvs_new(tmpctx);
10291029
cs.tlvs->splice_info = tal(ctx, struct tlv_commitment_signed_tlvs_splice_info);
10301030
cs.tlvs->splice_info->batch_size = 1;
1031-
set_cid(&cs.tlvs->splice_info->funding_txid);
1031+
set_bitcoin_txid(&cs.tlvs->splice_info->funding_txid);
10321032

10331033
msg = towire_struct_commitment_signed(ctx, &cs);
10341034
cs2 = fromwire_struct_commitment_signed(ctx, msg);

0 commit comments

Comments
 (0)