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.
This commit is contained in:
Dusty Daemon 2025-05-05 15:46:50 -04:00 committed by Rusty Russell
parent 9a3c3c0a3e
commit 4466286167
3 changed files with 13 additions and 14 deletions

View File

@ -1201,7 +1201,7 @@ static u8 *send_commit_part(const tal_t *ctx,
struct tlv_commitment_signed_tlvs_splice_info);
cs_tlv->splice_info->batch_size = batch_size;
derive_channel_id(&cs_tlv->splice_info->funding_txid, funding);
cs_tlv->splice_info->funding_txid = funding->txid;
}
txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map,
@ -1934,7 +1934,6 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
const u8 * msg2;
struct bitcoin_outpoint outpoint;
struct amount_sat funding_sats;
struct channel_id active_id;
const struct commitsig **commitsigs;
int remote_anchor_outnum;
struct pubkey funding_pubkeys[NUM_SIDES] =
@ -1960,16 +1959,16 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
* ...
* - MUST ignore `commitment_signed` messages where `splice_channel_id`
* does not match the `channel_id` of the confirmed splice. */
derive_channel_id(&active_id, &peer->channel->funding);
if (peer->splice_state->await_commitment_succcess
&& !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) {
if (!channel_id_eq(&active_id,
&cs_tlv->splice_info->funding_txid)) {
if (!bitcoin_txid_eq(&peer->channel->funding.txid,
&cs_tlv->splice_info->funding_txid)) {
status_info("Ignoring stale commit_sig for channel_id"
" %s, as %s is locked in now.",
fmt_channel_id(tmpctx,
&cs_tlv->splice_info->funding_txid),
fmt_channel_id(tmpctx, &active_id));
fmt_bitcoin_txid(tmpctx,
&cs_tlv->splice_info->funding_txid),
fmt_bitcoin_txid(tmpctx,
&peer->channel->funding.txid));
return NULL;
}
}
@ -2071,8 +2070,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
fmt_bitcoin_outpoint(tmpctx, &outpoint),
fmt_amount_sat(tmpctx, funding_sats),
cs_tlv && cs_tlv->splice_info
? fmt_channel_id(tmpctx,
&cs_tlv->splice_info->funding_txid)
? fmt_bitcoin_txid(tmpctx,
&cs_tlv->splice_info->funding_txid)
: "N/A",
peer->splice_state->await_commitment_succcess ? "yes"
: "no",

View File

@ -301,7 +301,7 @@ msgdata,commitment_signed,htlc_signature,signature,num_htlcs
msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
tlvtype,commitment_signed_tlvs,splice_info,0
tlvdata,commitment_signed_tlvs,splice_info,batch_size,u16,
tlvdata,commitment_signed_tlvs,splice_info,funding_txid,channel_id,
tlvdata,commitment_signed_tlvs,splice_info,funding_txid,sha256,
msgtype,revoke_and_ack,133
msgdata,revoke_and_ack,channel_id,channel_id,
msgdata,revoke_and_ack,per_commitment_secret,byte,32

1 msgtype,init,16
301 msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
302 tlvtype,commitment_signed_tlvs,splice_info,0
303 tlvdata,commitment_signed_tlvs,splice_info,batch_size,u16,
304 tlvdata,commitment_signed_tlvs,splice_info,funding_txid,channel_id, tlvdata,commitment_signed_tlvs,splice_info,funding_txid,sha256,
305 msgtype,revoke_and_ack,133
306 msgdata,revoke_and_ack,channel_id,channel_id,
307 msgdata,revoke_and_ack,per_commitment_secret,byte,32

View File

@ -40,9 +40,9 @@ static void set_scid(struct short_channel_id *scid)
memset(scid, 2, sizeof(struct short_channel_id));
}
static void set_cid(struct channel_id *cid)
static void set_bitcoin_txid(struct bitcoin_txid *cid)
{
memset(cid, 2, sizeof(struct channel_id));
memset(cid, 2, sizeof(struct bitcoin_txid));
}
/* Size up to field. */
@ -1028,7 +1028,7 @@ int main(int argc, char *argv[])
cs.tlvs = tlv_commitment_signed_tlvs_new(tmpctx);
cs.tlvs->splice_info = tal(ctx, struct tlv_commitment_signed_tlvs_splice_info);
cs.tlvs->splice_info->batch_size = 1;
set_cid(&cs.tlvs->splice_info->funding_txid);
set_bitcoin_txid(&cs.tlvs->splice_info->funding_txid);
msg = towire_struct_commitment_signed(ctx, &cs);
cs2 = fromwire_struct_commitment_signed(ctx, msg);