Skip to content

Commit

Permalink
Merge pull request #3058 from marta-lokhova/restore_genesis_state
Browse files Browse the repository at this point in the history
Restore genesis state when in memory mode

Reviewed-by: MonsieurNicolas
  • Loading branch information
latobarita authored May 20, 2021
2 parents ff5b373 + 68cb89b commit 2b01403
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/ApplicationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,26 @@ setupApp(Config& cfg, VirtualClock& clock, uint32_t startAtLedger,
return nullptr;
}

app->getLedgerManager().loadLastKnownLedger(nullptr);
auto lcl = app->getLedgerManager().getLastClosedLedgerHeader();

if (cfg.isInMemoryMode() &&
lcl.header.ledgerSeq == LedgerManager::GENESIS_LEDGER_SEQ)
{
// If ledger is genesis, rebuild genesis state from buckets
if (!applyBucketsForLCL(*app))
{
return nullptr;
}
}

bool doCatchupForInMemoryMode =
cfg.isInMemoryMode() && startAtLedger != 0 && !startAtHash.empty();
if (doCatchupForInMemoryMode)
{
app->getLedgerManager().loadLastKnownLedger(nullptr);
auto lcl = app->getLedgerManager().getLastClosedLedgerHeader();
if (canRebuildInMemoryLedgerFromBuckets(startAtLedger,
lcl.header.ledgerSeq))
// At this point, setupApp has either confirmed that we can rebuild from
// the existing buckets, or reset the DB to genesis
if (lcl.header.ledgerSeq != LedgerManager::GENESIS_LEDGER_SEQ)
{
auto lclHashStr = binToHex(lcl.hash);
if (lcl.header.ledgerSeq == startAtLedger &&
Expand Down

0 comments on commit 2b01403

Please sign in to comment.