tools/generate_wire.py: make functions allocate the TLV.

Requiring the caller to allocate them is ugly, and differs from
other types.

This means we need a context arg if we don't have one already.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-03-23 10:01:14 +10:30
parent 2b422272e5
commit a770f51d0e
32 changed files with 199 additions and 199 deletions

View File

@@ -664,17 +664,21 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
enum channel_add_err add_err;
struct htlc *htlc;
#if EXPERIMENTAL_FEATURES
struct tlv_update_add_tlvs *tlvs = tlv_update_add_tlvs_new(msg);
struct tlv_update_add_tlvs *tlvs;
#endif
struct pubkey *blinding = NULL;
if (!fromwire_update_add_htlc(msg, &channel_id, &id, &amount,
&payment_hash, &cltv_expiry,
onion_routing_packet
if (!fromwire_update_add_htlc
#if EXPERIMENTAL_FEATURES
, tlvs
(msg, msg, &channel_id, &id, &amount,
&payment_hash, &cltv_expiry,
onion_routing_packet, &tlvs)
#else
(msg, &channel_id, &id, &amount,
&payment_hash, &cltv_expiry,
onion_routing_packet)
#endif
))
)
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad peer_add_htlc %s", tal_hex(msg, msg));
@@ -1987,14 +1991,14 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
{
struct channel_id channel_id;
u8 *scriptpubkey;
struct tlv_shutdown_tlvs *tlvs = tlv_shutdown_tlvs_new(tmpctx);
struct tlv_shutdown_tlvs *tlvs;
struct bitcoin_outpoint *wrong_funding;
/* Disable the channel. */
send_channel_update(peer, ROUTING_FLAGS_DISABLED);
if (!fromwire_shutdown(tmpctx, shutdown, &channel_id, &scriptpubkey,
tlvs))
&tlvs))
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad shutdown %s", tal_hex(peer, shutdown));
@@ -2112,18 +2116,26 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
struct secret your_last_per_commitment_secret;
struct pubkey my_current_per_commitment_point;
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
struct tlv_channel_reestablish_tlvs *tlvs;
#endif
if (!fromwire_channel_reestablish(msg, &channel_id,
if (!fromwire_channel_reestablish
#if EXPERIMENTAL_FEATURES
(tmpctx, msg, &channel_id,
&next_commitment_number,
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point
#if EXPERIMENTAL_FEATURES
, tlvs
&my_current_per_commitment_point,
&tlvs)
#else
(msg, &channel_id,
&next_commitment_number,
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point)
#endif
))
)
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad channel_reestablish %s", tal_hex(peer, msg));
@@ -2838,6 +2850,7 @@ skip_tlvs:
capture_premature_msg(&premature_msgs, msg));
#if EXPERIMENTAL_FEATURES
/* Initialize here in case we don't read it below! */
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
/* FIXME: v0.10.1 would send a different tlv set, due to older spec.
@@ -2856,13 +2869,13 @@ skip_tlvs:
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
} else if (!fromwire_channel_reestablish(msg,
} else if (!fromwire_channel_reestablish(tmpctx, msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point,
recv_tlvs)) {
&recv_tlvs)) {
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",

View File

@@ -278,10 +278,9 @@ receive_offer(struct per_peer_state *pps,
} while (!msg);
their_sig.sighash_type = SIGHASH_ALL;
close_tlvs = tlv_closing_signed_tlvs_new(msg);
if (!fromwire_closing_signed(msg, &their_channel_id,
if (!fromwire_closing_signed(msg, msg, &their_channel_id,
&received_fee, &their_sig.s,
close_tlvs))
&close_tlvs))
peer_failed_warn(pps, channel_id,
"Expected closing_signed: %s",
tal_hex(tmpctx, msg));

View File

@@ -197,8 +197,8 @@ static struct tlv_encrypted_data_tlv *decrypt_encmsg(const tal_t *ctx,
* - if the `enctlv` is not a valid TLV...
* - MUST drop the message.
*/
encmsg = tlv_encrypted_data_tlv_new(ctx);
if (!fromwire_tlv_encrypted_data_tlv(&cursor, &maxlen, encmsg)
encmsg = fromwire_tlv_encrypted_data_tlv(ctx, &cursor, &maxlen);
if (!encmsg
|| !tlv_fields_valid(encmsg->fields, NULL, NULL))
return tal_free(encmsg);

View File

@@ -166,17 +166,18 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
const struct chainparams *must_be_chain,
char **fail)
{
struct tlv_offer *offer = tlv_offer_new(ctx);
struct tlv_offer *offer;
const u8 *data;
size_t dlen;
data = string_to_data(tmpctx, b12, b12len, "lno", &dlen, fail);
if (!data)
return tal_free(offer);
return NULL;;
if (!fromwire_tlv_offer(&data, &dlen, offer)) {
offer = fromwire_tlv_offer(ctx, &data, &dlen);
if (!offer) {
*fail = tal_fmt(ctx, "invalid offer data");
return tal_free(offer);
return NULL;
}
*fail = check_features_and_chain(ctx,
@@ -219,17 +220,18 @@ struct tlv_invoice_request *invrequest_decode(const tal_t *ctx,
const struct chainparams *must_be_chain,
char **fail)
{
struct tlv_invoice_request *invrequest = tlv_invoice_request_new(ctx);
struct tlv_invoice_request *invrequest;
const u8 *data;
size_t dlen;
data = string_to_data(tmpctx, b12, b12len, "lnr", &dlen, fail);
if (!data)
return tal_free(invrequest);
return NULL;
if (!fromwire_tlv_invoice_request(&data, &dlen, invrequest)) {
invrequest = fromwire_tlv_invoice_request(ctx, &data, &dlen);
if (!invrequest) {
*fail = tal_fmt(ctx, "invalid invoice_request data");
return tal_free(invrequest);
return NULL;
}
*fail = check_features_and_chain(ctx,
@@ -258,17 +260,18 @@ struct tlv_invoice *invoice_decode_nosig(const tal_t *ctx,
const struct chainparams *must_be_chain,
char **fail)
{
struct tlv_invoice *invoice = tlv_invoice_new(ctx);
struct tlv_invoice *invoice;
const u8 *data;
size_t dlen;
data = string_to_data(tmpctx, b12, b12len, "lni", &dlen, fail);
if (!data)
return tal_free(invoice);
return NULL;
if (!fromwire_tlv_invoice(&data, &dlen, invoice)) {
invoice = fromwire_tlv_invoice(ctx, &data, &dlen);
if (!invoice) {
*fail = tal_fmt(ctx, "invalid invoice data");
return tal_free(invoice);
return NULL;
}
*fail = check_features_and_chain(ctx,

View File

@@ -173,7 +173,6 @@ static struct tlv_tlv_payload *decrypt_tlv(const tal_t *ctx,
const u8 *cursor;
size_t max;
int ret;
struct tlv_tlv_payload *tlv;
subkey_from_hmac("rho", blinding_ss, &rho);
if (tal_bytelen(enc) < crypto_aead_chacha20poly1305_ietf_ABYTES)
@@ -192,13 +191,9 @@ static struct tlv_tlv_payload *decrypt_tlv(const tal_t *ctx,
if (ret != 0)
return NULL;
tlv = tlv_tlv_payload_new(ctx);
cursor = dec;
max = tal_bytelen(dec);
if (!fromwire_tlv_tlv_payload(&cursor, &max, tlv))
return tal_free(tlv);
return tlv;
return fromwire_tlv_tlv_payload(ctx, &cursor, &max);
}
#endif /* EXPERIMENTAL_FEATURES */
@@ -219,8 +214,8 @@ struct onion_payload *onion_decode(const tal_t *ctx,
if (!pull_payload_length(&cursor, &max, true, &len))
goto general_fail;
tlv = tlv_tlv_payload_new(p);
if (!fromwire_tlv_tlv_payload(&cursor, &max, tlv)) {
tlv = fromwire_tlv_tlv_payload(p, &cursor, &max);
if (!tlv) {
/* FIXME: Fill in correct thing here! */
goto general_fail;
}

View File

@@ -132,8 +132,7 @@ static u8 *next_onion(const tal_t *ctx, u8 *omsg,
cursor = rs->raw_payload;
max = tal_bytelen(rs->raw_payload);
maxlen = fromwire_bigsize(&cursor, &max);
om = tlv_onionmsg_payload_new(tmpctx);
assert(fromwire_tlv_onionmsg_payload(&cursor, &maxlen, om));
om = fromwire_tlv_onionmsg_payload(tmpctx, &cursor, &maxlen);
if (rs->nextcase == ONION_END)
return NULL;

View File

@@ -68,16 +68,16 @@ u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice */
bool fromwire_tlv_invoice(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice * record UNNEEDED)
struct tlv_invoice *fromwire_tlv_invoice(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice_request */
bool fromwire_tlv_invoice_request(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice_request * record UNNEEDED)
struct tlv_invoice_request *fromwire_tlv_invoice_request(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice_request called!\n"); abort(); }
/* Generated stub for fromwire_tlv_offer */
bool fromwire_tlv_offer(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_offer * record UNNEEDED)
struct tlv_offer *fromwire_tlv_offer(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_offer called!\n"); abort(); }
/* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
@@ -110,15 +110,6 @@ void sighash_from_merkle(const char *messagename UNNEEDED,
const struct sha256 *merkle UNNEEDED,
struct sha256 *sighash UNNEEDED)
{ fprintf(stderr, "sighash_from_merkle called!\n"); abort(); }
/* Generated stub for tlv_invoice_new */
struct tlv_invoice *tlv_invoice_new(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "tlv_invoice_new called!\n"); abort(); }
/* Generated stub for tlv_invoice_request_new */
struct tlv_invoice_request *tlv_invoice_request_new(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "tlv_invoice_request_new called!\n"); abort(); }
/* Generated stub for tlv_offer_new */
struct tlv_offer *tlv_offer_new(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "tlv_offer_new called!\n"); abort(); }
/* Generated stub for towire */
void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "towire called!\n"); abort(); }

View File

@@ -158,16 +158,18 @@ int main(int argc, char *argv[])
/* Now do it via type-specific fromwire. */
if (streq(tlvtype, "n1")) {
struct tlv_n1 *n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *n1;
size_t len = tal_bytelen(tlv);
assert(fromwire_tlv_n1(&tlv, &len, n1));
n1 = fromwire_tlv_n1(tmpctx, &tlv, &len);
assert(n1);
assert(len == 0);
merkle_tlv(n1->fields, &merkle);
assert(sha256_eq(&merkle, &expected_merkle));
} else if (streq(tlvtype, "offer")) {
struct tlv_offer *offer = tlv_offer_new(tmpctx);
struct tlv_offer *offer;
size_t len = tal_bytelen(tlv);
assert(fromwire_tlv_offer(&tlv, &len, offer));
offer = fromwire_tlv_offer(tmpctx, &tlv, &len);
assert(offer);
assert(len == 0);
merkle_tlv(offer->fields, &merkle);
assert(sha256_eq(&merkle, &expected_merkle));

View File

@@ -117,9 +117,7 @@ static void merkle_n1(const struct tlv_n1 *n1, struct sha256 *test_m)
towire_tlv_n1(&v, n1);
len = tal_bytelen(v);
tmp = tlv_n1_new(tmpctx);
if (!fromwire_tlv_n1(cast_const2(const u8 **, &v), &len, tmp))
abort();
tmp = fromwire_tlv_n1(tmpctx, cast_const2(const u8 **, &v), &len);
assert(len == 0);
merkle_tlv(tmp->fields, test_m);

View File

@@ -71,16 +71,16 @@ u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice */
bool fromwire_tlv_invoice(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice * record UNNEEDED)
struct tlv_invoice *fromwire_tlv_invoice(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice_request */
bool fromwire_tlv_invoice_request(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice_request * record UNNEEDED)
struct tlv_invoice_request *fromwire_tlv_invoice_request(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice_request called!\n"); abort(); }
/* Generated stub for fromwire_tlv_offer */
bool fromwire_tlv_offer(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_offer * record UNNEEDED)
struct tlv_offer *fromwire_tlv_offer(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_offer called!\n"); abort(); }
/* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
@@ -113,15 +113,6 @@ void sighash_from_merkle(const char *messagename UNNEEDED,
const struct sha256 *merkle UNNEEDED,
struct sha256 *sighash UNNEEDED)
{ fprintf(stderr, "sighash_from_merkle called!\n"); abort(); }
/* Generated stub for tlv_invoice_new */
struct tlv_invoice *tlv_invoice_new(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "tlv_invoice_new called!\n"); abort(); }
/* Generated stub for tlv_invoice_request_new */
struct tlv_invoice_request *tlv_invoice_request_new(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "tlv_invoice_request_new called!\n"); abort(); }
/* Generated stub for tlv_offer_new */
struct tlv_offer *tlv_offer_new(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "tlv_offer_new called!\n"); abort(); }
/* Generated stub for to_bech32_charset */
char *to_bech32_charset(const tal_t *ctx UNNEEDED,
const char *hrp UNNEEDED, const u8 *data UNNEEDED)

View File

@@ -278,8 +278,7 @@ static void check_nannounce(const u8 *nannounce,
u32 timestamp;
u8 rgb_color[3], alias[32];
struct node_id node_id;
struct tlv_node_ann_tlvs *na_tlvs
= tlv_node_ann_tlvs_new(tmpctx);
struct tlv_node_ann_tlvs *na_tlvs;
assert(fromwire_node_announcement(nannounce, nannounce,
&sig, &features,
&timestamp,
@@ -287,7 +286,7 @@ static void check_nannounce(const u8 *nannounce,
rgb_color,
alias,
&addresses,
na_tlvs));
&na_tlvs));
assert(node_id_eq(&node_id, n));
}

View File

@@ -101,8 +101,8 @@ void handle_onion_message(struct daemon *daemon,
return;
}
om = tlv_onionmsg_payload_new(msg);
if (!fromwire_tlv_onionmsg_payload(&cursor, &maxlen, om)) {
om = fromwire_tlv_onionmsg_payload(msg, &cursor, &maxlen);
if (!om) {
status_peer_debug(&peer->id, "onion msg: invalid onionmsg_payload %s",
tal_hex(tmpctx, rs->raw_payload));
return;

View File

@@ -47,7 +47,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
{
u8 *msg = cryptomsg_decrypt_body(tmpctx, &peer->cs, peer->msg);
u8 *globalfeatures, *features;
struct tlv_init_tlvs *tlvs = tlv_init_tlvs_new(msg);
struct tlv_init_tlvs *tlvs;
struct wireaddr *remote_addr;
if (!msg)
@@ -64,7 +64,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
if (unlikely(is_unknown_msg_discardable(msg)))
return read_init(conn, peer);
if (!fromwire_init(tmpctx, msg, &globalfeatures, &features, tlvs)) {
if (!fromwire_init(tmpctx, msg, &globalfeatures, &features, &tlvs)) {
status_peer_debug(&peer->id,
"bad fromwire_init '%s', closing",
tal_hex(tmpctx, msg));

View File

@@ -83,10 +83,9 @@ static u32 get_node_announce_timestamp(const u8 *msg)
u8 *features, *addresses;
struct tlv_node_ann_tlvs *na_tlvs;
na_tlvs = tlv_node_ann_tlvs_new(tmpctx);
if (fromwire_node_announcement(tmpctx, msg, &sig, &features, &timestamp,
&id, rgb_color, alias, &addresses,
na_tlvs))
&na_tlvs))
return timestamp;
errx(1, "Invalid node_announcement");

View File

@@ -154,13 +154,12 @@ static bool get_node_announcement(const tal_t *ctx,
msg = gossip_store_get(tmpctx, daemon->rstate->gs, n->bcast.index);
/* Note: validity of node_id is already checked. */
na_tlvs = tlv_node_ann_tlvs_new(ctx);
if (!fromwire_node_announcement(ctx, msg,
&signature, features,
&timestamp,
&id, rgb_color, alias,
&addresses,
na_tlvs)) {
&na_tlvs)) {
status_broken("Bad local node_announcement @%u: %s",
n->bcast.index, tal_hex(tmpctx, msg));
return false;

View File

@@ -242,11 +242,10 @@ const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg)
u8 *encoded;
struct short_channel_id *scids;
bigsize_t *flags;
struct tlv_query_short_channel_ids_tlvs *tlvs
= tlv_query_short_channel_ids_tlvs_new(tmpctx);
struct tlv_query_short_channel_ids_tlvs *tlvs;
if (!fromwire_query_short_channel_ids(tmpctx, msg, &chain, &encoded,
tlvs)) {
&tlvs)) {
return towire_warningfmt(peer, NULL,
"Bad query_short_channel_ids w/tlvs %s",
tal_hex(tmpctx, msg));
@@ -645,12 +644,11 @@ const u8 *handle_query_channel_range(struct peer *peer, const u8 *msg)
struct bitcoin_blkid chain_hash;
u32 first_blocknum, number_of_blocks;
enum query_option_flags query_option_flags;
struct tlv_query_channel_range_tlvs *tlvs
= tlv_query_channel_range_tlvs_new(msg);
struct tlv_query_channel_range_tlvs *tlvs;
if (!fromwire_query_channel_range(msg, &chain_hash,
if (!fromwire_query_channel_range(msg, msg, &chain_hash,
&first_blocknum, &number_of_blocks,
tlvs)) {
&tlvs)) {
return towire_warningfmt(peer, NULL,
"Bad query_channel_range w/tlvs %s",
tal_hex(tmpctx, msg));
@@ -741,12 +739,11 @@ const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)
void (*cb)(struct peer *peer,
u32 first_blocknum, u32 number_of_blocks,
const struct range_query_reply *replies);
struct tlv_reply_channel_range_tlvs *tlvs
= tlv_reply_channel_range_tlvs_new(tmpctx);
struct tlv_reply_channel_range_tlvs *tlvs;
if (!fromwire_reply_channel_range(tmpctx, msg, &chain, &first_blocknum,
&number_of_blocks, &sync_complete,
&encoded, tlvs)) {
&encoded, &tlvs)) {
return towire_warningfmt(peer, NULL,
"Bad reply_channel_range w/tlvs %s",
tal_hex(tmpctx, msg));

View File

@@ -1564,12 +1564,11 @@ bool routing_add_node_announcement(struct routing_state *rstate,
tal_steal(tmpctx, msg);
/* Note: validity of node_id is already checked. */
na_tlv = tlv_node_ann_tlvs_new(tmpctx);
if (!fromwire_node_announcement(tmpctx, msg,
&signature, &features, &timestamp,
&node_id, rgb_color, alias,
&addresses,
na_tlv)) {
&na_tlv)) {
return false;
}
@@ -1705,12 +1704,11 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann,
*was_unknown = false;
serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0);
na_tlv = tlv_node_ann_tlvs_new(tmpctx);
if (!fromwire_node_announcement(tmpctx, serialized,
&signature, &features, &timestamp,
&node_id, rgb_color, alias,
&addresses,
na_tlv)) {
&na_tlv)) {
/* BOLT #7:
*
* - if `node_id` is NOT a valid compressed public key:

View File

@@ -148,8 +148,8 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
submsglen = tal_bytelen(submsg);
subptr = submsg;
payload->om = tlv_onionmsg_payload_new(payload);
if (!fromwire_tlv_onionmsg_payload(&subptr, &submsglen, payload->om)) {
payload->om = fromwire_tlv_onionmsg_payload(payload, &subptr, &submsglen);
if (!payload->om) {
log_broken(ld->log, "bad got_onionmsg_tous om: %s",
tal_hex(tmpctx, msg));
return;

View File

@@ -404,9 +404,9 @@ static void handle_peer_shutdown(struct state *state, u8 *msg)
{
u8 *scriptpubkey;
struct channel_id cid;
struct tlv_shutdown_tlvs *tlvs = tlv_shutdown_tlvs_new(msg);
struct tlv_shutdown_tlvs *tlvs;
if (!fromwire_shutdown(tmpctx, msg, &cid, &scriptpubkey, tlvs))
if (!fromwire_shutdown(tmpctx, msg, &cid, &scriptpubkey, &tlvs))
open_err_warn(state, "Bad shutdown %s", tal_hex(msg, msg));
if (tal_count(state->upfront_shutdown_script[REMOTE])
@@ -2037,9 +2037,8 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
struct tx_state *tx_state = state->tx_state;
state->our_role = TX_ACCEPTER;
open_tlv = tlv_opening_tlvs_new(tmpctx);
if (!fromwire_open_channel2(oc2_msg, &chain_hash,
if (!fromwire_open_channel2(tmpctx, oc2_msg, &chain_hash,
&cid,
&tx_state->feerate_per_kw_funding,
&state->feerate_per_kw_commitment,
@@ -2057,7 +2056,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
&state->their_points.htlc,
&state->first_per_commitment_point[REMOTE],
&state->channel_flags,
open_tlv))
&open_tlv))
open_err_fatal(state, "Parsing open_channel2 %s",
tal_hex(tmpctx, oc2_msg));
@@ -2748,8 +2747,7 @@ static void opener_start(struct state *state, u8 *msg)
if (!msg)
return;
a_tlv = notleak(tlv_accept_tlvs_new(state));
if (!fromwire_accept_channel2(msg, &cid,
if (!fromwire_accept_channel2(state, msg, &cid,
&tx_state->accepter_funding,
&tx_state->remoteconf.dust_limit,
&tx_state->remoteconf.max_htlc_value_in_flight,
@@ -2763,9 +2761,11 @@ static void opener_start(struct state *state, u8 *msg)
&state->their_points.delayed_payment,
&state->their_points.htlc,
&state->first_per_commitment_point[REMOTE],
a_tlv))
&a_tlv))
open_err_fatal(state, "Parsing accept_channel2 %s",
tal_hex(msg, msg));
/* FIXME: why? */
notleak(a_tlv);
if (!channel_id_eq(&cid, &state->channel_id)) {
struct channel_id future_chan_id;
@@ -3559,22 +3559,25 @@ static void do_reconnect_dance(struct state *state)
msg));
if (!fromwire_channel_reestablish
#if EXPERIMENTAL_FEATURES
(tmpctx, msg, &cid,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commit_secret,
&remote_current_per_commit_point,
&tlvs)
#else
(msg, &cid,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commit_secret,
&remote_current_per_commit_point
#if EXPERIMENTAL_FEATURES
, tlvs
&remote_current_per_commit_point)
#endif
))
)
open_err_fatal(state, "Bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
#if EXPERIMENTAL_FEATURES
tal_free(tlvs);
#endif /* EXPERIMENTAL_FEATURES */
check_channel_id(state, &cid, &state->channel_id);
status_debug("Got dualopend reestablish commit=%"PRIu64

View File

@@ -376,8 +376,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
* `payment_basepoint`, or `delayed_payment_basepoint` are not
* valid secp256k1 pubkeys in compressed format.
*/
accept_tlvs = tlv_accept_channel_tlvs_new(tmpctx);
if (!fromwire_accept_channel(msg, &id_in,
if (!fromwire_accept_channel(tmpctx, msg, &id_in,
&state->remoteconf.dust_limit,
&state->remoteconf.max_htlc_value_in_flight,
&state->remoteconf.channel_reserve,
@@ -391,7 +390,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
&state->their_points.delayed_payment,
&state->their_points.htlc,
&state->first_per_commitment_point[REMOTE],
accept_tlvs)) {
&accept_tlvs)) {
peer_failed_err(state->pps,
&state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg));
@@ -774,8 +773,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
struct wally_tx_output *direct_outputs[NUM_SIDES];
struct penalty_base *pbase;
struct tlv_accept_channel_tlvs *accept_tlvs;
struct tlv_open_channel_tlvs *open_tlvs
= tlv_open_channel_tlvs_new(tmpctx);
struct tlv_open_channel_tlvs *open_tlvs;
/* BOLT #2:
*
@@ -785,7 +783,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* `payment_basepoint`, or `delayed_payment_basepoint` are not valid
* secp256k1 pubkeys in compressed format.
*/
if (!fromwire_open_channel(open_channel_msg, &chain_hash,
if (!fromwire_open_channel(tmpctx, open_channel_msg, &chain_hash,
&state->channel_id,
&state->funding_sats,
&state->push_msat,
@@ -803,7 +801,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&theirs.htlc,
&state->first_per_commitment_point[REMOTE],
&channel_flags,
open_tlvs))
&open_tlvs))
peer_failed_err(state->pps,
&state->channel_id,
"Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg));

View File

@@ -113,14 +113,14 @@ static struct command_result *handle_error(struct command *cmd,
data = json_tok_bin_from_hex(cmd, buf, errtok);
dlen = tal_bytelen(data);
err = tlv_invoice_error_new(cmd);
details = json_out_new(cmd);
plugin_log(cmd->plugin, LOG_DBG, "errtok = %.*s",
json_tok_full_len(errtok),
json_tok_full(buf, errtok));
json_out_start(details, NULL, '{');
if (!fromwire_tlv_invoice_error(&data, &dlen, err)) {
err = fromwire_tlv_invoice_error(cmd, &data, &dlen);
if (!err) {
plugin_log(cmd->plugin, LOG_DBG,
"Invalid invoice_error %.*s",
json_tok_full_len(errtok),
@@ -185,8 +185,8 @@ static struct command_result *handle_invreq_response(struct command *cmd,
invbin = json_tok_bin_from_hex(cmd, buf, invtok);
len = tal_bytelen(invbin);
inv = tlv_invoice_new(cmd);
if (!fromwire_tlv_invoice(&invbin, &len, inv)) {
inv = fromwire_tlv_invoice(cmd, &invbin, &len);
if (!inv) {
badfield = "invoice";
goto badinv;
}
@@ -1083,8 +1083,8 @@ force_payer_secret(struct command *cmd,
towire_tlv_invoice_request(&msg, invreq);
p = msg;
len = tal_bytelen(msg);
sent->invreq = tlv_invoice_request_new(cmd);
if (!fromwire_tlv_invoice_request(&p, &len, sent->invreq))
sent->invreq = fromwire_tlv_invoice_request(cmd, &p, &len);
if (!sent->invreq)
plugin_err(cmd->plugin,
"Could not remarshall invreq %s", tal_hex(tmpctx, msg));
@@ -1469,8 +1469,8 @@ static struct command_result *listsendpays_done(struct command *cmd,
towire_tlv_invoice(&msg, sent->inv);
p = msg;
len = tal_bytelen(msg);
sent->inv = tlv_invoice_new(cmd);
if (!fromwire_tlv_invoice(&p, &len, sent->inv))
sent->inv = fromwire_tlv_invoice(cmd, &p, &len);
if (!sent->inv)
plugin_err(cmd->plugin,
"Could not remarshall %s", tal_hex(tmpctx, msg));

View File

@@ -351,13 +351,13 @@ static struct command_result *htlc_accepted_call(struct command *cmd,
return htlc_accepted_continue(cmd, NULL);
max = tal_bytelen(rawpayload);
payload = tlv_tlv_payload_new(cmd);
s = fromwire_bigsize(&rawpayload, &max);
if (s != max) {
return htlc_accepted_continue(cmd, NULL);
}
if (!fromwire_tlv_tlv_payload(&rawpayload, &max, payload)) {
payload = fromwire_tlv_tlv_payload(cmd, &rawpayload, &max);
if (!payload) {
plugin_log(
cmd->plugin, LOG_UNUSUAL, "Malformed TLV payload %.*s",
json_tok_full_len(params),

View File

@@ -329,8 +329,8 @@ struct command_result *handle_invoice(struct command *cmd,
inv->reply_path = tal_steal(inv, reply_path);
inv->inv = tlv_invoice_new(cmd);
if (!fromwire_tlv_invoice(&invbin, &len, inv->inv)) {
inv->inv = fromwire_tlv_invoice(cmd, &invbin, &len);
if (!inv->inv) {
return fail_inv(cmd, inv,
"Invalid invoice %s",
tal_hex(tmpctx, invbin));

View File

@@ -857,8 +857,8 @@ struct command_result *handle_invoice_request(struct command *cmd,
ir->reply_path = tal_steal(ir, reply_path);
ir->invreq = tlv_invoice_request_new(cmd);
if (!fromwire_tlv_invoice_request(&invreqbin, &len, ir->invreq)) {
ir->invreq = fromwire_tlv_invoice_request(cmd, &invreqbin, &len);
if (!ir->invreq) {
return fail_invreq(cmd, ir,
"Invalid invreq %s",
tal_hex(tmpctx, invreqbin));

View File

@@ -460,7 +460,6 @@ static void json_add_node(struct json_stream *js,
struct json_escape *esc;
struct tlv_node_ann_tlvs *na_tlvs;
na_tlvs = tlv_node_ann_tlvs_new(tmpctx);
if (!fromwire_node_announcement(nannounce, nannounce,
&signature,
&features,
@@ -469,7 +468,7 @@ static void json_add_node(struct json_stream *js,
rgb_color,
alias,
&addresses,
na_tlvs)) {
&na_tlvs)) {
plugin_log(plugin, LOG_BROKEN,
"Cannot parse stored node_announcement"
" for %s at %u: %s",

View File

@@ -93,8 +93,8 @@ struct ${tlv.struct_name()} *${tlv.struct_name()}_new(const tal_t *ctx);
* current namespace are stored in the `fields` member. Validity can be
* checked using ${tlv.name}_is_valid.
*/
bool fromwire_${tlv.name}(const u8 **cursor, size_t *max,
struct ${tlv.struct_name()} * record);
struct ${tlv.struct_name()} *fromwire_${tlv.name}(const tal_t *ctx,
const u8 **cursor, size_t *max);
/**
* Serialize a TLV stream for the ${tlv.name} namespace.

View File

@@ -266,9 +266,12 @@ void towire_${tlv.name}(u8 **pptr, const struct ${tlv.struct_name()} *record)
}
bool fromwire_${tlv.name}(const u8 **cursor, size_t *max, struct ${tlv.struct_name()} *record)
struct ${tlv.name} *fromwire_${tlv.name}(const tal_t *ctx, const u8 **cursor, size_t *max)
{
return fromwire_tlv(cursor, max, tlvs_${tlv.name}, ${len(tlv.messages)}, record, &record->fields);
struct ${tlv.name} *record = ${tlv.name}_new(ctx);
if (!fromwire_tlv(cursor, max, tlvs_${tlv.name}, ${len(tlv.messages)}, record, &record->fields))
return tal_free(record);
return record;
}
bool ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record, size_t *err_index)
@@ -345,7 +348,7 @@ bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}
if f.type_obj.is_varsize():
typename = typename + ' *'
type_ = f.type_obj.name
varsized = f.type_obj.is_varsize()
varsized = f.type_obj.is_varsize() or f.type_obj.is_tlv()
%> \
% for c in f.field_comments:
/*${c} */
@@ -357,7 +360,9 @@ bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}
% if f.len_field_of:
${f.name} = fromwire_${type_}(&cursor, &plen);
% elif f.type_obj.is_tlv():
fromwire_${f.type_obj.tlv.name}(&cursor, &plen, ${f.name});
*${f.name} = fromwire_${f.type_obj.tlv.name}(ctx, &cursor, &plen);
if (!*${f.name})
return false;
% elif f.is_array() or f.is_varlen():
% if f.type_obj.has_array_helper():
fromwire_${type_}_array(&cursor, &plen, ${'*' if f.is_varlen() else ''}${f.name}, ${f.size('plen')});

View File

@@ -48,7 +48,7 @@ bool print${options.enum_name}_message(const u8 *msg)
% endif
printf("${f.name}=");
% if f.type_obj.is_tlv():
printwire_tlvs(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen, print_tlvs_${f.type_obj.tlv.name}, ARRAY_SIZE(print_tlvs_${f.type_obj.tlv.name}));
printwire_${f.type_obj.tlv.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen);
% elif f.is_array() or f.is_varlen():
% if f.type_obj.has_array_helper():
printwire_${f.type_obj.name}_array(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen, ${f.size('*plen')});

View File

@@ -358,7 +358,7 @@ class Type(FieldSet):
def is_varsize(self):
""" A type is variably sized if it's marked as such (in varsize_types)
or it contains a field of variable length """
return self.name in self.varsize_types or self.has_len_fields()
return self.name in self.varsize_types or self.has_len_fields() or self.is_tlv()
def add_comments(self, comments):
self.type_comments = comments

View File

@@ -10,7 +10,6 @@
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)
{ fprintf(stderr, "fromwire_peektype called!\n"); abort(); }
/* Could not find declaration for fromwire_test_enum */
/* Generated stub for printwire_amount_msat */
bool printwire_amount_msat(const char *fieldname UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED)
{ fprintf(stderr, "printwire_amount_msat called!\n"); abort(); }

View File

@@ -107,6 +107,7 @@ struct msg_update_fulfill_htlc {
struct msg_shutdown {
struct channel_id channel_id;
u8 *scriptpubkey;
struct tlv_shutdown_tlvs *tlvs;
};
struct msg_funding_signed {
struct channel_id temporary_channel_id;
@@ -218,6 +219,7 @@ struct msg_update_add_htlc {
u32 expiry;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
struct tlv_update_add_tlvs *tlvs;
};
struct msg_update_fee {
struct channel_id channel_id;
@@ -288,9 +290,8 @@ static void *towire_struct_open_channel(const tal_t *ctx,
static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, const void *p)
{
struct msg_open_channel *s = tal(ctx, struct msg_open_channel);
s->tlvs = tlv_open_channel_tlvs_new(s);
if (fromwire_open_channel(p,
if (fromwire_open_channel(s, p,
&s->chain_hash,
&s->temporary_channel_id,
&s->funding_satoshis,
@@ -309,7 +310,7 @@ static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, c
&s->htlc_basepoint,
&s->first_per_commitment_point,
&s->channel_flags,
s->tlvs))
&s->tlvs))
return s;
return tal_free(s);
}
@@ -338,9 +339,8 @@ static void *towire_struct_accept_channel(const tal_t *ctx,
static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ctx, const void *p)
{
struct msg_accept_channel *s = tal(ctx, struct msg_accept_channel);
s->tlvs = tlv_accept_channel_tlvs_new(s);
if (fromwire_accept_channel(p,
if (fromwire_accept_channel(s, p,
&s->temporary_channel_id,
&s->dust_limit_satoshis,
&s->max_htlc_value_in_flight_msat,
@@ -355,7 +355,7 @@ static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ct
&s->htlc_basepoint,
&s->delayed_payment_basepoint,
&s->first_per_commitment_point,
s->tlvs))
&s->tlvs))
return s;
return tal_free(s);
}
@@ -377,7 +377,6 @@ static void *towire_struct_node_announcement(const tal_t *ctx,
static struct msg_node_announcement *fromwire_struct_node_announcement(const tal_t *ctx, const void *p)
{
struct msg_node_announcement *s = tal(ctx, struct msg_node_announcement);
s->tlvs = tlv_node_ann_tlvs_new(s);
if (!fromwire_node_announcement(s, p,
&s->signature,
&s->features,
@@ -386,7 +385,7 @@ static struct msg_node_announcement *fromwire_struct_node_announcement(const tal
s->rgb_color,
s->alias,
&s->addresses,
s->tlvs))
&s->tlvs))
return tal_free(s);
return s;
}
@@ -628,12 +627,11 @@ static struct msg_closing_signed *fromwire_struct_closing_signed(const tal_t *ct
struct msg_closing_signed *s = tal(ctx, struct msg_closing_signed);
struct tlv_closing_signed_tlvs *close_tlvs;
close_tlvs = tlv_closing_signed_tlvs_new(ctx);
if (fromwire_closing_signed(p,
if (fromwire_closing_signed(ctx, p,
&s->channel_id,
&s->fee_satoshis,
&s->signature,
close_tlvs))
&close_tlvs))
return s;
return tal_free(s);
}
@@ -654,7 +652,7 @@ static struct msg_shutdown *fromwire_struct_shutdown(const tal_t *ctx, const voi
if (!fromwire_shutdown(s, p,
&s->channel_id,
&s->scriptpubkey,
NULL))
&s->tlvs))
return tal_free(s);
return s;
}
@@ -721,15 +719,24 @@ static struct msg_update_add_htlc *fromwire_struct_update_add_htlc(const tal_t *
{
struct msg_update_add_htlc *s = tal(ctx, struct msg_update_add_htlc);
if (fromwire_update_add_htlc(p,
if (fromwire_update_add_htlc
#if EXPERIMENTAL_FEATURES
(s, p,
&s->channel_id,
&s->id,
&s->amount_msat,
&s->payment_hash,
&s->expiry,
s->onion_routing_packet,
&s->tlvs
#else
(p,
&s->channel_id,
&s->id,
&s->amount_msat,
&s->payment_hash,
&s->expiry,
s->onion_routing_packet
#if EXPERIMENTAL_FEATURES
,NULL
#endif
))
return s;
@@ -768,12 +775,11 @@ static void *towire_struct_init(const tal_t *ctx,
static struct msg_init *fromwire_struct_init(const tal_t *ctx, const void *p)
{
struct msg_init *s = tal(ctx, struct msg_init);
s->tlvs = tlv_init_tlvs_new(s);
if (!fromwire_init(s, p,
&s->globalfeatures,
&s->localfeatures,
s->tlvs))
&s->tlvs))
return tal_free(s);
return s;

View File

@@ -459,62 +459,63 @@ int main(int argc, char *argv[])
tlv3_node_id.amount_msat_2 = AMOUNT_MSAT(2);
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_either); i++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n2 *tlv_n2 = tlv_n2_new(tmpctx);
struct tlv_n1 *tlv_n1;
struct tlv_n2 *tlv_n2;
const u8 *p, *orig_p;
size_t max;
orig_p = stream(tmpctx, invalid_streams_either[i].hex);
max = tal_count(orig_p);
p = orig_p;
assert((!fromwire_tlv_n1(&p, &max, tlv_n1) && !p) ||
!tlv_n1_is_valid(tlv_n1, NULL));
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert((!tlv_n1 && !p) || !tlv_n1_is_valid(tlv_n1, NULL));
assert(strstr(invalid_streams_either[i].reason, reason));
max = tal_count(orig_p);
p = orig_p;
assert((!fromwire_tlv_n2(&p, &max, tlv_n2) && !p) ||
!tlv_n2_is_valid(tlv_n2, NULL));
tlv_n2 = fromwire_tlv_n2(tmpctx, &p, &max);
assert((!tlv_n2 && !p) || !tlv_n2_is_valid(tlv_n2, NULL));
assert(strstr(invalid_streams_either[i].reason, reason));
}
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_n1); i++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *tlv_n1;
const u8 *p;
size_t max;
p = stream(tmpctx, invalid_streams_n1[i].hex);
max = tal_count(p);
assert((!fromwire_tlv_n1(&p, &max, tlv_n1) && !p) ||
!tlv_n1_is_valid(tlv_n1, NULL));
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert((!tlv_n1 && !p) || !tlv_n1_is_valid(tlv_n1, NULL));
assert(strstr(invalid_streams_n1[i].reason, reason));
}
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_n1_combo); i++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *tlv_n1;
const u8 *p;
size_t max;
p = stream(tmpctx, invalid_streams_n1_combo[i].hex);
max = tal_count(p);
assert((!fromwire_tlv_n1(&p, &max, tlv_n1) && !p) ||
!tlv_n1_is_valid(tlv_n1, NULL));
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert((!tlv_n1 && !p) || !tlv_n1_is_valid(tlv_n1, NULL));
assert(strstr(invalid_streams_n1_combo[i].reason, reason));
}
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_n2_combo); i++) {
struct tlv_n2 *tlv_n2 = tlv_n2_new(tmpctx);
struct tlv_n2 *tlv_n2;
const u8 *p;
size_t max;
p = stream(tmpctx, invalid_streams_n2_combo[i].hex);
max = tal_count(p);
assert((!fromwire_tlv_n2(&p, &max, tlv_n2) && !p) ||
tlv_n2 = fromwire_tlv_n2(tmpctx, &p, &max);
assert((!tlv_n2 && !p) ||
!tlv_n2_is_valid(tlv_n2, NULL));
assert(strstr(invalid_streams_n2_combo[i].reason, reason));
}
for (size_t i = 0; i < ARRAY_SIZE(valid_streams); i++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *tlv_n1;
const u8 *orig_p, *p;
u8 *p2;
size_t max;
@@ -523,7 +524,8 @@ int main(int argc, char *argv[])
max = tal_count(orig_p);
p = orig_p;
assert(fromwire_tlv_n1(&p, &max, tlv_n1) &&
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert(tlv_n1 &&
tlv_n1_is_valid(tlv_n1, NULL));
assert(max == 0);
assert(tlv_n1_eq(tlv_n1, &valid_streams[i].expect));
@@ -545,8 +547,8 @@ int main(int argc, char *argv[])
*/
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_either); i++) {
for (size_t j = 0; j < ARRAY_SIZE(valid_streams); j++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n2 *tlv_n2 = tlv_n2_new(tmpctx);
struct tlv_n1 *tlv_n1;
struct tlv_n2 *tlv_n2;
const u8 *orig_p, *p;
size_t max;
@@ -555,39 +557,43 @@ int main(int argc, char *argv[])
invalid_streams_either[i].hex);
max = tal_count(orig_p);
p = orig_p;
assert((!fromwire_tlv_n1(&p, &max, tlv_n1) && !p) ||
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert((!tlv_n1 && !p) ||
!tlv_n1_is_valid(tlv_n1, NULL));
max = tal_count(orig_p);
p = orig_p;
assert((!fromwire_tlv_n2(&p, &max, tlv_n2) && !p) ||
tlv_n2 = fromwire_tlv_n2(tmpctx, &p, &max);
assert((!tlv_n2 && !p) ||
!tlv_n2_is_valid(tlv_n2, NULL));
}
}
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_n1); i++) {
for (size_t j = 0; j < ARRAY_SIZE(valid_streams); j++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *tlv_n1;
const u8 *p;
size_t max;
p = stream2(tmpctx, valid_streams[j].hex,
invalid_streams_n1[i].hex);
max = tal_count(p);
assert((!fromwire_tlv_n1(&p, &max, tlv_n1) && !p) ||
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert((!tlv_n1 && !p) ||
!tlv_n1_is_valid(tlv_n1, NULL));
}
}
for (size_t i = 0; i < ARRAY_SIZE(invalid_streams_n1_combo); i++) {
for (size_t j = 0; j < ARRAY_SIZE(valid_streams); j++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *tlv_n1;
const u8 *p;
size_t max;
p = stream2(tmpctx, valid_streams[j].hex,
invalid_streams_n1_combo[i].hex);
max = tal_count(p);
assert((!fromwire_tlv_n1(&p, &max, tlv_n1) && !p) ||
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert((!tlv_n1 && !p) ||
!tlv_n1_is_valid(tlv_n1, NULL));
}
}
@@ -599,7 +605,7 @@ int main(int argc, char *argv[])
*/
for (size_t i = 0; i < ARRAY_SIZE(valid_streams); i++) {
for (size_t j = i+1; j < ARRAY_SIZE(valid_streams); j++) {
struct tlv_n1 *tlv_n1 = tlv_n1_new(tmpctx);
struct tlv_n1 *tlv_n1;
const u8 *orig_p, *p;
size_t max;
bool expect_success;
@@ -617,7 +623,8 @@ int main(int argc, char *argv[])
expect_success = pull_type(valid_streams[i].hex)
< pull_type(valid_streams[j].hex);
assert(fromwire_tlv_n1(&p, &max, tlv_n1) &&
tlv_n1 = fromwire_tlv_n1(tmpctx, &p, &max);
assert(tlv_n1 &&
tlv_n1_is_valid(tlv_n1, NULL) == expect_success);
if (!expect_success)