Skip to content

Commit

Permalink
chanbackup: add helpers to verify peer_storage as well in verifybackup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Sharma authored and Aditya Sharma committed Oct 14, 2023
1 parent 2b6feba commit 02dae15
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions plugins/chanbackup.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,37 @@ static bool verify_bkp(struct command *cmd,
return true;
}

static struct command_result *after_fetchscb(struct command *cmd,
const u8 *hexdata,
struct json_stream *response)
{
u64 version;
u32 timestamp;
struct scb_chan **scb;

if (tal_bytelen(hexdata) == 0) {
json_add_string(response, "peer_storage",
"Does not exist!");
return command_finished(cmd, response);
}

if (!fromwire_static_chan_backup(cmd,
hexdata,
&version,
&timestamp,
&scb)) {
json_add_string(response, "peer_storage", "Corrupted SCB on disk!");
return command_finished(cmd, response);
}

if (version != VERSION) {
json_add_string(response,"peer_storage",
"Incompatible version, Contact the admin or update the backup immediately!");
return command_finished(cmd, response);
}
json_add_bool(response, "peer_storage", true);
return command_finished(cmd, response);
}

static struct command_result *json_verifybackup(struct command *cmd,
const char *buf,
Expand All @@ -844,8 +875,11 @@ static struct command_result *json_verifybackup(struct command *cmd,
json_add_bool(response, "emergency.recover", true);
}

return command_finished(cmd, response);

return jsonrpc_get_datastore_binary(cmd->plugin,
cmd,
"chanbackup/latestscb",
after_fetchscb,
response);
}

static const char *init(struct plugin *p,
Expand Down

0 comments on commit 02dae15

Please sign in to comment.