common/channel_type: wrapper for generated 'struct channel_type'.

We make it a first-class citizen internally, even though we won't use
it over the wire (at least, non-experimental builds).  This scheme
follows the latest draft, in which features are flagged compulsory.

We also add several helper functions.

Since uses the *even* bits (as per latest spec), not the *odd* bits,
we have some other fixups.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-09-09 12:20:52 +09:30
committed by Christian Decker
parent 1b8551923d
commit cb22015b2a
74 changed files with 404 additions and 122 deletions

View File

@@ -11,6 +11,7 @@ WIRE_HEADERS := wire/onion_defs.h \
wire/onion$(EXP)_wiregen.h \
wire/bolt12$(EXP)_wiregen.h \
wire/common_wiregen.h \
wire/channel_type_wiregen.h \
wire/peer$(EXP)_printgen.h \
wire/onion$(EXP)_printgen.h
@@ -24,11 +25,13 @@ WIRE_SRC := wire/wire_sync.c \
wire/common_wiregen.c \
wire/bolt12$(EXP)_wiregen.c \
wire/peer$(EXP)_wiregen.c \
wire/channel_type_wiregen.c \
wire/onion$(EXP)_wiregen.c
WIRE_PRINT_SRC := \
wire/onion$(EXP)_printgen.c \
wire/peer$(EXP)_printgen.c
wire/peer$(EXP)_printgen.c \
wire/channel_type_printgen.c
WIRE_OBJS := $(WIRE_SRC:.c=.o)
WIRE_PRINT_OBJS := $(WIRE_PRINT_SRC:.c=.o)
@@ -45,7 +48,8 @@ WIRE_NONEXP_HEADERS := wire/peer_wiregen.h \
wire/onion_wiregen.h \
wire/bolt12_wiregen.h \
wire/peer_printgen.h \
wire/onion_printgen.h
wire/onion_printgen.h \
wire/channel_type_printgen.h
ALL_C_SOURCES += $(WIRE_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC)
@@ -125,8 +129,9 @@ wire/onion_wiregen.h_args := --include='bitcoin/short_channel_id.h' --include='b
wire/onion_wiregen.c_args := -s --expose-tlv-type=tlv_payload
# Same for _exp versions
wire/peer_exp_wiregen.h_args := $(wire/peer_wiregen.h_args)
wire/peer_exp_wiregen.h_args := $(wire/peer_wiregen.h_args) --include='wire/channel_type_wiregen.h'
wire/peer_exp_wiregen.c_args := $(wire/peer_wiregen.c_args)
wire/peer_exp_printgen.h_args := --include='wire/channel_type_printgen.h'
wire/onion_exp_wiregen.h_args := $(wire/onion_wiregen.h_args)
wire/onion_exp_wiregen.c_args := $(wire/onion_wiregen.c_args)
@@ -138,6 +143,9 @@ wire/bolt12_exp_wiregen.c_args := $(wire/bolt12_wiregen.c_args)
wire/peer_wiregen.h_args := --include='common/channel_id.h' --include='bitcoin/tx.h' --include='bitcoin/preimage.h' --include='bitcoin/short_channel_id.h' --include='common/node_id.h' --include='common/bigsize.h' --include='bitcoin/block.h' --include='bitcoin/privkey.h' -s --expose-tlv-type=n1 --expose-tlv-type=n2
wire/channel_type_wiregen.h_args := -s
wire/channel_type_wiregen.c_args := $(wire/channel_type_wiregen.h_args)
# All generated wire/ files depend on this Makefile
$(filter %printgen.h %printgen.c %wiregen.h %wiregen.c, $(WIRE_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) $(WIRE_HEADERS) $(WIRE_NONEXP_HEADERS)): wire/Makefile

2
wire/bolt12_wiregen.c generated
View File

@@ -1684,4 +1684,4 @@ bool invoice_error_is_valid(const struct tlv_invoice_error *record, size_t *err_
return tlv_fields_valid(record->fields, NULL, err_index);
}
// SHA256STAMP:53c38e8f9d5938a10c80fffa22d9093be51728cf59d3ef13ec477c848e9d48d1
// SHA256STAMP:d6c9a7b168be00b6c823052f1c62bf4fec8792ca81bc9125173af0bd357885f4

2
wire/bolt12_wiregen.h generated
View File

@@ -323,4 +323,4 @@ struct fallback_address *fromwire_fallback_address(const tal_t *ctx, const u8 **
#endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */
// SHA256STAMP:53c38e8f9d5938a10c80fffa22d9093be51728cf59d3ef13ec477c848e9d48d1
// SHA256STAMP:d6c9a7b168be00b6c823052f1c62bf4fec8792ca81bc9125173af0bd357885f4

View File

@@ -0,0 +1,4 @@
# Why not let our generator generate this too?
subtype,channel_type
subtypedata,channel_type,len,u16,
subtypedata,channel_type,features,byte,len
1 # Why not let our generator generate this too?
2 subtype,channel_type
3 subtypedata,channel_type,len,u16,
4 subtypedata,channel_type,features,byte,len

2
wire/common_wiregen.c generated
View File

@@ -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:0f582c50fa133054209e1f89e22ae78f969ada0d08ce162c63700051a6a25a9e
// SHA256STAMP:402f88d03a71eaf310e65fcd62fd87becf788a30626ed96c8eab3da538717a60

2
wire/common_wiregen.h generated
View File

@@ -41,4 +41,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg);
#endif /* LIGHTNING_WIRE_COMMON_WIREGEN_H */
// SHA256STAMP:0f582c50fa133054209e1f89e22ae78f969ada0d08ce162c63700051a6a25a9e
// SHA256STAMP:402f88d03a71eaf310e65fcd62fd87becf788a30626ed96c8eab3da538717a60

View File

@@ -1,6 +1,6 @@
--- wire/peer_wire.csv 2021-05-09 15:44:59.166135652 +0930
+++ wire/peer_wire.csv.raw 2021-05-11 09:59:31.695459756 +0930
@@ -221,6 +131,18 @@
@@ -221,6 +131,15 @@
msgdata,channel_reestablish,next_revocation_number,u64,
msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
msgdata,channel_reestablish,my_current_per_commitment_point,point,
@@ -13,9 +13,6 @@
+tlvdata,channel_reestablish_tlvs,current_type,type,channel_type,
+tlvtype,channel_reestablish_tlvs,upgradable,7
+tlvdata,channel_reestablish_tlvs,upgradable,upgrades,channel_type,...
+subtype,channel_type
+subtypedata,channel_type,len,u16,
+subtypedata,channel_type,features,byte,len
msgtype,announcement_signatures,259
msgdata,announcement_signatures,channel_id,channel_id,
msgdata,announcement_signatures,short_channel_id,short_channel_id,

2
wire/onion_printgen.c generated
View File

@@ -859,4 +859,4 @@ void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) {
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_encmsg_tlvs, ARRAY_SIZE(print_tlvs_encmsg_tlvs));
}
}
// SHA256STAMP:a2a9a3075de158a886d768a148ca3dde70956188f7be6cc141cce25211cf1258
// SHA256STAMP:09dc1e023332a80d6e5b948472d121823404a3d7bfc843142b00ead7892148a1

2
wire/onion_printgen.h generated
View File

@@ -58,4 +58,4 @@ void printwire_mpp_timeout(const char *fieldname, const u8 *cursor);
void printwire_onionmsg_path(const char *fieldname, const u8 **cursor, size_t *plen);
#endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */
// SHA256STAMP:a2a9a3075de158a886d768a148ca3dde70956188f7be6cc141cce25211cf1258
// SHA256STAMP:09dc1e023332a80d6e5b948472d121823404a3d7bfc843142b00ead7892148a1

2
wire/onion_wiregen.c generated
View File

@@ -1026,4 +1026,4 @@ bool fromwire_mpp_timeout(const void *p)
return false;
return cursor != NULL;
}
// SHA256STAMP:a2a9a3075de158a886d768a148ca3dde70956188f7be6cc141cce25211cf1258
// SHA256STAMP:09dc1e023332a80d6e5b948472d121823404a3d7bfc843142b00ead7892148a1

2
wire/onion_wiregen.h generated
View File

@@ -317,4 +317,4 @@ bool fromwire_mpp_timeout(const void *p);
#endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */
// SHA256STAMP:a2a9a3075de158a886d768a148ca3dde70956188f7be6cc141cce25211cf1258
// SHA256STAMP:09dc1e023332a80d6e5b948472d121823404a3d7bfc843142b00ead7892148a1

2
wire/peer_printgen.c generated
View File

@@ -3139,4 +3139,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:bf392c19e6fd1e87040d84d0de259dcec0fa52b4d78e613629ef049e373e1d78
// SHA256STAMP:594dbd4e700334431fccd0dc7bd7ef22ca033299d24ba92f920601a807291c64

2
wire/peer_printgen.h generated
View File

@@ -99,4 +99,4 @@ void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor
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:bf392c19e6fd1e87040d84d0de259dcec0fa52b4d78e613629ef049e373e1d78
// SHA256STAMP:594dbd4e700334431fccd0dc7bd7ef22ca033299d24ba92f920601a807291c64

2
wire/peer_wiregen.c generated
View File

@@ -2589,4 +2589,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:bf392c19e6fd1e87040d84d0de259dcec0fa52b4d78e613629ef049e373e1d78
// SHA256STAMP:594dbd4e700334431fccd0dc7bd7ef22ca033299d24ba92f920601a807291c64

2
wire/peer_wiregen.h generated
View File

@@ -981,4 +981,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec
#endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */
// SHA256STAMP:bf392c19e6fd1e87040d84d0de259dcec0fa52b4d78e613629ef049e373e1d78
// SHA256STAMP:594dbd4e700334431fccd0dc7bd7ef22ca033299d24ba92f920601a807291c64

View File

@@ -12,6 +12,7 @@
#include <ccan/str/hex/hex.h>
#include <common/amount.h>
#include <common/bigsize.h>
#include <common/channel_type.h>
#include <bitcoin/chainparams.h>
#include <common/setup.h>
#include <common/sphinx.h>
@@ -21,6 +22,12 @@
extern secp256k1_context *secp256k1_ctx;
/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_channel_type */
struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED)
{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); }
/* Generated stub for towire_channel_type */
void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED)
{ fprintf(stderr, "towire_channel_type called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
/* memsetting pubkeys doesn't work */

View File

@@ -1,5 +1,6 @@
#include <ccan/array_size/array_size.h>
#include <ccan/str/hex/hex.h>
#include <common/channel_type.h>
#include <common/utils.h>
#include <stdio.h>
#include <wally_core.h>
@@ -28,9 +29,15 @@ static const char *reason;
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_channel_type */
struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED)
{ fprintf(stderr, "fromwire_channel_type 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_channel_type */
void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED)
{ fprintf(stderr, "towire_channel_type called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */