From fda5f0b42736612e8e6b8025c558d7ca1665f4c9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 15 May 2020 19:59:53 +0930 Subject: [PATCH] common/channel_id: move channel_id into its own file. The definition was in wire/wire.h, and helper functions in fromwire.c! Signed-off-by: Rusty Russell --- channeld/Makefile | 1 + channeld/test/run-commit_tx.c | 8 ++++++ channeld/test/run-full_channel.c | 8 ++++++ cli/test/run-large-input.c | 8 ++++++ cli/test/run-remove-hint.c | 8 ++++++ closingd/Makefile | 1 + common/Makefile | 1 + common/channel_id.c | 26 ++++++++++++++++++ common/channel_id.h | 29 +++++++++++++++++++++ common/coin_mvt.h | 1 + common/json_helpers.c | 1 + common/json_tok.c | 1 + common/peer_status_wire.csv | 1 + connectd/Makefile | 1 + devtools/Makefile | 1 + gossipd/Makefile | 1 + gossipd/test/run-bench-find_route.c | 7 +++++ gossipd/test/run-crc32_of_update.c | 7 +++++ gossipd/test/run-extended-info.c | 7 +++++ gossipd/test/run-find_route-specific.c | 7 +++++ gossipd/test/run-find_route.c | 7 +++++ gossipd/test/run-next_block_range.c | 7 +++++ gossipd/test/run-overlong.c | 7 +++++ gossipd/test/run-txout_failure.c | 7 +++++ hsmd/Makefile | 1 + lightningd/Makefile | 1 + lightningd/json.c | 1 + lightningd/options.c | 1 + lightningd/test/run-find_my_abspath.c | 7 +++++ lightningd/test/run-invoice-select-inchan.c | 11 ++++++++ lightningd/test/run-jsonrpc.c | 7 +++++ lightningd/test/run-log-pruning.c | 7 +++++ onchaind/Makefile | 1 + openingd/Makefile | 1 + openingd/opening_wire.csv | 1 + wallet/test/run-wallet.c | 4 +++ wire/Makefile | 2 +- wire/fromwire.c | 24 ----------------- wire/test/run-peer-wire.c | 7 +++++ wire/test/run-tlvstream.c | 7 +++++ wire/towire.c | 5 ---- wire/wire.h | 11 -------- 42 files changed, 211 insertions(+), 41 deletions(-) create mode 100644 common/channel_id.c create mode 100644 common/channel_id.h diff --git a/channeld/Makefile b/channeld/Makefile index 5929c53a46fa..fc563c9cb01b 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -42,6 +42,7 @@ CHANNELD_COMMON_OBJS := \ common/bip32.o \ common/blinding.o \ common/channel_config.o \ + common/channel_id.o \ common/crypto_state.o \ common/crypto_sync.o \ common/cryptomsg.o \ diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index c3f0d5982f71..b7505919d1fd 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -13,6 +13,7 @@ static bool print_superverbose; #include #include #include +#include #include #include @@ -26,12 +27,19 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN /* Generated stub for bigsize_put */ size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) { fprintf(stderr, "bigsize_put called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for status_fmt */ void status_fmt(enum log_level level UNNEEDED, const struct node_id *peer UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* bitcoind loves its backwards txids! */ diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 8bbd46ee965a..e358f4e67074 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,10 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN /* Generated stub for bigsize_put */ size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) { fprintf(stderr, "bigsize_put called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for memleak_add_helper_ */ void memleak_add_helper_(const tal_t *p UNNEEDED, void (*cb)(struct htable *memtable UNNEEDED, const tal_t *)){ } @@ -31,6 +36,9 @@ void memleak_remove_htable(struct htable *memtable UNNEEDED, const struct htable void status_failed(enum status_failreason code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_failed called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ void status_fmt(enum log_level level UNUSED, diff --git a/cli/test/run-large-input.c b/cli/test/run-large-input.c index d9c9fcd866e9..812296b3affa 100644 --- a/cli/test/run-large-input.c +++ b/cli/test/run-large-input.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,10 @@ size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for json_add_member */ void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, @@ -85,6 +90,9 @@ void json_object_end(struct json_stream *js UNNEEDED) /* Generated stub for json_object_start */ void json_object_start(struct json_stream *ks UNNEEDED, const char *fieldname UNNEEDED) { fprintf(stderr, "json_object_start called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for version_and_exit */ char *version_and_exit(const void *unused UNNEEDED) { fprintf(stderr, "version_and_exit called!\n"); abort(); } diff --git a/cli/test/run-remove-hint.c b/cli/test/run-remove-hint.c index 57541e6ca060..19d0c7622639 100644 --- a/cli/test/run-remove-hint.c +++ b/cli/test/run-remove-hint.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,10 @@ size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for json_add_member */ void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, @@ -88,6 +93,9 @@ void json_object_end(struct json_stream *js UNNEEDED) /* Generated stub for json_object_start */ void json_object_start(struct json_stream *ks UNNEEDED, const char *fieldname UNNEEDED) { fprintf(stderr, "json_object_start called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for version_and_exit */ char *version_and_exit(const void *unused UNNEEDED) { fprintf(stderr, "version_and_exit called!\n"); abort(); } diff --git a/closingd/Makefile b/closingd/Makefile index 7b3877c7f620..99a8e5f748d7 100644 --- a/closingd/Makefile +++ b/closingd/Makefile @@ -46,6 +46,7 @@ CLOSINGD_COMMON_OBJS := \ common/base32.o \ common/bigsize.o \ common/bip32.o \ + common/channel_id.o \ common/close_tx.o \ common/crypto_state.o \ common/crypto_sync.o \ diff --git a/common/Makefile b/common/Makefile index cf77ce064838..a374bda05df8 100644 --- a/common/Makefile +++ b/common/Makefile @@ -10,6 +10,7 @@ COMMON_SRC_NOGEN := \ common/blinding.c \ common/bolt11.c \ common/channel_config.c \ + common/channel_id.c \ common/coin_mvt.c \ common/close_tx.c \ common/configdir.c \ diff --git a/common/channel_id.c b/common/channel_id.c new file mode 100644 index 000000000000..71069bf652e7 --- /dev/null +++ b/common/channel_id.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +void derive_channel_id(struct channel_id *channel_id, + const struct bitcoin_txid *txid, u16 txout) +{ + BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid)); + memcpy(channel_id, txid, sizeof(*channel_id)); + channel_id->id[sizeof(*channel_id)-2] ^= txout >> 8; + channel_id->id[sizeof(*channel_id)-1] ^= txout; +} + +void towire_channel_id(u8 **pptr, const struct channel_id *channel_id) +{ + towire(pptr, channel_id, sizeof(*channel_id)); +} + +void fromwire_channel_id(const u8 **cursor, size_t *max, + struct channel_id *channel_id) +{ + fromwire(cursor, max, channel_id, sizeof(*channel_id)); +} + +REGISTER_TYPE_TO_HEXSTR(channel_id); diff --git a/common/channel_id.h b/common/channel_id.h new file mode 100644 index 000000000000..514186bcebe3 --- /dev/null +++ b/common/channel_id.h @@ -0,0 +1,29 @@ +#ifndef LIGHTNING_COMMON_CHANNEL_ID_H +#define LIGHTNING_COMMON_CHANNEL_ID_H +#include "config.h" +#include +#include + +struct bitcoin_txid; + +/* BOLT #2: + * + * This message introduces the `channel_id` to identify the channel. It's + * derived from the funding transaction by combining the `funding_txid` and + * the `funding_output_index`, using big-endian exclusive-OR + * (i.e. `funding_output_index` alters the last 2 bytes). + */ +struct channel_id { + u8 id[32]; +}; +/* Define channel_id_eq (no padding) */ +STRUCTEQ_DEF(channel_id, 0, id); + +void derive_channel_id(struct channel_id *channel_id, + const struct bitcoin_txid *txid, u16 txout); + +/* 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, + struct channel_id *channel_id); +#endif /* LIGHTNING_COMMON_CHANNEL_ID_H */ diff --git a/common/coin_mvt.h b/common/coin_mvt.h index 6c51a0f94fde..319e0a08c2a7 100644 --- a/common/coin_mvt.h +++ b/common/coin_mvt.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/common/json_helpers.c b/common/json_helpers.c index 60ef36c85912..2d04d492498d 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/common/json_tok.c b/common/json_tok.c index a08de9e0e157..b7d8c9bb8577 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/common/peer_status_wire.csv b/common/peer_status_wire.csv index 57e9187253bc..27b5792f5d6c 100644 --- a/common/peer_status_wire.csv +++ b/common/peer_status_wire.csv @@ -1,3 +1,4 @@ +#include #include # An error occurred: if error_for_them, that to go to them. diff --git a/connectd/Makefile b/connectd/Makefile index 28d41d7e4dd9..e57178a9c449 100644 --- a/connectd/Makefile +++ b/connectd/Makefile @@ -44,6 +44,7 @@ CONNECTD_COMMON_OBJS := \ common/bech32_util.o \ common/bigsize.o \ common/bip32.o \ + common/channel_id.o \ common/crypto_state.o \ common/cryptomsg.o \ common/daemon.o \ diff --git a/devtools/Makefile b/devtools/Makefile index 579483869a25..db787722f1aa 100644 --- a/devtools/Makefile +++ b/devtools/Makefile @@ -17,6 +17,7 @@ DEVTOOLS_COMMON_OBJS := \ common/bech32_util.o \ common/bigsize.o \ common/bolt11.o \ + common/channel_id.o \ common/crypto_state.o \ common/decode_array.o \ common/features.o \ diff --git a/gossipd/Makefile b/gossipd/Makefile index 7de9fae19ec6..c8df85f8a379 100644 --- a/gossipd/Makefile +++ b/gossipd/Makefile @@ -46,6 +46,7 @@ GOSSIPD_COMMON_OBJS := \ common/bech32_util.o \ common/bigsize.o \ common/bip32.o \ + common/channel_id.o \ common/crypto_state.o \ common/cryptomsg.o \ common/daemon.o \ diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 89c26b483e92..b3e99ad795ad 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -37,6 +37,10 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_amount */ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_sat *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_amount called!\n"); abort(); } @@ -96,6 +100,9 @@ char *sanitize_error(const tal_t *ctx UNNEEDED, const u8 *errmsg UNNEEDED, void status_failed(enum status_failreason code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_failed called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-crc32_of_update.c b/gossipd/test/run-crc32_of_update.c index 6f3f99a36654..d9dde74136d9 100644 --- a/gossipd/test/run-crc32_of_update.c +++ b/gossipd/test/run-crc32_of_update.c @@ -31,6 +31,10 @@ struct peer *find_peer(struct daemon *daemon UNNEEDED, const struct node_id *id /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_dev_set_max_scids_encode_size */ bool fromwire_gossip_dev_set_max_scids_encode_size(const void *p UNNEEDED, u32 *max UNNEEDED) { fprintf(stderr, "fromwire_gossip_dev_set_max_scids_encode_size called!\n"); abort(); } @@ -118,6 +122,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-extended-info.c b/gossipd/test/run-extended-info.c index 76d7b1ed73f7..5461669d02c7 100644 --- a/gossipd/test/run-extended-info.c +++ b/gossipd/test/run-extended-info.c @@ -36,6 +36,10 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *e /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_dev_set_max_scids_encode_size */ bool fromwire_gossip_dev_set_max_scids_encode_size(const void *p UNNEEDED, u32 *max UNNEEDED) { fprintf(stderr, "fromwire_gossip_dev_set_max_scids_encode_size called!\n"); abort(); } @@ -88,6 +92,9 @@ void queue_peer_from_store(struct peer *peer UNNEEDED, /* Generated stub for queue_peer_msg */ void queue_peer_msg(struct peer *peer UNNEEDED, const u8 *msg TAKES UNNEEDED) { fprintf(stderr, "queue_peer_msg called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 3eaf9dd8095f..56f4ef42ce75 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -24,6 +24,10 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_amount */ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_sat *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_amount called!\n"); abort(); } @@ -83,6 +87,9 @@ char *sanitize_error(const tal_t *ctx UNNEEDED, const u8 *errmsg UNNEEDED, void status_failed(enum status_failreason code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_failed called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 513e42df3411..75d80b4d27e4 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -24,6 +24,10 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_amount */ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_sat *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_amount called!\n"); abort(); } @@ -83,6 +87,9 @@ char *sanitize_error(const tal_t *ctx UNNEEDED, const u8 *errmsg UNNEEDED, void status_failed(enum status_failreason code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_failed called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-next_block_range.c b/gossipd/test/run-next_block_range.c index 0395c292cdfb..048c08811767 100644 --- a/gossipd/test/run-next_block_range.c +++ b/gossipd/test/run-next_block_range.c @@ -10,6 +10,10 @@ /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for json_add_member */ void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, @@ -73,6 +77,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for would_ratelimit_cupdate */ bool would_ratelimit_cupdate(struct routing_state *rstate UNNEEDED, const struct half_chan *hc UNNEEDED, diff --git a/gossipd/test/run-overlong.c b/gossipd/test/run-overlong.c index 262f70d9ce96..5160e33c01a3 100644 --- a/gossipd/test/run-overlong.c +++ b/gossipd/test/run-overlong.c @@ -24,6 +24,10 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_amount */ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_sat *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_amount called!\n"); abort(); } @@ -83,6 +87,9 @@ char *sanitize_error(const tal_t *ctx UNNEEDED, const u8 *errmsg UNNEEDED, void status_failed(enum status_failreason code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_failed called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-txout_failure.c b/gossipd/test/run-txout_failure.c index 8ff9712c9ab1..528b83d2f03c 100644 --- a/gossipd/test/run-txout_failure.c +++ b/gossipd/test/run-txout_failure.c @@ -12,6 +12,10 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_gossipd_local_add_channel */ bool fromwire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED, u8 **features UNNEEDED) { fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); } @@ -95,6 +99,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_errorfmt */ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/hsmd/Makefile b/hsmd/Makefile index 9b4c49c25bf4..ee89860e773f 100644 --- a/hsmd/Makefile +++ b/hsmd/Makefile @@ -16,6 +16,7 @@ HSMD_COMMON_OBJS := \ common/amount.o \ common/bigsize.o \ common/bip32.o \ + common/channel_id.o \ common/daemon.o \ common/daemon_conn.o \ common/derive_basepoints.o \ diff --git a/lightningd/Makefile b/lightningd/Makefile index 51c69531ee94..846af1314c53 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -24,6 +24,7 @@ LIGHTNINGD_COMMON_OBJS := \ common/bip32.o \ common/blinding.o \ common/bolt11.o \ + common/channel_id.o \ common/channel_config.o \ common/coin_mvt.o \ common/configdir.o \ diff --git a/lightningd/json.c b/lightningd/json.c index c1752556e9f6..4b790761d5a0 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/lightningd/options.c b/lightningd/options.c index d8c5d9cfa2bc..aeba673cc6b9 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index ddef0220c5cd..0c231c3bb314 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -81,6 +81,10 @@ void free_htlcs(struct lightningd *ld UNNEEDED, const struct channel *channel UN /* Generated stub for free_unreleased_txs */ void free_unreleased_txs(struct wallet *w UNNEEDED) { fprintf(stderr, "free_unreleased_txs called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_status_fail */ bool fromwire_status_fail(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, enum status_failreason *failreason UNNEEDED, wirestring **desc UNNEEDED) { fprintf(stderr, "fromwire_status_fail called!\n"); abort(); } @@ -213,6 +217,9 @@ void setup_topology(struct chain_topology *topology UNNEEDED, struct timers *tim /* Generated stub for timer_expired */ void timer_expired(tal_t *ctx UNNEEDED, struct timer *timer UNNEEDED) { fprintf(stderr, "timer_expired called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for txfilter_add_derkey */ void txfilter_add_derkey(struct txfilter *filter UNNEEDED, const u8 derkey[PUBKEY_CMPR_LEN]) diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 496f2fa53030..130c66eaa646 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -81,6 +81,10 @@ void connect_succeeded(struct lightningd *ld UNNEEDED, const struct peer *peer U void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED, const struct wireaddr_internal *addrhint TAKES UNNEEDED) { fprintf(stderr, "delay_then_reconnect called!\n"); abort(); } +/* Generated stub for derive_channel_id */ +void derive_channel_id(struct channel_id *channel_id UNNEEDED, + const struct bitcoin_txid *txid UNNEEDED, u16 txout UNNEEDED) +{ fprintf(stderr, "derive_channel_id called!\n"); abort(); } /* Generated stub for dup_fee_states */ struct fee_states *dup_fee_states(const tal_t *ctx UNNEEDED, const struct fee_states *fee_states TAKES UNNEEDED) @@ -110,6 +114,10 @@ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr /* Generated stub for fromwire_channel_dev_memleak_reply */ bool fromwire_channel_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED) { fprintf(stderr, "fromwire_channel_dev_memleak_reply called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for fromwire_connect_peer_connected */ bool fromwire_connect_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct per_peer_state **pps UNNEEDED, u8 **features UNNEEDED) { fprintf(stderr, "fromwire_connect_peer_connected called!\n"); abort(); } @@ -402,6 +410,9 @@ u8 *towire_channel_dev_memleak(const tal_t *ctx UNNEEDED) /* Generated stub for towire_channel_dev_reenable_commit */ u8 *towire_channel_dev_reenable_commit(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_channel_dev_reenable_commit called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* Generated stub for towire_channel_send_shutdown */ u8 *towire_channel_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED) { fprintf(stderr, "towire_channel_send_shutdown called!\n"); abort(); } diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 8f296aeb8064..ed283b3507c9 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -27,6 +27,10 @@ const char *feerate_name(enum feerate feerate UNNEEDED) /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for json_to_pubkey */ bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct pubkey *pubkey UNNEEDED) @@ -104,6 +108,9 @@ struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name bool plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, tal_t *cb_arg STEALS UNNEEDED) { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ bool deprecated_apis; diff --git a/lightningd/test/run-log-pruning.c b/lightningd/test/run-log-pruning.c index c9b4cb3da693..2ee49dfe19f6 100644 --- a/lightningd/test/run-log-pruning.c +++ b/lightningd/test/run-log-pruning.c @@ -25,6 +25,10 @@ struct command_result *command_success(struct command *cmd UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } /* Generated stub for json_add_member */ void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, @@ -64,6 +68,9 @@ void notify_warning(struct lightningd *ld UNNEEDED, struct log_entry *l UNNEEDED bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t params[] UNNEEDED, ...) { fprintf(stderr, "param called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ int main(void) diff --git a/onchaind/Makefile b/onchaind/Makefile index 3985cca6e376..3e2ff59b104b 100644 --- a/onchaind/Makefile +++ b/onchaind/Makefile @@ -51,6 +51,7 @@ ONCHAIND_COMMON_OBJS := \ common/bigsize.o \ common/bip32.o \ common/coin_mvt.o \ + common/channel_id.o \ common/daemon.o \ common/daemon_conn.o \ common/derive_basepoints.o \ diff --git a/openingd/Makefile b/openingd/Makefile index fb787195e9b6..65d49cfbe1ca 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -40,6 +40,7 @@ OPENINGD_COMMON_OBJS := \ common/bigsize.o \ common/bip32.o \ common/channel_config.o \ + common/channel_id.o \ common/crypto_state.o \ common/crypto_sync.o \ common/cryptomsg.o \ diff --git a/openingd/opening_wire.csv b/openingd/opening_wire.csv index 8af31da54180..95e531e6df7b 100644 --- a/openingd/opening_wire.csv +++ b/openingd/opening_wire.csv @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 8cdda0b73a1a..4e22fd28de74 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -98,6 +98,10 @@ struct onionreply *create_onionreply(const tal_t *ctx UNNEEDED, void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED, const struct wireaddr_internal *addrhint TAKES UNNEEDED) { fprintf(stderr, "delay_then_reconnect called!\n"); abort(); } +/* Generated stub for derive_channel_id */ +void derive_channel_id(struct channel_id *channel_id UNNEEDED, + const struct bitcoin_txid *txid UNNEEDED, u16 txout UNNEEDED) +{ fprintf(stderr, "derive_channel_id called!\n"); abort(); } /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/wire/Makefile b/wire/Makefile index cb687f177882..02d2de0dda80 100644 --- a/wire/Makefile +++ b/wire/Makefile @@ -74,7 +74,7 @@ wire/gen_peer_wire_csv wire/gen_onion_wire_csv: config.vars # for testing and to prevent compile error about them being unused. # This will be easier if test vectors are moved to separate files. wire/gen_peer_wire.h: wire/gen_peer_wire_csv $(WIRE_BOLT_DEPS) wire/Makefile - $(BOLT_GEN) -s --expose-tlv-type=n1 --expose-tlv-type=n2 --page header $@ wire_type < $< > $@ + $(BOLT_GEN) --include='common/channel_id.h' -s --expose-tlv-type=n1 --expose-tlv-type=n2 --page header $@ wire_type < $< > $@ wire/gen_peer_wire.c: wire/gen_peer_wire_csv $(WIRE_BOLT_DEPS) wire/Makefile $(BOLT_GEN) -s --expose-tlv-type=n1 --expose-tlv-type=n2 --page impl ${@:.c=.h} wire_type < $< > $@ diff --git a/wire/fromwire.c b/wire/fromwire.c index 2938bcc0fdbd..54a4c16b35c1 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -242,12 +242,6 @@ void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor, fromwire_fail(cursor, max); } -void fromwire_channel_id(const u8 **cursor, size_t *max, - struct channel_id *channel_id) -{ - fromwire(cursor, max, channel_id, sizeof(*channel_id)); -} - void fromwire_short_channel_id(const u8 **cursor, size_t *max, struct short_channel_id *short_channel_id) { @@ -347,24 +341,6 @@ char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max) return NULL; } -REGISTER_TYPE_TO_HEXSTR(channel_id); - -/* BOLT #2: - * - * This message introduces the `channel_id` to identify the channel. It's - * derived from the funding transaction by combining the `funding_txid` and - * the `funding_output_index`, using big-endian exclusive-OR - * (i.e. `funding_output_index` alters the last 2 bytes). - */ -void derive_channel_id(struct channel_id *channel_id, - const struct bitcoin_txid *txid, u16 txout) -{ - BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid)); - memcpy(channel_id, txid, sizeof(*channel_id)); - channel_id->id[sizeof(*channel_id)-2] ^= txout >> 8; - channel_id->id[sizeof(*channel_id)-1] ^= txout; -} - struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx, const u8 **cursor, size_t *max) { diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index a848bb00df90..bec4ecd85b93 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -34,6 +34,13 @@ bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED) struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED) { fprintf(stderr, "amount_sat_sub called!\n"); abort(); } +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* memsetting pubkeys doesn't work */ diff --git a/wire/test/run-tlvstream.c b/wire/test/run-tlvstream.c index 14ecf9c670f1..3dde124f05b4 100644 --- a/wire/test/run-tlvstream.c +++ b/wire/test/run-tlvstream.c @@ -17,6 +17,13 @@ static const char *reason; #include /* AUTOGENERATED MOCKS START */ +/* Generated stub for fromwire_channel_id */ +void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_id */ +void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) +{ fprintf(stderr, "towire_channel_id called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ diff --git a/wire/towire.c b/wire/towire.c index 889aae8c4bbf..1a351f960cb9 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -150,11 +150,6 @@ void towire_secp256k1_ecdsa_recoverable_signature(u8 **pptr, towire_u8(pptr, recid); } -void towire_channel_id(u8 **pptr, const struct channel_id *channel_id) -{ - towire(pptr, channel_id, sizeof(*channel_id)); -} - void towire_short_channel_id(u8 **pptr, const struct short_channel_id *short_channel_id) { diff --git a/wire/wire.h b/wire/wire.h index a9bc8e89d9d7..3d4f3294ee43 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -18,11 +18,6 @@ #include #include -struct channel_id { - u8 id[32]; -}; -/* Define channel_id_eq (no padding) */ -STRUCTEQ_DEF(channel_id, 0, id); struct bitcoin_blkid; struct bitcoin_signature; @@ -41,9 +36,6 @@ typedef bigsize varint; #define fromwire_varint fromwire_bigsize #define towire_varint towire_bigsize -void derive_channel_id(struct channel_id *channel_id, - const struct bitcoin_txid *txid, u16 txout); - /* Read the type; returns -1 if not long enough. cursor is a tal ptr. */ int fromwire_peektype(const u8 *cursor); const void *fromwire_fail(const u8 **cursor, size_t *max); @@ -57,7 +49,6 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr, const secp256k1_ecdsa_signature *signature); void towire_secp256k1_ecdsa_recoverable_signature(u8 **pptr, const secp256k1_ecdsa_recoverable_signature *rsig); -void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); void towire_short_channel_id(u8 **pptr, const struct short_channel_id *short_channel_id); void towire_short_channel_id_dir(u8 **pptr, @@ -114,8 +105,6 @@ void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max, void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor, size_t *max, secp256k1_ecdsa_recoverable_signature *rsig); -void fromwire_channel_id(const u8 **cursor, size_t *max, - struct channel_id *channel_id); void fromwire_short_channel_id(const u8 **cursor, size_t *max, struct short_channel_id *short_channel_id); void fromwire_short_channel_id_dir(const u8 **cursor, size_t *max,