Skip to content

Commit 35b5281

Browse files
committed
splice: Implement start_batch
Implement the sending of `start_batch` as per t-bast’s spec. We ignoring it when receving, as we don’t need it. Changelog-Added: support for `start_batch`
1 parent 9d160eb commit 35b5281

File tree

10 files changed

+68
-2
lines changed

10 files changed

+68
-2
lines changed

channeld/channeld.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,44 @@ static s64 sats_diff(struct amount_sat a, struct amount_sat b)
12741274
return (s64)a.satoshis - (s64)b.satoshis; /* Raw: splicing numbers can wrap! */
12751275
}
12761276

1277+
static void send_message_batch(struct peer *peer, u8 **msgs)
1278+
{
1279+
size_t size;
1280+
u8 *batch_msg, *final_msg, *final_msg_ptr;
1281+
1282+
size = 0;
1283+
for(u32 i = 0; i < tal_count(msgs); i++)
1284+
size += tal_bytelen(msgs[i]);
1285+
1286+
/* Only append `start_batch` if batch is more than 1 */
1287+
if (tal_count(msgs) > 1) {
1288+
batch_msg = towire_start_batch(NULL, &peer->channel_id,
1289+
tal_count(msgs));
1290+
size += tal_bytelen(batch_msg);
1291+
}
1292+
1293+
/* Now we know the size of our `final_msg` so we allocate. */
1294+
final_msg = tal_arr(NULL, u8, size);
1295+
final_msg_ptr = final_msg;
1296+
1297+
/* Append the `start_batch` here, again if batch is more than 1 */
1298+
if (tal_count(msgs) > 1) {
1299+
memcpy(final_msg_ptr, batch_msg, tal_bytelen(batch_msg));
1300+
final_msg_ptr += tal_bytelen(batch_msg);
1301+
tal_free(batch_msg);
1302+
}
1303+
1304+
/* Now copy the bytes from all messages in `msgs` */
1305+
for(u32 i = 0; i < tal_count(msgs); i++) {
1306+
memcpy(final_msg_ptr, msgs[i], tal_bytelen(msgs[i]));
1307+
final_msg_ptr += tal_bytelen(msgs[i]);
1308+
}
1309+
1310+
assert(final_msg + size == final_msg_ptr);
1311+
peer_write(peer->pps, final_msg);
1312+
tal_free(final_msg);
1313+
}
1314+
12771315
static void send_commit(struct peer *peer)
12781316
{
12791317
const struct htlc **changed_htlcs;
@@ -1440,8 +1478,7 @@ static void send_commit(struct peer *peer)
14401478

14411479
peer->next_index[REMOTE]++;
14421480

1443-
for(u32 i = 0; i < tal_count(msgs); i++)
1444-
peer_write(peer->pps, take(msgs[i]));
1481+
send_message_batch(peer, msgs);
14451482

14461483
maybe_send_shutdown(peer);
14471484

@@ -4850,6 +4887,9 @@ static void peer_in(struct peer *peer, const u8 *msg)
48504887
case WIRE_UPDATE_ADD_HTLC:
48514888
handle_peer_add_htlc(peer, msg);
48524889
return;
4890+
case WIRE_START_BATCH:
4891+
/* We can safely ignore these messages as we dont need them. */
4892+
return;
48534893
case WIRE_COMMITMENT_SIGNED:
48544894
handle_peer_commit_sig_batch(peer, msg, 0,
48554895
peer->channel->funding_pubkey[REMOTE],

common/gossmap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ const void *gossmap_stream_next(const tal_t *ctx,
17991799
case WIRE_UPDATE_FULFILL_HTLC:
18001800
case WIRE_UPDATE_FAIL_HTLC:
18011801
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
1802+
case WIRE_START_BATCH:
18021803
case WIRE_COMMITMENT_SIGNED:
18031804
case WIRE_REVOKE_AND_ACK:
18041805
case WIRE_UPDATE_FEE:

common/interactivetx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ static u8 *read_next_msg(const tal_t *ctx,
163163
case WIRE_UPDATE_FULFILL_HTLC:
164164
case WIRE_UPDATE_FAIL_HTLC:
165165
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
166+
case WIRE_START_BATCH:
166167
case WIRE_COMMITMENT_SIGNED:
167168
case WIRE_REVOKE_AND_ACK:
168169
case WIRE_UPDATE_FEE:
@@ -771,6 +772,7 @@ char *process_interactivetx_updates(const tal_t *ctx,
771772
case WIRE_UPDATE_FULFILL_HTLC:
772773
case WIRE_UPDATE_FAIL_HTLC:
773774
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
775+
case WIRE_START_BATCH:
774776
case WIRE_COMMITMENT_SIGNED:
775777
case WIRE_REVOKE_AND_ACK:
776778
case WIRE_UPDATE_FEE:

connectd/gossip_rcvd_filter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static bool is_msg_gossip_broadcast(const u8 *cursor)
7373
case WIRE_UPDATE_FULFILL_HTLC:
7474
case WIRE_UPDATE_FAIL_HTLC:
7575
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
76+
case WIRE_START_BATCH:
7677
case WIRE_COMMITMENT_SIGNED:
7778
case WIRE_REVOKE_AND_ACK:
7879
case WIRE_UPDATE_FEE:

connectd/gossip_store.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static bool public_msg_type(enum peer_wire type)
8282
case WIRE_UPDATE_FULFILL_HTLC:
8383
case WIRE_UPDATE_FAIL_HTLC:
8484
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
85+
case WIRE_START_BATCH:
8586
case WIRE_COMMITMENT_SIGNED:
8687
case WIRE_REVOKE_AND_ACK:
8788
case WIRE_UPDATE_FEE:

connectd/multiplex.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ static bool is_urgent(enum peer_wire type)
382382
/* These are time-sensitive, and so send without delay. */
383383
case WIRE_PING:
384384
case WIRE_PONG:
385+
case WIRE_START_BATCH:
385386
case WIRE_COMMITMENT_SIGNED:
386387
case WIRE_REVOKE_AND_ACK:
387388
return true;
@@ -440,6 +441,10 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
440441

441442
set_urgent_flag(peer, is_urgent(type));
442443

444+
/* DTODO: If needed, split start_batch message back into multiple
445+
* individual write events. Currently we send all messages in the batch
446+
* in a single write event. */
447+
443448
/* We free this and the encrypted version in next write_to_peer */
444449
peer->sent_to_peer = cryptomsg_encrypt_msg(peer, &peer->cs, msg);
445450
return io_write(peer->to_peer,

gossipd/gossipd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ static void handle_recv_gossip(struct daemon *daemon, const u8 *outermsg)
244244
case WIRE_UPDATE_FULFILL_HTLC:
245245
case WIRE_UPDATE_FAIL_HTLC:
246246
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
247+
case WIRE_START_BATCH:
247248
case WIRE_COMMITMENT_SIGNED:
248249
case WIRE_REVOKE_AND_ACK:
249250
case WIRE_UPDATE_FEE:

openingd/dualopend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
16731673
case WIRE_UPDATE_FULFILL_HTLC:
16741674
case WIRE_UPDATE_FAIL_HTLC:
16751675
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
1676+
case WIRE_START_BATCH:
16761677
case WIRE_COMMITMENT_SIGNED:
16771678
case WIRE_REVOKE_AND_ACK:
16781679
case WIRE_UPDATE_FEE:
@@ -2057,6 +2058,7 @@ static bool run_tx_interactive(struct state *state,
20572058
case WIRE_UPDATE_FULFILL_HTLC:
20582059
case WIRE_UPDATE_FAIL_HTLC:
20592060
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
2061+
case WIRE_START_BATCH:
20602062
case WIRE_COMMITMENT_SIGNED:
20612063
case WIRE_REVOKE_AND_ACK:
20622064
case WIRE_UPDATE_FEE:
@@ -4209,6 +4211,9 @@ static u8 *handle_peer_in(struct state *state)
42094211
}
42104212
accepter_start(state, msg);
42114213
return NULL;
4214+
case WIRE_START_BATCH:
4215+
/* We ignore batch messages as we dont need them */
4216+
return NULL;
42124217
case WIRE_COMMITMENT_SIGNED:
42134218
handle_commit_signed(state, msg);
42144219
return NULL;

wire/peer_wire.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static bool unknown_type(enum peer_wire t)
2121
case WIRE_UPDATE_FULFILL_HTLC:
2222
case WIRE_UPDATE_FAIL_HTLC:
2323
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
24+
case WIRE_START_BATCH:
2425
case WIRE_COMMITMENT_SIGNED:
2526
case WIRE_REVOKE_AND_ACK:
2627
case WIRE_UPDATE_FEE:
@@ -89,6 +90,7 @@ bool is_msg_for_gossipd(const u8 *cursor)
8990
case WIRE_UPDATE_FULFILL_HTLC:
9091
case WIRE_UPDATE_FAIL_HTLC:
9192
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
93+
case WIRE_START_BATCH:
9294
case WIRE_COMMITMENT_SIGNED:
9395
case WIRE_REVOKE_AND_ACK:
9496
case WIRE_UPDATE_FEE:
@@ -345,6 +347,11 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
345347
* 2. data:
346348
* * [`channel_id`:`channel_id`]
347349
*/
350+
case WIRE_START_BATCH:
351+
/* 1. type: 127 (`start_batch`)
352+
* 2. data:
353+
* * [`channel_id`:`channel_id`]
354+
*/
348355
case WIRE_COMMITMENT_SIGNED:
349356
/* BOLT #2:
350357
* 1. type: 132 (`commitment_signed`)

wire/peer_wire.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ msgdata,update_fail_malformed_htlc,channel_id,channel_id,
293293
msgdata,update_fail_malformed_htlc,id,u64,
294294
msgdata,update_fail_malformed_htlc,sha256_of_onion,sha256,
295295
msgdata,update_fail_malformed_htlc,failure_code,u16,
296+
msgtype,start_batch,127
297+
msgdata,start_batch,channel_id,channel_id,
298+
msgdata,start_batch,batch_size,u16,
296299
msgtype,commitment_signed,132
297300
msgdata,commitment_signed,channel_id,channel_id,
298301
msgdata,commitment_signed,signature,signature,

0 commit comments

Comments
 (0)