From d3bdb073b5aa00f1cbe01105a23395ce26fa1712 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 4 Jan 2017 14:09:21 +1030 Subject: [PATCH] wire/gen_peer_wire_csv: update to latest spec #1 In particular, add features bitfields. Signed-off-by: Rusty Russell --- daemon/p2p_announce.c | 25 ++++++++----- wire/gen_peer_wire_csv | 7 ++-- wire/test/run-peer-wire.c | 75 +++++++++++++++++++++++---------------- 3 files changed, 67 insertions(+), 40 deletions(-) diff --git a/daemon/p2p_announce.c b/daemon/p2p_announce.c index 5e7a64ed2..88a76f09b 100644 --- a/daemon/p2p_announce.c +++ b/daemon/p2p_announce.c @@ -147,19 +147,22 @@ void handle_channel_announcement( struct pubkey bitcoin_key_1; struct pubkey bitcoin_key_2; const tal_t *tmpctx = tal_tmpctx(peer); + u8 *features; serialized = tal_dup_arr(tmpctx, u8, announce, len, 0); - if (!fromwire_channel_announcement(serialized, NULL, + if (!fromwire_channel_announcement(tmpctx, serialized, NULL, &node_signature_1, &node_signature_2, &channel_id, &bitcoin_signature_1, &bitcoin_signature_2, &node_id_1, &node_id_2, - &bitcoin_key_1, &bitcoin_key_2)) { + &bitcoin_key_1, &bitcoin_key_2, + &features)) { tal_free(tmpctx); return; } + // FIXME: Check features! //FIXME(cdecker) Check signatures, when the spec is settled //FIXME(cdecker) Check chain topology for the anchor TX @@ -278,16 +281,18 @@ void handle_node_announcement( struct pubkey node_id; u8 rgb_color[3]; u8 alias[32]; + u8 *features; const tal_t *tmpctx = tal_tmpctx(peer); serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0); - if (!fromwire_node_announcement(serialized, NULL, + if (!fromwire_node_announcement(tmpctx, serialized, NULL, &signature, ×tamp, &ipv6, &port, - &node_id, rgb_color, alias)) { + &node_id, rgb_color, alias, &features)) { tal_free(tmpctx); return; } + // FIXME: Check features! log_debug_struct(peer->log, "Received node_announcement for node %s", struct pubkey, &node_id); @@ -393,13 +398,15 @@ static void broadcast_node_announcement(struct lightningd_state *dstate) serialized = towire_node_announcement(tmpctx, &signature, timestamp, &ipv6, dstate->portnum, - &dstate->id, rgb_color, alias); + &dstate->id, rgb_color, alias, + 0, NULL); privkey_sign(dstate, serialized + 66, tal_count(serialized) - 66, &signature); serialized = towire_node_announcement(tmpctx, &signature, timestamp, &ipv6, dstate->portnum, - &dstate->id, rgb_color, alias); + &dstate->id, rgb_color, alias, + 0, NULL); broadcast(dstate, WIRE_NODE_ANNOUNCEMENT, serialized, NULL); tal_free(tmpctx); } @@ -458,7 +465,8 @@ static void broadcast_channel_announcement(struct lightningd_state *dstate, stru node_id[0], node_id[1], bitcoin_key[0], - bitcoin_key[1]); + bitcoin_key[1], + 0, NULL); privkey_sign(dstate, serialized + 128, tal_count(serialized) - 128, my_node_signature); serialized = towire_channel_announcement(tmpctx, &node_signature[0], @@ -469,7 +477,8 @@ static void broadcast_channel_announcement(struct lightningd_state *dstate, stru node_id[0], node_id[1], bitcoin_key[0], - bitcoin_key[1]); + bitcoin_key[1], + 0, NULL); broadcast(dstate, WIRE_CHANNEL_ANNOUNCEMENT, serialized, NULL); tal_free(tmpctx); } diff --git a/wire/gen_peer_wire_csv b/wire/gen_peer_wire_csv index dc42884cf..e64eaf3c5 100644 --- a/wire/gen_peer_wire_csv +++ b/wire/gen_peer_wire_csv @@ -99,6 +99,8 @@ channel_announcement,264,node-id-1,33 channel_announcement,297,node-id-2,33 channel_announcement,330,bitcoin-key-1,33 channel_announcement,363,bitcoin-key-2,33 +channel_announcement,396,len,2 +channel_announcement,398,features,len node_announcement,257 node_announcement,0,signature,64 node_announcement,64,timestamp,4 @@ -106,8 +108,9 @@ node_announcement,68,ipv6,16 node_announcement,84,port,2 node_announcement,86,node-id,33 node_announcement,119,rgb-color,3 -node_announcement,122,pad,2 -node_announcement,124,alias,32 +node_announcement,122,alias,32 +node_announcement,154,len,2 +node_announcement,156,features,len channel_update,258 channel_update,0,signature,64 channel_update,64,channel-id,8 diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index dc5b5ebae..92831da44 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -162,8 +162,9 @@ struct msg_node_announcement { u16 port; struct pubkey node_id; u8 rgb_color[3]; - u8 padding[2]; u8 alias[32]; + u16 len; + u8 *features; }; struct msg_open_channel { struct channel_id temporary_channel_id; @@ -197,6 +198,8 @@ struct msg_channel_announcement { struct pubkey node_id_2; struct pubkey bitcoin_key_1; struct pubkey bitcoin_key_2; + u16 len; + u8 *features; }; struct msg_init { u16 gflen; @@ -229,13 +232,15 @@ static void *towire_struct_channel_announcement(const tal_t *ctx, &s->node_id_1, &s->node_id_2, &s->bitcoin_key_1, - &s->bitcoin_key_2); + &s->bitcoin_key_2, + s->len, + s->features); } -static struct msg_channel_announcement *fromwire_struct_channel_announcement(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_channel_announcement *fromwire_struct_channel_announcement(const tal_t *ctx, const void *p, size_t *plen) { struct msg_channel_announcement *s = tal(ctx, struct msg_channel_announcement); - if (!fromwire_channel_announcement(p, plen, + if (!fromwire_channel_announcement(s, p, plen, &s->node_signature_1, &s->node_signature_2, &s->channel_id, @@ -244,8 +249,10 @@ static struct msg_channel_announcement *fromwire_struct_channel_announcement(con &s->node_id_1, &s->node_id_2, &s->bitcoin_key_1, - &s->bitcoin_key_2)) + &s->bitcoin_key_2, + &s->features)) return tal_free(s); + s->len = tal_count(s->features); return s; } @@ -270,7 +277,7 @@ static void *towire_struct_open_channel(const tal_t *ctx, &s->first_per_commitment_point); } -static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, const void *p, size_t *plen) { struct msg_open_channel *s = tal(ctx, struct msg_open_channel); @@ -313,7 +320,7 @@ static void *towire_struct_accept_channel(const tal_t *ctx, &s->first_per_commitment_point); } -static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ctx, const void *p, size_t *plen) { struct msg_accept_channel *s = tal(ctx, struct msg_accept_channel); @@ -338,7 +345,6 @@ static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ct static void *towire_struct_node_announcement(const tal_t *ctx, const struct msg_node_announcement *s) { - towire_pad_arr = s->padding; return towire_node_announcement(ctx, &s->signature, s->timestamp, @@ -346,22 +352,24 @@ static void *towire_struct_node_announcement(const tal_t *ctx, s->port, &s->node_id, s->rgb_color, - s->alias); + s->alias, + s->len, s->features); } -static struct msg_node_announcement *fromwire_struct_node_announcement(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_node_announcement *fromwire_struct_node_announcement(const tal_t *ctx, const void *p, size_t *plen) { struct msg_node_announcement *s = tal(ctx, struct msg_node_announcement); - fromwire_pad_arr = s->padding; - if (!fromwire_node_announcement(p, plen, + if (!fromwire_node_announcement(s, p, plen, &s->signature, &s->timestamp, &s->ipv6, &s->port, &s->node_id, s->rgb_color, - s->alias)) + s->alias, + &s->features)) return tal_free(s); + s->len = tal_count(s->features); return s; } @@ -379,7 +387,7 @@ static void *towire_struct_channel_update(const tal_t *ctx, s->fee_proportional_millionths); } -static struct msg_channel_update *fromwire_struct_channel_update(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_channel_update *fromwire_struct_channel_update(const tal_t *ctx, const void *p, size_t *plen) { struct msg_channel_update *s = tal(ctx, struct msg_channel_update); @@ -407,7 +415,7 @@ static void *towire_struct_funding_locked(const tal_t *ctx, &s->next_per_commitment_point); } -static struct msg_funding_locked *fromwire_struct_funding_locked(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_funding_locked *fromwire_struct_funding_locked(const tal_t *ctx, const void *p, size_t *plen) { struct msg_funding_locked *s = tal(ctx, struct msg_funding_locked); @@ -430,7 +438,7 @@ static void *towire_struct_update_fail_htlc(const tal_t *ctx, s->reason); } -static struct msg_update_fail_htlc *fromwire_struct_update_fail_htlc(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_update_fail_htlc *fromwire_struct_update_fail_htlc(const tal_t *ctx, const void *p, size_t *plen) { struct msg_update_fail_htlc *s = tal(ctx, struct msg_update_fail_htlc); @@ -451,7 +459,7 @@ static void *towire_struct_update_fulfill_htlc(const tal_t *ctx, &s->payment_preimage); } -static struct msg_update_fulfill_htlc *fromwire_struct_update_fulfill_htlc(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_update_fulfill_htlc *fromwire_struct_update_fulfill_htlc(const tal_t *ctx, const void *p, size_t *plen) { struct msg_update_fulfill_htlc *s = tal(ctx, struct msg_update_fulfill_htlc); @@ -473,7 +481,7 @@ static void *towire_struct_commit_sig(const tal_t *ctx, s->htlc_signature); } -static struct msg_commit_sig *fromwire_struct_commit_sig(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_commit_sig *fromwire_struct_commit_sig(const tal_t *ctx, const void *p, size_t *plen) { struct msg_commit_sig *s = tal(ctx, struct msg_commit_sig); @@ -498,7 +506,7 @@ static void *towire_struct_revoke_and_ack(const tal_t *ctx, s->htlc_timeout_signature); } -static struct msg_revoke_and_ack *fromwire_struct_revoke_and_ack(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_revoke_and_ack *fromwire_struct_revoke_and_ack(const tal_t *ctx, const void *p, size_t *plen) { struct msg_revoke_and_ack *s = tal(ctx, struct msg_revoke_and_ack); @@ -522,7 +530,7 @@ static void *towire_struct_funding_signed(const tal_t *ctx, &s->signature); } -static struct msg_funding_signed *fromwire_struct_funding_signed(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_funding_signed *fromwire_struct_funding_signed(const tal_t *ctx, const void *p, size_t *plen) { struct msg_funding_signed *s = tal(ctx, struct msg_funding_signed); @@ -542,7 +550,7 @@ static void *towire_struct_closing_signed(const tal_t *ctx, &s->signature); } -static struct msg_closing_signed *fromwire_struct_closing_signed(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_closing_signed *fromwire_struct_closing_signed(const tal_t *ctx, const void *p, size_t *plen) { struct msg_closing_signed *s = tal(ctx, struct msg_closing_signed); @@ -563,7 +571,7 @@ static void *towire_struct_shutdown(const tal_t *ctx, s->scriptpubkey); } -static struct msg_shutdown *fromwire_struct_shutdown(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_shutdown *fromwire_struct_shutdown(const tal_t *ctx, const void *p, size_t *plen) { struct msg_shutdown *s = tal(ctx, struct msg_shutdown); @@ -585,7 +593,7 @@ static void *towire_struct_funding_created(const tal_t *ctx, &s->signature); } -static struct msg_funding_created *fromwire_struct_funding_created(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_funding_created *fromwire_struct_funding_created(const tal_t *ctx, const void *p, size_t *plen) { struct msg_funding_created *s = tal(ctx, struct msg_funding_created); @@ -607,7 +615,7 @@ static void *towire_struct_error(const tal_t *ctx, s->data); } -static struct msg_error *fromwire_struct_error(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_error *fromwire_struct_error(const tal_t *ctx, const void *p, size_t *plen) { struct msg_error *s = tal(ctx, struct msg_error); @@ -631,7 +639,7 @@ static void *towire_struct_update_add_htlc(const tal_t *ctx, s->onion_routing_packet); } -static struct msg_update_add_htlc *fromwire_struct_update_add_htlc(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_update_add_htlc *fromwire_struct_update_add_htlc(const tal_t *ctx, const void *p, size_t *plen) { struct msg_update_add_htlc *s = tal(ctx, struct msg_update_add_htlc); @@ -655,7 +663,7 @@ static void *towire_struct_update_fee(const tal_t *ctx, s->feerate_per_kw); } -static struct msg_update_fee *fromwire_struct_update_fee(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_update_fee *fromwire_struct_update_fee(const tal_t *ctx, const void *p, size_t *plen) { struct msg_update_fee *s = tal(ctx, struct msg_update_fee); @@ -676,7 +684,7 @@ static void *towire_struct_init(const tal_t *ctx, s->localfeatures); } -static struct msg_init *fromwire_struct_init(const tal_t *ctx, const u8 *p, size_t *plen) +static struct msg_init *fromwire_struct_init(const tal_t *ctx, const void *p, size_t *plen) { struct msg_init *s = tal(ctx, struct msg_init); @@ -693,7 +701,8 @@ static struct msg_init *fromwire_struct_init(const tal_t *ctx, const u8 *p, size static bool channel_announcement_eq(const struct msg_channel_announcement *a, const struct msg_channel_announcement *b) { - return structeq(a, b); + return eq_upto(a, b, len) + && eq_var(a, b, len, features); } static bool funding_locked_eq(const struct msg_funding_locked *a, @@ -806,8 +815,8 @@ static bool update_add_htlc_eq(const struct msg_update_add_htlc *a, static bool node_announcement_eq(const struct msg_node_announcement *a, const struct msg_node_announcement *b) { - return eq_with(a, b, port) - && eq_between(a, b, node_id, alias); + return eq_with(a, b, alias) + && eq_var(a, b, len, features); } /* Try flipping each bit, try running short. */ @@ -857,6 +866,9 @@ int main(void) set_pubkey(&ca.node_id_2); set_pubkey(&ca.bitcoin_key_1); set_pubkey(&ca.bitcoin_key_2); + ca.len = 2; + ca.features = tal_arr(ctx, u8, 2); + memset(ca.features, 2, 2); msg = towire_struct_channel_announcement(ctx, &ca); len = tal_count(msg); @@ -1041,6 +1053,9 @@ int main(void) memset(&na, 2, sizeof(na)); set_pubkey(&na.node_id); + na.len = 2; + na.features = tal_arr(ctx, u8, 2); + memset(na.features, 2, 2); msg = towire_struct_node_announcement(ctx, &na); len = tal_count(msg);