liquidity-ads: import from spec

Import the wires from spec. Here we go!
This commit is contained in:
niftynei 2021-06-10 12:54:08 -05:00 committed by neil saitug
parent 376e6f8bd1
commit 5b3c02f401
18 changed files with 548 additions and 37 deletions

View File

@ -2098,6 +2098,9 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_UPDATE_FEE:
handle_peer_feechange(peer, msg);
return;
case WIRE_UPDATE_BLOCKHEIGHT:
/* FIXME: do this! */
break;
case WIRE_REVOKE_AND_ACK:
handle_peer_revoke_and_ack(peer, msg);
return;

View File

@ -48,6 +48,7 @@ common/test/run-route common/test/run-route-specific: \
common/test/run-gossmap_local: \
wire/fromwire.o \
wire/peer$(EXP)_wiregen.o \
wire/tlvstream.o \
wire/towire.o
common/test/run-bolt12_merkle: \

View File

@ -9,6 +9,7 @@
#include <common/amount.h>
#include <common/setup.h>
#include <stdio.h>
#include <wire/tlvstream.h>
/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_bigsize */
@ -18,26 +19,12 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_tlv */
bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
void *record UNNEEDED, struct tlv_field **fields UNNEEDED)
{ fprintf(stderr, "fromwire_tlv called!\n"); abort(); }
/* Generated stub for tlv_fields_valid */
bool tlv_fields_valid(const struct tlv_field *fields UNNEEDED, u64 *allow_extra UNNEEDED,
size_t *err_index UNNEEDED)
{ fprintf(stderr, "tlv_fields_valid called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }
/* Generated stub for towire_channel_id */
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
/* Generated stub for towire_tlv */
void towire_tlv(u8 **pptr UNNEEDED,
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
const void *record UNNEEDED)
{ fprintf(stderr, "towire_tlv called!\n"); abort(); }
/* Generated stub for type_to_string_ */
const char *type_to_string_(const tal_t *ctx UNNEEDED, const char *typename UNNEEDED,
union printable_types u UNNEEDED)
@ -291,13 +278,16 @@ 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);
assert(fromwire_node_announcement(nannounce, nannounce,
&sig, &features,
&timestamp,
&node_id,
rgb_color,
alias,
&addresses));
&addresses,
na_tlvs));
assert(node_id_eq(&node_id, n));
}

View File

@ -88,9 +88,12 @@ static u32 get_node_announce_timestamp(const u8 *msg)
struct node_id id;
u8 rgb_color[3], alias[32];
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))
&id, rgb_color, alias, &addresses,
na_tlvs))
return timestamp;
errx(1, "Invalid node_announcement");

View File

@ -201,14 +201,17 @@ static void print_nannounce(const struct node_id *nodeid,
struct sha256_double hash;
secp256k1_ecdsa_signature sig;
char alias[33];
struct tlv_node_ann_tlvs *tlvs;
u8 *nannounce;
memset(&sig, 0, sizeof(sig));
assert(hex_str_size(sizeof(*nodeid)) >= sizeof(alias));
hex_encode(nodeid, hex_data_size(sizeof(alias)), alias, sizeof(alias));
tlvs = tlv_node_ann_tlvs_new(NULL);
nannounce = towire_node_announcement(NULL, &sig, NULL, opts->timestamp,
nodeid, nodeid->k, (u8 *)alias,
opts->addresses);
opts->addresses,
tlvs);
sha256_double(&hash, nannounce + node_announcement_offset,
tal_count(nannounce) - node_announcement_offset);
sign_hash(privkey, &hash, &sig);
@ -221,6 +224,22 @@ static void print_nannounce(const struct node_id *nodeid,
printf(" rgb_color=%s\n", tal_hexstr(NULL, nodeid->k, 3));
printf(" alias=%s\n", tal_hexstr(NULL, alias, 32));
printf(" addresses=%s\n", tal_hex(NULL, opts->addresses));
if (tlvs->option_will_fund) {
struct lease_rates *rates = tlvs->option_will_fund;
printf(" TLV option_will_fund\n");
printf(" lease_fee_basis=%d\n",
rates->lease_fee_basis);
printf(" lease_fee_base_sat=%d\n",
rates->lease_fee_base_sat);
printf(" funding_weight=%d\n",
rates->funding_weight);
printf(" channel_fee_max_proportional_thousandths=%d\n",
rates->channel_fee_max_proportional_thousandths);
printf(" channel_fee_max_base_msat=%d\n",
rates->channel_fee_max_base_msat);
}
tal_free(tlvs);
}
int main(int argc, char *argv[])

View File

@ -30,6 +30,7 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
{
u8 *addresses = tal_arr(tmpctx, u8, 0);
u8 *announcement;
struct tlv_node_ann_tlvs *na_tlv;
size_t i;
if (!sig)
@ -38,13 +39,15 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
for (i = 0; i < tal_count(daemon->announcable); i++)
towire_wireaddr(&addresses, &daemon->announcable[i]);
na_tlv = tlv_node_ann_tlvs_new(tmpctx);
announcement =
towire_node_announcement(ctx, sig,
daemon->our_features->bits
[NODE_ANNOUNCE_FEATURE],
timestamp,
&daemon->id, daemon->rgb, daemon->alias,
addresses);
addresses,
na_tlv);
return announcement;
}

View File

@ -164,6 +164,7 @@ static bool get_node_announcement(const tal_t *ctx,
secp256k1_ecdsa_signature signature;
u32 timestamp;
u8 *addresses;
struct tlv_node_ann_tlvs *na_tlvs;
if (!n->bcast.index)
return false;
@ -171,11 +172,13 @@ 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)) {
&addresses,
na_tlvs)) {
status_broken("Bad local node_announcement @%u: %s",
n->bcast.index, tal_hex(tmpctx, msg));
return false;
@ -728,6 +731,7 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:

View File

@ -1598,6 +1598,7 @@ bool routing_add_node_announcement(struct routing_state *rstate,
u8 rgb_color[3];
u8 alias[32];
u8 *features, *addresses;
struct tlv_node_ann_tlvs *na_tlv;
if (was_unknown)
*was_unknown = false;
@ -1607,10 +1608,12 @@ 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)) {
&addresses,
na_tlv)) {
return false;
}
@ -1737,15 +1740,18 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann,
u8 *features, *addresses;
struct wireaddr *wireaddrs;
size_t len = tal_count(node_ann);
struct tlv_node_ann_tlvs *na_tlv;
if (was_unknown)
*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)) {
&addresses,
na_tlv)) {
/* BOLT #7:
*
* - if `node_id` is NOT a valid compressed public key:

View File

@ -1251,6 +1251,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
@ -1598,6 +1599,7 @@ static bool run_tx_interactive(struct state *state,
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
@ -3344,6 +3346,7 @@ static u8 *handle_peer_in(struct state *state)
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:

View File

@ -521,7 +521,9 @@ static void json_add_node(struct json_stream *js,
struct node_id nid;
struct wireaddr *addrs;
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,
@ -529,7 +531,8 @@ static void json_add_node(struct json_stream *js,
&nid,
rgb_color,
alias,
&addresses)) {
&addresses,
na_tlvs)) {
plugin_log(plugin, LOG_BROKEN,
"Cannot parse stored node_announcement"
" for %s at %u: %s",

View File

@ -0,0 +1,48 @@
--- wire/peer_wire.csv 2021-06-10 12:47:17.225844741 -0500
+++ - 2021-06-10 12:47:40.960373156 -0500
@@ -143,6 +139,9 @@
tlvtype,opening_tlvs,option_upfront_shutdown_script,1
tlvdata,opening_tlvs,option_upfront_shutdown_script,shutdown_len,u16,
tlvdata,opening_tlvs,option_upfront_shutdown_script,shutdown_scriptpubkey,byte,shutdown_len
+tlvtype,opening_tlvs,request_funds,3
+tlvdata,opening_tlvs,request_funds,requested_sats,u64,
+tlvdata,opening_tlvs,request_funds,blockheight,u32,
msgtype,accept_channel2,65
msgdata,accept_channel2,channel_id,channel_id,
msgdata,accept_channel2,funding_satoshis,u64,
@@ -162,6 +161,15 @@
tlvtype,accept_tlvs,option_upfront_shutdown_script,1
tlvdata,accept_tlvs,option_upfront_shutdown_script,shutdown_len,u16,
tlvdata,accept_tlvs,option_upfront_shutdown_script,shutdown_scriptpubkey,byte,shutdown_len
+tlvtype,accept_tlvs,will_fund,2
+tlvdata,accept_tlvs,will_fund,signature,signature,
+tlvdata,accept_tlvs,will_fund,lease_rates,lease_rates,
+subtype,lease_rates
+subtypedata,lease_rates,channel_fee_max_base_msat,u32,
+subtypedata,lease_rates,channel_fee_max_proportional_thousandths,u16,
+subtypedata,lease_rates,funding_weight,u16,
+subtypedata,lease_rates,lease_fee_base_sat,u32,
+subtypedata,lease_rates,lease_fee_basis,tu32,
msgtype,init_rbf,72
msgdata,init_rbf,channel_id,channel_id,
msgdata,init_rbf,funding_satoshis,u64,
@@ -215,6 +219,9 @@
msgtype,update_fee,134
msgdata,update_fee,channel_id,channel_id,
msgdata,update_fee,feerate_per_kw,u32,
+msgtype,update_blockheight,137
+msgdata,update_blockheight,channel_id,channel_id,
+msgdata,update_blockheight,blockheight,u32,
msgtype,channel_reestablish,136
msgdata,channel_reestablish,channel_id,channel_id,
msgdata,channel_reestablish,next_commitment_number,u64,
@@ -249,6 +256,9 @@
msgdata,node_announcement,alias,byte,32
msgdata,node_announcement,addrlen,u16,
msgdata,node_announcement,addresses,byte,addrlen
+msgdata,node_announcement,tlvs,node_ann_tlvs,
+tlvtype,node_ann_tlvs,option_will_fund,1
+tlvdata,node_ann_tlvs,option_will_fund,lease_rates,lease_rates,
msgtype,channel_update,258
msgdata,channel_update,signature,signature,
msgdata,channel_update,chain_hash,chain_hash,

146
wire/peer_printgen.c generated
View File

@ -128,6 +128,10 @@ void printpeer_wire_message(const u8 *msg)
printf("WIRE_UPDATE_FEE:\n");
printwire_update_fee("update_fee", msg);
return;
case WIRE_UPDATE_BLOCKHEIGHT:
printf("WIRE_UPDATE_BLOCKHEIGHT:\n");
printwire_update_blockheight("update_blockheight", msg);
return;
case WIRE_CHANNEL_REESTABLISH:
printf("WIRE_CHANNEL_REESTABLISH:\n");
printwire_channel_reestablish("channel_reestablish", msg);
@ -196,6 +200,52 @@ void printwire_witness_element(const char *fieldname, const u8 **cursor, size_t
}
void printwire_lease_rates(const char *fieldname, const u8 **cursor, size_t *plen)
{
printf("funding_weight=");
u16 funding_weight = fromwire_u16(cursor, plen);
printwire_u16(tal_fmt(NULL, "%s.funding_weight", fieldname), &funding_weight);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("lease_fee_basis=");
u16 lease_fee_basis = fromwire_u16(cursor, plen);
printwire_u16(tal_fmt(NULL, "%s.lease_fee_basis", fieldname), &lease_fee_basis);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("channel_fee_max_proportional_thousandths=");
u16 channel_fee_max_proportional_thousandths = fromwire_u16(cursor, plen);
printwire_u16(tal_fmt(NULL, "%s.channel_fee_max_proportional_thousandths", fieldname), &channel_fee_max_proportional_thousandths);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("lease_fee_base_sat=");
u32 lease_fee_base_sat = fromwire_u32(cursor, plen);
printwire_u32(tal_fmt(NULL, "%s.lease_fee_base_sat", fieldname), &lease_fee_base_sat);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("channel_fee_max_base_msat=");
u32 channel_fee_max_base_msat = fromwire_tu32(cursor, plen);
printwire_u32(tal_fmt(NULL, "%s.channel_fee_max_base_msat", fieldname), &channel_fee_max_base_msat);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
}
void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor, size_t *plen)
{
@ -461,10 +511,33 @@ static void printwire_tlv_opening_tlvs_option_upfront_shutdown_script(const char
return;
}
}
static void printwire_tlv_opening_tlvs_request_funds(const char *fieldname, const u8 **cursor, size_t *plen)
{
printf("(msg_name=%s)\n", "request_funds");
printf("requested_sats=");
u64 requested_sats = fromwire_u64(cursor, plen);
printwire_u64(tal_fmt(NULL, "%s.requested_sats", fieldname), &requested_sats);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("blockheight=");
u32 blockheight = fromwire_u32(cursor, plen);
printwire_u32(tal_fmt(NULL, "%s.blockheight", fieldname), &blockheight);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
}
static const struct tlv_print_record_type print_tlvs_opening_tlvs[] = {
{ 1, printwire_tlv_opening_tlvs_option_upfront_shutdown_script },
{ 3, printwire_tlv_opening_tlvs_request_funds },
};
static void printwire_tlv_accept_tlvs_option_upfront_shutdown_script(const char *fieldname, const u8 **cursor, size_t *plen)
@ -484,10 +557,30 @@ static void printwire_tlv_accept_tlvs_option_upfront_shutdown_script(const char
return;
}
}
static void printwire_tlv_accept_tlvs_will_fund(const char *fieldname, const u8 **cursor, size_t *plen)
{
printf("(msg_name=%s)\n", "will_fund");
printf("signature=");
secp256k1_ecdsa_signature signature;
fromwire_secp256k1_ecdsa_signature(cursor, plen, &signature);
printwire_secp256k1_ecdsa_signature(tal_fmt(NULL, "%s.signature", fieldname), &signature);
if (!*cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("lease_rates=");
printf("{\n");
printwire_lease_rates(tal_fmt(NULL, "%s.lease_rates", fieldname), cursor, plen);
printf("}\n");
}
static const struct tlv_print_record_type print_tlvs_accept_tlvs[] = {
{ 1, printwire_tlv_accept_tlvs_option_upfront_shutdown_script },
{ 2, printwire_tlv_accept_tlvs_will_fund },
};
static void printwire_tlv_shutdown_tlvs_wrong_funding(const char *fieldname, const u8 **cursor, size_t *plen)
@ -518,6 +611,21 @@ static const struct tlv_print_record_type print_tlvs_shutdown_tlvs[] = {
{ 100, printwire_tlv_shutdown_tlvs_wrong_funding },
};
static void printwire_tlv_node_ann_tlvs_option_will_fund(const char *fieldname, const u8 **cursor, size_t *plen)
{
printf("(msg_name=%s)\n", "option_will_fund");
printf("lease_rates=");
printf("{\n");
printwire_lease_rates(tal_fmt(NULL, "%s.lease_rates", fieldname), cursor, plen);
printf("}\n");
}
static const struct tlv_print_record_type print_tlvs_node_ann_tlvs[] = {
{ 1, printwire_tlv_node_ann_tlvs_option_will_fund },
};
static void printwire_tlv_query_short_channel_ids_tlvs_query_flags(const char *fieldname, const u8 **cursor, size_t *plen)
{
printf("(msg_name=%s)\n", "query_flags");
@ -2246,6 +2354,37 @@ void printwire_update_fee(const char *fieldname, const u8 *cursor)
}
if (plen != 0)
printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen));
}
void printwire_update_blockheight(const char *fieldname, const u8 *cursor)
{
size_t plen = tal_count(cursor);
if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_BLOCKHEIGHT) {
printf("WRONG TYPE?!\n");
return;
}
printf("channel_id=");
struct channel_id channel_id;
fromwire_channel_id(&cursor, &plen, &channel_id);
printwire_channel_id(tal_fmt(NULL, "%s.channel_id", fieldname), &channel_id);
if (!cursor) {
printf("**TRUNCATED**\n");
return;
}
printf("blockheight=");
u32 blockheight = fromwire_u32(&cursor, &plen);
printwire_u32(tal_fmt(NULL, "%s.blockheight", fieldname), &blockheight);
if (!cursor) {
printf("**TRUNCATED**\n");
return;
}
if (plen != 0)
printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen));
}
@ -2545,6 +2684,8 @@ void printwire_node_announcement(const char *fieldname, const u8 *cursor)
printf("**TRUNCATED**\n");
return;
}
printf("tlvs=");
printwire_tlvs(tal_fmt(NULL, "%s.tlvs", fieldname), &cursor, &plen, print_tlvs_node_ann_tlvs, ARRAY_SIZE(print_tlvs_node_ann_tlvs));
if (plen != 0)
@ -2922,6 +3063,9 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) {
if (strcmp(tlv_name, "shutdown_tlvs") == 0) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_shutdown_tlvs, ARRAY_SIZE(print_tlvs_shutdown_tlvs));
}
if (strcmp(tlv_name, "node_ann_tlvs") == 0) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_node_ann_tlvs, ARRAY_SIZE(print_tlvs_node_ann_tlvs));
}
if (strcmp(tlv_name, "query_short_channel_ids_tlvs") == 0) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_query_short_channel_ids_tlvs, ARRAY_SIZE(print_tlvs_query_short_channel_ids_tlvs));
}
@ -2935,4 +3079,4 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_onion_message_tlvs, ARRAY_SIZE(print_tlvs_onion_message_tlvs));
}
}
// SHA256STAMP:a3a508935b99ff0b985d0774432ae9d98f3ec7660bf4edf64095a3d0a37ba0e8
// SHA256STAMP:4751c4834d5db7d170f8e1ee40ea8b5e12b5552780d37b099fe5fae6f0342c9e

5
wire/peer_printgen.h generated
View File

@ -68,6 +68,8 @@ void printwire_revoke_and_ack(const char *fieldname, const u8 *cursor);
void printwire_update_fee(const char *fieldname, const u8 *cursor);
void printwire_update_blockheight(const char *fieldname, const u8 *cursor);
void printwire_channel_reestablish(const char *fieldname, const u8 *cursor);
void printwire_announcement_signatures(const char *fieldname, const u8 *cursor);
@ -92,8 +94,9 @@ void printwire_onion_message(const char *fieldname, const u8 *cursor);
void printwire_witness_element(const char *fieldname, const u8 **cursor, size_t *plen);
void printwire_lease_rates(const char *fieldname, const u8 **cursor, size_t *plen);
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);
void printwire_witness_stack(const char *fieldname, const u8 **cursor, size_t *plen);
#endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */
// SHA256STAMP:a3a508935b99ff0b985d0774432ae9d98f3ec7660bf4edf64095a3d0a37ba0e8
// SHA256STAMP:4751c4834d5db7d170f8e1ee40ea8b5e12b5552780d37b099fe5fae6f0342c9e

View File

@ -21,6 +21,7 @@ static bool unknown_type(enum peer_wire t)
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_CHANNEL_ANNOUNCEMENT:
@ -83,6 +84,7 @@ bool is_msg_for_gossipd(const u8 *cursor)
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:

View File

@ -143,6 +143,9 @@ msgdata,open_channel2,tlvs,opening_tlvs,
tlvtype,opening_tlvs,option_upfront_shutdown_script,1
tlvdata,opening_tlvs,option_upfront_shutdown_script,shutdown_len,u16,
tlvdata,opening_tlvs,option_upfront_shutdown_script,shutdown_scriptpubkey,byte,shutdown_len
tlvtype,opening_tlvs,request_funds,3
tlvdata,opening_tlvs,request_funds,requested_sats,u64,
tlvdata,opening_tlvs,request_funds,blockheight,u32,
msgtype,accept_channel2,65
msgdata,accept_channel2,channel_id,channel_id,
msgdata,accept_channel2,funding_satoshis,u64,
@ -162,6 +165,15 @@ msgdata,accept_channel2,tlvs,accept_tlvs,
tlvtype,accept_tlvs,option_upfront_shutdown_script,1
tlvdata,accept_tlvs,option_upfront_shutdown_script,shutdown_len,u16,
tlvdata,accept_tlvs,option_upfront_shutdown_script,shutdown_scriptpubkey,byte,shutdown_len
tlvtype,accept_tlvs,will_fund,2
tlvdata,accept_tlvs,will_fund,signature,signature,
tlvdata,accept_tlvs,will_fund,lease_rates,lease_rates,
subtype,lease_rates
subtypedata,lease_rates,funding_weight,u16,
subtypedata,lease_rates,lease_fee_basis,u16,
subtypedata,lease_rates,channel_fee_max_proportional_thousandths,u16,
subtypedata,lease_rates,lease_fee_base_sat,u32,
subtypedata,lease_rates,channel_fee_max_base_msat,tu32,
msgtype,init_rbf,72
msgdata,init_rbf,channel_id,channel_id,
msgdata,init_rbf,funding_satoshis,u64,
@ -215,6 +227,9 @@ msgdata,revoke_and_ack,next_per_commitment_point,point,
msgtype,update_fee,134
msgdata,update_fee,channel_id,channel_id,
msgdata,update_fee,feerate_per_kw,u32,
msgtype,update_blockheight,137
msgdata,update_blockheight,channel_id,channel_id,
msgdata,update_blockheight,blockheight,u32,
msgtype,channel_reestablish,136
msgdata,channel_reestablish,channel_id,channel_id,
msgdata,channel_reestablish,next_commitment_number,u64,
@ -249,6 +264,9 @@ msgdata,node_announcement,rgb_color,byte,3
msgdata,node_announcement,alias,byte,32
msgdata,node_announcement,addrlen,u16,
msgdata,node_announcement,addresses,byte,addrlen
msgdata,node_announcement,tlvs,node_ann_tlvs,
tlvtype,node_ann_tlvs,option_will_fund,1
tlvdata,node_ann_tlvs,option_will_fund,lease_rates,lease_rates,
msgtype,channel_update,258
msgdata,channel_update,signature,signature,
msgdata,channel_update,chain_hash,chain_hash,

1 msgtype,init,16
143 tlvtype,opening_tlvs,option_upfront_shutdown_script,1
144 tlvdata,opening_tlvs,option_upfront_shutdown_script,shutdown_len,u16,
145 tlvdata,opening_tlvs,option_upfront_shutdown_script,shutdown_scriptpubkey,byte,shutdown_len
146 tlvtype,opening_tlvs,request_funds,3
147 tlvdata,opening_tlvs,request_funds,requested_sats,u64,
148 tlvdata,opening_tlvs,request_funds,blockheight,u32,
149 msgtype,accept_channel2,65
150 msgdata,accept_channel2,channel_id,channel_id,
151 msgdata,accept_channel2,funding_satoshis,u64,
165 tlvtype,accept_tlvs,option_upfront_shutdown_script,1
166 tlvdata,accept_tlvs,option_upfront_shutdown_script,shutdown_len,u16,
167 tlvdata,accept_tlvs,option_upfront_shutdown_script,shutdown_scriptpubkey,byte,shutdown_len
168 tlvtype,accept_tlvs,will_fund,2
169 tlvdata,accept_tlvs,will_fund,signature,signature,
170 tlvdata,accept_tlvs,will_fund,lease_rates,lease_rates,
171 subtype,lease_rates
172 subtypedata,lease_rates,funding_weight,u16,
173 subtypedata,lease_rates,lease_fee_basis,u16,
174 subtypedata,lease_rates,channel_fee_max_proportional_thousandths,u16,
175 subtypedata,lease_rates,lease_fee_base_sat,u32,
176 subtypedata,lease_rates,channel_fee_max_base_msat,tu32,
177 msgtype,init_rbf,72
178 msgdata,init_rbf,channel_id,channel_id,
179 msgdata,init_rbf,funding_satoshis,u64,
227 msgtype,update_fee,134
228 msgdata,update_fee,channel_id,channel_id,
229 msgdata,update_fee,feerate_per_kw,u32,
230 msgtype,update_blockheight,137
231 msgdata,update_blockheight,channel_id,channel_id,
232 msgdata,update_blockheight,blockheight,u32,
233 msgtype,channel_reestablish,136
234 msgdata,channel_reestablish,channel_id,channel_id,
235 msgdata,channel_reestablish,next_commitment_number,u64,
264 msgdata,node_announcement,alias,byte,32
265 msgdata,node_announcement,addrlen,u16,
266 msgdata,node_announcement,addresses,byte,addrlen
267 msgdata,node_announcement,tlvs,node_ann_tlvs,
268 tlvtype,node_ann_tlvs,option_will_fund,1
269 tlvdata,node_ann_tlvs,option_will_fund,lease_rates,lease_rates,
270 msgtype,channel_update,258
271 msgdata,channel_update,signature,signature,
272 msgdata,channel_update,chain_hash,chain_hash,

168
wire/peer_wiregen.c generated
View File

@ -49,6 +49,7 @@ const char *peer_wire_name(int e)
case WIRE_COMMITMENT_SIGNED: return "WIRE_COMMITMENT_SIGNED";
case WIRE_REVOKE_AND_ACK: return "WIRE_REVOKE_AND_ACK";
case WIRE_UPDATE_FEE: return "WIRE_UPDATE_FEE";
case WIRE_UPDATE_BLOCKHEIGHT: return "WIRE_UPDATE_BLOCKHEIGHT";
case WIRE_CHANNEL_REESTABLISH: return "WIRE_CHANNEL_REESTABLISH";
case WIRE_ANNOUNCEMENT_SIGNATURES: return "WIRE_ANNOUNCEMENT_SIGNATURES";
case WIRE_CHANNEL_ANNOUNCEMENT: return "WIRE_CHANNEL_ANNOUNCEMENT";
@ -98,6 +99,7 @@ bool peer_wire_is_defined(u16 type)
case WIRE_COMMITMENT_SIGNED:;
case WIRE_REVOKE_AND_ACK:;
case WIRE_UPDATE_FEE:;
case WIRE_UPDATE_BLOCKHEIGHT:;
case WIRE_CHANNEL_REESTABLISH:;
case WIRE_ANNOUNCEMENT_SIGNATURES:;
case WIRE_CHANNEL_ANNOUNCEMENT:;
@ -138,6 +140,26 @@ fromwire_u8_array(cursor, plen, witness_element->witness, len);
return witness_element;
}
/* SUBTYPE: LEASE_RATES */
void towire_lease_rates(u8 **p, const struct lease_rates *lease_rates)
{
towire_u16(p, lease_rates->funding_weight);
towire_u16(p, lease_rates->lease_fee_basis);
towire_u16(p, lease_rates->channel_fee_max_proportional_thousandths);
towire_u32(p, lease_rates->lease_fee_base_sat);
towire_tu32(p, lease_rates->channel_fee_max_base_msat);
}
void fromwire_lease_rates(const u8 **cursor, size_t *plen, struct lease_rates *lease_rates)
{
lease_rates->funding_weight = fromwire_u16(cursor, plen);
lease_rates->lease_fee_basis = fromwire_u16(cursor, plen);
lease_rates->channel_fee_max_proportional_thousandths = fromwire_u16(cursor, plen);
lease_rates->lease_fee_base_sat = fromwire_u32(cursor, plen);
lease_rates->channel_fee_max_base_msat = fromwire_tu32(cursor, plen);
}
/* SUBTYPE: CHANNEL_UPDATE_CHECKSUMS */
void towire_channel_update_checksums(u8 **p, const struct channel_update_checksums *channel_update_checksums)
{
@ -609,20 +631,46 @@ static void fromwire_tlv_opening_tlvs_option_upfront_shutdown_script(const u8 **
r->option_upfront_shutdown_script->shutdown_scriptpubkey = shutdown_len ? tal_arr(r->option_upfront_shutdown_script, u8, shutdown_len) : NULL;
fromwire_u8_array(cursor, plen, r->option_upfront_shutdown_script->shutdown_scriptpubkey, shutdown_len);
}
/* OPENING_TLVS MSG: request_funds */
static u8 *towire_tlv_opening_tlvs_request_funds(const tal_t *ctx, const void *vrecord)
{
const struct tlv_opening_tlvs *r = vrecord;
u8 *ptr;
if (!r->request_funds)
return NULL;
ptr = tal_arr(ctx, u8, 0);
towire_u64(&ptr, r->request_funds->requested_sats);
towire_u32(&ptr, r->request_funds->blockheight);
return ptr;
}
static void fromwire_tlv_opening_tlvs_request_funds(const u8 **cursor, size_t *plen, void *vrecord)
{
struct tlv_opening_tlvs *r = vrecord;
r->request_funds = tal(r, struct tlv_opening_tlvs_request_funds);
r->request_funds->requested_sats = fromwire_u64(cursor, plen);
r->request_funds->blockheight = fromwire_u32(cursor, plen);
}
static const struct tlv_record_type tlvs_opening_tlvs[] = {
{ 1, towire_tlv_opening_tlvs_option_upfront_shutdown_script, fromwire_tlv_opening_tlvs_option_upfront_shutdown_script },
{ 3, towire_tlv_opening_tlvs_request_funds, fromwire_tlv_opening_tlvs_request_funds },
};
void towire_opening_tlvs(u8 **pptr, const struct tlv_opening_tlvs *record)
{
towire_tlv(pptr, tlvs_opening_tlvs, 1, record);
towire_tlv(pptr, tlvs_opening_tlvs, 2, record);
}
bool fromwire_opening_tlvs(const u8 **cursor, size_t *max, struct tlv_opening_tlvs *record)
{
return fromwire_tlv(cursor, max, tlvs_opening_tlvs, 1, record, &record->fields);
return fromwire_tlv(cursor, max, tlvs_opening_tlvs, 2, record, &record->fields);
}
bool opening_tlvs_is_valid(const struct tlv_opening_tlvs *record, size_t *err_index)
@ -669,20 +717,46 @@ static void fromwire_tlv_accept_tlvs_option_upfront_shutdown_script(const u8 **c
r->option_upfront_shutdown_script->shutdown_scriptpubkey = shutdown_len ? tal_arr(r->option_upfront_shutdown_script, u8, shutdown_len) : NULL;
fromwire_u8_array(cursor, plen, r->option_upfront_shutdown_script->shutdown_scriptpubkey, shutdown_len);
}
/* ACCEPT_TLVS MSG: will_fund */
static u8 *towire_tlv_accept_tlvs_will_fund(const tal_t *ctx, const void *vrecord)
{
const struct tlv_accept_tlvs *r = vrecord;
u8 *ptr;
if (!r->will_fund)
return NULL;
ptr = tal_arr(ctx, u8, 0);
towire_secp256k1_ecdsa_signature(&ptr, &r->will_fund->signature);
towire_lease_rates(&ptr, &r->will_fund->lease_rates);
return ptr;
}
static void fromwire_tlv_accept_tlvs_will_fund(const u8 **cursor, size_t *plen, void *vrecord)
{
struct tlv_accept_tlvs *r = vrecord;
r->will_fund = tal(r, struct tlv_accept_tlvs_will_fund);
fromwire_secp256k1_ecdsa_signature(cursor, plen, &r->will_fund->signature);
fromwire_lease_rates(cursor, plen, &r->will_fund->lease_rates);
}
static const struct tlv_record_type tlvs_accept_tlvs[] = {
{ 1, towire_tlv_accept_tlvs_option_upfront_shutdown_script, fromwire_tlv_accept_tlvs_option_upfront_shutdown_script },
{ 2, towire_tlv_accept_tlvs_will_fund, fromwire_tlv_accept_tlvs_will_fund },
};
void towire_accept_tlvs(u8 **pptr, const struct tlv_accept_tlvs *record)
{
towire_tlv(pptr, tlvs_accept_tlvs, 1, record);
towire_tlv(pptr, tlvs_accept_tlvs, 2, record);
}
bool fromwire_accept_tlvs(const u8 **cursor, size_t *max, struct tlv_accept_tlvs *record)
{
return fromwire_tlv(cursor, max, tlvs_accept_tlvs, 1, record, &record->fields);
return fromwire_tlv(cursor, max, tlvs_accept_tlvs, 2, record, &record->fields);
}
bool accept_tlvs_is_valid(const struct tlv_accept_tlvs *record, size_t *err_index)
@ -748,6 +822,61 @@ bool shutdown_tlvs_is_valid(const struct tlv_shutdown_tlvs *record, size_t *err_
}
struct tlv_node_ann_tlvs *tlv_node_ann_tlvs_new(const tal_t *ctx)
{
/* Initialize everything to NULL. (Quiet, C pedants!) */
struct tlv_node_ann_tlvs *inst = talz(ctx, struct tlv_node_ann_tlvs);
/* Initialized the fields to an empty array. */
inst->fields = tal_arr(inst, struct tlv_field, 0);
return inst;
}
/* NODE_ANN_TLVS MSG: option_will_fund */
static u8 *towire_tlv_node_ann_tlvs_option_will_fund(const tal_t *ctx, const void *vrecord)
{
const struct tlv_node_ann_tlvs *r = vrecord;
u8 *ptr;
if (!r->option_will_fund)
return NULL;
ptr = tal_arr(ctx, u8, 0);
towire_lease_rates(&ptr, r->option_will_fund);
return ptr;
}
static void fromwire_tlv_node_ann_tlvs_option_will_fund(const u8 **cursor, size_t *plen, void *vrecord)
{
struct tlv_node_ann_tlvs *r = vrecord;
r->option_will_fund = tal(r, struct lease_rates);
fromwire_lease_rates(cursor, plen, &*r->option_will_fund);
}
static const struct tlv_record_type tlvs_node_ann_tlvs[] = {
{ 1, towire_tlv_node_ann_tlvs_option_will_fund, fromwire_tlv_node_ann_tlvs_option_will_fund },
};
void towire_node_ann_tlvs(u8 **pptr, const struct tlv_node_ann_tlvs *record)
{
towire_tlv(pptr, tlvs_node_ann_tlvs, 1, record);
}
bool fromwire_node_ann_tlvs(const u8 **cursor, size_t *max, struct tlv_node_ann_tlvs *record)
{
return fromwire_tlv(cursor, max, tlvs_node_ann_tlvs, 1, record, &record->fields);
}
bool node_ann_tlvs_is_valid(const struct tlv_node_ann_tlvs *record, size_t *err_index)
{
return tlv_fields_valid(record->fields, NULL, err_index);
}
struct tlv_query_short_channel_ids_tlvs *tlv_query_short_channel_ids_tlvs_new(const tal_t *ctx)
{
/* Initialize everything to NULL. (Quiet, C pedants!) */
@ -1926,6 +2055,29 @@ bool fromwire_update_fee(const void *p, struct channel_id *channel_id, u32 *feer
return cursor != NULL;
}
/* WIRE: UPDATE_BLOCKHEIGHT */
u8 *towire_update_blockheight(const tal_t *ctx, const struct channel_id *channel_id, u32 blockheight)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_UPDATE_BLOCKHEIGHT);
towire_channel_id(&p, channel_id);
towire_u32(&p, blockheight);
return memcheck(p, tal_count(p));
}
bool fromwire_update_blockheight(const void *p, struct channel_id *channel_id, u32 *blockheight)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_UPDATE_BLOCKHEIGHT)
return false;
fromwire_channel_id(&cursor, &plen, channel_id);
*blockheight = fromwire_u32(&cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNEL_REESTABLISH */
u8 *towire_channel_reestablish(const tal_t *ctx, const struct channel_id *channel_id, u64 next_commitment_number, u64 next_revocation_number, const struct secret *your_last_per_commitment_secret, const struct pubkey *my_current_per_commitment_point)
{
@ -2031,7 +2183,7 @@ bool fromwire_channel_announcement(const tal_t *ctx, const void *p, secp256k1_ec
}
/* WIRE: NODE_ANNOUNCEMENT */
u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const u8 *features, u32 timestamp, const struct node_id *node_id, const u8 rgb_color[3], const u8 alias[32], const u8 *addresses)
u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const u8 *features, u32 timestamp, const struct node_id *node_id, const u8 rgb_color[3], const u8 alias[32], const u8 *addresses, const struct tlv_node_ann_tlvs *tlvs)
{
u16 flen = tal_count(features);
u16 addrlen = tal_count(addresses);
@ -2047,10 +2199,11 @@ u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *
towire_u8_array(&p, alias, 32);
towire_u16(&p, addrlen);
towire_u8_array(&p, addresses, addrlen);
towire_node_ann_tlvs(&p, tlvs);
return memcheck(p, tal_count(p));
}
bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *signature, u8 **features, u32 *timestamp, struct node_id *node_id, u8 rgb_color[3], u8 alias[32], u8 **addresses)
bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *signature, u8 **features, u32 *timestamp, struct node_id *node_id, u8 rgb_color[3], u8 alias[32], u8 **addresses, struct tlv_node_ann_tlvs *tlvs)
{
u16 flen;
u16 addrlen;
@ -2073,6 +2226,7 @@ bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa
// 2nd case addresses
*addresses = addrlen ? tal_arr(ctx, u8, addrlen) : NULL;
fromwire_u8_array(&cursor, &plen, *addresses, addrlen);
fromwire_node_ann_tlvs(&cursor, &plen, tlvs);
return cursor != NULL;
}
@ -2330,4 +2484,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:a3a508935b99ff0b985d0774432ae9d98f3ec7660bf4edf64095a3d0a37ba0e8
// SHA256STAMP:4751c4834d5db7d170f8e1ee40ea8b5e12b5552780d37b099fe5fae6f0342c9e

77
wire/peer_wiregen.h generated
View File

@ -46,6 +46,7 @@ enum peer_wire {
WIRE_COMMITMENT_SIGNED = 132,
WIRE_REVOKE_AND_ACK = 133,
WIRE_UPDATE_FEE = 134,
WIRE_UPDATE_BLOCKHEIGHT = 137,
WIRE_CHANNEL_REESTABLISH = 136,
WIRE_ANNOUNCEMENT_SIGNATURES = 259,
WIRE_CHANNEL_ANNOUNCEMENT = 256,
@ -73,6 +74,13 @@ bool peer_wire_is_defined(u16 type);
struct witness_element {
u8 *witness;
};
struct lease_rates {
u16 funding_weight;
u16 lease_fee_basis;
u16 channel_fee_max_proportional_thousandths;
u32 lease_fee_base_sat;
u32 channel_fee_max_base_msat;
};
struct channel_update_checksums {
u32 checksum_node_id_1;
u32 checksum_node_id_2;
@ -92,9 +100,17 @@ struct tlv_n1_tlv3 {
struct tlv_opening_tlvs_option_upfront_shutdown_script {
u8 *shutdown_scriptpubkey;
};
struct tlv_opening_tlvs_request_funds {
u64 requested_sats;
u32 blockheight;
};
struct tlv_accept_tlvs_option_upfront_shutdown_script {
u8 *shutdown_scriptpubkey;
};
struct tlv_accept_tlvs_will_fund {
secp256k1_ecdsa_signature signature;
struct lease_rates lease_rates;
};
struct tlv_shutdown_tlvs_wrong_funding {
struct bitcoin_txid txid;
u32 outnum;
@ -158,6 +174,7 @@ struct tlv_opening_tlvs {
/* TODO The following explicit fields could just point into the
* tlv_field entries above to save on memory. */
struct tlv_opening_tlvs_option_upfront_shutdown_script *option_upfront_shutdown_script;
struct tlv_opening_tlvs_request_funds *request_funds;
};
struct tlv_accept_tlvs {
/* Raw fields including unknown ones. */
@ -166,6 +183,7 @@ struct tlv_accept_tlvs {
/* TODO The following explicit fields could just point into the
* tlv_field entries above to save on memory. */
struct tlv_accept_tlvs_option_upfront_shutdown_script *option_upfront_shutdown_script;
struct tlv_accept_tlvs_will_fund *will_fund;
};
struct tlv_shutdown_tlvs {
/* Raw fields including unknown ones. */
@ -175,6 +193,14 @@ struct tlv_shutdown_tlvs {
* tlv_field entries above to save on memory. */
struct tlv_shutdown_tlvs_wrong_funding *wrong_funding;
};
struct tlv_node_ann_tlvs {
/* Raw fields including unknown ones. */
struct tlv_field *fields;
/* TODO The following explicit fields could just point into the
* tlv_field entries above to save on memory. */
struct lease_rates *option_will_fund;
};
struct tlv_query_short_channel_ids_tlvs {
/* Raw fields including unknown ones. */
struct tlv_field *fields;
@ -529,6 +555,43 @@ void towire_shutdown_tlvs(u8 **pptr, const struct tlv_shutdown_tlvs *record);
bool shutdown_tlvs_is_valid(const struct tlv_shutdown_tlvs *record,
size_t *err_index);
struct tlv_node_ann_tlvs *tlv_node_ann_tlvs_new(const tal_t *ctx);
/**
* Deserialize a TLV stream for the node_ann_tlvs namespace.
*
* This function will parse any TLV stream, as long as the type, length and
* value fields are formatted correctly. Fields that are not known in the
* current namespace are stored in the `fields` member. Validity can be
* checked using node_ann_tlvs_is_valid.
*/
bool fromwire_node_ann_tlvs(const u8 **cursor, size_t *max,
struct tlv_node_ann_tlvs * record);
/**
* Serialize a TLV stream for the node_ann_tlvs namespace.
*
* This function only considers known fields from the node_ann_tlvs namespace,
* and will ignore any fields that may be stored in the `fields` member. This
* ensures that the resulting stream is valid according to
* `node_ann_tlvs_is_valid`.
*/
void towire_node_ann_tlvs(u8 **pptr, const struct tlv_node_ann_tlvs *record);
/**
* Check that the TLV stream is valid.
*
* Enforces the followin validity rules:
* - Types must be in monotonic non-repeating order
* - We must understand all even types
*
* Returns false if an error was detected, otherwise returns true. If err_index
* is non-null and we detect an error it is set to the index of the first error
* detected.
*/
bool node_ann_tlvs_is_valid(const struct tlv_node_ann_tlvs *record,
size_t *err_index);
struct tlv_query_short_channel_ids_tlvs *tlv_query_short_channel_ids_tlvs_new(const tal_t *ctx);
/**
@ -681,6 +744,10 @@ bool onion_message_tlvs_is_valid(const struct tlv_onion_message_tlvs *record,
void towire_witness_element(u8 **p, const struct witness_element *witness_element);
struct witness_element *fromwire_witness_element(const tal_t *ctx, const u8 **cursor, size_t *plen);
/* SUBTYPE: LEASE_RATES */
void towire_lease_rates(u8 **p, const struct lease_rates *lease_rates);
void fromwire_lease_rates(const u8 **cursor, size_t *plen, struct lease_rates *lease_rates);
/* SUBTYPE: CHANNEL_UPDATE_CHECKSUMS */
void towire_channel_update_checksums(u8 **p, const struct channel_update_checksums *channel_update_checksums);
void fromwire_channel_update_checksums(const u8 **cursor, size_t *plen, struct channel_update_checksums *channel_update_checksums);
@ -809,6 +876,10 @@ bool fromwire_revoke_and_ack(const void *p, struct channel_id *channel_id, struc
u8 *towire_update_fee(const tal_t *ctx, const struct channel_id *channel_id, u32 feerate_per_kw);
bool fromwire_update_fee(const void *p, struct channel_id *channel_id, u32 *feerate_per_kw);
/* WIRE: UPDATE_BLOCKHEIGHT */
u8 *towire_update_blockheight(const tal_t *ctx, const struct channel_id *channel_id, u32 blockheight);
bool fromwire_update_blockheight(const void *p, struct channel_id *channel_id, u32 *blockheight);
/* WIRE: CHANNEL_REESTABLISH */
u8 *towire_channel_reestablish(const tal_t *ctx, const struct channel_id *channel_id, u64 next_commitment_number, u64 next_revocation_number, const struct secret *your_last_per_commitment_secret, const struct pubkey *my_current_per_commitment_point);
bool fromwire_channel_reestablish(const void *p, struct channel_id *channel_id, u64 *next_commitment_number, u64 *next_revocation_number, struct secret *your_last_per_commitment_secret, struct pubkey *my_current_per_commitment_point);
@ -822,8 +893,8 @@ u8 *towire_channel_announcement(const tal_t *ctx, const secp256k1_ecdsa_signatur
bool fromwire_channel_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *node_signature_1, secp256k1_ecdsa_signature *node_signature_2, secp256k1_ecdsa_signature *bitcoin_signature_1, secp256k1_ecdsa_signature *bitcoin_signature_2, u8 **features, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, struct node_id *node_id_1, struct node_id *node_id_2, struct pubkey *bitcoin_key_1, struct pubkey *bitcoin_key_2);
/* WIRE: NODE_ANNOUNCEMENT */
u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const u8 *features, u32 timestamp, const struct node_id *node_id, const u8 rgb_color[3], const u8 alias[32], const u8 *addresses);
bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *signature, u8 **features, u32 *timestamp, struct node_id *node_id, u8 rgb_color[3], u8 alias[32], u8 **addresses);
u8 *towire_node_announcement(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const u8 *features, u32 timestamp, const struct node_id *node_id, const u8 rgb_color[3], const u8 alias[32], const u8 *addresses, const struct tlv_node_ann_tlvs *tlvs);
bool fromwire_node_announcement(const tal_t *ctx, const void *p, secp256k1_ecdsa_signature *signature, u8 **features, u32 *timestamp, struct node_id *node_id, u8 rgb_color[3], u8 alias[32], u8 **addresses, struct tlv_node_ann_tlvs *tlvs);
/* WIRE: CHANNEL_UPDATE */
u8 *towire_channel_update(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths);
@ -859,4 +930,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec
#endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */
// SHA256STAMP:a3a508935b99ff0b985d0774432ae9d98f3ec7660bf4edf64095a3d0a37ba0e8
// SHA256STAMP:4751c4834d5db7d170f8e1ee40ea8b5e12b5552780d37b099fe5fae6f0342c9e

View File

@ -167,6 +167,7 @@ struct msg_node_announcement {
u8 alias[32];
u8 *features;
u8 *addresses;
struct tlv_node_ann_tlvs *tlvs;
};
struct msg_open_channel {
struct bitcoin_blkid chain_hash;
@ -371,12 +372,14 @@ static void *towire_struct_node_announcement(const tal_t *ctx,
&s->node_id,
s->rgb_color,
s->alias,
s->addresses);
s->addresses,
s->tlvs);
}
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,
@ -384,7 +387,8 @@ static struct msg_node_announcement *fromwire_struct_node_announcement(const tal
&s->node_id,
s->rgb_color,
s->alias,
&s->addresses))
&s->addresses,
s->tlvs))
return tal_free(s);
return s;
}
@ -925,9 +929,37 @@ static bool update_add_htlc_eq(const struct msg_update_add_htlc *a,
return eq_with(a, b, onion_routing_packet);
}
static bool
lease_rates_eq(const struct lease_rates *a,
const struct lease_rates *b)
{
return eq_field(a, b, channel_fee_max_base_msat)
&& eq_field(a, b, channel_fee_max_proportional_thousandths)
&& eq_field(a, b, funding_weight)
&& eq_field(a, b, lease_fee_base_sat)
&& eq_field(a, b, lease_fee_basis);
}
static bool node_announcement_eq(const struct msg_node_announcement *a,
const struct msg_node_announcement *b)
{
/* Both or neither */
if (!a->tlvs != !b->tlvs)
return false;
if (!a->tlvs)
goto body_check;
/* Both or neither */
if (!a->tlvs->option_will_fund != !b->tlvs->option_will_fund)
return false;
if (a->tlvs->option_will_fund
&& !lease_rates_eq(a->tlvs->option_will_fund,
b->tlvs->option_will_fund))
return false;
body_check:
return eq_with(a, b, node_id)
&& eq_field(a, b, rgb_color)
&& eq_field(a, b, alias)
@ -1165,11 +1197,15 @@ int main(int argc, char *argv[])
memset(na.features, 2, 2);
na.addresses = tal_arr(ctx, u8, 2);
memset(na.addresses, 2, 2);
na.tlvs= tlv_node_ann_tlvs_new(ctx);
na.tlvs->option_will_fund = tal(ctx, struct lease_rates);
memset(na.tlvs->option_will_fund, 2,
sizeof(*na.tlvs->option_will_fund));
msg = towire_struct_node_announcement(ctx, &na);
na2 = fromwire_struct_node_announcement(ctx, msg);
assert(node_announcement_eq(&na, na2));
test_corruption(&na, na2, node_announcement);
test_corruption_tlv(&na, na2, node_announcement);
tal_free(ctx);
common_shutdown();