Skip to content

Commit 56d1681

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 29f3c66 commit 56d1681

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
@@ -1202,7 +1202,7 @@ static u8 *send_commit_part(const tal_t *ctx,
12021202
struct tlv_commitment_signed_tlvs_splice_info);
12031203

12041204
cs_tlv->splice_info->batch_size = batch_size;
1205-
derive_channel_id(&cs_tlv->splice_info->funding_txid, funding);
1205+
cs_tlv->splice_info->funding_txid = funding->txid;
12061206
}
12071207

12081208
txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map,
@@ -1932,7 +1932,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19321932
const u8 * msg2;
19331933
struct bitcoin_outpoint outpoint;
19341934
struct amount_sat funding_sats;
1935-
struct channel_id active_id;
19361935
const struct commitsig **commitsigs;
19371936
int remote_anchor_outnum;
19381937
struct pubkey funding_pubkeys[NUM_SIDES] =
@@ -1958,16 +1957,16 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19581957
* ...
19591958
* - MUST ignore `commitment_signed` messages where `splice_channel_id`
19601959
* does not match the `channel_id` of the confirmed splice. */
1961-
derive_channel_id(&active_id, &peer->channel->funding);
19621960
if (peer->splice_state->await_commitment_succcess
19631961
&& !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) {
1964-
if (!channel_id_eq(&active_id,
1965-
&cs_tlv->splice_info->funding_txid)) {
1962+
if (!bitcoin_txid_eq(&peer->channel->funding.txid,
1963+
&cs_tlv->splice_info->funding_txid)) {
19661964
status_info("Ignoring stale commit_sig for channel_id"
19671965
" %s, as %s is locked in now.",
1968-
fmt_channel_id(tmpctx,
1969-
&cs_tlv->splice_info->funding_txid),
1970-
fmt_channel_id(tmpctx, &active_id));
1966+
fmt_bitcoin_txid(tmpctx,
1967+
&cs_tlv->splice_info->funding_txid),
1968+
fmt_bitcoin_txid(tmpctx,
1969+
&peer->channel->funding.txid));
19711970
return NULL;
19721971
}
19731972
}
@@ -2069,8 +2068,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20692068
fmt_bitcoin_outpoint(tmpctx, &outpoint),
20702069
fmt_amount_sat(tmpctx, funding_sats),
20712070
cs_tlv && cs_tlv->splice_info
2072-
? fmt_channel_id(tmpctx,
2073-
&cs_tlv->splice_info->funding_txid)
2071+
? fmt_bitcoin_txid(tmpctx,
2072+
&cs_tlv->splice_info->funding_txid)
20742073
: "N/A",
20752074
peer->splice_state->await_commitment_succcess ? "yes"
20762075
: "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)