Browse Source

plugin: remove boutique features.

We now manipulate the global features directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
b7db588a8a
  1. 2
      connectd/connect_wire.csv
  2. 11
      connectd/connectd.c
  3. 5
      connectd/peer_exchange_initmsg.c
  4. 3
      connectd/peer_exchange_initmsg.h
  5. 4
      gossipd/gossip_generation.c
  6. 2
      gossipd/gossip_wire.csv
  7. 1
      gossipd/gossipd.c
  8. 3
      gossipd/gossipd.h
  9. 10
      lightningd/connect_control.c
  10. 8
      lightningd/gossip_control.c
  11. 9
      lightningd/invoice.c
  12. 46
      lightningd/plugin.c
  13. 27
      lightningd/plugin.h
  14. 7
      lightningd/test/run-invoice-select-inchan.c

2
connectd/connect_wire.csv

@ -17,8 +17,6 @@ msgdata,connectctl_init,dev_allow_localhost,bool,
msgdata,connectctl_init,use_dns,bool, msgdata,connectctl_init,use_dns,bool,
msgdata,connectctl_init,tor_password,wirestring, msgdata,connectctl_init,tor_password,wirestring,
msgdata,connectctl_init,use_v3_autotor,bool, msgdata,connectctl_init,use_v3_autotor,bool,
msgdata,connectctl_init,init_featurebits_len,u16,
msgdata,connectctl_init,init_featurebits,u8,init_featurebits_len
# Connectd->master, here are the addresses I bound, can announce. # Connectd->master, here are the addresses I bound, can announce.
msgtype,connectctl_init_reply,2100 msgtype,connectctl_init_reply,2100

Can't render this file because it has a wrong number of fields in line 7.

11
connectd/connectd.c

@ -154,9 +154,6 @@ struct daemon {
/* Allow to define the default behavior of tor services calls*/ /* Allow to define the default behavior of tor services calls*/
bool use_v3_autotor; bool use_v3_autotor;
/* featurebits that we support internally, and via plugins */
u8 *init_featurebits;
}; };
/* Peers we're trying to reach: we iterate through addrs until we succeed /* Peers we're trying to reach: we iterate through addrs until we succeed
@ -475,8 +472,7 @@ static struct io_plan *handshake_in_success(struct io_conn *conn,
struct node_id id; struct node_id id;
node_id_from_pubkey(&id, id_key); node_id_from_pubkey(&id, id_key);
status_peer_debug(&id, "Connect IN"); status_peer_debug(&id, "Connect IN");
return peer_exchange_initmsg(conn, daemon, cs, &id, addr, return peer_exchange_initmsg(conn, daemon, cs, &id, addr);
daemon->init_featurebits);
} }
/*~ When we get a connection in we set up its network address then call /*~ When we get a connection in we set up its network address then call
@ -536,8 +532,7 @@ static struct io_plan *handshake_out_success(struct io_conn *conn,
node_id_from_pubkey(&id, key); node_id_from_pubkey(&id, key);
connect->connstate = "Exchanging init messages"; connect->connstate = "Exchanging init messages";
status_peer_debug(&id, "Connect OUT"); status_peer_debug(&id, "Connect OUT");
return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr, return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr);
connect->daemon->init_featurebits);
} }
struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect) struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
@ -1202,7 +1197,7 @@ static struct io_plan *connect_init(struct io_conn *conn,
&proxyaddr, &daemon->use_proxy_always, &proxyaddr, &daemon->use_proxy_always,
&daemon->dev_allow_localhost, &daemon->use_dns, &daemon->dev_allow_localhost, &daemon->use_dns,
&tor_password, &tor_password,
&daemon->use_v3_autotor, &daemon->init_featurebits)) { &daemon->use_v3_autotor)) {
/* This is a helper which prints the type expected and the actual /* This is a helper which prints the type expected and the actual
* message, then exits (it should never be called!). */ * message, then exits (it should never be called!). */
master_badmsg(WIRE_CONNECTCTL_INIT, msg); master_badmsg(WIRE_CONNECTCTL_INIT, msg);

5
connectd/peer_exchange_initmsg.c

@ -155,8 +155,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct crypto_state *cs, const struct crypto_state *cs,
const struct node_id *id, const struct node_id *id,
const struct wireaddr_internal *addr, const struct wireaddr_internal *addr)
const u8 *init_featurebits)
{ {
/* If conn is closed, forget peer */ /* If conn is closed, forget peer */
struct peer *peer = tal(conn, struct peer); struct peer *peer = tal(conn, struct peer);
@ -201,7 +200,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
* from now on they'll all go in initfeatures. */ * from now on they'll all go in initfeatures. */
peer->msg = towire_init(NULL, peer->msg = towire_init(NULL,
get_offered_globalinitfeatures(tmpctx), get_offered_globalinitfeatures(tmpctx),
init_featurebits, get_offered_initfeatures(tmpctx),
tlvs); tlvs);
status_peer_io(LOG_IO_OUT, &peer->id, peer->msg); status_peer_io(LOG_IO_OUT, &peer->id, peer->msg);
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg)); peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));

3
connectd/peer_exchange_initmsg.h

@ -14,7 +14,6 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct crypto_state *cs, const struct crypto_state *cs,
const struct node_id *id, const struct node_id *id,
const struct wireaddr_internal *addr, const struct wireaddr_internal *addr);
const u8 *init_featurebits);
#endif /* LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H */ #endif /* LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H */

4
gossipd/gossip_generation.c

@ -1,6 +1,7 @@
/* Routines to make our own gossip messages. Not as in "we're the gossip /* Routines to make our own gossip messages. Not as in "we're the gossip
* generation, man!" */ * generation, man!" */
#include <ccan/mem/mem.h> #include <ccan/mem/mem.h>
#include <common/features.h>
#include <common/memleak.h> #include <common/memleak.h>
#include <common/status.h> #include <common/status.h>
#include <common/timeout.h> #include <common/timeout.h>
@ -37,7 +38,8 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
towire_wireaddr(&addresses, &daemon->announcable[i]); towire_wireaddr(&addresses, &daemon->announcable[i]);
announcement = announcement =
towire_node_announcement(ctx, sig, daemon->nodefeatures, timestamp, towire_node_announcement(ctx, sig, get_offered_nodefeatures(tmpctx),
timestamp,
&daemon->id, daemon->rgb, daemon->alias, &daemon->id, daemon->rgb, daemon->alias,
addresses); addresses);
return announcement; return announcement;

2
gossipd/gossip_wire.csv

@ -8,8 +8,6 @@ msgtype,gossipctl_init,3000
msgdata,gossipctl_init,chainparams,chainparams, msgdata,gossipctl_init,chainparams,chainparams,
msgdata,gossipctl_init,feature_set,feature_set, msgdata,gossipctl_init,feature_set,feature_set,
msgdata,gossipctl_init,id,node_id, msgdata,gossipctl_init,id,node_id,
msgdata,gossipctl_init,gflen,u16,
msgdata,gossipctl_init,globalfeatures,u8,gflen
msgdata,gossipctl_init,rgb,u8,3 msgdata,gossipctl_init,rgb,u8,3
msgdata,gossipctl_init,alias,u8,32 msgdata,gossipctl_init,alias,u8,32
msgdata,gossipctl_init,num_announcable,u16, msgdata,gossipctl_init,num_announcable,u16,

Can't render this file because it has a wrong number of fields in line 7.

1
gossipd/gossipd.c

@ -834,7 +834,6 @@ static struct io_plan *gossip_init(struct io_conn *conn,
&chainparams, &chainparams,
&feature_set, &feature_set,
&daemon->id, &daemon->id,
&daemon->nodefeatures,
daemon->rgb, daemon->rgb,
daemon->alias, daemon->alias,
&daemon->announcable, &daemon->announcable,

3
gossipd/gossipd.h

@ -42,9 +42,6 @@ struct daemon {
/* Timers: we batch gossip, and also refresh announcements */ /* Timers: we batch gossip, and also refresh announcements */
struct timers timers; struct timers timers;
/* Features to list in node_announcement. */
u8 *nodefeatures;
/* Alias (not NUL terminated) and favorite color for node_announcement */ /* Alias (not NUL terminated) and favorite color for node_announcement */
u8 alias[32]; u8 alias[32];
u8 rgb[3]; u8 rgb[3];

10
lightningd/connect_control.c

@ -337,7 +337,7 @@ static void connect_init_done(struct subd *connectd,
int connectd_init(struct lightningd *ld) int connectd_init(struct lightningd *ld)
{ {
int fds[2]; int fds[2];
u8 *msg, *init_features; u8 *msg;
int hsmfd; int hsmfd;
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr; struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
enum addr_listen_announce *listen_announce = ld->proposed_listen_announce; enum addr_listen_announce *listen_announce = ld->proposed_listen_announce;
@ -362,12 +362,6 @@ int connectd_init(struct lightningd *ld)
*listen_announce = ADDR_LISTEN_AND_ANNOUNCE; *listen_announce = ADDR_LISTEN_AND_ANNOUNCE;
} }
init_features =
featurebits_or(tmpctx,
take(plugins_collect_featurebits(
tmpctx, ld->plugins, PLUGIN_FEATURES_INIT)),
take(get_offered_initfeatures(tmpctx)));
msg = towire_connectctl_init( msg = towire_connectctl_init(
tmpctx, chainparams, tmpctx, chainparams,
ld->feature_set, ld->feature_set,
@ -377,7 +371,7 @@ int connectd_init(struct lightningd *ld)
ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup, ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup,
IFDEV(ld->dev_allow_localhost, false), ld->config.use_dns, IFDEV(ld->dev_allow_localhost, false), ld->config.use_dns,
ld->tor_service_password ? ld->tor_service_password : "", ld->tor_service_password ? ld->tor_service_password : "",
ld->config.use_v3_autotor, init_features); ld->config.use_v3_autotor);
subd_req(ld->connectd, ld->connectd, take(msg), -1, 0, subd_req(ld->connectd, ld->connectd, take(msg), -1, 0,
connect_init_done, NULL); connect_init_done, NULL);

8
lightningd/gossip_control.c

@ -191,7 +191,7 @@ static void gossip_topology_synced(struct chain_topology *topo, void *unused)
* message */ * message */
void gossip_init(struct lightningd *ld, int connectd_fd) void gossip_init(struct lightningd *ld, int connectd_fd)
{ {
u8 *msg, *node_featurebits; u8 *msg;
int hsmfd; int hsmfd;
hsmfd = hsm_get_global_fd(ld, HSM_CAP_SIGN_GOSSIP); hsmfd = hsm_get_global_fd(ld, HSM_CAP_SIGN_GOSSIP);
@ -206,17 +206,11 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
topology_add_sync_waiter(ld->gossip, ld->topology, topology_add_sync_waiter(ld->gossip, ld->topology,
gossip_topology_synced, NULL); gossip_topology_synced, NULL);
node_featurebits =
featurebits_or(tmpctx, take(get_offered_nodefeatures(tmpctx)),
take(plugins_collect_featurebits(
tmpctx, ld->plugins, PLUGIN_FEATURES_NODE)));
msg = towire_gossipctl_init( msg = towire_gossipctl_init(
tmpctx, tmpctx,
chainparams, chainparams,
ld->feature_set, ld->feature_set,
&ld->id, &ld->id,
node_featurebits,
ld->rgb, ld->rgb,
ld->alias, ld->alias,
ld->announcable, ld->announcable,

9
lightningd/invoice.c

@ -1013,14 +1013,7 @@ static struct command_result *json_invoice(struct command *cmd,
info->b11->description_hash = NULL; info->b11->description_hash = NULL;
info->b11->payment_secret = tal_dup(info->b11, struct secret, info->b11->payment_secret = tal_dup(info->b11, struct secret,
&payment_secret); &payment_secret);
info->b11->features = get_offered_bolt11features(info->b11);
/* Which features should we announce to the node receiving this invoice?
* This is a combination of natively supported features and featurebits
* that plugins asked us to include in the invoice. */
info->b11->features = featurebits_or(
info->b11, take(get_offered_bolt11features(NULL)),
take(plugins_collect_featurebits(NULL, cmd->ld->plugins,
PLUGIN_FEATURES_INVOICE)));
#if DEVELOPER #if DEVELOPER
info->b11->routes = unpack_routes(info->b11, buffer, routes); info->b11->routes = unpack_routes(info->b11, buffer, routes);

46
lightningd/plugin.c

@ -47,18 +47,6 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
return p; return p;
} }
u8 *plugins_collect_featurebits(const tal_t *ctx, const struct plugins *plugins,
enum plugin_features_type type)
{
struct plugin *p;
u8 *res = tal_arr(ctx, u8, 0);
list_for_each(&plugins->plugins, p, list) {
if (p->featurebits[type])
res = featurebits_or(ctx, take(res), p->featurebits[type]);
}
return res;
}
static void destroy_plugin(struct plugin *p) static void destroy_plugin(struct plugin *p)
{ {
plugin_hook_unregister_all(p); plugin_hook_unregister_all(p);
@ -82,9 +70,6 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES)
p->plugins = plugins; p->plugins = plugins;
p->cmd = tal_strdup(p, path); p->cmd = tal_strdup(p, path);
for (int i = 0; i < NUM_PLUGIN_FEATURES_TYPE; i++)
p->featurebits[i] = NULL;
p->plugin_state = UNCONFIGURED; p->plugin_state = UNCONFIGURED;
p->js_arr = tal_arr(p, struct json_stream *, 0); p->js_arr = tal_arr(p, struct json_stream *, 0);
p->used = 0; p->used = 0;
@ -868,12 +853,8 @@ static void plugin_manifest_timeout(struct plugin *plugin)
fatal("Can't recover from plugin failure, terminating."); fatal("Can't recover from plugin failure, terminating.");
} }
/* List of JSON keys matching `plugin_features_type`. */ /* List of JSON keys matching `enum feature_place`. */
static const char *plugin_features_type_names[] = {"node", "init", "invoice", "channel"}; static const char *plugin_feature_place_names[] = {"init", NULL, "node", "channel", "invoice"};
static const size_t plugin_features_fset[] = {NODE_ANNOUNCE_FEATURE,
INIT_FEATURE,
BOLT11_FEATURE,
CHANNEL_FEATURE};
bool plugin_parse_getmanifest_response(const char *buffer, bool plugin_parse_getmanifest_response(const char *buffer,
const jsmntok_t *toks, const jsmntok_t *toks,
@ -881,7 +862,6 @@ bool plugin_parse_getmanifest_response(const char *buffer,
struct plugin *plugin) struct plugin *plugin)
{ {
const jsmntok_t *resulttok, *dynamictok, *featurestok, *tok; const jsmntok_t *resulttok, *dynamictok, *featurestok, *tok;
u8 *featurebits;
resulttok = json_get_member(buffer, toks, "result"); resulttok = json_get_member(buffer, toks, "result");
if (!resulttok || resulttok->type != JSMN_OBJECT) if (!resulttok || resulttok->type != JSMN_OBJECT)
@ -899,21 +879,24 @@ bool plugin_parse_getmanifest_response(const char *buffer,
bool have_featurebits = false; bool have_featurebits = false;
struct feature_set *fset = talz(tmpctx, struct feature_set); struct feature_set *fset = talz(tmpctx, struct feature_set);
for (int i = 0; i < NUM_PLUGIN_FEATURES_TYPE; i++) { BUILD_ASSERT(ARRAY_SIZE(plugin_feature_place_names)
== ARRAY_SIZE(fset->bits));
for (int i = 0; i < ARRAY_SIZE(fset->bits); i++) {
/* We don't allow setting the obs global init */
if (!plugin_feature_place_names[i])
continue;
tok = json_get_member(buffer, featurestok, tok = json_get_member(buffer, featurestok,
plugin_features_type_names[i]); plugin_feature_place_names[i]);
if (!tok) if (!tok)
continue; continue;
featurebits = fset->bits[i] = json_tok_bin_from_hex(fset, buffer, tok);
json_tok_bin_from_hex(plugin, buffer, tok); have_featurebits |= tal_bytelen(fset->bits[i]) > 0;
have_featurebits |= tal_bytelen(featurebits) > 0;
if (featurebits) { if (!fset->bits[i]) {
plugin->featurebits[i] = featurebits;
} else {
plugin_kill( plugin_kill(
plugin, plugin,
"Featurebits returned by plugin is not a " "Featurebits returned by plugin is not a "
@ -921,7 +904,6 @@ bool plugin_parse_getmanifest_response(const char *buffer,
tok->end - tok->start, buffer + tok->start); tok->end - tok->start, buffer + tok->start);
return true; return true;
} }
fset->bits[plugin_features_fset[i]] = featurebits;
} }
if (plugin->dynamic && have_featurebits) { if (plugin->dynamic && have_featurebits) {

27
lightningd/plugin.h

@ -26,23 +26,6 @@ enum plugin_state {
CONFIGURED CONFIGURED
}; };
/**
* A plugin may register any number of featurebits that should be added to
* various messages as part of their manifest. The following enum enumerates
* the possible locations the featurebits can be added to, and are used as
* indices into the array of featurebits in the plugin struct itself.
*
* If you edit this make sure that there is a matching entry in the
* `plugin_features_type_names[]` array in plugin.c.
*/
enum plugin_features_type {
PLUGIN_FEATURES_NODE,
PLUGIN_FEATURES_INIT,
PLUGIN_FEATURES_INVOICE,
PLUGIN_FEATURES_CHANNEL,
};
#define NUM_PLUGIN_FEATURES_TYPE (PLUGIN_FEATURES_INVOICE+1)
/** /**
* A plugin, exposed as a stub so we can pass it as an argument. * A plugin, exposed as a stub so we can pass it as an argument.
*/ */
@ -83,11 +66,6 @@ struct plugin {
/* An array of subscribed topics */ /* An array of subscribed topics */
char **subscriptions; char **subscriptions;
/* Featurebits for various locations that the plugin
* registered. Indices correspond to the `plugin_features_type`
* enum. */
u8 *featurebits[NUM_PLUGIN_FEATURES_TYPE];
}; };
/** /**
@ -279,9 +257,4 @@ struct log *plugin_get_log(struct plugin *plugin);
* call both! */ * call both! */
struct plugin_destroyed *plugin_detect_destruction(const struct plugin *plugin); struct plugin_destroyed *plugin_detect_destruction(const struct plugin *plugin);
bool was_plugin_destroyed(struct plugin_destroyed *destroyed); bool was_plugin_destroyed(struct plugin_destroyed *destroyed);
/* Gather all the features of the given type that plugins registered. */
u8 *plugins_collect_featurebits(const tal_t *ctx, const struct plugins *plugins,
enum plugin_features_type type);
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */ #endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */

7
lightningd/test/run-invoice-select-inchan.c

@ -99,9 +99,6 @@ const u8 *failmsg_incorrect_or_unknown(const tal_t *ctx UNNEEDED,
/* Generated stub for fatal */ /* Generated stub for fatal */
void fatal(const char *fmt UNNEEDED, ...) void fatal(const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "fatal called!\n"); abort(); } { fprintf(stderr, "fatal called!\n"); abort(); }
/* Generated stub for featurebits_or */
u8 *featurebits_or(const tal_t *ctx UNNEEDED, const u8 *f1 TAKES UNNEEDED, const u8 *f2 TAKES UNNEEDED)
{ fprintf(stderr, "featurebits_or called!\n"); abort(); }
/* Generated stub for feature_is_set */ /* Generated stub for feature_is_set */
bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED) bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED)
{ fprintf(stderr, "feature_is_set called!\n"); abort(); } { fprintf(stderr, "feature_is_set called!\n"); abort(); }
@ -384,10 +381,6 @@ void per_peer_state_set_fds(struct per_peer_state *pps UNNEEDED,
void plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, void plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED,
void *payload UNNEEDED, void *cb_arg UNNEEDED) void *payload UNNEEDED, void *cb_arg UNNEEDED)
{ fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); } { fprintf(stderr, "plugin_hook_call_ called!\n"); abort(); }
/* Generated stub for plugins_collect_featurebits */
u8 *plugins_collect_featurebits(const tal_t *ctx UNNEEDED, const struct plugins *plugins UNNEEDED,
enum plugin_features_type type UNNEEDED)
{ fprintf(stderr, "plugins_collect_featurebits called!\n"); abort(); }
/* Generated stub for subd_release_channel */ /* Generated stub for subd_release_channel */
void subd_release_channel(struct subd *owner UNNEEDED, void *channel UNNEEDED) void subd_release_channel(struct subd *owner UNNEEDED, void *channel UNNEEDED)
{ fprintf(stderr, "subd_release_channel called!\n"); abort(); } { fprintf(stderr, "subd_release_channel called!\n"); abort(); }

Loading…
Cancel
Save