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,
|
|
|
|
};
|
|
|
|
#define NUM_FEATURE_PLACE (BOLT11_FEATURE+1)
|
|
|
|
|
|
|
|
/* The complete set of features for all contexts */
|
|
|
|
struct feature_set {
|
|
|
|
u8 *bits[NUM_FEATURE_PLACE];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialize core features (for lightningd). */
|
|
|
|
struct feature_set *features_core_init(const u8 *features TAKES);
|
|
|
|
|
2020-03-31 00:39:00 +02:00
|
|
|
/* Initialize subdaemon features. */
|
|
|
|
void features_init(struct feature_set *fset TAKES);
|
|
|
|
|
2020-03-31 00:39:00 +02:00
|
|
|
/* Free feature allocations */
|
|
|
|
void features_cleanup(void);
|
|
|
|
|
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-03-31 00:39:00 +02:00
|
|
|
/* Add features supplied by a plugin: returns false if we already have them */
|
|
|
|
bool features_additional(const struct feature_set *feature_set);
|
|
|
|
|
2019-11-23 01:19:23 +01:00
|
|
|
/* Returns -1 if we're OK with all these offered features, otherwise first
|
|
|
|
* unsupported (even) feature. */
|
|
|
|
int features_unsupported(const u8 *features);
|
2018-01-12 14:35:52 +01:00
|
|
|
|
2018-09-28 05:24:24 +02:00
|
|
|
/* For sending our features: tal_count() returns length. */
|
2019-11-23 01:19:23 +01:00
|
|
|
u8 *get_offered_initfeatures(const tal_t *ctx);
|
|
|
|
u8 *get_offered_globalinitfeatures(const tal_t *ctx);
|
2019-10-04 03:14:00 +02:00
|
|
|
u8 *get_offered_nodefeatures(const tal_t *ctx);
|
2019-11-23 01:19:23 +01:00
|
|
|
u8 *get_offered_bolt11features(const tal_t *ctx);
|
2018-03-13 16:41:55 +01:00
|
|
|
|
2020-03-31 00:39:00 +02:00
|
|
|
/* For the features in channel_announcement */
|
|
|
|
u8 *get_agreed_channelfeatures(const tal_t *ctx, const u8 *theirfeatures);
|
|
|
|
|
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? */
|
2019-10-11 04:52:04 +02:00
|
|
|
bool feature_negotiated(const u8 *lfeatures, size_t f);
|
2018-12-03 00:05:06 +01:00
|
|
|
|
2019-08-29 03:01:55 +02:00
|
|
|
/* Return a list of what features we advertize. */
|
|
|
|
const char **list_supported_features(const tal_t *ctx);
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
2019-09-20 08:57:20 +02:00
|
|
|
/* BOLT #9:
|
2018-03-13 16:41:55 +01:00
|
|
|
*
|
2020-01-31 02:37:12 +01:00
|
|
|
* | Bits | Name |...
|
|
|
|
* | 0/1 | `option_data_loss_protect` |...
|
|
|
|
* | 3 | `initial_routing_sync` |...
|
|
|
|
* | 4/5 | `option_upfront_shutdown_script` |...
|
|
|
|
* | 6/7 | `gossip_queries` |...
|
|
|
|
* | 8/9 | `var_onion_optin` |...
|
|
|
|
* | 10/11 | `gossip_queries_ex` |...
|
2020-01-31 02:39:12 +01:00
|
|
|
* | 12/13 | `option_static_remotekey` |...
|
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
|
2018-01-12 14:35:52 +01:00
|
|
|
|
2020-01-31 02:40:36 +01:00
|
|
|
/* BOLT #9:
|
2019-11-23 01:19:23 +01:00
|
|
|
*
|
|
|
|
* | 14/15 | `payment_secret` |... IN9 ...
|
|
|
|
* | 16/17 | `basic_mpp` |... IN9 ...
|
|
|
|
*/
|
|
|
|
#define OPT_PAYMENT_SECRET 14
|
|
|
|
#define OPT_BASIC_MPP 16
|
|
|
|
|
2018-01-12 14:35:52 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_FEATURES_H */
|