From 6f38656268128b144fdaf2a729d0a1769a04171a Mon Sep 17 00:00:00 2001 From: marta-lokhova Date: Wed, 4 Jan 2023 13:17:48 -0800 Subject: [PATCH] Do not require trusted hash for current catchup --- src/main/CommandLine.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/CommandLine.cpp b/src/main/CommandLine.cpp index 1e920a8ea0..cd57092dd5 100644 --- a/src/main/CommandLine.cpp +++ b/src/main/CommandLine.cpp @@ -502,10 +502,13 @@ parseCatchup(std::string const& catchup, std::string const& hash, throw std::runtime_error(errorMessage); } - Hash validHash; + std::optional validHash; try { - validHash = hexToBin256(hash); + if (!hash.empty()) + { + validHash = std::make_optional(hexToBin256(hash)); + } } catch (std::exception&) { @@ -518,6 +521,13 @@ parseCatchup(std::string const& catchup, std::string const& hash, ? CatchupConfiguration::Mode::OFFLINE_COMPLETE : CatchupConfiguration::Mode::OFFLINE_BASIC; auto ledger = parseLedger(catchup.substr(0, separatorIndex)); + if (ledger == CatchupConfiguration::CURRENT) + { + CLOG_WARNING(History, + "Catching up to `current` ledger of an untrusted " + "archive. If you want to ensure validity of replayed " + "data, pass ledger number and trusted hash instead."); + } auto count = parseLedgerCount(catchup.substr(separatorIndex + 1)); if (hash.empty()) { @@ -525,8 +535,8 @@ parseCatchup(std::string const& catchup, std::string const& hash, } else { - return CatchupConfiguration( - {ledger, std::make_optional(validHash)}, count, mode); + releaseAssert(validHash.has_value()); + return CatchupConfiguration({ledger, validHash}, count, mode); } } catch (std::exception&) @@ -908,7 +918,8 @@ runCatchup(CommandLineArgs const& args) app->resetLedgerState(); lm.startNewLedger(); } - else if (hash.empty() && !forceUntrusted) + else if (hash.empty() && !forceUntrusted && + cc.toLedger() != CatchupConfiguration::CURRENT) { std::string msg = "Unsafe command: use --trusted-checkpoint-hashes or "