options: create enable/disable option for peer storage.

Since it's not spec-final yet (hell, it's not even properly specified
yet!) we need to put it behind an experimental flag.

Unfortunately, we don't have support for doing this in a plugin; a
plugin must present features before parsing options.  So we need to do
it in core.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-02-05 14:14:00 +10:30 committed by Alex Myers
parent c60ea5bcbb
commit a71bd3ea37
6 changed files with 57 additions and 15 deletions

View file

@ -62,6 +62,7 @@ On success, an object is returned, containing:
- **experimental-offers** (boolean, optional): `experimental-offers` field from config or cmdline, or default - **experimental-offers** (boolean, optional): `experimental-offers` field from config or cmdline, or default
- **experimental-shutdown-wrong-funding** (boolean, optional): `experimental-shutdown-wrong-funding` field from config or cmdline, or default - **experimental-shutdown-wrong-funding** (boolean, optional): `experimental-shutdown-wrong-funding` field from config or cmdline, or default
- **experimental-websocket-port** (u16, optional): `experimental-websocket-port` field from config or cmdline, or default - **experimental-websocket-port** (u16, optional): `experimental-websocket-port` field from config or cmdline, or default
- **experimental-peer-storage** (boolean, optional): `experimental-peer-storage` field from config or cmdline, or default *(added v23.02)*
- **database-upgrade** (boolean, optional): `database-upgrade` field from config or cmdline - **database-upgrade** (boolean, optional): `database-upgrade` field from config or cmdline
- **rgb** (hex, optional): `rgb` field from config or cmdline, or default (always 6 characters) - **rgb** (hex, optional): `rgb` field from config or cmdline, or default (always 6 characters)
- **alias** (string, optional): `alias` field from config or cmdline, or default - **alias** (string, optional): `alias` field from config or cmdline, or default
@ -223,4 +224,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning> Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:581225b26efd84bfa99dc98e7a91e6fae11ef0b11939031d3da07f751f6d8f87) [comment]: # ( SHA256STAMP:1088401b9aeae1e079dab550d3b035ef82195f0466ad471bc7373386182f37dc)

View file

@ -714,6 +714,12 @@ connections on that port, on any IPv4 and IPv6 addresses you listen
to ([bolt][bolt] #891). The normal protocol is expected to be sent over WebSocket binary to ([bolt][bolt] #891). The normal protocol is expected to be sent over WebSocket binary
frames once the connection is upgraded. frames once the connection is upgraded.
* **experimental-peer-storage**
Specifying this option means we will store up to 64k of encrypted
data for our peers, and give them our (encrypted!) backup data to
store as well, based on a protocol similar to [bolt][bolt] #881.
BUGS BUGS
---- ----

View file

@ -137,6 +137,11 @@
"type": "u16", "type": "u16",
"description": "`experimental-websocket-port` field from config or cmdline, or default" "description": "`experimental-websocket-port` field from config or cmdline, or default"
}, },
"experimental-peer-storage": {
"type": "boolean",
"added": "v23.02",
"description": "`experimental-peer-storage` field from config or cmdline, or default"
},
"database-upgrade": { "database-upgrade": {
"type": "boolean", "type": "boolean",
"description": "`database-upgrade` field from config or cmdline" "description": "`database-upgrade` field from config or cmdline"

View file

@ -1078,6 +1078,15 @@ static char *opt_set_shutdown_wrong_funding(struct lightningd *ld)
return NULL; return NULL;
} }
static char *opt_set_peer_storage(struct lightningd *ld)
{
feature_set_or(ld->our_features,
take(feature_set_for_feature(NULL, OPT_PROVIDE_PEER_BACKUP_STORAGE)));
feature_set_or(ld->our_features,
take(feature_set_for_feature(NULL, OPT_WANT_PEER_BACKUP_STORAGE)));
return NULL;
}
static char *opt_set_offers(struct lightningd *ld) static char *opt_set_offers(struct lightningd *ld)
{ {
ld->config.exp_offers = true; ld->config.exp_offers = true;
@ -1156,6 +1165,9 @@ static void register_opts(struct lightningd *ld)
opt_register_early_noarg("--experimental-shutdown-wrong-funding", opt_register_early_noarg("--experimental-shutdown-wrong-funding",
opt_set_shutdown_wrong_funding, ld, opt_set_shutdown_wrong_funding, ld,
"EXPERIMENTAL: allow shutdown with alternate txids"); "EXPERIMENTAL: allow shutdown with alternate txids");
opt_register_early_noarg("--experimental-peer-storage",
opt_set_peer_storage, ld,
"EXPERIMENTAL: enable peer backup storage and restore");
opt_register_early_arg("--announce-addr-dns", opt_register_early_arg("--announce-addr-dns",
opt_set_bool_arg, opt_show_bool, opt_set_bool_arg, opt_show_bool,
&ld->announce_dns, &ld->announce_dns,
@ -1641,6 +1653,11 @@ static void add_config(struct lightningd *ld,
feature_offered(ld->our_features feature_offered(ld->our_features
->bits[INIT_FEATURE], ->bits[INIT_FEATURE],
OPT_SHUTDOWN_WRONG_FUNDING)); OPT_SHUTDOWN_WRONG_FUNDING));
} else if (opt->cb == (void *)opt_set_peer_storage) {
json_add_bool(response, name0,
feature_offered(ld->our_features
->bits[INIT_FEATURE],
OPT_PROVIDE_PEER_BACKUP_STORAGE));
} else if (opt->cb == (void *)plugin_opt_flag_set) { } else if (opt->cb == (void *)plugin_opt_flag_set) {
/* Noop, they will get added below along with the /* Noop, they will get added below along with the
* OPT_HASARG options. */ * OPT_HASARG options. */

View file

@ -30,6 +30,7 @@
/* Global secret object to keep the derived encryption key for the SCB */ /* Global secret object to keep the derived encryption key for the SCB */
static struct secret secret; static struct secret secret;
static bool peer_backup;
/* Helper to fetch out SCB from the RPC call */ /* Helper to fetch out SCB from the RPC call */
static bool json_to_scb_chan(const char *buffer, static bool json_to_scb_chan(const char *buffer,
@ -530,6 +531,9 @@ static struct command_result *peer_connected(struct command *cmd,
u8 *serialise_scb; u8 *serialise_scb;
const char *err; const char *err;
if (!peer_backup)
return command_hook_success(cmd);
serialise_scb = towire_peer_storage(cmd, serialise_scb = towire_peer_storage(cmd,
get_file_data(tmpctx, cmd->plugin)); get_file_data(tmpctx, cmd->plugin));
node_id = tal(cmd, struct node_id); node_id = tal(cmd, struct node_id);
@ -592,13 +596,15 @@ static struct command_result *handle_your_peer_storage(struct command *cmd,
{ {
struct node_id node_id; struct node_id node_id;
u8 *payload, *payload_deserialise; u8 *payload, *payload_deserialise;
const char *err = json_scan(cmd, buf, params, const char *err;
"{payload:%,peer_id:%}",
JSON_SCAN_TAL(cmd, if (!peer_backup)
json_tok_bin_from_hex, return command_hook_success(cmd);
&payload),
JSON_SCAN(json_to_node_id, err = json_scan(cmd, buf, params,
&node_id)); "{payload:%,peer_id:%}",
JSON_SCAN_TAL(cmd, json_tok_bin_from_hex, &payload),
JSON_SCAN(json_to_node_id, &node_id));
if (err) { if (err) {
plugin_err(cmd->plugin, plugin_err(cmd->plugin,
"`your_peer_storage` response did not scan %s: %.*s", "`your_peer_storage` response did not scan %s: %.*s",
@ -737,6 +743,14 @@ static const char *init(struct plugin *p,
struct scb_chan **scb_chan; struct scb_chan **scb_chan;
const char *info = "scb secret"; const char *info = "scb secret";
u8 *info_hex = tal_dup_arr(tmpctx, u8, (u8*)info, strlen(info), 0); u8 *info_hex = tal_dup_arr(tmpctx, u8, (u8*)info, strlen(info), 0);
u8 *features;
/* Figure out if they specified --experimental-peer-storage */
rpc_scan(p, "getinfo",
take(json_out_obj(NULL, NULL, NULL)),
"{our_features:{init:%}}",
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &features));
peer_backup = feature_offered(features, OPT_WANT_PEER_BACKUP_STORAGE);
rpc_scan(p, "staticbackup", rpc_scan(p, "staticbackup",
take(json_out_obj(NULL, NULL, NULL)), take(json_out_obj(NULL, NULL, NULL)),
@ -799,12 +813,8 @@ static const struct plugin_command commands[] = {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
setup_locale(); setup_locale();
struct feature_set *features = feature_set_for_feature(NULL, OPT_WANT_PEER_BACKUP_STORAGE);
feature_set_or(features,
take(feature_set_for_feature(NULL,
OPT_PROVIDE_PEER_BACKUP_STORAGE)));
plugin_main(argv, init, PLUGIN_STATIC, true, features, plugin_main(argv, init, PLUGIN_STATIC, true, NULL,
commands, ARRAY_SIZE(commands), commands, ARRAY_SIZE(commands),
notifs, ARRAY_SIZE(notifs), hooks, ARRAY_SIZE(hooks), notifs, ARRAY_SIZE(notifs), hooks, ARRAY_SIZE(hooks),
NULL, 0, /* Notification topics we publish */ NULL, 0, /* Notification topics we publish */

View file

@ -2510,8 +2510,11 @@ def test_restorefrompeer(node_factory, bitcoind):
""" """
Test restorefrompeer Test restorefrompeer
""" """
l1, l2 = node_factory.get_nodes(2, opts=[{'allow_broken_log': True, 'may_reconnect': True}, l1, l2 = node_factory.get_nodes(2, [{'allow_broken_log': True,
{'may_reconnect': True}]) 'experimental-peer-storage': None,
'may_reconnect': True},
{'experimental-peer-storage': None,
'may_reconnect': True}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.rpc.connect(l2.info['id'], 'localhost', l2.port)