From 58c9a6a0041231a4c28e5c69852c0628453e69d6 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 30 Jan 2020 16:08:09 +0100 Subject: [PATCH] plugin: Include featurebits registered by plugins in invoices --- lightningd/invoice.c | 8 +++++++- lightningd/test/run-invoice-select-inchan.c | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lightningd/invoice.c b/lightningd/invoice.c index dde292477..4bbceea97 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -1002,8 +1002,14 @@ static struct command_result *json_invoice(struct command *cmd, info->b11->description_hash = NULL; info->b11->payment_secret = tal_dup(info->b11, struct 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(info->b11)), + take(plugins_collect_featurebits(tmpctx, cmd->ld->plugins, + PLUGIN_FEATURES_INVOICE))); #if DEVELOPER info->b11->routes = unpack_routes(info->b11, buffer, routes); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 0f2702f84..e227c282b 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -95,6 +95,9 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, /* Generated stub for fatal */ void fatal(const char *fmt UNNEEDED, ...) { 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 */ bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED) { fprintf(stderr, "feature_is_set called!\n"); abort(); } @@ -377,6 +380,10 @@ 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 *payload UNNEEDED, void *cb_arg UNNEEDED) { 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 */ void subd_release_channel(struct subd *owner UNNEEDED, void *channel UNNEEDED) { fprintf(stderr, "subd_release_channel called!\n"); abort(); }