Skip to content

Commit

Permalink
Do not require trusted hash for current catchup
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Jan 4, 2023
1 parent d260875 commit 6f38656
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,13 @@ parseCatchup(std::string const& catchup, std::string const& hash,
throw std::runtime_error(errorMessage);
}

Hash validHash;
std::optional<Hash> validHash;
try
{
validHash = hexToBin256(hash);
if (!hash.empty())
{
validHash = std::make_optional<Hash>(hexToBin256(hash));
}
}
catch (std::exception&)
{
Expand All @@ -518,15 +521,22 @@ 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())
{
return CatchupConfiguration(ledger, count, mode);
}
else
{
return CatchupConfiguration(
{ledger, std::make_optional<Hash>(validHash)}, count, mode);
releaseAssert(validHash.has_value());
return CatchupConfiguration({ledger, validHash}, count, mode);
}
}
catch (std::exception&)
Expand Down Expand Up @@ -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 "
Expand Down

0 comments on commit 6f38656

Please sign in to comment.