From 21122af3a89b335fad4696a5586662e7194b08d1 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 22 Oct 2020 13:20:29 -0500 Subject: [PATCH] dev-force-features: adds a second valid format for forcing features The previous dev-force-features forced you to explicitly declare every desired feature bit in an array, for each set. Here, we allow you to also denote adding/subtracing a feature bit by just passing in the number of the bit to flip and the direction to turn it. e.g. 'dev-force-features': '+223' Will turn on opt_dual_fund/odd. 'dev-force-features': '-16' Will flag off opt_basic_mpp. --- lightningd/options.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lightningd/options.c b/lightningd/options.c index a48332213..264a32484 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -516,8 +516,29 @@ static char *opt_force_featureset(const char *optarg, struct lightningd *ld) { char **parts = tal_strsplit(tmpctx, optarg, "/", STR_EMPTY_OK); - if (tal_count(parts) != NUM_FEATURE_PLACE) - return "Expected 5 feature sets (init, globalinit, node_announce, channel, bolt11) separated by /"; + if (tal_count(parts) != NUM_FEATURE_PLACE) { + if (!strstarts(optarg, "-") && !strstarts(optarg, "+")) + return "Expected 5 feature sets (init, globalinit," + " node_announce, channel, bolt11) separated" + " by / OR +/-"; + + char *endp; + long int n = strtol(optarg + 1, &endp, 10); + const struct feature_set *f; + if (*endp || endp == optarg + 1) + return "Invalid feature number"; + + f = feature_set_for_feature(NULL, n); + if (strstarts(optarg, "-") + && !feature_set_sub(ld->our_features, take(f))) + return "Feature unknown"; + + if (strstarts(optarg, "+") + && !feature_set_or(ld->our_features, take(f))) + return "Feature already flagged-on"; + + return NULL; + } for (size_t i = 0; parts[i]; i++) { char **bits = tal_strsplit(tmpctx, parts[i], ",", STR_EMPTY_OK); tal_resize(&ld->our_features->bits[i], 0);