mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
lightningd: mark explicitly what commands are dev-only.
And require --developer to use them. Also refuse redirection to deprecated APIs if deprecated APIs are disabled! Changelog-Removed: `dev-sendcustommsg` (use `sendcustommsg`, which was added in v0.10.1) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
1ecf31bae7
commit
de81a59b1e
@ -2132,7 +2132,8 @@ static const struct json_command dev_feerate_command = {
|
||||
"dev-feerate",
|
||||
"developer",
|
||||
json_dev_feerate,
|
||||
"Set feerate for {id} to {feerate}"
|
||||
"Set feerate for {id} to {feerate}",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_feerate_command);
|
||||
|
||||
@ -2185,7 +2186,8 @@ static const struct json_command dev_quiesce_command = {
|
||||
"dev-quiesce",
|
||||
"developer",
|
||||
json_dev_quiesce,
|
||||
"Initiate quiscence protocol with peer"
|
||||
"Initiate quiscence protocol with peer",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_quiesce_command);
|
||||
#endif /* DEVELOPER */
|
||||
|
@ -824,20 +824,6 @@ static const struct json_command sendcustommsg_command = {
|
||||
|
||||
AUTODATA(json_command, &sendcustommsg_command);
|
||||
|
||||
#ifdef COMPAT_V0100
|
||||
#ifdef DEVELOPER
|
||||
static const struct json_command dev_sendcustommsg_command = {
|
||||
"dev-sendcustommsg",
|
||||
"utility",
|
||||
json_sendcustommsg,
|
||||
"Send a custom message to the peer with the given {node_id}",
|
||||
.verbose = "dev-sendcustommsg node_id hexcustommsg",
|
||||
};
|
||||
|
||||
AUTODATA(json_command, &dev_sendcustommsg_command);
|
||||
#endif /* DEVELOPER */
|
||||
#endif /* COMPAT_V0100 */
|
||||
|
||||
#if DEVELOPER
|
||||
static struct command_result *json_dev_suppress_gossip(struct command *cmd,
|
||||
const char *buffer,
|
||||
@ -857,7 +843,8 @@ static const struct json_command dev_suppress_gossip = {
|
||||
"dev-suppress-gossip",
|
||||
"developer",
|
||||
json_dev_suppress_gossip,
|
||||
"Stop this node from sending any more gossip."
|
||||
"Stop this node from sending any more gossip.",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_suppress_gossip);
|
||||
|
||||
@ -879,7 +866,8 @@ static const struct json_command dev_report_fds = {
|
||||
"dev-report-fds",
|
||||
"developer",
|
||||
json_dev_report_fds,
|
||||
"Ask connectd to report status of all its open files."
|
||||
"Ask connectd to report status of all its open files.",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_report_fds);
|
||||
#endif /* DEVELOPER */
|
||||
|
@ -3538,7 +3538,8 @@ static const struct json_command queryrates_command = {
|
||||
"channels",
|
||||
json_queryrates,
|
||||
"Ask a peer what their contribution and liquidity rates are"
|
||||
" for the given {amount} and {requested_amt}"
|
||||
" for the given {amount} and {requested_amt}",
|
||||
.dev_only = true,
|
||||
};
|
||||
|
||||
AUTODATA(json_command, &queryrates_command);
|
||||
|
@ -560,7 +560,8 @@ static const struct json_command dev_set_max_scids_encode_size = {
|
||||
"dev-set-max-scids-encode-size",
|
||||
"developer",
|
||||
json_dev_set_max_scids_encode_size,
|
||||
"Set {max} bytes of short_channel_ids per reply_channel_range"
|
||||
"Set {max} bytes of short_channel_ids per reply_channel_range",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_set_max_scids_encode_size);
|
||||
|
||||
@ -603,7 +604,8 @@ static const struct json_command dev_compact_gossip_store = {
|
||||
"dev-compact-gossip-store",
|
||||
"developer",
|
||||
json_dev_compact_gossip_store,
|
||||
"Ask gossipd to rewrite the gossip store."
|
||||
"Ask gossipd to rewrite the gossip store.",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_compact_gossip_store);
|
||||
|
||||
@ -630,7 +632,8 @@ static const struct json_command dev_gossip_set_time = {
|
||||
"dev-gossip-set-time",
|
||||
"developer",
|
||||
json_dev_gossip_set_time,
|
||||
"Ask gossipd to update the current time."
|
||||
"Ask gossipd to update the current time.",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_gossip_set_time);
|
||||
#endif /* DEVELOPER */
|
||||
|
@ -1455,7 +1455,7 @@ static const struct json_command delexpiredinvoice_command = {
|
||||
"payment",
|
||||
json_delexpiredinvoice,
|
||||
"Delete all expired invoices that expired as of given {maxexpirytime} (a UNIX epoch time), or all expired invoices if not specified",
|
||||
true /*deprecated*/
|
||||
.deprecated = true,
|
||||
};
|
||||
AUTODATA(json_command, &delexpiredinvoice_command);
|
||||
|
||||
|
@ -310,7 +310,8 @@ static const struct json_command dev_command = {
|
||||
"dev crash\n"
|
||||
" Crash lightningd by calling fatal()\n"
|
||||
"dev slowcmd {msec}\n"
|
||||
" Torture test for slow commands, optional {msec}\n"
|
||||
" Torture test for slow commands, optional {msec}\n",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_command);
|
||||
#endif /* DEVELOPER */
|
||||
@ -405,6 +406,10 @@ static struct command_result *json_help(struct command *cmd,
|
||||
return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
|
||||
"Deprecated command %s",
|
||||
cmdname);
|
||||
if (!cmd->ld->developer && one_cmd->dev_only)
|
||||
return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
|
||||
"Developer-only command %s",
|
||||
cmdname);
|
||||
} else
|
||||
one_cmd = NULL;
|
||||
|
||||
@ -741,6 +746,18 @@ static void replace_command(struct rpc_command_hook_payload *p,
|
||||
buffer + method->start);
|
||||
goto fail;
|
||||
}
|
||||
if (p->cmd->json_cmd->deprecated && !p->cmd->ld->deprecated_apis) {
|
||||
bad = tal_fmt(tmpctx, "redirected to deprecated command '%.*s'",
|
||||
method->end - method->start,
|
||||
buffer + method->start);
|
||||
goto fail;
|
||||
}
|
||||
if (p->cmd->json_cmd->dev_only && !p->cmd->ld->developer) {
|
||||
bad = tal_fmt(tmpctx, "redirected to developer-only command '%.*s'",
|
||||
method->end - method->start,
|
||||
buffer + method->start);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
jsonrpc = json_get_member(buffer, replacetok, "jsonrpc");
|
||||
if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) {
|
||||
@ -966,6 +983,12 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
|
||||
json_tok_full_len(method),
|
||||
json_tok_full(jcon->buffer, method));
|
||||
}
|
||||
if (c->json_cmd->dev_only && !jcon->ld->developer) {
|
||||
return command_fail(c, JSONRPC2_METHOD_NOT_FOUND,
|
||||
"Command %.*s is developer-only",
|
||||
json_tok_full_len(method),
|
||||
json_tok_full(jcon->buffer, method));
|
||||
}
|
||||
|
||||
rpc_hook = tal(c, struct rpc_command_hook_payload);
|
||||
rpc_hook->cmd = c;
|
||||
|
@ -59,8 +59,9 @@ struct json_command {
|
||||
const jsmntok_t *obj,
|
||||
const jsmntok_t *params);
|
||||
const char *description;
|
||||
bool deprecated;
|
||||
const char *verbose;
|
||||
bool dev_only;
|
||||
bool deprecated;
|
||||
};
|
||||
|
||||
struct jsonrpc_notification {
|
||||
|
@ -84,7 +84,8 @@ static const struct json_command dev_memdump_command = {
|
||||
"dev-memdump",
|
||||
"developer",
|
||||
json_memdump,
|
||||
"Show memory objects currently in use"
|
||||
"Show memory objects currently in use",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_memdump_command);
|
||||
|
||||
@ -308,7 +309,8 @@ static const struct json_command dev_memleak_command = {
|
||||
"dev-memleak",
|
||||
"developer",
|
||||
json_memleak,
|
||||
"Show unreferenced memory objects"
|
||||
"Show unreferenced memory objects",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_memleak_command);
|
||||
#endif /* DEVELOPER */
|
||||
|
@ -2978,7 +2978,8 @@ static const struct json_command dev_sign_last_tx = {
|
||||
"dev-sign-last-tx",
|
||||
"developer",
|
||||
json_sign_last_tx,
|
||||
"Sign and show the last commitment transaction with peer {id}"
|
||||
"Sign and show the last commitment transaction with peer {id}",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_sign_last_tx);
|
||||
|
||||
@ -3019,7 +3020,8 @@ static const struct json_command dev_fail_command = {
|
||||
"dev-fail",
|
||||
"developer",
|
||||
json_dev_fail,
|
||||
"Fail with peer {id}"
|
||||
"Fail with peer {id}",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_fail_command);
|
||||
|
||||
@ -3078,7 +3080,8 @@ static const struct json_command dev_reenable_commit = {
|
||||
"dev-reenable-commit",
|
||||
"developer",
|
||||
json_dev_reenable_commit,
|
||||
"Re-enable the commit timer on peer {id}"
|
||||
"Re-enable the commit timer on peer {id}",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_reenable_commit);
|
||||
|
||||
@ -3194,8 +3197,9 @@ static const struct json_command dev_forget_channel_command = {
|
||||
"dev-forget-channel",
|
||||
"developer",
|
||||
json_dev_forget_channel,
|
||||
"Forget the channel with peer {id}, ignore UTXO check with {force}='true'.", false,
|
||||
"Forget the channel with peer {id}. Checks if the channel is still active by checking its funding transaction. Check can be ignored by setting {force} to 'true'"
|
||||
"Forget the channel with peer {id}, ignore UTXO check with {force}='true'.",
|
||||
.verbose = "Forget the channel with peer {id}. Checks if the channel is still active by checking its funding transaction. Check can be ignored by setting {force} to 'true'",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_forget_channel_command);
|
||||
|
||||
|
@ -2986,8 +2986,8 @@ static const struct json_command dev_ignore_htlcs = {
|
||||
"dev-ignore-htlcs",
|
||||
"developer",
|
||||
json_dev_ignore_htlcs,
|
||||
"Set ignoring incoming HTLCs for peer {id} to {ignore}", false,
|
||||
"Set/unset ignoring of all incoming HTLCs. For testing only."
|
||||
"Set ignoring incoming HTLCs for peer {id} to {ignore}",
|
||||
.dev_only = true,
|
||||
};
|
||||
|
||||
AUTODATA(json_command, &dev_ignore_htlcs);
|
||||
|
@ -1263,6 +1263,7 @@ static const char *plugin_rpcmethod_add(struct plugin *plugin,
|
||||
} else
|
||||
cmd->deprecated = false;
|
||||
|
||||
cmd->dev_only = false;
|
||||
cmd->dispatch = plugin_rpcmethod_dispatch;
|
||||
if (!jsonrpc_command_add(plugin->plugins->ld->jsonrpc, cmd, usage)) {
|
||||
struct plugin *p =
|
||||
|
@ -18,7 +18,7 @@ def on_rpc_command(plugin, rpc_command, **kwargs):
|
||||
# Return a custom result to the command
|
||||
return {"return": {"result": ["Custom rpc_command_1 result"]}}
|
||||
elif request["method"] == "help":
|
||||
request["method"] = "autocleaninvoice"
|
||||
request["method"] = "listconfigs"
|
||||
return {"replace": request}
|
||||
return {"result": "continue"}
|
||||
|
||||
|
@ -1489,7 +1489,7 @@ def test_rpc_command_hook(node_factory):
|
||||
assert funds[0] == "Custom rpc_command_1 result"
|
||||
|
||||
# Test command redirection to a plugin
|
||||
l1.rpc.call('help', [0])
|
||||
l1.rpc.call('help', ['developer'])
|
||||
|
||||
# Check the 'already modified' warning is not logged on just 'continue'
|
||||
assert not l1.daemon.is_in_log("rpc_command hook 'listfunds' already modified, ignoring.")
|
||||
|
@ -183,8 +183,8 @@ static const struct json_command newaddr_command = {
|
||||
"newaddr",
|
||||
"bitcoin",
|
||||
json_newaddr,
|
||||
"Get a new {bech32} (or all) address to fund a channel", false,
|
||||
"Generates a new address that belongs to the internal wallet. Funds sent to these addresses will be managed by lightningd. Use `withdraw` to withdraw funds to an external wallet."
|
||||
"Get a new {bech32} (or all) address to fund a channel",
|
||||
.verbose = "Generates a new address that belongs to the internal wallet. Funds sent to these addresses will be managed by lightningd. Use `withdraw` to withdraw funds to an external wallet."
|
||||
};
|
||||
AUTODATA(json_command, &newaddr_command);
|
||||
|
||||
@ -266,8 +266,8 @@ static const struct json_command listaddrs_command = {
|
||||
"developer",
|
||||
json_listaddrs,
|
||||
"Show addresses list up to derivation {index} (default is the last bip32 index)",
|
||||
false,
|
||||
"Show addresses of your internal wallet. Use `newaddr` to generate a new address."
|
||||
.verbose = "Show addresses of your internal wallet. Use `newaddr` to generate a new address.",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &listaddrs_command);
|
||||
|
||||
@ -419,8 +419,7 @@ static const struct json_command listfunds_command = {
|
||||
"utility",
|
||||
json_listfunds,
|
||||
"Show available funds from the internal wallet",
|
||||
false,
|
||||
"Returns a list of funds (outputs) that can be used "
|
||||
.verbose = "Returns a list of funds (outputs) that can be used "
|
||||
"by the internal wallet to open new channels "
|
||||
"or can be withdrawn, using the `withdraw` command, to another wallet. "
|
||||
"Includes spent outputs if {spent} is set to true."
|
||||
@ -499,8 +498,8 @@ static const struct json_command dev_rescan_output_command = {
|
||||
"developer",
|
||||
json_dev_rescan_outputs,
|
||||
"Synchronize the state of our funds with bitcoind",
|
||||
false,
|
||||
"For each output stored in the internal wallet ask `bitcoind` whether we are in sync with its state (spent vs. unspent)"
|
||||
.verbose = "For each output stored in the internal wallet ask `bitcoind` whether we are in sync with its state (spent vs. unspent)",
|
||||
.dev_only = true,
|
||||
};
|
||||
AUTODATA(json_command, &dev_rescan_output_command);
|
||||
|
||||
@ -601,8 +600,7 @@ static const struct json_command listtransactions_command = {
|
||||
"payment",
|
||||
json_listtransactions,
|
||||
"List transactions that we stored in the wallet",
|
||||
false,
|
||||
"Returns transactions tracked in the wallet. This includes deposits, "
|
||||
.verbose = "Returns transactions tracked in the wallet. This includes deposits, "
|
||||
"withdrawals and transactions related to channels. A transaction may have "
|
||||
"multiple types, e.g., a transaction may both be a close and a deposit if "
|
||||
"it closes the channel and returns funds to the wallet."
|
||||
|
Loading…
Reference in New Issue
Block a user