Skip to content

Commit 21963e2

Browse files
committed
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.
1 parent cb1878b commit 21963e2

File tree

5 files changed

+55
-18
lines changed

5 files changed

+55
-18
lines changed

channeld/channeld.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static void channel_announcement_negotiate(struct peer *peer)
587587
static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
588588
{
589589
struct channel_id chanid;
590-
590+
struct tlv_funding_locked_tlvs *tlvs;
591591
/* BOLT #2:
592592
*
593593
* A node:
@@ -603,8 +603,8 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
603603
return;
604604

605605
peer->old_remote_per_commit = peer->remote_per_commit;
606-
if (!fromwire_funding_locked(msg, &chanid,
607-
&peer->remote_per_commit))
606+
if (!fromwire_funding_locked(msg, msg, &chanid,
607+
&peer->remote_per_commit, &tlvs))
608608
peer_failed_warn(peer->pps, &peer->channel_id,
609609
"Bad funding_locked %s", tal_hex(msg, msg));
610610

@@ -2928,13 +2928,14 @@ static void peer_reconnect(struct peer *peer,
29282928
&& peer->next_index[LOCAL] == 1
29292929
&& next_commitment_number == 1) {
29302930
u8 *msg;
2931+
struct tlv_funding_locked_tlvs *tlvs = tlv_funding_locked_tlvs_new(tmpctx);
29312932

29322933
status_debug("Retransmitting funding_locked for channel %s",
29332934
type_to_string(tmpctx, struct channel_id, &peer->channel_id));
29342935
/* Contains per commit point #1, for first post-opening commit */
29352936
msg = towire_funding_locked(NULL,
29362937
&peer->channel_id,
2937-
&peer->next_local_per_commit);
2938+
&peer->next_local_per_commit, tlvs);
29382939
peer_write(peer->pps, take(msg));
29392940
}
29402941

@@ -3234,9 +3235,12 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
32343235
peer->next_index[LOCAL],
32353236
type_to_string(tmpctx, struct pubkey,
32363237
&peer->next_local_per_commit));
3237-
msg = towire_funding_locked(NULL,
3238-
&peer->channel_id,
3239-
&peer->next_local_per_commit);
3238+
struct tlv_funding_locked_tlvs *tlvs =
3239+
tlv_funding_locked_tlvs_new(tmpctx);
3240+
3241+
msg = towire_funding_locked(
3242+
NULL, &peer->channel_id,
3243+
&peer->next_local_per_commit, tlvs);
32403244
peer_write(peer->pps, take(msg));
32413245

32423246
peer->funding_locked[LOCAL] = true;

openingd/dualopend.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,9 @@ static u8 *handle_funding_locked(struct state *state, u8 *msg)
11321132
{
11331133
struct channel_id cid;
11341134
struct pubkey remote_per_commit;
1135+
struct tlv_funding_locked_tlvs *tlvs;
11351136

1136-
if (!fromwire_funding_locked(msg, &cid, &remote_per_commit))
1137+
if (!fromwire_funding_locked(tmpctx, msg, &cid, &remote_per_commit, &tlvs))
11371138
open_err_fatal(state, "Bad funding_locked %s",
11381139
tal_hex(msg, msg));
11391140

@@ -3392,13 +3393,12 @@ static void send_funding_locked(struct state *state)
33923393
{
33933394
u8 *msg;
33943395
struct pubkey next_local_per_commit;
3395-
3396+
struct tlv_funding_locked_tlvs *tlvs = tlv_funding_locked_tlvs_new(tmpctx);
33963397
/* Figure out the next local commit */
33973398
hsm_per_commitment_point(1, &next_local_per_commit);
33983399

3399-
msg = towire_funding_locked(NULL,
3400-
&state->channel_id,
3401-
&next_local_per_commit);
3400+
msg = towire_funding_locked(NULL, &state->channel_id,
3401+
&next_local_per_commit, tlvs);
34023402
peer_write(state->pps, take(msg));
34033403

34043404
state->funding_locked[LOCAL] = true;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/wire/peer_wire.csv b/wire/peer_wire.csv
2+
index a028ddc66..fc24b61ef 100644
3+
--- a/wire/peer_wire.csv
4+
+++ b/wire/peer_wire.csv
5+
@@ -126,6 +126,9 @@ msgdata,funding_signed,signature,signature,
6+
msgtype,funding_locked,36
7+
msgdata,funding_locked,channel_id,channel_id,
8+
msgdata,funding_locked,next_per_commitment_point,point,
9+
+msgdata,funding_locked,tlvs,funding_locked_tlvs,
10+
+tlvtype,funding_locked_tlvs,alias,1
11+
+tlvdata,funding_locked_tlvs,alias,scid,short_channel_id,
12+
msgtype,open_channel2,64
13+
msgdata,open_channel2,chain_hash,chain_hash,
14+
msgdata,open_channel2,channel_id,channel_id,

wire/peer_wire.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ msgdata,funding_signed,signature,signature,
126126
msgtype,funding_locked,36
127127
msgdata,funding_locked,channel_id,channel_id,
128128
msgdata,funding_locked,next_per_commitment_point,point,
129+
msgdata,funding_locked,tlvs,funding_locked_tlvs,
130+
tlvtype,funding_locked_tlvs,alias,1
131+
tlvdata,funding_locked_tlvs,alias,scid,short_channel_id,
129132
msgtype,open_channel2,64
130133
msgdata,open_channel2,chain_hash,chain_hash,
131134
msgdata,open_channel2,channel_id,channel_id,

wire/test/run-peer-wire.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "common/amount.c"
88
#include "common/channel_id.c"
99
#include "common/node_id.c"
10+
#include "wire/tlvstream.h"
1011

1112
#include <stdio.h>
1213

@@ -34,6 +35,11 @@ static void set_node_id(struct node_id *id)
3435
memset(id->k, 2, sizeof(id->k));
3536
}
3637

38+
static void set_scid(struct short_channel_id *scid)
39+
{
40+
memset(scid, 2, sizeof(struct short_channel_id));
41+
}
42+
3743
/* Size up to field. */
3844
#define upto_field(p, field) \
3945
((char *)&(p)->field - (char *)(p))
@@ -146,6 +152,7 @@ struct msg_channel_update_opt_htlc_max {
146152
struct msg_funding_locked {
147153
struct channel_id channel_id;
148154
struct pubkey next_per_commitment_point;
155+
struct tlv_funding_locked_tlvs *tlvs;
149156
};
150157
struct msg_announcement_signatures {
151158
struct channel_id channel_id;
@@ -463,20 +470,23 @@ static struct msg_channel_update_opt_htlc_max
463470
}
464471

465472
static void *towire_struct_funding_locked(const tal_t *ctx,
466-
const struct msg_funding_locked *s)
473+
const struct msg_funding_locked *s)
467474
{
468475
return towire_funding_locked(ctx,
469476
&s->channel_id,
470-
&s->next_per_commitment_point);
477+
&s->next_per_commitment_point,
478+
s->tlvs);
471479
}
472480

473481
static struct msg_funding_locked *fromwire_struct_funding_locked(const tal_t *ctx, const void *p)
474482
{
475483
struct msg_funding_locked *s = tal(ctx, struct msg_funding_locked);
476484

477-
if (fromwire_funding_locked(p,
485+
if (fromwire_funding_locked(ctx,
486+
p,
478487
&s->channel_id,
479-
&s->next_per_commitment_point))
488+
&s->next_per_commitment_point,
489+
&s->tlvs))
480490
return s;
481491
return tal_free(s);
482492
}
@@ -801,7 +811,9 @@ static bool channel_announcement_eq(const struct msg_channel_announcement *a,
801811
static bool funding_locked_eq(const struct msg_funding_locked *a,
802812
const struct msg_funding_locked *b)
803813
{
804-
return memcmp(a, b, sizeof(*a)) == 0;
814+
return eq_upto(a, b, tlvs) &&
815+
memeq(a->tlvs->alias, sizeof(a->tlvs->alias), b->tlvs->alias,
816+
sizeof(b->tlvs->alias));
805817
}
806818

807819
static bool announcement_signatures_eq(const struct msg_announcement_signatures *a,
@@ -1044,12 +1056,16 @@ int main(int argc, char *argv[])
10441056
test_corruption(&ca, ca2, channel_announcement);
10451057

10461058
memset(&fl, 2, sizeof(fl));
1059+
fl.tlvs = tlv_funding_locked_tlvs_new(ctx);
1060+
fl.tlvs->alias = tal(ctx, struct short_channel_id);
1061+
set_scid(fl.tlvs->alias);
10471062
set_pubkey(&fl.next_per_commitment_point);
10481063

10491064
msg = towire_struct_funding_locked(ctx, &fl);
10501065
fl2 = fromwire_struct_funding_locked(ctx, msg);
10511066
assert(funding_locked_eq(&fl, fl2));
1052-
test_corruption(&fl, fl2, funding_locked);
1067+
/* FIXME: Corruptions in the TLV can still parse correctly, but won't be equal. */
1068+
/*test_corruption_tlv(&fl, fl2, funding_locked);*/
10531069

10541070
memset(&as, 2, sizeof(as));
10551071

0 commit comments

Comments
 (0)