common: generalize extract_channel_id().

connectd is going to end up using this do demux; make it fast and complete.

Fixing this reveals a problem in openingd: it now extracts the channel_id
from funding_signed (which is where we transition off the temporary), and
gets upset.  So fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-12-28 09:54:09 +10:30
parent 5111f39d2a
commit 35e3c1866e
26 changed files with 264 additions and 60 deletions

View File

@@ -24,7 +24,7 @@ static bool print_superverbose;
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -88,10 +88,10 @@ void towire_channel_id(u8 **pptr, const struct channel_id *channel_id)
towire(pptr, channel_id, sizeof(*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) 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); REGISTER_TYPE_TO_HEXSTR(channel_id);

View File

@@ -38,6 +38,6 @@ void derive_tmp_channel_id(struct channel_id *channel_id,
/* Marshalling/unmarshalling functions */ /* Marshalling/unmarshalling functions */
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); 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); struct channel_id *channel_id);
#endif /* LIGHTNING_COMMON_CHANNEL_ID_H */ #endif /* LIGHTNING_COMMON_CHANNEL_ID_H */

View File

@@ -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, bool is_wrong_channel(const u8 *msg, const struct channel_id *expected,
struct channel_id *actual) struct channel_id *actual)
{ {
if (!expected)
return false;
if (!extract_channel_id(msg, actual)) if (!extract_channel_id(msg, actual))
return false; return false;

View File

@@ -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) struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -19,7 +19,7 @@
/* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -22,7 +22,7 @@ int features_unsupported(const struct feature_set *our_features UNNEEDED,
enum feature_place p UNNEEDED) enum feature_place p UNNEEDED)
{ fprintf(stderr, "features_unsupported called!\n"); abort(); } { fprintf(stderr, "features_unsupported called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_onionmsg_path */ /* Generated stub for fromwire_onionmsg_path */

View File

@@ -16,7 +16,7 @@
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for towire_bigsize */ /* Generated stub for towire_bigsize */

View File

@@ -25,7 +25,7 @@
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_tlv */ /* Generated stub for fromwire_tlv */

View File

@@ -18,7 +18,7 @@
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_tlv */ /* Generated stub for fromwire_tlv */

View File

@@ -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) struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } { fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -203,7 +203,7 @@ void fixup_htlcs_out(struct lightningd *ld UNNEEDED)
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_channeld_dev_memleak_reply */ /* Generated stub for fromwire_channeld_dev_memleak_reply */

View File

@@ -22,7 +22,7 @@ const char *feerate_name(enum feerate feerate UNNEEDED)
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -57,7 +57,7 @@ void fatal(const char *fmt UNNEEDED, ...)
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) /*~ Handle random messages we might get during opening negotiation, (eg. gossip)
* returning the first non-handled one, or NULL if we aborted negotiation. */ * returning the first non-handled one, or NULL if we aborted negotiation. */
static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, 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 /* This is an event loop of its own. That's generally considered poor
* form, but we use it in a very limited way. */ * 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 * keeps things simple: if we wanted to change this, we would
* probably be best with another daemon to de-multiplex them; * probably be best with another daemon to de-multiplex them;
* this could be connectd itself, in fact. */ * 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", status_debug("Rejecting %s for unknown channel_id %s",
peer_wire_name(fromwire_peektype(msg)), peer_wire_name(fromwire_peektype(msg)),
type_to_string(tmpctx, struct channel_id, 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"); "Funding channel start: offered, now waiting for accept_channel");
/* ... since their reply should be immediate. */ /* ... since their reply should be immediate. */
msg = opening_negotiate_msg(tmpctx, state, true); msg = opening_negotiate_msg(tmpctx, state, true, NULL);
if (!msg) if (!msg)
return NULL; 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"); "Funding channel: create first tx, now waiting for their signature");
/* Now they send us their signature for that first commitment /* Now they send us their signature for that first commitment
* transaction. */ * transaction. Note that errors may refer to the temporary channel
msg = opening_negotiate_msg(tmpctx, state, true); * id (state->channel_id), but success should refer to the new
* "cid" */
msg = opening_negotiate_msg(tmpctx, state, true, &cid);
if (!msg) if (!msg)
goto fail; 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"); "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 */ /* 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) if (!msg)
return NULL; return NULL;

View File

@@ -9,7 +9,7 @@
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_node_id */ /* Generated stub for fromwire_node_id */

View File

@@ -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) bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } { fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for json_add_amount_msat_compat */ /* Generated stub for json_add_amount_msat_compat */

View File

@@ -1,4 +1,5 @@
#include "config.h" #include "config.h"
#include <ccan/mem/mem.h>
#include <wire/peer_wire.h> #include <wire/peer_wire.h>
static bool unknown_type(enum peer_wire t) 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. */ /* Extract channel_id from various packets, return true if possible. */
bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id) bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
{ {
struct amount_sat ignored_sat; const u8 *cursor = in_pkt;
struct amount_msat ignored_msat; size_t max = tal_bytelen(in_pkt);
u64 ignored_u64; enum peer_wire t;
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
if (fromwire_channel_reestablish(in_pkt, channel_id, t = fromwire_u16(&cursor, &max);
&ignored_u64, &ignored_u64,
&ignored_secret, &ignored_pubkey /* 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 #if EXPERIMENTAL_FEATURES
, reestab_tlvs case WIRE_STFU:
/* BOLT-quiescent #2:
* 1. type: 2 (`stfu`)
* 2. data:
* * [`channel_id`:`channel_id`]
*/
#endif #endif
)) return fromwire_channel_id(&cursor, &max, channel_id);
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 false; return false;
} }

View File

@@ -26,7 +26,7 @@ static const char *reason;
const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash UNNEEDED) const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash UNNEEDED)
{ fprintf(stderr, "chainparams_by_chainhash called!\n"); abort(); } { fprintf(stderr, "chainparams_by_chainhash called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */ /* 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) struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for towire_channel_id */ /* Generated stub for towire_channel_id */