Skip to content

Commit

Permalink
wire: Add funding_locked tlv patch from PR lightning/bolts#910
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker committed Jun 29, 2022
1 parent 2b5b5cc commit aa4e1b3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
18 changes: 11 additions & 7 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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));

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions openingd/dualopend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions wire/extracted_peer_06_zeroconf.patch
Original file line number Diff line number Diff line change
@@ -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,
3 changes: 3 additions & 0 deletions wire/peer_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 22 additions & 6 deletions wire/test/run-peer-wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "common/amount.c"
#include "common/channel_id.c"
#include "common/node_id.c"
#include "wire/tlvstream.h"

#include <stdio.h>

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit aa4e1b3

Please sign in to comment.