diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index 7610fbd9a..f222e7ae3 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -24,7 +24,7 @@ static bool print_superverbose; bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/cli/test/run-human-mode.c b/cli/test/run-human-mode.c index a3a122b1d..bf7c4a25f 100644 --- a/cli/test/run-human-mode.c +++ b/cli/test/run-human-mode.c @@ -70,7 +70,7 @@ struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UN bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/cli/test/run-large-input.c b/cli/test/run-large-input.c index 7bb642333..40c8d67f9 100644 --- a/cli/test/run-large-input.c +++ b/cli/test/run-large-input.c @@ -70,7 +70,7 @@ struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UN bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/cli/test/run-remove-hint.c b/cli/test/run-remove-hint.c index 3311a9aec..18e21e490 100644 --- a/cli/test/run-remove-hint.c +++ b/cli/test/run-remove-hint.c @@ -73,7 +73,7 @@ struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UN bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/common/channel_id.c b/common/channel_id.c index 517427b74..c2f4ce6e0 100644 --- a/common/channel_id.c +++ b/common/channel_id.c @@ -88,10 +88,10 @@ 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, +bool fromwire_channel_id(const u8 **cursor, size_t *max, struct channel_id *channel_id) { - fromwire(cursor, max, channel_id, sizeof(*channel_id)); + return fromwire(cursor, max, channel_id, sizeof(*channel_id)) != NULL; } REGISTER_TYPE_TO_HEXSTR(channel_id); diff --git a/common/channel_id.h b/common/channel_id.h index 81b6ef024..d6ce8687a 100644 --- a/common/channel_id.h +++ b/common/channel_id.h @@ -38,6 +38,6 @@ void derive_tmp_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, +bool fromwire_channel_id(const u8 **cursor, size_t *max, struct channel_id *channel_id); #endif /* LIGHTNING_COMMON_CHANNEL_ID_H */ diff --git a/common/read_peer_msg.c b/common/read_peer_msg.c index dc58c4a8c..f40c15c46 100644 --- a/common/read_peer_msg.c +++ b/common/read_peer_msg.c @@ -103,6 +103,9 @@ bool is_peer_error(const tal_t *ctx, const u8 *msg, bool is_wrong_channel(const u8 *msg, const struct channel_id *expected, struct channel_id *actual) { + if (!expected) + return false; + if (!extract_channel_id(msg, actual)) return false; diff --git a/common/test/run-blindedpath_enctlv.c b/common/test/run-blindedpath_enctlv.c index a1d32e5a3..9c619b7b3 100644 --- a/common/test/run-blindedpath_enctlv.c +++ b/common/test/run-blindedpath_enctlv.c @@ -50,7 +50,7 @@ struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/common/test/run-blindedpath_onion.c b/common/test/run-blindedpath_onion.c index 191e157af..4b51804ea 100644 --- a/common/test/run-blindedpath_onion.c +++ b/common/test/run-blindedpath_onion.c @@ -56,7 +56,7 @@ struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/common/test/run-bolt12_merkle-json.c b/common/test/run-bolt12_merkle-json.c index eb62379cb..ebdd325d5 100644 --- a/common/test/run-bolt12_merkle-json.c +++ b/common/test/run-bolt12_merkle-json.c @@ -19,7 +19,7 @@ /* AUTOGENERATED MOCKS START */ /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/common/test/run-bolt12_merkle.c b/common/test/run-bolt12_merkle.c index 1610e3ea8..83abb27d1 100644 --- a/common/test/run-bolt12_merkle.c +++ b/common/test/run-bolt12_merkle.c @@ -22,7 +22,7 @@ int features_unsupported(const struct feature_set *our_features UNNEEDED, enum feature_place p UNNEEDED) { fprintf(stderr, "features_unsupported called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_onionmsg_path */ diff --git a/common/test/run-gossmap_local.c b/common/test/run-gossmap_local.c index 605c2cb8d..1d8d19cc9 100644 --- a/common/test/run-gossmap_local.c +++ b/common/test/run-gossmap_local.c @@ -16,7 +16,7 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_bigsize */ diff --git a/common/test/run-route-specific.c b/common/test/run-route-specific.c index e58ef4689..a591f16cd 100644 --- a/common/test/run-route-specific.c +++ b/common/test/run-route-specific.c @@ -25,7 +25,7 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_tlv */ diff --git a/common/test/run-route.c b/common/test/run-route.c index e1fac36eb..ad6fadc8e 100644 --- a/common/test/run-route.c +++ b/common/test/run-route.c @@ -18,7 +18,7 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_tlv */ diff --git a/common/test/run-route_blinding_override_test.c b/common/test/run-route_blinding_override_test.c index 5025c8ff7..b8e2552cb 100644 --- a/common/test/run-route_blinding_override_test.c +++ b/common/test/run-route_blinding_override_test.c @@ -63,7 +63,7 @@ struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/common/test/run-route_blinding_test.c b/common/test/run-route_blinding_test.c index d9f141839..22076d956 100644 --- a/common/test/run-route_blinding_test.c +++ b/common/test/run-route_blinding_test.c @@ -63,7 +63,7 @@ struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index f7896a0c1..f64cd1d4f 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -73,7 +73,7 @@ void free_htlcs(struct lightningd *ld UNNEEDED, const struct channel *channel UN bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 8a8e54769..020921cbd 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -203,7 +203,7 @@ void fixup_htlcs_out(struct lightningd *ld UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_channeld_dev_memleak_reply */ diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 1479612d1..01806dadf 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -22,7 +22,7 @@ const char *feerate_name(enum feerate feerate UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/lightningd/test/run-log-pruning.c b/lightningd/test/run-log-pruning.c index 6bda5f337..3db0a81dc 100644 --- a/lightningd/test/run-log-pruning.c +++ b/lightningd/test/run-log-pruning.c @@ -21,7 +21,7 @@ struct command_result *command_success(struct command *cmd UNNEEDED, bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/lightningd/test/run-shuffle_fds.c b/lightningd/test/run-shuffle_fds.c index 7f9a38060..c2a00d667 100644 --- a/lightningd/test/run-shuffle_fds.c +++ b/lightningd/test/run-shuffle_fds.c @@ -57,7 +57,7 @@ void fatal(const char *fmt UNNEEDED, ...) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/openingd/openingd.c b/openingd/openingd.c index 54f4be846..fede6c811 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -177,7 +177,8 @@ static void set_reserve(struct state *state, const struct amount_sat dust_limit) /*~ 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, - bool am_opener) + bool am_opener, + const struct channel_id *alternate) { /* This is an event loop of its own. That's generally considered poor * form, but we use it in a very limited way. */ @@ -250,7 +251,8 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, * keeps things simple: if we wanted to change this, we would * probably be best with another daemon to de-multiplex them; * this could be connectd itself, in fact. */ - if (is_wrong_channel(msg, &state->channel_id, &actual)) { + if (is_wrong_channel(msg, &state->channel_id, &actual) + && is_wrong_channel(msg, alternate, &actual)) { status_debug("Rejecting %s for unknown channel_id %s", peer_wire_name(fromwire_peektype(msg)), type_to_string(tmpctx, struct channel_id, @@ -401,7 +403,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) "Funding channel start: offered, now waiting for accept_channel"); /* ... since their reply should be immediate. */ - msg = opening_negotiate_msg(tmpctx, state, true); + msg = opening_negotiate_msg(tmpctx, state, true, NULL); if (!msg) return NULL; @@ -652,8 +654,10 @@ static bool funder_finalize_channel_setup(struct state *state, "Funding channel: create first tx, now waiting for their signature"); /* Now they send us their signature for that first commitment - * transaction. */ - msg = opening_negotiate_msg(tmpctx, state, true); + * transaction. Note that errors may refer to the temporary channel + * id (state->channel_id), but success should refer to the new + * "cid" */ + msg = opening_negotiate_msg(tmpctx, state, true, &cid); if (!msg) goto fail; @@ -1052,7 +1056,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) "Incoming channel: accepted, now waiting for them to create funding tx"); /* This is a loop which handles gossip until we get a non-gossip msg */ - msg = opening_negotiate_msg(tmpctx, state, false); + msg = opening_negotiate_msg(tmpctx, state, false, NULL); if (!msg) return NULL; diff --git a/plugins/test/run-funder_policy.c b/plugins/test/run-funder_policy.c index 8efb543e5..a91a58676 100644 --- a/plugins/test/run-funder_policy.c +++ b/plugins/test/run-funder_policy.c @@ -9,7 +9,7 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_node_id */ diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 3999a31cf..2ca73fd94 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -21,7 +21,7 @@ bool feature_offered(const u8 *features UNNEEDED, size_t f UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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_amount_msat_compat */ diff --git a/wire/peer_wire.c b/wire/peer_wire.c index 33156f8be..1ed291db5 100644 --- a/wire/peer_wire.c +++ b/wire/peer_wire.c @@ -1,4 +1,5 @@ #include "config.h" +#include #include static bool unknown_type(enum peer_wire t) @@ -172,38 +173,234 @@ bool is_unknown_msg_discardable(const u8 *cursor) /* Extract channel_id from various packets, return true if possible. */ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id) { - struct amount_sat ignored_sat; - struct amount_msat ignored_msat; - u64 ignored_u64; - u32 ignored_u32; - u16 ignored_u16; - u8 ignored_u8; - struct pubkey ignored_pubkey; - struct bitcoin_blkid ignored_chainhash; - struct secret ignored_secret; - struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(tmpctx); -#if EXPERIMENTAL_FEATURES - struct tlv_channel_reestablish_tlvs *reestab_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx); -#endif + const u8 *cursor = in_pkt; + size_t max = tal_bytelen(in_pkt); + enum peer_wire t; - if (fromwire_channel_reestablish(in_pkt, channel_id, - &ignored_u64, &ignored_u64, - &ignored_secret, &ignored_pubkey + t = fromwire_u16(&cursor, &max); + + /* We carefully quote bolts here, in case anything changes! */ + switch (t) { + /* These ones don't have a channel_id */ + case WIRE_INIT: + case WIRE_PING: + case WIRE_PONG: + case WIRE_CHANNEL_ANNOUNCEMENT: + case WIRE_NODE_ANNOUNCEMENT: + case WIRE_CHANNEL_UPDATE: + case WIRE_QUERY_SHORT_CHANNEL_IDS: + case WIRE_REPLY_SHORT_CHANNEL_IDS_END: + case WIRE_QUERY_CHANNEL_RANGE: + case WIRE_REPLY_CHANNEL_RANGE: + case WIRE_GOSSIP_TIMESTAMP_FILTER: + case WIRE_OBS2_ONION_MESSAGE: + case WIRE_ONION_MESSAGE: + return false; + + /* Special cases: */ + case WIRE_ERROR: + /* BOLT #1: + * 1. type: 17 (`error`) + * 2. data: + * * [`channel_id`:`channel_id`] + *... + * The channel is referred to by `channel_id`, unless + * `channel_id` is 0 + */ + /* fall thru */ + case WIRE_WARNING: + /* BOLT-warning #1: + * 1. type: 1 (`warning`) + * 2. data: + * * [`channel_id`:`channel_id`] + *... + * The channel is referred to by `channel_id`, unless + * `channel_id` is 0 + */ + if (!fromwire_channel_id(&cursor, &max, channel_id)) + return false; + if (memeqzero(channel_id->id, sizeof(channel_id->id))) + return false; + return true; + + case WIRE_OPEN_CHANNEL: + /* BOLT #2: + * 1. type: 32 (`open_channel`) + * 2. data: + * * [`chain_hash`:`chain_hash`] + * * [`32*byte`:`temporary_channel_id`] + */ + case WIRE_OPEN_CHANNEL2: + /* BOLT-dualfund #2: + * 1. type: 64 (`open_channel2`) + * 2. data: + * * [`chain_hash`:`chain_hash`] + * * [`channel_id`:`zerod_channel_id`] + */ + + /* Skip over chain_hash */ + fromwire_pad(&cursor, &max, sizeof(struct bitcoin_blkid)); + + /* These have them at the start */ + case WIRE_TX_ADD_INPUT: + /* BOLT-dualfund #2: + * 1. type: 66 (`tx_add_input`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_TX_ADD_OUTPUT: + /* BOLT-dualfund #2: + * 1. type: 67 (`tx_add_output`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_TX_REMOVE_INPUT: + /* BOLT-dualfund #2: + * 1. type: 68 (`tx_remove_input`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_TX_REMOVE_OUTPUT: + /* BOLT-dualfund #2: + * 1. type: 69 (`tx_remove_output`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_TX_COMPLETE: + /* BOLT-dualfund #2: + * 1. type: 70 (`tx_complete`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_TX_SIGNATURES: + /* BOLT-dualfund #2: + * 1. type: 71 (`tx_signatures`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_ACCEPT_CHANNEL: + /* BOLT #2: + * 1. type: 33 (`accept_channel`) + * 2. data: + * * [`32*byte`:`temporary_channel_id`] + */ + case WIRE_FUNDING_CREATED: + /* BOLT #2: + * 1. type: 34 (`funding_created`) + * 2. data: + * * [`32*byte`:`temporary_channel_id`] + */ + case WIRE_FUNDING_SIGNED: + /* BOLT #2: + * 1. type: 35 (`funding_signed`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_FUNDING_LOCKED: + /* BOLT #2: + * 1. type: 36 (`funding_locked`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_ACCEPT_CHANNEL2: + /* BOLT-dualfund #2: + * 1. type: 65 (`accept_channel2`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_INIT_RBF: + /* BOLT-dualfund #2: + * 1. type: 72 (`init_rbf`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_ACK_RBF: + /* BOLT-dualfund #2: + * 1. type: 73 (`ack_rbf`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_SHUTDOWN: + /* BOLT #2: + * 1. type: 38 (`shutdown`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_CLOSING_SIGNED: + /* BOLT #2: + * 1. type: 39 (`closing_signed`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_UPDATE_ADD_HTLC: + /* BOLT #2: + * 1. type: 128 (`update_add_htlc`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_UPDATE_FULFILL_HTLC: + /* BOLT #2: + * 1. type: 130 (`update_fulfill_htlc`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_UPDATE_FAIL_HTLC: + /* BOLT #2: + * 1. type: 131 (`update_fail_htlc`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_UPDATE_FAIL_MALFORMED_HTLC: + /* BOLT #2: + * 1. type: 135 (`update_fail_malformed_htlc`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_COMMITMENT_SIGNED: + /* BOLT #2: + * 1. type: 132 (`commitment_signed`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_REVOKE_AND_ACK: + /* BOLT #2: + * 1. type: 133 (`revoke_and_ack`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_UPDATE_FEE: + /* BOLT #2: + * 1. type: 134 (`update_fee`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_UPDATE_BLOCKHEIGHT: + /* BOLT-liquidity-ads #2: + * 1. type: 137 (`update_blockheight`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_CHANNEL_REESTABLISH: + /* BOLT #2: + * 1. type: 136 (`channel_reestablish`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ + case WIRE_ANNOUNCEMENT_SIGNATURES: + /* BOLT #7: + * 1. type: 259 (`announcement_signatures`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ #if EXPERIMENTAL_FEATURES - , reestab_tlvs + case WIRE_STFU: + /* BOLT-quiescent #2: + * 1. type: 2 (`stfu`) + * 2. data: + * * [`channel_id`:`channel_id`] + */ #endif - )) - return true; - if (fromwire_open_channel(in_pkt, &ignored_chainhash, - channel_id, &ignored_sat, - &ignored_msat, &ignored_sat, - &ignored_msat, &ignored_sat, - &ignored_msat, &ignored_u32, - &ignored_u16, &ignored_u16, - &ignored_pubkey, &ignored_pubkey, - &ignored_pubkey, &ignored_pubkey, - &ignored_pubkey, &ignored_pubkey, - &ignored_u8, tlvs)) - return true; + return fromwire_channel_id(&cursor, &max, channel_id); + } return false; } diff --git a/wire/test/run-tlvstream.c b/wire/test/run-tlvstream.c index b658d85f8..76b27b612 100644 --- a/wire/test/run-tlvstream.c +++ b/wire/test/run-tlvstream.c @@ -26,7 +26,7 @@ static const char *reason; const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash UNNEEDED) { fprintf(stderr, "chainparams_by_chainhash called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ -void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, +bool 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 */