2018-01-12 14:35:52 +01:00
|
|
|
#ifndef LIGHTNING_COMMON_FEATURES_H
|
|
|
|
#define LIGHTNING_COMMON_FEATURES_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
|
2020-03-31 00:39:00 +02:00
|
|
|
enum feature_place {
|
|
|
|
INIT_FEATURE,
|
|
|
|
GLOBAL_INIT_FEATURE,
|
|
|
|
NODE_ANNOUNCE_FEATURE,
|
|
|
|
CHANNEL_FEATURE,
|
|
|
|
BOLT11_FEATURE,
|
2022-11-09 03:32:00 +01:00
|
|
|
BOLT12_OFFER_FEATURE,
|
|
|
|
BOLT12_INVREQ_FEATURE,
|
|
|
|
BOLT12_INVOICE_FEATURE,
|
2020-03-31 00:39:00 +02:00
|
|
|
};
|
2022-11-09 03:32:00 +01:00
|
|
|
#define NUM_FEATURE_PLACE (BOLT12_INVOICE_FEATURE+1)
|
2020-03-31 15:32:16 +02:00
|
|
|
extern const char *feature_place_names[NUM_FEATURE_PLACE];
|
|
|
|
|
2020-03-31 00:39:00 +02:00
|
|
|
/* The complete set of features for all contexts */
|
|
|
|
struct feature_set {
|
|
|
|
u8 *bits[NUM_FEATURE_PLACE];
|
|
|
|
};
|
|
|
|
|
2020-04-02 06:04:47 +02:00
|
|
|
/* Create feature set for a known feature. */
|
|
|
|
struct feature_set *feature_set_for_feature(const tal_t *ctx, int feature);
|
2020-03-31 00:39:00 +02:00
|
|
|
|
2020-04-02 06:04:47 +02:00
|
|
|
/* Marshalling a feature set */
|
2020-03-31 00:39:00 +02:00
|
|
|
struct feature_set *fromwire_feature_set(const tal_t *ctx,
|
|
|
|
const u8 **ptr, size_t *max);
|
|
|
|
void towire_feature_set(u8 **pptr, const struct feature_set *fset);
|
|
|
|
|
2020-04-02 06:04:47 +02:00
|
|
|
/* a |= b, or returns false if features already in a */
|
|
|
|
bool feature_set_or(struct feature_set *a,
|
|
|
|
const struct feature_set *b TAKES);
|
2020-03-31 00:39:00 +02:00
|
|
|
|
2020-10-22 20:18:38 +02:00
|
|
|
/* a - b, or returns false if features not already in a */
|
|
|
|
bool feature_set_sub(struct feature_set *a,
|
|
|
|
const struct feature_set *b TAKES);
|
|
|
|
|
2019-11-23 01:19:23 +01:00
|
|
|
/* Returns -1 if we're OK with all these offered features, otherwise first
|
|
|
|
* unsupported (even) feature. */
|
2020-04-03 02:03:59 +02:00
|
|
|
int features_unsupported(const struct feature_set *our_features,
|
|
|
|
const u8 *their_features,
|
2020-04-02 06:04:47 +02:00
|
|
|
enum feature_place p);
|
2018-03-13 16:41:55 +01:00
|
|
|
|
2020-03-31 00:39:00 +02:00
|
|
|
/* For the features in channel_announcement */
|
2020-04-02 06:04:47 +02:00
|
|
|
u8 *get_agreed_channelfeatures(const tal_t *ctx,
|
2020-04-03 02:03:59 +02:00
|
|
|
const struct feature_set *our_features,
|
2020-04-02 06:04:47 +02:00
|
|
|
const u8 *theirfeatures);
|
2020-03-31 00:39:00 +02:00
|
|
|
|
2018-03-13 16:41:55 +01:00
|
|
|
/* Is this feature bit requested? (Either compulsory or optional) */
|
|
|
|
bool feature_offered(const u8 *features, size_t f);
|
|
|
|
|
2018-12-03 00:05:06 +01:00
|
|
|
/* Was this feature bit offered by them and us? */
|
2020-04-03 02:03:59 +02:00
|
|
|
bool feature_negotiated(const struct feature_set *our_features,
|
|
|
|
const u8 *their_features, size_t f);
|
2018-12-03 00:05:06 +01:00
|
|
|
|
2020-08-13 19:38:02 +02:00
|
|
|
/* Features can depend on other features: both must be set!
|
|
|
|
* Sets @depender, @missing_dependency if returns false.
|
|
|
|
*/
|
|
|
|
bool feature_check_depends(const u8 *their_features,
|
|
|
|
size_t *depender, size_t *missing_dependency);
|
|
|
|
|
2020-04-02 06:04:47 +02:00
|
|
|
/* Return a list of what (init) features we advertize. */
|
|
|
|
const char **list_supported_features(const tal_t *ctx,
|
2020-04-03 02:03:59 +02:00
|
|
|
const struct feature_set *fset);
|
2019-08-29 03:01:55 +02:00
|
|
|
|
2021-09-23 04:29:48 +02:00
|
|
|
/* Give a name for this feature */
|
|
|
|
const char *feature_name(const tal_t *ctx, size_t f);
|
|
|
|
|
2019-09-03 06:16:03 +02:00
|
|
|
/* Low-level helpers to deal with big-endian bitfields. */
|
|
|
|
bool feature_is_set(const u8 *features, size_t bit);
|
|
|
|
void set_feature_bit(u8 **ptr, u32 bit);
|
|
|
|
|
2020-01-30 15:40:09 +01:00
|
|
|
/* Given two featurebit vectors, combine them by applying a logical OR. */
|
|
|
|
u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES);
|
2022-04-15 14:24:09 +02:00
|
|
|
/* Unset a given bit in a featurebits string */
|
|
|
|
void featurebits_unset(u8 **ptr, size_t bit);
|
2020-01-30 15:40:09 +01:00
|
|
|
|
2021-06-04 07:13:47 +02:00
|
|
|
/* Are these two feature bitsets functionally equal (one may have
|
|
|
|
* trailing zeroes)? */
|
|
|
|
bool featurebits_eq(const u8 *f1, const u8 *f2);
|
|
|
|
|
2021-06-04 03:53:55 +02:00
|
|
|
/* Good for debugging: returns comma-separated string of bits. */
|
|
|
|
const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits);
|
|
|
|
|
2022-04-14 14:35:39 +02:00
|
|
|
struct feature_set *feature_set_dup(const tal_t *ctx,
|
|
|
|
const struct feature_set *other);
|
|
|
|
|
2019-09-20 08:57:20 +02:00
|
|
|
/* BOLT #9:
|
2019-08-28 06:09:04 +02:00
|
|
|
*
|
|
|
|
* Flags are numbered from the least-significant bit, at bit 0 (i.e. 0x1,
|
|
|
|
* an _even_ bit). They are generally assigned in pairs so that features
|
|
|
|
* can be introduced as optional (_odd_ bits) and later upgraded to be compulsory
|
|
|
|
* (_even_ bits), which will be refused by outdated nodes:
|
|
|
|
* see [BOLT #1: The `init` Message](01-messaging.md#the-init-message).
|
|
|
|
*/
|
|
|
|
#define COMPULSORY_FEATURE(x) ((x) & 0xFFFFFFFE)
|
|
|
|
#define OPTIONAL_FEATURE(x) ((x) | 1)
|
2018-03-13 16:41:55 +01:00
|
|
|
|
2023-07-27 23:37:52 +02:00
|
|
|
/* BOLT-a526652801a541ed33b34d000a3b686a857c811f #9:
|
2018-03-13 16:41:55 +01:00
|
|
|
*
|
2022-07-23 08:54:19 +02:00
|
|
|
* | Bits | Name |...
|
|
|
|
* | 0/1 | `option_data_loss_protect` |... IN ...
|
|
|
|
* | 3 | `initial_routing_sync` |... I ...
|
|
|
|
* | 4/5 | `option_upfront_shutdown_script` |... IN ...
|
|
|
|
* | 6/7 | `gossip_queries` |... IN ...
|
|
|
|
* | 8/9 | `var_onion_optin` |... IN9 ...
|
|
|
|
* | 10/11 | `gossip_queries_ex` |... IN ...
|
|
|
|
* | 12/13 | `option_static_remotekey` |... IN ...
|
|
|
|
* | 14/15 | `payment_secret` |... IN9 ...
|
|
|
|
* | 16/17 | `basic_mpp` |... IN9 ...
|
|
|
|
* | 18/19 | `option_support_large_channel` |... IN ...
|
|
|
|
* | 20/21 | `option_anchor_outputs` |... IN ...
|
|
|
|
* | 22/23 | `option_anchors_zero_fee_htlc_tx` |... IN ...
|
2023-04-07 08:55:33 +02:00
|
|
|
* | 24/25 | `option_route_blinding` |...IN9 ...
|
2022-07-23 08:54:19 +02:00
|
|
|
* | 26/27 | `option_shutdown_anysegwit` |... IN ...
|
|
|
|
* | 44/45 | `option_channel_type` |... IN ...
|
|
|
|
* | 48/49 | `option_payment_metadata` |... 9 ...
|
2023-07-27 23:37:52 +02:00
|
|
|
* | 62/63 | `option_splice` |... IN ...
|
2019-08-28 06:09:04 +02:00
|
|
|
*/
|
2019-10-11 04:52:04 +02:00
|
|
|
#define OPT_DATA_LOSS_PROTECT 0
|
|
|
|
#define OPT_INITIAL_ROUTING_SYNC 2
|
|
|
|
#define OPT_UPFRONT_SHUTDOWN_SCRIPT 4
|
|
|
|
#define OPT_GOSSIP_QUERIES 6
|
2020-01-31 02:37:12 +01:00
|
|
|
#define OPT_VAR_ONION 8
|
2019-10-11 04:52:04 +02:00
|
|
|
#define OPT_GOSSIP_QUERIES_EX 10
|
|
|
|
#define OPT_STATIC_REMOTEKEY 12
|
2019-11-23 01:19:23 +01:00
|
|
|
#define OPT_PAYMENT_SECRET 14
|
|
|
|
#define OPT_BASIC_MPP 16
|
2020-04-02 06:09:47 +02:00
|
|
|
#define OPT_LARGE_CHANNELS 18
|
2020-08-13 19:39:02 +02:00
|
|
|
#define OPT_ANCHOR_OUTPUTS 20
|
2022-03-31 11:10:50 +02:00
|
|
|
#define OPT_ANCHORS_ZERO_FEE_HTLC_TX 22
|
2023-04-07 08:55:33 +02:00
|
|
|
#define OPT_ROUTE_BLINDING 24
|
2021-02-24 03:53:12 +01:00
|
|
|
#define OPT_SHUTDOWN_ANYSEGWIT 26
|
2022-07-23 08:54:19 +02:00
|
|
|
#define OPT_CHANNEL_TYPE 44
|
2022-03-31 11:10:50 +02:00
|
|
|
#define OPT_PAYMENT_METADATA 48
|
2023-08-10 02:20:29 +02:00
|
|
|
|
|
|
|
/* BOLT-splice #9:
|
|
|
|
* | 62/63 | `option_splice` | ... IN ...
|
|
|
|
*/
|
2023-08-10 02:20:38 +02:00
|
|
|
#define OPT_SPLICE 62
|
2023-08-10 02:20:29 +02:00
|
|
|
#define OPT_EXPERIMENTAL_SPLICE 162
|
2021-02-24 03:53:12 +01:00
|
|
|
|
2021-03-12 01:21:21 +01:00
|
|
|
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #9:
|
|
|
|
* | 28/29 | `option_dual_fund` | ... IN9 ...
|
2020-12-10 01:10:17 +01:00
|
|
|
*/
|
2021-03-12 01:21:21 +01:00
|
|
|
#define OPT_DUAL_FUND 28
|
2020-12-10 01:10:17 +01:00
|
|
|
|
2022-04-14 14:35:39 +02:00
|
|
|
/* BOLT-519be05f61e2c35ddf95b731203f89b4ee0946c3 #9:
|
|
|
|
* | 46/47 | `option_scid_alias` | ... IN ...
|
|
|
|
* | 50/51 | `option_eroconf` | ... IN ...
|
|
|
|
*/
|
|
|
|
#define OPT_SCID_ALIAS 46
|
|
|
|
#define OPT_ZEROCONF 50
|
|
|
|
|
2021-10-08 01:31:04 +02:00
|
|
|
/* BOLT-quiescent #9:
|
|
|
|
* | 34/35 | `option_quiesce` | ... IN ...
|
|
|
|
*/
|
|
|
|
#define OPT_QUIESCE 34
|
|
|
|
|
2021-11-30 04:06:05 +01:00
|
|
|
/* BOLT-offers #9:
|
2020-04-11 04:48:51 +02:00
|
|
|
*
|
2021-11-30 04:06:05 +01:00
|
|
|
* | 38/39 | `option_onion_messages` |... IN ...
|
2020-04-11 04:48:51 +02:00
|
|
|
*/
|
2021-07-02 02:11:30 +02:00
|
|
|
#define OPT_ONION_MESSAGES 38
|
2021-03-15 04:39:44 +01:00
|
|
|
|
|
|
|
#define OPT_SHUTDOWN_WRONG_FUNDING 104
|
|
|
|
|
2023-02-04 06:48:24 +01:00
|
|
|
/* BOLT-peer-storage #9:
|
|
|
|
*
|
|
|
|
* | 40/41 | `want_peer_backup_storage` | Want to use other nodes to store encrypted backup data | IN ...
|
|
|
|
* | 42/43 | `provide_peer_backup_storage` | Can store other nodes' encrypted backup data | IN ...
|
|
|
|
*/
|
|
|
|
#define OPT_WANT_PEER_BACKUP_STORAGE 40
|
|
|
|
#define OPT_PROVIDE_PEER_BACKUP_STORAGE 42
|
|
|
|
|
2018-01-12 14:35:52 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_FEATURES_H */
|