From 540c68d7cad4ca8295e97e52576f64e13d7a26d0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 May 2018 14:38:11 +0930 Subject: [PATCH] gossipd/gossip_constants.h: Single place for BOLT constants. Signed-off-by: Rusty Russell --- channeld/Makefile | 2 +- channeld/channel.c | 2 +- gossipd/Makefile | 4 ++-- gossipd/gossip_constants.h | 33 +++++++++++++++++++++++++++++++++ gossipd/routing.h | 12 +----------- lightningd/channel_control.c | 1 + lightningd/peer_control.h | 2 -- 7 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 gossipd/gossip_constants.h diff --git a/channeld/Makefile b/channeld/Makefile index 7769e638f..c63071534 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -93,7 +93,7 @@ channeld/gen_full_channel_error_names.h: channeld/full_channel_error.h ccan/ccan ccan/ccan/cdump/tools/cdump-enumstr channeld/full_channel_error.h > $@ -$(LIGHTNINGD_CHANNEL_OBJS): $(LIGHTNINGD_HEADERS) +$(LIGHTNINGD_CHANNEL_OBJS): $(LIGHTNINGD_HEADERS) $(LIGHTNINGD_GOSSIP_CONTROL_HEADERS) channeld/gen_channel_wire.h: $(WIRE_GEN) channeld/channel_wire.csv $(WIRE_GEN) --header $@ channel_wire_type < channeld/channel_wire.csv > $@ diff --git a/channeld/channel.c b/channeld/channel.c index e6e2ae90f..3da6b0b79 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/gossipd/Makefile b/gossipd/Makefile index 8f44fc7f2..cabbab3b1 100644 --- a/gossipd/Makefile +++ b/gossipd/Makefile @@ -7,7 +7,7 @@ gossipd-wrongdir: default: gossipd-all # Control daemon uses this: -LIGHTNINGD_GOSSIP_CONTROL_HEADERS := gossipd/gen_gossip_wire.h +LIGHTNINGD_GOSSIP_CONTROL_HEADERS := gossipd/gen_gossip_wire.h gossipd/gossip_constants.h LIGHTNINGD_GOSSIP_CONTROL_SRC := gossipd/gen_gossip_wire.c LIGHTNINGD_GOSSIP_CONTROL_OBJS := $(LIGHTNINGD_GOSSIP_CONTROL_SRC:.c=.o) @@ -28,7 +28,7 @@ LIGHTNINGD_GOSSIP_OBJS := $(LIGHTNINGD_GOSSIP_SRC:.c=.o) # Make sure these depend on everything. ALL_OBJS += $(LIGHTNINGD_GOSSIP_OBJS) ALL_PROGRAMS += lightningd/lightning_gossipd -ALL_GEN_HEADERS += $(LIGHTNINGD_GOSSIP_CONTROL_HEADERS) +ALL_GEN_HEADERS += gossipd/gen_gossip_wire.h # For checking LIGHTNINGD_GOSSIP_ALLSRC_NOGEN := $(filter-out gossipd/gen_%, $(LIGHTNINGD_GOSSIP_CLIENT_SRC) $(LIGHTNINGD_GOSSIP_SRC)) diff --git a/gossipd/gossip_constants.h b/gossipd/gossip_constants.h new file mode 100644 index 000000000..4b1e0c040 --- /dev/null +++ b/gossipd/gossip_constants.h @@ -0,0 +1,33 @@ +#ifndef LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H +#define LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H + +/* BOLT #4: + * + * - Length: the maximum route length is limited to 20 hops. + *... + * 1. type: `onion_packet` + * 2. data: + * * [`1`:`version`] + * * [`33`:`public_key`] + * * [`20*65`:`hops_data`] + */ +#define ROUTING_MAX_HOPS 20 + +/* BOLT #7: + * + * The `flags` bitfield...individual bits: + *... + * | 0 | `direction` | Direction this update refers to. | + * | 1 | `disable` | Disable the channel. | + */ +#define ROUTING_FLAGS_DIRECTION (1 << 0) +#define ROUTING_FLAGS_DISABLED (1 << 1) + +/* BOLT #7: + * + * - MUST NOT send `announcement_signatures` messages until `funding_locked` + * has been sent AND the funding transaction has at least six confirmations. + */ +#define ANNOUNCE_MIN_DEPTH 6 + +#endif /* LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H */ diff --git a/gossipd/routing.h b/gossipd/routing.h index cc6257756..83ea09aa6 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -6,21 +6,11 @@ #include #include #include +#include #include #include #include -#define ROUTING_MAX_HOPS 20 -/* BOLT #7: - * - * The `flags` bitfield...individual bits: - *... - * | 0 | `direction` | Direction this update refers to. | - * | 1 | `disable` | Disable the channel. | - */ -#define ROUTING_FLAGS_DIRECTION (1 << 0) -#define ROUTING_FLAGS_DISABLED (1 << 1) - struct half_chan { /* Cached `channel_update` which initialized below (or NULL) */ const u8 *channel_update; diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 6bc694e7c..7d5905710 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index c87bed3f9..642fbc02b 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -14,8 +14,6 @@ #include #include -#define ANNOUNCE_MIN_DEPTH 6 - struct crypto_state; struct peer {