Skip to content

Commit 7d6f604

Browse files
committed
splice: Remove batch_size from commitment_signed
The new spec sends `batch_size` in `start_batch` and removes it from `commitment_signed` so we need to stop processing it in `commitment_signed`. Since the tlv is now reduced to one element and that automagically turns it into a direct use TLV so we have to update the code everywhere it is referenced.
1 parent 4e17472 commit 7d6f604

File tree

3 files changed

+15
-46
lines changed

3 files changed

+15
-46
lines changed

channeld/channeld.c

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,12 +1197,7 @@ static u8 *send_commit_part(const tal_t *ctx,
11971197
(int)splice_amnt, (int)remote_splice_amnt,
11981198
remote_index);
11991199

1200-
if (batch_size > 1) {
1201-
cs_tlv->splice_info = tal(cs_tlv, struct tlv_commitment_signed_tlvs_splice_info);
1202-
1203-
cs_tlv->splice_info->batch_size = batch_size;
1204-
cs_tlv->splice_info->funding_txid = funding->txid;
1205-
}
1200+
cs_tlv->splice_info = tal_dup(cs_tlv, struct bitcoin_txid, &funding->txid);
12061201
}
12071202

12081203
txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map,
@@ -1963,11 +1958,11 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19631958
if (peer->splice_state->await_commitment_succcess
19641959
&& !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) {
19651960
if (!bitcoin_txid_eq(&peer->channel->funding.txid,
1966-
&cs_tlv->splice_info->funding_txid)) {
1961+
cs_tlv->splice_info)) {
19671962
status_info("Ignoring stale commit_sig for channel_id"
19681963
" %s, as %s is locked in now.",
19691964
fmt_bitcoin_txid(tmpctx,
1970-
&cs_tlv->splice_info->funding_txid),
1965+
cs_tlv->splice_info),
19711966
fmt_bitcoin_txid(tmpctx,
19721967
&peer->channel->funding.txid));
19731968
return NULL;
@@ -2017,22 +2012,17 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20172012
outpoint = peer->splice_state->inflights[commit_index - 1]->outpoint;
20182013
funding_sats = peer->splice_state->inflights[commit_index - 1]->amnt;
20192014

2020-
if (cs_tlv && cs_tlv->splice_info
2021-
&& cs_tlv->splice_info->batch_size == 1)
2022-
peer_failed_err(peer->pps, &peer->channel_id,
2023-
"batch_size can never be 1");
2024-
20252015
status_debug("handle_peer_commit_sig for inflight outpoint %s",
20262016
fmt_bitcoin_txid(tmpctx, &outpoint.txid));
20272017

20282018
if (cs_tlv->splice_info
20292019
&& !bitcoin_txid_eq(&outpoint.txid,
2030-
&cs_tlv->splice_info->funding_txid))
2020+
cs_tlv->splice_info))
20312021
peer_failed_err(peer->pps, &peer->channel_id,
20322022
"Expected commit sig message for %s but"
20332023
" got %s",
20342024
fmt_bitcoin_txid(tmpctx, &outpoint.txid),
2035-
fmt_bitcoin_txid(tmpctx, &cs_tlv->splice_info->funding_txid));
2025+
fmt_bitcoin_txid(tmpctx, cs_tlv->splice_info));
20362026
}
20372027
else {
20382028
outpoint = peer->channel->funding;
@@ -2089,7 +2079,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20892079
fmt_amount_sat(tmpctx, funding_sats),
20902080
cs_tlv && cs_tlv->splice_info
20912081
? fmt_bitcoin_txid(tmpctx,
2092-
&cs_tlv->splice_info->funding_txid)
2082+
cs_tlv->splice_info)
20932083
: "N/A",
20942084
peer->splice_state->await_commitment_succcess ? "yes"
20952085
: "no",
@@ -2253,7 +2243,7 @@ static int commit_index_from_msg(const u8 *msg, struct peer *peer)
22532243
if (!cs_tlv || !cs_tlv->splice_info)
22542244
return -1;
22552245

2256-
funding_txid = cs_tlv->splice_info->funding_txid;
2246+
funding_txid = *cs_tlv->splice_info;
22572247

22582248
if (bitcoin_txid_eq(&funding_txid, &peer->channel->funding.txid))
22592249
return 0;
@@ -2306,12 +2296,12 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23062296
s64 remote_splice_amnt,
23072297
u64 local_index,
23082298
const struct pubkey *local_per_commit,
2309-
bool allow_empty_commit)
2299+
bool allow_empty_commit,
2300+
u16 batch_size)
23102301
{
23112302
struct channel_id channel_id;
23122303
struct bitcoin_signature commit_sig;
23132304
secp256k1_ecdsa_signature *raw_sigs;
2314-
u16 batch_size;
23152305
const u8 **msg_batch;
23162306
enum peer_wire type;
23172307
struct tlv_commitment_signed_tlvs *cs_tlv
@@ -2323,11 +2313,6 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23232313
peer_failed_warn(peer->pps, &peer->channel_id,
23242314
"Bad commit_sig %s", tal_hex(msg, msg));
23252315

2326-
/* Default batch_size is 1 */
2327-
batch_size = 1;
2328-
if (cs_tlv->splice_info && cs_tlv->splice_info->batch_size)
2329-
batch_size = cs_tlv->splice_info->batch_size;
2330-
23312316
msg_batch = tal_arr(tmpctx, const u8*, batch_size);
23322317
msg_batch[0] = msg;
23332318
status_debug("msg_batch[0]: %p", msg_batch[0]);
@@ -2363,14 +2348,6 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23632348
" splice_info",
23642349
tal_hex(sub_msg, sub_msg), i, batch_size);
23652350

2366-
if (!sub_cs_tlv->splice_info
2367-
|| sub_cs_tlv->splice_info->batch_size != batch_size)
2368-
peer_failed_err(peer->pps, &peer->channel_id,
2369-
"batch_size value mismatch in"
2370-
" commit_sig bundle, item [%"PRIu16
2371-
"/%"PRIu16"] %s", i, batch_size,
2372-
tal_hex(sub_msg, sub_msg));
2373-
23742351
msg_batch[i] = sub_msg;
23752352
status_debug("msg_batch[%d]: %p", (int)i, msg_batch[i]);
23762353
}
@@ -4858,7 +4835,8 @@ static void peer_in(struct peer *peer, const u8 *msg)
48584835
NULL, 0, 0,
48594836
peer->next_index[LOCAL],
48604837
&peer->next_local_per_commit,
4861-
false);
4838+
false,
4839+
1);
48624840
return;
48634841
case WIRE_UPDATE_FEE:
48644842
handle_peer_feechange(peer, msg);

wire/peer_wire.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ msgdata,commitment_signed,num_htlcs,u16,
309309
msgdata,commitment_signed,htlc_signature,signature,num_htlcs
310310
msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
311311
tlvtype,commitment_signed_tlvs,splice_info,0
312-
tlvdata,commitment_signed_tlvs,splice_info,batch_size,u16,
313312
tlvdata,commitment_signed_tlvs,splice_info,funding_txid,sha256,
314313
msgtype,revoke_and_ack,133
315314
msgdata,revoke_and_ack,channel_id,channel_id,

wire/test/run-peer-wire.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -792,19 +792,12 @@ static bool update_fail_htlc_eq(const struct msg_update_fail_htlc *a,
792792
&& eq_var(a, b, reason);
793793
}
794794

795-
static bool tlv_splice_info_eq(const struct tlv_commitment_signed_tlvs_splice_info *a,
796-
const struct tlv_commitment_signed_tlvs_splice_info *b)
797-
{
798-
return eq_field(a, b, batch_size)
799-
&& eq_field(a, b, funding_txid);
800-
}
801-
802795
static bool commitment_signed_eq(const struct msg_commitment_signed *a,
803-
const struct msg_commitment_signed *b)
796+
const struct msg_commitment_signed *b)
804797
{
805798
return eq_upto(a, b, htlc_signature)
806799
&& eq_var(a, b, htlc_signature)
807-
&& eq_tlv(a, b, splice_info, tlv_splice_info_eq);
800+
&& eq_tlv(a, b, splice_info, bitcoin_txid_eq);
808801
}
809802

810803
static bool funding_signed_eq(const struct msg_funding_signed *a,
@@ -1026,9 +1019,8 @@ int main(int argc, char *argv[])
10261019
cs.htlc_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2);
10271020
memset(cs.htlc_signature, 2, sizeof(secp256k1_ecdsa_signature)*2);
10281021
cs.tlvs = tlv_commitment_signed_tlvs_new(tmpctx);
1029-
cs.tlvs->splice_info = tal(ctx, struct tlv_commitment_signed_tlvs_splice_info);
1030-
cs.tlvs->splice_info->batch_size = 1;
1031-
set_bitcoin_txid(&cs.tlvs->splice_info->funding_txid);
1022+
cs.tlvs->splice_info = tal(ctx, struct bitcoin_txid);
1023+
set_bitcoin_txid(cs.tlvs->splice_info);
10321024

10331025
msg = towire_struct_commitment_signed(ctx, &cs);
10341026
cs2 = fromwire_struct_commitment_signed(ctx, msg);

0 commit comments

Comments
 (0)