From 924aaf180e61dcd6c254c1c2aab32bf2e978a73d Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 10 Dec 2020 13:52:29 -0600 Subject: [PATCH] temp_channel_id: move to common We actually do need this for dualopend's, specifically for returning errors to open_channel2 --- common/channel_id.c | 18 ++++++++++++++++++ common/channel_id.h | 2 ++ openingd/openingd.c | 17 ----------------- wire/test/Makefile | 1 + 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/common/channel_id.c b/common/channel_id.c index eab9fa225..74e55b291 100644 --- a/common/channel_id.c +++ b/common/channel_id.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,23 @@ void derive_channel_id_v2(struct channel_id *channel_id, memcpy(channel_id, &sha, sizeof(*channel_id)); } +/* BOLT #2: + * + * The sending node: + *... + * - MUST ensure `temporary_channel_id` is unique from any other channel ID + * with the same peer. + */ +void temporary_channel_id(struct channel_id *channel_id) +{ + size_t i; + + /* Randomness FTW. */ + for (i = 0; i < sizeof(*channel_id); i++) + channel_id->id[i] = pseudorand(256); +} + + void towire_channel_id(u8 **pptr, const struct channel_id *channel_id) { towire(pptr, channel_id, sizeof(*channel_id)); diff --git a/common/channel_id.h b/common/channel_id.h index 4ff359cca..78e1109bd 100644 --- a/common/channel_id.h +++ b/common/channel_id.h @@ -26,6 +26,8 @@ void derive_channel_id(struct channel_id *channel_id, void derive_channel_id_v2(struct channel_id *channel_id, const struct pubkey *basepoint_1, const struct pubkey *basepoint_2); + +void temporary_channel_id(struct channel_id *channel_id); /* Marshalling/unmarshalling functions */ void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); void fromwire_channel_id(const u8 **cursor, size_t *max, diff --git a/openingd/openingd.c b/openingd/openingd.c index 3bb7a10b2..81e53c497 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -214,22 +213,6 @@ static void set_reserve(struct state *state, const struct amount_sat dust_limit) = dust_limit; } -/* BOLT #2: - * - * The sending node: - *... - * - MUST ensure `temporary_channel_id` is unique from any other channel ID - * with the same peer. - */ -static void temporary_channel_id(struct channel_id *channel_id) -{ - size_t i; - - /* Randomness FTW. */ - for (i = 0; i < sizeof(*channel_id); i++) - channel_id->id[i] = pseudorand(256); -} - /*~ Handle random messages we might get during opening negotiation, (eg. gossip) * returning the first non-handled one, or NULL if we aborted negotiation. */ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, diff --git a/wire/test/Makefile b/wire/test/Makefile index ebfc080fd..7bbf3349d 100644 --- a/wire/test/Makefile +++ b/wire/test/Makefile @@ -10,6 +10,7 @@ ALL_C_SOURCES += $(WIRE_TEST_SRC) ALL_TEST_PROGRAMS += $(WIRE_TEST_PROGRAMS) WIRE_TEST_COMMON_OBJS := \ + common/pseudorand.o \ common/setup.o \ common/utils.o