Skip to content

Commit

Permalink
setconfig: add transient option.
Browse files Browse the repository at this point in the history
Changelog-Added: JSON-RPC: `setconfig` now has a `transient` flag which means it won't rewrite your config file.
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 24, 2025
1 parent 98f15ae commit 5a80223
Show file tree
Hide file tree
Showing 12 changed files with 524 additions and 471 deletions.
5 changes: 5 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -3445,6 +3445,7 @@
},
"SetconfigRequest": {
"SetConfig.config": 1,
"SetConfig.transient": 3,
"SetConfig.val": 2
},
"SetconfigResponse": {
Expand Down Expand Up @@ -12210,6 +12211,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
"SetConfig.transient": {
"added": "v25.02",
"deprecated": null
},
"SetConfig.val": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20812,7 +20812,7 @@
},
"autoclean-expiredinvoices-age": {
"value_int": 300,
"source": "/tmp/.lightning/regtest/config:2",
"source": "/tmp/.lightning/regtest/config.setconfig:2",
"plugin": "/root/lightning/plugins/autoclean",
"dynamic": true
},
Expand Down Expand Up @@ -21121,7 +21121,7 @@
},
"min-capacity-sat": {
"value_int": 500000,
"source": "/tmp/.lightning/regtest/config:4",
"source": "/tmp/.lightning/regtest/config.setconfig:3",
"dynamic": true
},
"min-emergency-msat": {
Expand Down Expand Up @@ -32668,6 +32668,14 @@
"description": [
"Value of the config variable to be set or updated."
]
},
"transient": {
"type": "boolean",
"added": "v25.02",
"default": "False",
"description": [
"If set, this change does NOT try to alter the configuration files, so the change will be reverted on any restart."
]
}
}
},
Expand Down Expand Up @@ -32779,7 +32787,7 @@
"config": {
"config": "autoclean-expiredinvoices-age",
"value_int": 300,
"source": "/tmp/.lightning/regtest/config:2",
"source": "/tmp/.lightning/regtest/config.setconfig:2",
"plugin": "/root/lightning/plugins/autoclean",
"dynamic": true
}
Expand All @@ -32798,7 +32806,7 @@
"config": {
"config": "min-capacity-sat",
"value_int": 500000,
"source": "/tmp/.lightning/regtest/config:4",
"source": "/tmp/.lightning/regtest/config.setconfig:3",
"dynamic": true
}
}
Expand Down
908 changes: 454 additions & 454 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/schemas/lightning-listconfigs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2594,7 +2594,7 @@
},
"autoclean-expiredinvoices-age": {
"value_int": 300,
"source": "/tmp/.lightning/regtest/config:2",
"source": "/tmp/.lightning/regtest/config.setconfig:2",
"plugin": "/root/lightning/plugins/autoclean",
"dynamic": true
},
Expand Down Expand Up @@ -2903,7 +2903,7 @@
},
"min-capacity-sat": {
"value_int": 500000,
"source": "/tmp/.lightning/regtest/config:4",
"source": "/tmp/.lightning/regtest/config.setconfig:3",
"dynamic": true
},
"min-emergency-msat": {
Expand Down
12 changes: 10 additions & 2 deletions doc/schemas/lightning-setconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
"description": [
"Value of the config variable to be set or updated."
]
},
"transient": {
"type": "boolean",
"added": "v25.02",
"default": "False",
"description": [
"If set, this change does NOT try to alter the configuration files, so the change will be reverted on any restart."
]
}
}
},
Expand Down Expand Up @@ -149,7 +157,7 @@
"config": {
"config": "autoclean-expiredinvoices-age",
"value_int": 300,
"source": "/tmp/.lightning/regtest/config:2",
"source": "/tmp/.lightning/regtest/config.setconfig:2",
"plugin": "/root/lightning/plugins/autoclean",
"dynamic": true
}
Expand All @@ -168,7 +176,7 @@
"config": {
"config": "min-capacity-sat",
"value_int": 500000,
"source": "/tmp/.lightning/regtest/config:4",
"source": "/tmp/.lightning/regtest/config.setconfig:3",
"dynamic": true
}
}
Expand Down
14 changes: 9 additions & 5 deletions lightningd/configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ static void configvar_save(struct lightningd *ld,

static struct command_result *setconfig_success(struct command *cmd,
const struct opt_table *ot,
const char *val)
const char *val,
bool transient)
{
struct json_stream *response;
const char **names, *confline;
Expand All @@ -565,7 +566,8 @@ static struct command_result *setconfig_success(struct command *cmd,
else
confline = names[0];

configvar_save(cmd->ld, names, confline);
if (!transient)
configvar_save(cmd->ld, names, confline);

response = json_stream_success(cmd);
json_object_start(response, "config");
Expand All @@ -584,10 +586,12 @@ static struct command_result *json_setconfig(struct command *cmd,
const char *val;
char *err;
void *arg;
bool *transient;

if (!param_check(cmd, buffer, params,
p_req("config", param_opt_dynamic_config, &ot),
p_opt("val", param_string, &val),
p_opt_def("transient", param_bool, &transient, false),
NULL))
return command_param_failed();

Expand All @@ -608,7 +612,7 @@ static struct command_result *json_setconfig(struct command *cmd,
"%s does not take a value",
ot->names + 2);
if (is_plugin_opt(ot))
return plugin_set_dynamic_opt(cmd, ot, NULL,
return plugin_set_dynamic_opt(cmd, ot, NULL, *transient,
setconfig_success);
err = ot->cb(arg);
} else {
Expand All @@ -618,7 +622,7 @@ static struct command_result *json_setconfig(struct command *cmd,
"%s requires a value",
ot->names + 2);
if (is_plugin_opt(ot))
return plugin_set_dynamic_opt(cmd, ot, val,
return plugin_set_dynamic_opt(cmd, ot, val, *transient,
setconfig_success);
err = ot->cb_arg(val, arg);
}
Expand All @@ -628,7 +632,7 @@ static struct command_result *json_setconfig(struct command *cmd,
"Error setting %s: %s", ot->names + 2, err);
}

return setconfig_success(cmd, ot, val);
return setconfig_success(cmd, ot, val, *transient);
}

static const struct json_command setconfig_command = {
Expand Down
11 changes: 8 additions & 3 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,9 +2284,11 @@ struct plugin_set_return {
struct command *cmd;
const char *val;
const char *optname;
bool transient;
struct command_result *(*success)(struct command *,
const struct opt_table *,
const char *);
const char *,
bool);
};

static void plugin_setconfig_done(const char *buffer,
Expand Down Expand Up @@ -2327,7 +2329,7 @@ static void plugin_setconfig_done(const char *buffer,
t = json_get_member(buffer, toks, "result");
if (!t)
goto bad_response;
was_pending(psr->success(psr->cmd, ot, psr->val));
was_pending(psr->success(psr->cmd, ot, psr->val, psr->transient));
return;

bad_response:
Expand All @@ -2342,10 +2344,12 @@ static void plugin_setconfig_done(const char *buffer,
struct command_result *plugin_set_dynamic_opt(struct command *cmd,
const struct opt_table *ot,
const char *val,
bool transient,
struct command_result *(*success)
(struct command *,
const struct opt_table *,
const char *))
const char *,
bool))
{
struct plugin_opt *popt;
struct plugin *plugin;
Expand All @@ -2363,6 +2367,7 @@ struct command_result *plugin_set_dynamic_opt(struct command *cmd,
psr->val = val;
psr->optname = tal_strdup(psr, ot->names + 2);
psr->success = success;
psr->transient = transient;

if (command_check_only(cmd)) {
/* If plugin doesn't support check, we can't check */
Expand Down
4 changes: 3 additions & 1 deletion lightningd/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,10 @@ void json_add_config_plugin(struct json_stream *stream,
struct command_result *plugin_set_dynamic_opt(struct command *cmd,
const struct opt_table *ot,
const char *val,
bool transient,
struct command_result *(*success)
(struct command *,
const struct opt_table *,
const char *));
const char *,
bool));
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */
16 changes: 16 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,22 @@ def test_setconfig(node_factory, bitcoind):
assert lines[2] == 'min-capacity-sat=400000'
assert len(lines) == 3

# We can also set it transiently.
ret = l2.rpc.setconfig(config='min-capacity-sat', val=400001, transient=True)
assert ret == {'config':
{'config': 'min-capacity-sat',
'source': '{}:3'.format(configfile),
'value_int': 400001,
'dynamic': True}}

# So this won't change.
with open(configfile, 'r') as f:
lines = f.read().splitlines()
assert lines[0].startswith('# setconfig commented out: min-capacity-sat=500000')
assert lines[1].startswith('# Inserted by setconfig ')
assert lines[2] == 'min-capacity-sat=400000'
assert len(lines) == 3


@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")
def test_recover_command(node_factory, bitcoind):
Expand Down

0 comments on commit 5a80223

Please sign in to comment.