From aa4e1b3e7975a799375781f7535ba177276c932c Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 21 Apr 2022 13:24:53 +0200 Subject: [PATCH] wire: Add funding_locked tlv patch from PR lightning/bolts#910 Minimal set of changes to update the peer_wire.csv to include the TLV field in the `funding_locked` message, and add type 1=alias from that PR too. --- channeld/channeld.c | 18 ++++++++++------- openingd/dualopend.c | 10 +++++----- wire/extracted_peer_06_zeroconf.patch | 14 ++++++++++++++ wire/peer_wire.csv | 3 +++ wire/test/run-peer-wire.c | 28 +++++++++++++++++++++------ 5 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 wire/extracted_peer_06_zeroconf.patch diff --git a/channeld/channeld.c b/channeld/channeld.c index 72cd437bfdd2..336f849bbed5 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -587,7 +587,7 @@ static void channel_announcement_negotiate(struct peer *peer) static void handle_peer_funding_locked(struct peer *peer, const u8 *msg) { struct channel_id chanid; - + struct tlv_funding_locked_tlvs *tlvs; /* BOLT #2: * * A node: @@ -603,8 +603,8 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg) return; peer->old_remote_per_commit = peer->remote_per_commit; - if (!fromwire_funding_locked(msg, &chanid, - &peer->remote_per_commit)) + if (!fromwire_funding_locked(msg, msg, &chanid, + &peer->remote_per_commit, &tlvs)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad funding_locked %s", tal_hex(msg, msg)); @@ -2928,13 +2928,14 @@ static void peer_reconnect(struct peer *peer, && peer->next_index[LOCAL] == 1 && next_commitment_number == 1) { u8 *msg; + struct tlv_funding_locked_tlvs *tlvs = tlv_funding_locked_tlvs_new(tmpctx); status_debug("Retransmitting funding_locked for channel %s", type_to_string(tmpctx, struct channel_id, &peer->channel_id)); /* Contains per commit point #1, for first post-opening commit */ msg = towire_funding_locked(NULL, &peer->channel_id, - &peer->next_local_per_commit); + &peer->next_local_per_commit, tlvs); peer_write(peer->pps, take(msg)); } @@ -3234,9 +3235,12 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg) peer->next_index[LOCAL], type_to_string(tmpctx, struct pubkey, &peer->next_local_per_commit)); - msg = towire_funding_locked(NULL, - &peer->channel_id, - &peer->next_local_per_commit); + struct tlv_funding_locked_tlvs *tlvs = + tlv_funding_locked_tlvs_new(tmpctx); + + msg = towire_funding_locked( + NULL, &peer->channel_id, + &peer->next_local_per_commit, tlvs); peer_write(peer->pps, take(msg)); peer->funding_locked[LOCAL] = true; diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 8c425af01b5c..14b1b13bade8 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -1132,8 +1132,9 @@ static u8 *handle_funding_locked(struct state *state, u8 *msg) { struct channel_id cid; struct pubkey remote_per_commit; + struct tlv_funding_locked_tlvs *tlvs; - if (!fromwire_funding_locked(msg, &cid, &remote_per_commit)) + if (!fromwire_funding_locked(tmpctx, msg, &cid, &remote_per_commit, &tlvs)) open_err_fatal(state, "Bad funding_locked %s", tal_hex(msg, msg)); @@ -3392,13 +3393,12 @@ static void send_funding_locked(struct state *state) { u8 *msg; struct pubkey next_local_per_commit; - + struct tlv_funding_locked_tlvs *tlvs = tlv_funding_locked_tlvs_new(tmpctx); /* Figure out the next local commit */ hsm_per_commitment_point(1, &next_local_per_commit); - msg = towire_funding_locked(NULL, - &state->channel_id, - &next_local_per_commit); + msg = towire_funding_locked(NULL, &state->channel_id, + &next_local_per_commit, tlvs); peer_write(state->pps, take(msg)); state->funding_locked[LOCAL] = true; diff --git a/wire/extracted_peer_06_zeroconf.patch b/wire/extracted_peer_06_zeroconf.patch new file mode 100644 index 000000000000..5084b00cb7e3 --- /dev/null +++ b/wire/extracted_peer_06_zeroconf.patch @@ -0,0 +1,14 @@ +diff --git a/wire/peer_wire.csv b/wire/peer_wire.csv +index a028ddc66..fc24b61ef 100644 +--- a/wire/peer_wire.csv ++++ b/wire/peer_wire.csv +@@ -126,6 +126,9 @@ msgdata,funding_signed,signature,signature, + msgtype,funding_locked,36 + msgdata,funding_locked,channel_id,channel_id, + msgdata,funding_locked,next_per_commitment_point,point, ++msgdata,funding_locked,tlvs,funding_locked_tlvs, ++tlvtype,funding_locked_tlvs,alias,1 ++tlvdata,funding_locked_tlvs,alias,scid,short_channel_id, + msgtype,open_channel2,64 + msgdata,open_channel2,chain_hash,chain_hash, + msgdata,open_channel2,channel_id,channel_id, diff --git a/wire/peer_wire.csv b/wire/peer_wire.csv index 497d43b52fe8..d400da1b8a67 100644 --- a/wire/peer_wire.csv +++ b/wire/peer_wire.csv @@ -126,6 +126,9 @@ msgdata,funding_signed,signature,signature, msgtype,funding_locked,36 msgdata,funding_locked,channel_id,channel_id, msgdata,funding_locked,next_per_commitment_point,point, +msgdata,funding_locked,tlvs,funding_locked_tlvs, +tlvtype,funding_locked_tlvs,alias,1 +tlvdata,funding_locked_tlvs,alias,scid,short_channel_id, msgtype,open_channel2,64 msgdata,open_channel2,chain_hash,chain_hash, msgdata,open_channel2,channel_id,channel_id, diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 29c71fd484f5..e8de0a6adb7a 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -7,6 +7,7 @@ #include "common/amount.c" #include "common/channel_id.c" #include "common/node_id.c" +#include "wire/tlvstream.h" #include @@ -34,6 +35,11 @@ static void set_node_id(struct node_id *id) memset(id->k, 2, sizeof(id->k)); } +static void set_scid(struct short_channel_id *scid) +{ + memset(scid, 2, sizeof(struct short_channel_id)); +} + /* Size up to field. */ #define upto_field(p, field) \ ((char *)&(p)->field - (char *)(p)) @@ -146,6 +152,7 @@ struct msg_channel_update_opt_htlc_max { struct msg_funding_locked { struct channel_id channel_id; struct pubkey next_per_commitment_point; + struct tlv_funding_locked_tlvs *tlvs; }; struct msg_announcement_signatures { struct channel_id channel_id; @@ -463,20 +470,23 @@ static struct msg_channel_update_opt_htlc_max } static void *towire_struct_funding_locked(const tal_t *ctx, - const struct msg_funding_locked *s) + const struct msg_funding_locked *s) { return towire_funding_locked(ctx, &s->channel_id, - &s->next_per_commitment_point); + &s->next_per_commitment_point, + s->tlvs); } static struct msg_funding_locked *fromwire_struct_funding_locked(const tal_t *ctx, const void *p) { struct msg_funding_locked *s = tal(ctx, struct msg_funding_locked); - if (fromwire_funding_locked(p, + if (fromwire_funding_locked(ctx, + p, &s->channel_id, - &s->next_per_commitment_point)) + &s->next_per_commitment_point, + &s->tlvs)) return s; return tal_free(s); } @@ -801,7 +811,9 @@ static bool channel_announcement_eq(const struct msg_channel_announcement *a, static bool funding_locked_eq(const struct msg_funding_locked *a, const struct msg_funding_locked *b) { - return memcmp(a, b, sizeof(*a)) == 0; + return eq_upto(a, b, tlvs) && + memeq(a->tlvs->alias, sizeof(a->tlvs->alias), b->tlvs->alias, + sizeof(b->tlvs->alias)); } static bool announcement_signatures_eq(const struct msg_announcement_signatures *a, @@ -1044,12 +1056,16 @@ int main(int argc, char *argv[]) test_corruption(&ca, ca2, channel_announcement); memset(&fl, 2, sizeof(fl)); + fl.tlvs = tlv_funding_locked_tlvs_new(ctx); + fl.tlvs->alias = tal(ctx, struct short_channel_id); + set_scid(fl.tlvs->alias); set_pubkey(&fl.next_per_commitment_point); msg = towire_struct_funding_locked(ctx, &fl); fl2 = fromwire_struct_funding_locked(ctx, msg); assert(funding_locked_eq(&fl, fl2)); - test_corruption(&fl, fl2, funding_locked); + /* FIXME: Corruptions in the TLV can still parse correctly, but won't be equal. */ + /*test_corruption_tlv(&fl, fl2, funding_locked);*/ memset(&as, 2, sizeof(as));