mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
Plugins/chanbackup: Add RPC for recovering from the latestscb received from peers.
This commit is contained in:
@@ -258,7 +258,7 @@ static struct command_result *json_emergencyrecover(struct command *cmd,
|
|||||||
|
|
||||||
if (version != VERSION) {
|
if (version != VERSION) {
|
||||||
plugin_err(cmd->plugin,
|
plugin_err(cmd->plugin,
|
||||||
"Incompatible version, Contact the admin!");
|
"Incompatible SCB file version on disk, contact the admin!");
|
||||||
}
|
}
|
||||||
|
|
||||||
req = jsonrpc_request_start(cmd->plugin, cmd, "recoverchannel",
|
req = jsonrpc_request_start(cmd->plugin, cmd, "recoverchannel",
|
||||||
@@ -665,6 +665,67 @@ static struct command_result *handle_your_peer_storage(struct command *cmd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct command_result *after_latestscb(struct command *cmd,
|
||||||
|
const u8 *res,
|
||||||
|
void *cb_arg UNUSED)
|
||||||
|
{
|
||||||
|
u64 version;
|
||||||
|
u32 timestamp;
|
||||||
|
struct scb_chan **scb;
|
||||||
|
struct json_stream *response;
|
||||||
|
struct out_req *req;
|
||||||
|
|
||||||
|
if (tal_bytelen(res) == 0) {
|
||||||
|
response = jsonrpc_stream_success(cmd);
|
||||||
|
|
||||||
|
json_add_string(response, "result",
|
||||||
|
"No backup received from peers");
|
||||||
|
return command_finished(cmd, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fromwire_static_chan_backup(cmd,
|
||||||
|
res,
|
||||||
|
&version,
|
||||||
|
×tamp,
|
||||||
|
&scb)) {
|
||||||
|
plugin_err(cmd->plugin, "Corrupted SCB on disk!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version != VERSION) {
|
||||||
|
plugin_err(cmd->plugin,
|
||||||
|
"Incompatible version, Contact the admin!");
|
||||||
|
}
|
||||||
|
|
||||||
|
req = jsonrpc_request_start(cmd->plugin, cmd, "recoverchannel",
|
||||||
|
after_recover_rpc,
|
||||||
|
&forward_error, NULL);
|
||||||
|
|
||||||
|
json_array_start(req->js, "scb");
|
||||||
|
for (size_t i=0; i<tal_count(scb); i++) {
|
||||||
|
u8 *scb_hex = tal_arr(cmd, u8, 0);
|
||||||
|
towire_scb_chan(&scb_hex,scb[i]);
|
||||||
|
json_add_hex(req->js, NULL, scb_hex, tal_bytelen(scb_hex));
|
||||||
|
}
|
||||||
|
json_array_end(req->js);
|
||||||
|
|
||||||
|
return send_outreq(cmd->plugin, req);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct command_result *json_restorefrompeer(struct command *cmd,
|
||||||
|
const char *buf,
|
||||||
|
const jsmntok_t *params)
|
||||||
|
{
|
||||||
|
if (!param(cmd, buf, params, NULL))
|
||||||
|
return command_param_failed();
|
||||||
|
|
||||||
|
return jsonrpc_get_datastore_binary(cmd->plugin,
|
||||||
|
cmd,
|
||||||
|
"chanbackup/latestscb",
|
||||||
|
after_latestscb,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *init(struct plugin *p,
|
static const char *init(struct plugin *p,
|
||||||
const char *buf UNUSED,
|
const char *buf UNUSED,
|
||||||
const jsmntok_t *config UNUSED)
|
const jsmntok_t *config UNUSED)
|
||||||
@@ -719,6 +780,15 @@ static const struct plugin_command commands[] = { {
|
|||||||
"returns stub channel-id's on completion",
|
"returns stub channel-id's on completion",
|
||||||
json_emergencyrecover,
|
json_emergencyrecover,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"restorefrompeer",
|
||||||
|
"recovery",
|
||||||
|
"Checks if i have got a backup from a peer, and if so, will stub "
|
||||||
|
"those channels in the database and if is successful, will return "
|
||||||
|
"list of channels that have been successfully stubbed",
|
||||||
|
"return channel-id's on completion",
|
||||||
|
json_restorefrompeer,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
Reference in New Issue
Block a user