Browse Source

wire/tlvstream: add tlv_make_fields helper to populate ->fields array.

This is vital for calculating merkle trees; I previously used
towire+fromwire to get this!

Requires generation change so we can magic the ARRAY_SIZE var (the C
pre-processor can't uppercase things).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
fix-mocks
Rusty Russell 4 years ago
committed by neil saitug
parent
commit
ff8830876d
  1. 2
      channeld/channeld_wiregen.c
  2. 2
      channeld/channeld_wiregen.h
  3. 2
      closingd/closingd_wiregen.c
  4. 2
      closingd/closingd_wiregen.h
  5. 2
      common/peer_status_wiregen.c
  6. 2
      common/peer_status_wiregen.h
  7. 2
      common/status_wiregen.c
  8. 2
      common/status_wiregen.h
  9. 2
      connectd/connectd_gossipd_wiregen.c
  10. 2
      connectd/connectd_gossipd_wiregen.h
  11. 2
      connectd/connectd_wiregen.c
  12. 2
      connectd/connectd_wiregen.h
  13. 2
      gossipd/gossip_store_wiregen.c
  14. 2
      gossipd/gossip_store_wiregen.h
  15. 2
      gossipd/gossipd_peerd_wiregen.c
  16. 2
      gossipd/gossipd_peerd_wiregen.h
  17. 2
      gossipd/gossipd_wiregen.c
  18. 2
      gossipd/gossipd_wiregen.h
  19. 2
      hsmd/hsmd_wiregen.c
  20. 2
      hsmd/hsmd_wiregen.h
  21. 2
      onchaind/onchaind_wiregen.c
  22. 2
      onchaind/onchaind_wiregen.h
  23. 2
      openingd/dualopend_wiregen.c
  24. 2
      openingd/dualopend_wiregen.h
  25. 2
      openingd/openingd_wiregen.c
  26. 2
      openingd/openingd_wiregen.h
  27. 2
      tools/gen/header_template
  28. 2
      wire/common_wiregen.c
  29. 2
      wire/common_wiregen.h
  30. 2
      wire/onion_printgen.c
  31. 2
      wire/onion_printgen.h
  32. 2
      wire/onion_wiregen.c
  33. 4
      wire/onion_wiregen.h
  34. 2
      wire/peer_printgen.c
  35. 2
      wire/peer_printgen.h
  36. 2
      wire/peer_wiregen.c
  37. 6
      wire/peer_wiregen.h
  38. 24
      wire/tlvstream.c
  39. 8
      wire/tlvstream.h

2
channeld/channeld_wiregen.c

@ -1248,4 +1248,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
}
return cursor != NULL;
}
// SHA256STAMP:a33294db19a7303fee551c13179ad7d4b00acdefe081ce9a0d9806f4e44176fe
// SHA256STAMP:d9bd64dc170dd8cbc8329c2ae59bd251d7057f948f7ef527b8e769cfe267e937

2
channeld/channeld_wiregen.h

@ -246,4 +246,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */
// SHA256STAMP:a33294db19a7303fee551c13179ad7d4b00acdefe081ce9a0d9806f4e44176fe
// SHA256STAMP:d9bd64dc170dd8cbc8329c2ae59bd251d7057f948f7ef527b8e769cfe267e937

2
closingd/closingd_wiregen.c

@ -201,4 +201,4 @@ bool fromwire_closingd_complete(const void *p)
return false;
return cursor != NULL;
}
// SHA256STAMP:90bf34ec2ea0eea83908d5a5be93757fd5967d797258c358a60b4d7f2eff3801
// SHA256STAMP:e0edc6ae34e0b58fbc2f33b2a388ca55a4821422fcfafee098dc19b5e480b3d5

2
closingd/closingd_wiregen.h

@ -56,4 +56,4 @@ bool fromwire_closingd_complete(const void *p);
#endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */
// SHA256STAMP:90bf34ec2ea0eea83908d5a5be93757fd5967d797258c358a60b4d7f2eff3801
// SHA256STAMP:e0edc6ae34e0b58fbc2f33b2a388ca55a4821422fcfafee098dc19b5e480b3d5

2
common/peer_status_wiregen.c

@ -80,4 +80,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_
fromwire_u8_array(&cursor, &plen, *error_for_them, len);
return cursor != NULL;
}
// SHA256STAMP:ffe5ce4130de4968d0f46ba1dd28cfb4260caba13c9699c572dc3c192291fa60
// SHA256STAMP:612d608c07fc296757d24389b7a459a3f9b72285fafe342a5c8cd42fd3ec88af

2
common/peer_status_wiregen.h

@ -34,4 +34,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_
#endif /* LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H */
// SHA256STAMP:ffe5ce4130de4968d0f46ba1dd28cfb4260caba13c9699c572dc3c192291fa60
// SHA256STAMP:612d608c07fc296757d24389b7a459a3f9b72285fafe342a5c8cd42fd3ec88af

2
common/status_wiregen.c

@ -191,4 +191,4 @@ bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm,
*happenings = fromwire_wirestring(ctx, &cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:3d02340d94ac275095ca7839fed86b3da622aca2551e39a334a8c25c562a0ef7
// SHA256STAMP:022530b0ae77beecb3645526079c8727101593bd2a5881ecf556c9538c135d98

2
common/status_wiregen.h

@ -53,4 +53,4 @@ bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm,
#endif /* LIGHTNING_COMMON_STATUS_WIREGEN_H */
// SHA256STAMP:3d02340d94ac275095ca7839fed86b3da622aca2551e39a334a8c25c562a0ef7
// SHA256STAMP:022530b0ae77beecb3645526079c8727101593bd2a5881ecf556c9538c135d98

2
connectd/connectd_gossipd_wiregen.c

@ -161,4 +161,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi
fromwire_wireaddr(&cursor, &plen, *addrs + i);
return cursor != NULL;
}
// SHA256STAMP:1eaf731ef4b4233dc782d407020adf0d7c2729d9a7f80bcb83c69cb7a3d4555f
// SHA256STAMP:6d306e062eb24755e6585d52f4a06e9a74af50ac14e03546aaf2d8ed0c9242b5

2
connectd/connectd_gossipd_wiregen.h

@ -54,4 +54,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi
#endif /* LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H */
// SHA256STAMP:1eaf731ef4b4233dc782d407020adf0d7c2729d9a7f80bcb83c69cb7a3d4555f
// SHA256STAMP:6d306e062eb24755e6585d52f4a06e9a74af50ac14e03546aaf2d8ed0c9242b5

2
connectd/connectd_wiregen.c

@ -406,4 +406,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:28a1014a8d84df52f1ca48befe0a9af817dba4788e3bfd642e94e218583bcfce
// SHA256STAMP:3874bf7cdd0e406217e6e59e43fab1e287f61e1e027009e352646c24baab0568

2
connectd/connectd_wiregen.h

@ -103,4 +103,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H */
// SHA256STAMP:28a1014a8d84df52f1ca48befe0a9af817dba4788e3bfd642e94e218583bcfce
// SHA256STAMP:3874bf7cdd0e406217e6e59e43fab1e287f61e1e027009e352646c24baab0568

2
gossipd/gossip_store_wiregen.c

@ -187,4 +187,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str
fromwire_u8_array(&cursor, &plen, *features, flen);
return cursor != NULL;
}
// SHA256STAMP:ef3ea23ab28e4c27ad11e843929e17a304f58886570438d34f3fe9822af36dc9
// SHA256STAMP:6e03c4b93e8b0a2c6fd61f3bd0d23bf4898dd38d109c5a401ba05e9e4e68267e

2
gossipd/gossip_store_wiregen.h

@ -58,4 +58,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str
#endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H */
// SHA256STAMP:ef3ea23ab28e4c27ad11e843929e17a304f58886570438d34f3fe9822af36dc9
// SHA256STAMP:6e03c4b93e8b0a2c6fd61f3bd0d23bf4898dd38d109c5a401ba05e9e4e68267e

2
gossipd/gossipd_peerd_wiregen.c

@ -187,4 +187,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p
fromwire_u8_array(&cursor, &plen, *cannount, len);
return cursor != NULL;
}
// SHA256STAMP:467e6e1c97a006551a6ddd32fa4625f075628a268d689cbf65e2556b1e0781b7
// SHA256STAMP:18c1c9ce4dfed92c5fc6809cf716bf31cbb39fb8db124d43ead013088aff8b7c

2
gossipd/gossipd_peerd_wiregen.h

@ -64,4 +64,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p
#endif /* LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H */
// SHA256STAMP:467e6e1c97a006551a6ddd32fa4625f075628a268d689cbf65e2556b1e0781b7
// SHA256STAMP:18c1c9ce4dfed92c5fc6809cf716bf31cbb39fb8db124d43ead013088aff8b7c

2
gossipd/gossipd_wiregen.c

@ -857,4 +857,4 @@ bool fromwire_gossipd_new_blockheight(const void *p, u32 *blockheight)
*blockheight = fromwire_u32(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:957869c71b6b3ea4d1ec80c7ea4aa093b3738a4d9bc4d145fc429691ae7338e7
// SHA256STAMP:b9a39b664d2a598fb69e39147ff5d66e1abe5c9493db4a511bba6d2ecbcdfe29

2
gossipd/gossipd_wiregen.h

@ -199,4 +199,4 @@ bool fromwire_gossipd_new_blockheight(const void *p, u32 *blockheight);
#endif /* LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H */
// SHA256STAMP:957869c71b6b3ea4d1ec80c7ea4aa093b3738a4d9bc4d145fc429691ae7338e7
// SHA256STAMP:b9a39b664d2a598fb69e39147ff5d66e1abe5c9493db4a511bba6d2ecbcdfe29

2
hsmd/hsmd_wiregen.c

@ -1214,4 +1214,4 @@ bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const void *p
fromwire_u8_array(&cursor, &plen, *script, script_len);
return cursor != NULL;
}
// SHA256STAMP:abae586a8f129c46f47522b542ff868bdbdab5bda085c0874dbde87dccee4ac0
// SHA256STAMP:bbfe5b669e8a931aa5426be248dc8320a48f22fd5231612dfc1ce22a6f300668

2
hsmd/hsmd_wiregen.h

@ -271,4 +271,4 @@ bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx, const void *p
#endif /* LIGHTNING_HSMD_HSMD_WIREGEN_H */
// SHA256STAMP:abae586a8f129c46f47522b542ff868bdbdab5bda085c0874dbde87dccee4ac0
// SHA256STAMP:bbfe5b669e8a931aa5426be248dc8320a48f22fd5231612dfc1ce22a6f300668

2
onchaind/onchaind_wiregen.c

@ -635,4 +635,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt
fromwire_chain_coin_mvt(&cursor, &plen, mvt);
return cursor != NULL;
}
// SHA256STAMP:41d048b3838729465dedb317e7e44c381f6c96f02b78d2423ef504d01d5898f8
// SHA256STAMP:3e82025758cfaf2467242d259ac50c2ca66de3a8eabc1ff905aeb3effca0e5c7

2
onchaind/onchaind_wiregen.h

@ -161,4 +161,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt
#endif /* LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H */
// SHA256STAMP:41d048b3838729465dedb317e7e44c381f6c96f02b78d2423ef504d01d5898f8
// SHA256STAMP:3e82025758cfaf2467242d259ac50c2ca66de3a8eabc1ff905aeb3effca0e5c7

2
openingd/dualopend_wiregen.c

@ -485,4 +485,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:d7f4b124313a7d21052b25e737ec35bf6f5dfa3db37aa5ec13ac8cef8c120190
// SHA256STAMP:48dcbf79652c7cde9ad129b137cc60be72be6232ed20a8c2675a00f427ab6f91

2
openingd/dualopend_wiregen.h

@ -109,4 +109,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */
// SHA256STAMP:d7f4b124313a7d21052b25e737ec35bf6f5dfa3db37aa5ec13ac8cef8c120190
// SHA256STAMP:48dcbf79652c7cde9ad129b137cc60be72be6232ed20a8c2675a00f427ab6f91

2
openingd/openingd_wiregen.c

@ -579,4 +579,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:9c977c121d6ff95a6680804710457cf353ee1bb0686a4e51045017b7590fb428
// SHA256STAMP:2d53106a700f181fa46b0c82a9cb65e823bb9c39ec116adf72d24b52e27e05b6

2
openingd/openingd_wiregen.h

@ -121,4 +121,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H */
// SHA256STAMP:9c977c121d6ff95a6680804710457cf353ee1bb0686a4e51045017b7590fb428
// SHA256STAMP:2d53106a700f181fa46b0c82a9cb65e823bb9c39ec116adf72d24b52e27e05b6

2
tools/gen/header_template

@ -121,7 +121,7 @@ bool ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record,
size_t *err_index);
% if tlv.name in options.expose_tlv_type:
#define TLVS_${tlv.name.upper()}_ARRAY_SIZE ${len(tlv.messages)}
#define TLVS_ARRAY_SIZE_${tlv.name} ${len(tlv.messages)}
extern const struct tlv_record_type tlvs_${tlv.name}[];
<%!

2
wire/common_wiregen.c

@ -100,4 +100,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg)
fromwire_u8_array(&cursor, &plen, *msg, msg_len);
return cursor != NULL;
}
// SHA256STAMP:9d2e11b0a9eefdde3d80dc605aeda2c85089c894388740b1d94d7ca97bd95acc
// SHA256STAMP:83d7a6305b316f37ff2278d9c4fb2c9efa9381688b78b84dd0a8928ca67e1563

2
wire/common_wiregen.h

@ -41,4 +41,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg);
#endif /* LIGHTNING_WIRE_COMMON_WIREGEN_H */
// SHA256STAMP:9d2e11b0a9eefdde3d80dc605aeda2c85089c894388740b1d94d7ca97bd95acc
// SHA256STAMP:83d7a6305b316f37ff2278d9c4fb2c9efa9381688b78b84dd0a8928ca67e1563

2
wire/onion_printgen.c

@ -653,4 +653,4 @@ void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_tlv_payload, ARRAY_SIZE(print_tlvs_tlv_payload));
}
}
// SHA256STAMP:3edc0ac5906e013377cc195c01e5cb67274c2a7560f51b946ff5149d755d36bd
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede

2
wire/onion_printgen.h

@ -57,4 +57,4 @@ void printwire_mpp_timeout(const char *fieldname, const u8 *cursor);
#endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */
// SHA256STAMP:3edc0ac5906e013377cc195c01e5cb67274c2a7560f51b946ff5149d755d36bd
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede

2
wire/onion_wiregen.c

@ -697,4 +697,4 @@ bool fromwire_mpp_timeout(const void *p)
return false;
return cursor != NULL;
}
// SHA256STAMP:3edc0ac5906e013377cc195c01e5cb67274c2a7560f51b946ff5149d755d36bd
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede

4
wire/onion_wiregen.h

@ -104,7 +104,7 @@ void towire_tlv_payload(u8 **pptr, const struct tlv_tlv_payload *record);
bool tlv_payload_is_valid(const struct tlv_tlv_payload *record,
size_t *err_index);
#define TLVS_TLV_PAYLOAD_ARRAY_SIZE 4
#define TLVS_ARRAY_SIZE_tlv_payload 4
extern const struct tlv_record_type tlvs_tlv_payload[];
@ -207,4 +207,4 @@ bool fromwire_mpp_timeout(const void *p);
#endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */
// SHA256STAMP:3edc0ac5906e013377cc195c01e5cb67274c2a7560f51b946ff5149d755d36bd
// SHA256STAMP:c330a3a671d28980727dc42fb48b8f9051ee609c96445333105b7d5ab15d0ede

2
wire/peer_printgen.c

@ -2036,4 +2036,4 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_reply_channel_range_tlvs, ARRAY_SIZE(print_tlvs_reply_channel_range_tlvs));
}
}
// SHA256STAMP:a2fdacbfaf7025bcb919b426f2e17fdc317a0bc6a80fe3c05f5dedac30f00256
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92

2
wire/peer_printgen.h

@ -70,4 +70,4 @@ void printwire_gossip_timestamp_filter(const char *fieldname, const u8 *cursor);
void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor, size_t *plen);
void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen);
#endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */
// SHA256STAMP:a2fdacbfaf7025bcb919b426f2e17fdc317a0bc6a80fe3c05f5dedac30f00256
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92

2
wire/peer_wiregen.c

@ -1630,4 +1630,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec
*htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:a2fdacbfaf7025bcb919b426f2e17fdc317a0bc6a80fe3c05f5dedac30f00256
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92

6
wire/peer_wiregen.h

@ -223,7 +223,7 @@ void towire_n1(u8 **pptr, const struct tlv_n1 *record);
bool n1_is_valid(const struct tlv_n1 *record,
size_t *err_index);
#define TLVS_N1_ARRAY_SIZE 4
#define TLVS_ARRAY_SIZE_n1 4
extern const struct tlv_record_type tlvs_n1[];
@ -273,7 +273,7 @@ void towire_n2(u8 **pptr, const struct tlv_n2 *record);
bool n2_is_valid(const struct tlv_n2 *record,
size_t *err_index);
#define TLVS_N2_ARRAY_SIZE 2
#define TLVS_ARRAY_SIZE_n2 2
extern const struct tlv_record_type tlvs_n2[];
@ -595,4 +595,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec
#endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */
// SHA256STAMP:a2fdacbfaf7025bcb919b426f2e17fdc317a0bc6a80fe3c05f5dedac30f00256
// SHA256STAMP:cda6c1b9f5b71e94ce4d2791a16dfeddc52ea3b2ad09ce4915101fe6e41dfc92

24
wire/tlvstream.c

@ -271,3 +271,27 @@ void towire_tlv(u8 **pptr,
tal_free(val);
}
}
struct tlv_field *tlv_make_fields_(const struct tlv_record_type *types,
size_t num_types,
const void *record)
{
struct tlv_field *fields = tal_arr(record, struct tlv_field, 0);
for (size_t i = 0; i < num_types; i++) {
struct tlv_field f;
u8 *val;
if (i != 0)
assert(types[i].type > types[i-1].type);
val = types[i].towire(NULL, record);
if (!val)
continue;
f.meta = &types[i];
f.numtype = types[i].type;
f.length = tal_bytelen(val);
f.value = tal_steal(fields, val);
tal_arr_expand(&fields, f);
}
return fields;
}

8
wire/tlvstream.h

@ -30,6 +30,14 @@ struct tlv_field {
/* Given any tlvstream serialize the raw fields (untyped ones). */
void towire_tlvstream_raw(u8 **pptr, const struct tlv_field *fields);
/* Given a tlv record with manually-set fields, populate ->fields */
#define tlv_make_fields(tlv, type) \
tlv_make_fields_(tlvs_##type, TLVS_ARRAY_SIZE_##type, (tlv))
struct tlv_field *tlv_make_fields_(const struct tlv_record_type *types,
size_t num_types,
const void *record);
/* Generic TLV decode/encode */
bool fromwire_tlv(const u8 **cursor, size_t *max,
const struct tlv_record_type *types, size_t num_types,

Loading…
Cancel
Save