From 02dae1578a1974c5c4deb4927bf51399a39224a0 Mon Sep 17 00:00:00 2001 From: Aditya Sharma Date: Sat, 14 Oct 2023 10:50:34 +0530 Subject: [PATCH] chanbackup: add helpers to verify peer_storage as well in verifybackup. --- plugins/chanbackup.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/plugins/chanbackup.c b/plugins/chanbackup.c index c875eaa21a0c..095859b56c66 100644 --- a/plugins/chanbackup.c +++ b/plugins/chanbackup.c @@ -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, + ×tamp, + &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, @@ -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,