From 7a8e377b81af8198d5a5c42204b2d572e29e8cbf Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Fri, 4 Oct 2024 16:20:47 -0400 Subject: [PATCH] splice: Update `commitment_signed_tlvs` As per eclair spec proposal. 1) A renaming to `funding_txid` 2) Adding of `batch_size` to indicate how many commitment_signed msgs are expected. Changelog-None --- channeld/channeld.c | 36 ++++++++++++++++++++++++------------ wire/peer_wire.csv | 3 ++- wire/test/run-peer-wire.c | 14 +++++++++++--- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 96d6e190d..d90b06a3f 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1135,7 +1135,8 @@ static u8 *send_commit_part(const tal_t *ctx, s64 remote_splice_amnt, u64 remote_index, const struct pubkey *remote_per_commit, - struct local_anchor_info **anchor) + struct local_anchor_info **anchor, + u16 batch_size) { u8 *msg; struct bitcoin_signature commit_sig, *htlc_sigs; @@ -1159,8 +1160,11 @@ static u8 *send_commit_part(const tal_t *ctx, (int)splice_amnt, (int)remote_splice_amnt, remote_index); - cs_tlv->splice_info = tal(cs_tlv, struct channel_id); - derive_channel_id(cs_tlv->splice_info, funding); + cs_tlv->splice_info = tal(cs_tlv, + 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); } txs = channel_txs(tmpctx, funding, funding_sats, &htlc_map, @@ -1236,6 +1240,7 @@ static void send_commit(struct peer *peer) u32 feerate_target; u8 **msgs = tal_arr(tmpctx, u8*, 1); u8 *msg; + u16 batch_size = tal_count(peer->splice_state->inflights) + 1; struct local_anchor_info *local_anchor, *anchors_info; if (peer->dev_disable_commit && !*peer->dev_disable_commit) { @@ -1350,7 +1355,8 @@ static void send_commit(struct peer *peer) msgs[0] = send_commit_part(msgs, peer, &peer->channel->funding, peer->channel->funding_sats, changed_htlcs, true, 0, 0, peer->next_index[REMOTE], - &peer->remote_per_commit, &local_anchor); + &peer->remote_per_commit, &local_anchor, + batch_size); if (local_anchor) tal_arr_expand(&anchors_info, *local_anchor); @@ -1378,7 +1384,8 @@ static void send_commit(struct peer *peer) remote_splice_amnt, peer->next_index[REMOTE], &peer->remote_per_commit, - &local_anchor)); + &local_anchor, + batch_size); if (local_anchor) tal_arr_expand(&anchors_info, *local_anchor); } @@ -1877,10 +1884,12 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, 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)) { + if (!channel_id_eq(&active_id, + &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), + fmt_channel_id(tmpctx, + &cs_tlv->splice_info->funding_txid), fmt_channel_id(tmpctx, &active_id)); return NULL; } @@ -1983,7 +1992,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, fmt_channel_id(tmpctx, &active_id), cs_tlv && cs_tlv->splice_info ? fmt_channel_id(tmpctx, - cs_tlv->splice_info) + &cs_tlv->splice_info->funding_txid) : "N/A", peer->splice_state->await_commitment_succcess ? "yes" : "no", @@ -2737,7 +2746,8 @@ static struct commitsig *interactive_send_commitments(struct peer *peer, remote_splice_amnt, next_index_remote - 1, &peer->old_remote_per_commit, - &local_anchor)); + &local_anchor, + 1); } result = NULL; @@ -2793,7 +2803,8 @@ static struct commitsig *interactive_send_commitments(struct peer *peer, remote_splice_amnt, next_index_remote - 1, &peer->old_remote_per_commit, - &local_anchor)); + &local_anchor, + 1)); } /* Sending and receiving splice commit should not increment commit @@ -4559,6 +4570,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) u8 *msg; u8 **msgs = tal_arr(tmpctx, u8*, 1); struct local_anchor_info *local_anchor; + u16 batch_size = tal_count(peer->splice_state->inflights) + 1; status_debug("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u," " blockheight LOCAL=%u REMOTE=%u", @@ -4653,7 +4665,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) peer->channel->funding_sats, NULL, false, 0, 0, peer->next_index[REMOTE] - 1, &peer->remote_per_commit, - &local_anchor); + &local_anchor, batch_size); /* Loop over current inflights * BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: @@ -4679,7 +4691,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) remote_splice_amnt, peer->next_index[REMOTE] - 1, &peer->remote_per_commit, - &local_anchor)); + &local_anchor, batch_size)); } for(i = 0; i < tal_count(msgs); i++) diff --git a/wire/peer_wire.csv b/wire/peer_wire.csv index 3061e5791..66bb631a4 100644 --- a/wire/peer_wire.csv +++ b/wire/peer_wire.csv @@ -269,7 +269,8 @@ msgdata,commitment_signed,num_htlcs,u16, 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,splice_channel_id,channel_id, +tlvdata,commitment_signed_tlvs,splice_info,batch_size,u16, +tlvdata,commitment_signed_tlvs,splice_info,funding_txid,channel_id, msgtype,revoke_and_ack,133 msgdata,revoke_and_ack,channel_id,channel_id, msgdata,revoke_and_ack,per_commitment_secret,byte,32 diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index ad5379580..8700d201e 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -792,12 +792,19 @@ static bool update_fail_htlc_eq(const struct msg_update_fail_htlc *a, && eq_var(a, b, reason); } +static bool tlv_splice_info_eq(const struct tlv_commitment_signed_tlvs_splice_info *a, + const struct tlv_commitment_signed_tlvs_splice_info *b) +{ + return eq_field(a, b, batch_size) + && eq_field(a, b, funding_txid); +} + static bool commitment_signed_eq(const struct msg_commitment_signed *a, const struct msg_commitment_signed *b) { return eq_upto(a, b, htlc_signature) && eq_var(a, b, htlc_signature) - && eq_tlv(a, b, splice_info, channel_id_eq); + && eq_tlv(a, b, splice_info, tlv_splice_info_eq); } static bool funding_signed_eq(const struct msg_funding_signed *a, @@ -1019,8 +1026,9 @@ int main(int argc, char *argv[]) cs.htlc_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2); memset(cs.htlc_signature, 2, sizeof(secp256k1_ecdsa_signature)*2); cs.tlvs = tlv_commitment_signed_tlvs_new(tmpctx); - cs.tlvs->splice_info = tal(ctx, struct channel_id); - set_cid(cs.tlvs->splice_info); + 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); msg = towire_struct_commitment_signed(ctx, &cs); cs2 = fromwire_struct_commitment_signed(ctx, msg);