diff --git a/common/json_command.h b/common/json_command.h index 8cbfc4db4..f703bcd74 100644 --- a/common/json_command.h +++ b/common/json_command.h @@ -39,6 +39,9 @@ bool command_usage_only(const struct command *cmd); /* Do we allow deprecated apis? */ bool command_deprecated_apis(const struct command *cmd); +/* Do we allow dev commands? */ +bool command_dev_apis(const struct command *cmd); + /* If so, this is called. */ void command_set_usage(struct command *cmd, const char *usage); diff --git a/common/json_param.c b/common/json_param.c index 82d2594a1..dc302b00d 100644 --- a/common/json_param.c +++ b/common/json_param.c @@ -65,7 +65,9 @@ static struct command_result *make_callback(struct command *cmd, const jsmntok_t *tok) { /* If it had a default, free that now to avoid leak */ - if (def->style == PARAM_OPTIONAL_WITH_DEFAULT && !def->is_set) + if ((def->style == PARAM_OPTIONAL_WITH_DEFAULT + || def->style == PARAM_OPTIONAL_DEV_WITH_DEFAULT) + && !def->is_set) tal_free(*(void **)def->arg); def->is_set = true; @@ -115,6 +117,11 @@ static struct command_result *parse_by_position(struct command *cmd, } if (!json_tok_is_null(buffer, tok)) { + if (params[i].style == PARAM_OPTIONAL_DEV_WITH_DEFAULT + && !command_dev_apis(cmd)) { + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "Parameter %zu is developer-only", i); + } res = make_callback(cmd, params+i, buffer, tok); if (res) return res; @@ -176,6 +183,12 @@ static struct command_result *parse_by_name(struct command *cmd, p->name); } + if (p->style == PARAM_OPTIONAL_DEV_WITH_DEFAULT + && !command_dev_apis(cmd)) { + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "Parameter '%s' is developer-only", + p->name); + } res = make_callback(cmd, p, buffer, t + 1); if (res) return res; diff --git a/common/json_param.h b/common/json_param.h index f920791cd..fa37dfd03 100644 --- a/common/json_param.h +++ b/common/json_param.h @@ -78,6 +78,7 @@ enum param_style { PARAM_REQUIRED_ALLOW_DUPS, PARAM_OPTIONAL, PARAM_OPTIONAL_WITH_DEFAULT, + PARAM_OPTIONAL_DEV_WITH_DEFAULT, }; /* @@ -136,6 +137,21 @@ enum param_style { (const jsmntok_t *)NULL, \ (arg)) == (struct command_result *)NULL); }) +/* + * Add a dev-only parameter. *arg is set to @def if it isn't found. + */ +#define p_opt_dev(name, cbx, arg, def) \ + name"", \ + PARAM_OPTIONAL_DEV_WITH_DEFAULT, \ + (param_cbx)(cbx), \ + ({ (*arg) = tal((cmd), typeof(**arg)); \ + (**arg) = (def); \ + (arg) + 0*sizeof((cbx)((struct command *)NULL, \ + (const char *)NULL, \ + (const char *)NULL, \ + (const jsmntok_t *)NULL, \ + (arg)) == (struct command_result *)NULL); }) + /* Special flag for 'check' which allows any parameters. */ #define p_opt_any() "", PARAM_OPTIONAL, NULL, NULL diff --git a/common/test/run-json_filter.c b/common/test/run-json_filter.c index 58be0ca0c..4c31e1550 100644 --- a/common/test/run-json_filter.c +++ b/common/test/run-json_filter.c @@ -18,6 +18,9 @@ bool command_check_only(const struct command *cmd UNNEEDED) /* Generated stub for command_deprecated_apis */ bool command_deprecated_apis(const struct command *cmd UNNEEDED) { fprintf(stderr, "command_deprecated_apis called!\n"); abort(); } +/* Generated stub for command_dev_apis */ +bool command_dev_apis(const struct command *cmd UNNEEDED) +{ fprintf(stderr, "command_dev_apis called!\n"); abort(); } /* Generated stub for command_fail */ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index 64e246e00..120009514 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -50,6 +50,9 @@ bool command_check_only(const struct command *cmd UNNEEDED) /* Generated stub for command_deprecated_apis */ bool command_deprecated_apis(const struct command *cmd UNNEEDED) { fprintf(stderr, "command_deprecated_apis called!\n"); abort(); } +/* Generated stub for command_dev_apis */ +bool command_dev_apis(const struct command *cmd UNNEEDED) +{ fprintf(stderr, "command_dev_apis called!\n"); abort(); } /* Generated stub for command_fail */ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) diff --git a/common/test/run-param.c b/common/test/run-param.c index 6ee699a29..b62c838a6 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -49,6 +49,9 @@ struct command_result *command_fail(struct command *cmd, } /* AUTOGENERATED MOCKS START */ +/* Generated stub for command_dev_apis */ +bool command_dev_apis(const struct command *cmd UNNEEDED) +{ fprintf(stderr, "command_dev_apis called!\n"); abort(); } /* Generated stub for command_filter_ptr */ struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED) { fprintf(stderr, "command_filter_ptr called!\n"); abort(); } diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index f12d2e2bd..3e1a696f9 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -1295,6 +1295,11 @@ bool command_deprecated_apis(const struct command *cmd) return cmd->ld->deprecated_apis; } +bool command_dev_apis(const struct command *cmd) +{ + return cmd->ld->developer; +} + void command_set_usage(struct command *cmd, const char *usage TAKES) { usage = tal_strdup(cmd->ld, usage); diff --git a/plugins/libplugin.c b/plugins/libplugin.c index aa3eb9a43..f049d2759 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -505,6 +505,11 @@ bool command_deprecated_apis(const struct command *cmd) return deprecated_apis; } +bool command_dev_apis(const struct command *cmd) +{ + return cmd->plugin->developer; +} + /* FIXME: would be good to support this! */ bool command_check_only(const struct command *cmd) { diff --git a/plugins/renepay/payment.c b/plugins/renepay/payment.c index 0a95ae766..465201613 100644 --- a/plugins/renepay/payment.c +++ b/plugins/renepay/payment.c @@ -20,7 +20,7 @@ struct payment *payment_new(const tal_t *ctx, unsigned int maxdelay, u64 retryfor, u16 final_cltv, - /* Tweakable in DEVELOPER mode */ + /* Tweakable in --developer mode */ u64 base_fee_penalty, u64 prob_cost_factor, u64 riskfactor_millionths,