Skip to content

Commit b63f9c2

Browse files
ddustinrustyrussell
authored andcommitted
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 882a953 commit b63f9c2

File tree

4 files changed

+23
-46
lines changed

4 files changed

+23
-46
lines changed

channeld/channeld.c

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

1163-
if (batch_size > 1) {
1164-
cs_tlv->splice_info = tal(cs_tlv, struct tlv_commitment_signed_tlvs_splice_info);
1165-
1166-
cs_tlv->splice_info->batch_size = batch_size;
1167-
cs_tlv->splice_info->funding_txid = funding->txid;
1168-
}
1163+
cs_tlv->splice_info = tal_dup(cs_tlv, struct bitcoin_txid, &funding->txid);
11691164
}
11701165

11711166
txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map,
@@ -1926,11 +1921,11 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19261921
if (peer->splice_state->await_commitment_succcess
19271922
&& !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) {
19281923
if (!bitcoin_txid_eq(&peer->channel->funding.txid,
1929-
&cs_tlv->splice_info->funding_txid)) {
1924+
cs_tlv->splice_info)) {
19301925
status_info("Ignoring stale commit_sig for channel_id"
19311926
" %s, as %s is locked in now.",
19321927
fmt_bitcoin_txid(tmpctx,
1933-
&cs_tlv->splice_info->funding_txid),
1928+
cs_tlv->splice_info),
19341929
fmt_bitcoin_txid(tmpctx,
19351930
&peer->channel->funding.txid));
19361931
return NULL;
@@ -1980,22 +1975,17 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19801975
outpoint = peer->splice_state->inflights[commit_index - 1]->outpoint;
19811976
funding_sats = peer->splice_state->inflights[commit_index - 1]->amnt;
19821977

1983-
if (cs_tlv && cs_tlv->splice_info
1984-
&& cs_tlv->splice_info->batch_size == 1)
1985-
peer_failed_err(peer->pps, &peer->channel_id,
1986-
"batch_size can never be 1");
1987-
19881978
status_debug("handle_peer_commit_sig for inflight outpoint %s",
19891979
fmt_bitcoin_txid(tmpctx, &outpoint.txid));
19901980

19911981
if (cs_tlv->splice_info
19921982
&& !bitcoin_txid_eq(&outpoint.txid,
1993-
&cs_tlv->splice_info->funding_txid))
1983+
cs_tlv->splice_info))
19941984
peer_failed_err(peer->pps, &peer->channel_id,
19951985
"Expected commit sig message for %s but"
19961986
" got %s",
19971987
fmt_bitcoin_txid(tmpctx, &outpoint.txid),
1998-
fmt_bitcoin_txid(tmpctx, &cs_tlv->splice_info->funding_txid));
1988+
fmt_bitcoin_txid(tmpctx, cs_tlv->splice_info));
19991989
}
20001990
else {
20011991
outpoint = peer->channel->funding;
@@ -2052,7 +2042,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20522042
fmt_amount_sat(tmpctx, funding_sats),
20532043
cs_tlv && cs_tlv->splice_info
20542044
? fmt_bitcoin_txid(tmpctx,
2055-
&cs_tlv->splice_info->funding_txid)
2045+
cs_tlv->splice_info)
20562046
: "N/A",
20572047
peer->splice_state->await_commitment_succcess ? "yes"
20582048
: "no",
@@ -2216,7 +2206,7 @@ static int commit_index_from_msg(const u8 *msg, struct peer *peer)
22162206
if (!cs_tlv || !cs_tlv->splice_info)
22172207
return -1;
22182208

2219-
funding_txid = cs_tlv->splice_info->funding_txid;
2209+
funding_txid = *cs_tlv->splice_info;
22202210

22212211
if (bitcoin_txid_eq(&funding_txid, &peer->channel->funding.txid))
22222212
return 0;
@@ -2269,12 +2259,12 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
22692259
s64 remote_splice_amnt,
22702260
u64 local_index,
22712261
const struct pubkey *local_per_commit,
2272-
bool allow_empty_commit)
2262+
bool allow_empty_commit,
2263+
u16 batch_size)
22732264
{
22742265
struct channel_id channel_id;
22752266
struct bitcoin_signature commit_sig;
22762267
secp256k1_ecdsa_signature *raw_sigs;
2277-
u16 batch_size;
22782268
const u8 **msg_batch;
22792269
enum peer_wire type;
22802270
struct tlv_commitment_signed_tlvs *cs_tlv
@@ -2286,11 +2276,6 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
22862276
peer_failed_warn(peer->pps, &peer->channel_id,
22872277
"Bad commit_sig %s", tal_hex(msg, msg));
22882278

2289-
/* Default batch_size is 1 */
2290-
batch_size = 1;
2291-
if (cs_tlv->splice_info && cs_tlv->splice_info->batch_size)
2292-
batch_size = cs_tlv->splice_info->batch_size;
2293-
22942279
msg_batch = tal_arr(tmpctx, const u8*, batch_size);
22952280
msg_batch[0] = msg;
22962281
status_debug("msg_batch[0]: %p", msg_batch[0]);
@@ -2326,14 +2311,6 @@ static struct commitsig_info *handle_peer_commit_sig_batch(struct peer *peer,
23262311
" splice_info",
23272312
tal_hex(sub_msg, sub_msg), i, batch_size);
23282313

2329-
if (!sub_cs_tlv->splice_info
2330-
|| sub_cs_tlv->splice_info->batch_size != batch_size)
2331-
peer_failed_err(peer->pps, &peer->channel_id,
2332-
"batch_size value mismatch in"
2333-
" commit_sig bundle, item [%"PRIu16
2334-
"/%"PRIu16"] %s", i, batch_size,
2335-
tal_hex(sub_msg, sub_msg));
2336-
23372314
msg_batch[i] = sub_msg;
23382315
status_debug("msg_batch[%d]: %p", (int)i, msg_batch[i]);
23392316
}
@@ -4914,7 +4891,8 @@ static void peer_in(struct peer *peer, const u8 *msg)
49144891
NULL, 0, 0,
49154892
peer->next_index[LOCAL],
49164893
&peer->next_local_per_commit,
4917-
false);
4894+
false,
4895+
1); /* Batch size default is 1 */
49184896
return;
49194897
case WIRE_UPDATE_FEE:
49204898
handle_peer_feechange(peer, msg);

wire/extracted_peer_12_splice_update.patch

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ index 9abcb0e64..e2aae8efb 100644
2222
msgtype,commitment_signed,132
2323
msgdata,commitment_signed,channel_id,channel_id,
2424
msgdata,commitment_signed,signature,signature,
25+
@@ -309,6 +309,5 @@ msgdata,commitment_signed,num_htlcs,u16,
26+
msgdata,commitment_signed,htlc_signature,signature,num_htlcs
27+
msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
28+
tlvtype,commitment_signed_tlvs,splice_info,0
29+
-tlvdata,commitment_signed_tlvs,splice_info,batch_size,u16,
30+
tlvdata,commitment_signed_tlvs,splice_info,funding_txid,sha256,
31+
msgtype,revoke_and_ack,133
32+
msgdata,revoke_and_ack,channel_id,channel_id,

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)