Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 303950a

Browse files
committedFeb 28, 2025
Remove obsolete history mode from Config, and state rebuild functionality from LedgerManager
1 parent 89b85a1 commit 303950a

8 files changed

+23
-66
lines changed
 

‎src/herder/HerderImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ HerderImpl::processExternalized(uint64 slotIndex, StellarValue const& value,
306306
mPendingEnvelopes.getTxSet(value.txSetHash);
307307

308308
// save the SCP messages in the database
309-
if (mApp.getConfig().MODE_STORES_HISTORY_MISC)
309+
if (mApp.getConfig().modeStoresHistory())
310310
{
311311
ZoneNamedN(updateSCPHistoryZone, "update SCP history", true);
312312
if (slotIndex != 0)

‎src/ledger/LedgerManagerImpl.cpp

+17-47
Original file line numberDiff line numberDiff line change
@@ -328,50 +328,24 @@ LedgerManagerImpl::loadLastKnownLedger(bool restoreBucketlist)
328328
// Step 2. Restore LedgerHeader from DB based on the ledger hash derived
329329
// earlier, or verify we're at genesis if in no-history mode
330330
std::optional<LedgerHeader> latestLedgerHeader;
331-
if (mApp.getConfig().MODE_STORES_HISTORY_LEDGERHEADERS)
331+
auto currentLedger =
332+
LedgerHeaderUtils::loadByHash(getDatabase(), lastLedgerHash);
333+
if (!currentLedger)
332334
{
333-
if (mRebuildInMemoryState)
334-
{
335-
LedgerHeader lh;
336-
CLOG_INFO(Ledger,
337-
"Setting empty ledger while core rebuilds state: {}",
338-
ledgerAbbrev(lh));
339-
setLedgerTxnHeader(lh, mApp);
340-
latestLedgerHeader = lh;
341-
}
342-
else
343-
{
344-
auto currentLedger =
345-
LedgerHeaderUtils::loadByHash(getDatabase(), lastLedgerHash);
346-
if (!currentLedger)
347-
{
348-
throw std::runtime_error("Could not load ledger from database");
349-
}
350-
351-
if (currentLedger->ledgerSeq != has.currentLedger)
352-
{
353-
throw std::runtime_error("Invalid database state: last known "
354-
"ledger does not agree with HAS");
355-
}
356-
357-
CLOG_INFO(Ledger, "Loaded LCL header from database: {}",
358-
ledgerAbbrev(*currentLedger));
359-
setLedgerTxnHeader(*currentLedger, mApp);
360-
latestLedgerHeader = *currentLedger;
361-
}
335+
throw std::runtime_error("Could not load ledger from database");
362336
}
363-
else
337+
338+
if (currentLedger->ledgerSeq != has.currentLedger)
364339
{
365-
// In no-history mode, this method should only be called when
366-
// the LCL is genesis.
367-
releaseAssertOrThrow(getLCLState().ledgerHeader.hash == lastLedgerHash);
368-
releaseAssertOrThrow(getLCLState().ledgerHeader.header.ledgerSeq ==
369-
GENESIS_LEDGER_SEQ);
370-
CLOG_INFO(Ledger, "LCL is genesis: {}",
371-
ledgerAbbrev(getLCLState().ledgerHeader));
372-
latestLedgerHeader = getLCLState().ledgerHeader.header;
340+
throw std::runtime_error("Invalid database state: last known "
341+
"ledger does not agree with HAS");
373342
}
374343

344+
CLOG_INFO(Ledger, "Loaded LCL header from database: {}",
345+
ledgerAbbrev(*currentLedger));
346+
setLedgerTxnHeader(*currentLedger, mApp);
347+
latestLedgerHeader = *currentLedger;
348+
375349
releaseAssert(latestLedgerHeader.has_value());
376350

377351
auto missing = mApp.getBucketManager().checkForMissingBucketsFiles(has);
@@ -947,7 +921,7 @@ LedgerManagerImpl::applyLedger(LedgerCloseData const& ledgerData,
947921
// Subtle: after this call, `header` is invalidated, and is not safe to use
948922
auto txResultSet = applyTransactions(*applicableTxSet, mutableTxResults,
949923
ltx, ledgerCloseMeta);
950-
if (mApp.getConfig().MODE_STORES_HISTORY_MISC)
924+
if (mApp.getConfig().modeStoresHistory())
951925
{
952926
auto ledgerSeq = ltx.loadHeader().current().ledgerSeq;
953927
mApp.getHistoryManager().appendTransactionSet(ledgerSeq, txSet,
@@ -1758,14 +1732,10 @@ LedgerManagerImpl::storePersistentStateAndLedgerHeaderInDB(
17581732

17591733
mApp.getPersistentState().setState(PersistentState::kHistoryArchiveState,
17601734
has.toString(), sess);
1761-
1762-
if (mApp.getConfig().MODE_STORES_HISTORY_LEDGERHEADERS && storeHeader)
1735+
LedgerHeaderUtils::storeInDatabase(mApp.getDatabase(), header, sess);
1736+
if (appendToCheckpoint)
17631737
{
1764-
LedgerHeaderUtils::storeInDatabase(mApp.getDatabase(), header, sess);
1765-
if (appendToCheckpoint)
1766-
{
1767-
mApp.getHistoryManager().appendLedgerHeader(header);
1768-
}
1738+
mApp.getHistoryManager().appendLedgerHeader(header);
17691739
}
17701740

17711741
return has;

‎src/ledger/LedgerManagerImpl.h

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class LedgerManagerImpl : public LedgerManager
9999
SorobanMetrics mSorobanMetrics;
100100

101101
VirtualClock::time_point mLastClose;
102-
bool mRebuildInMemoryState{false};
103102

104103
// Use mutex to guard ledger state during apply
105104
mutable std::recursive_mutex mLedgerStateMutex;

‎src/main/ApplicationImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ ApplicationImpl::validateAndLogConfig()
725725

726726
if (getHistoryArchiveManager().publishEnabled())
727727
{
728-
if (!mConfig.modeStoresAllHistory())
728+
if (!mConfig.modeStoresHistory())
729729
{
730730
throw std::invalid_argument(
731731
"Core is not configured to store history, but "

‎src/main/CommandHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CommandHandler::CommandHandler(Application& app) : mApp(app)
8585
}
8686

8787
mServer->add404(std::bind(&CommandHandler::fileNotFound, this, _1, _2));
88-
if (mApp.getConfig().modeStoresAnyHistory())
88+
if (mApp.getConfig().modeStoresHistory())
8989
{
9090
addRoute("maintenance", &CommandHandler::maintenance);
9191
}

‎src/main/Config.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ Config::Config() : NODE_SEED(SecretKey::random())
121121
// non configurable
122122
MODE_ENABLES_BUCKETLIST = true;
123123
MODE_STORES_HISTORY_MISC = true;
124-
MODE_STORES_HISTORY_LEDGERHEADERS = true;
125124
MODE_DOES_CATCHUP = true;
126125
MODE_AUTO_STARTS_OVERLAY = true;
127126
OP_APPLY_SLEEP_TIME_DURATION_FOR_TESTING =
@@ -2391,15 +2390,9 @@ Config::modeDoesCatchupWithBucketList() const
23912390
}
23922391

23932392
bool
2394-
Config::modeStoresAllHistory() const
2393+
Config::modeStoresHistory() const
23952394
{
2396-
return MODE_STORES_HISTORY_LEDGERHEADERS && MODE_STORES_HISTORY_MISC;
2397-
}
2398-
2399-
bool
2400-
Config::modeStoresAnyHistory() const
2401-
{
2402-
return MODE_STORES_HISTORY_LEDGERHEADERS || MODE_STORES_HISTORY_MISC;
2395+
return MODE_STORES_HISTORY_MISC;
24032396
}
24042397

24052398
bool

‎src/main/Config.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ class Config : public std::enable_shared_from_this<Config>
492492
// fees, and scp history in the database
493493
bool MODE_STORES_HISTORY_MISC;
494494

495-
// A config parameter that stores ledger headers in the database
496-
bool MODE_STORES_HISTORY_LEDGERHEADERS;
497-
498495
// A config parameter that controls whether core automatically catches up
499496
// when it has buffered enough input; if false an out-of-sync node will
500497
// remain out-of-sync, buffering ledgers from the network in memory until
@@ -805,8 +802,7 @@ class Config : public std::enable_shared_from_this<Config>
805802

806803
bool modeDoesCatchupWithBucketList() const;
807804
bool isPersistingBucketListDBIndexes() const;
808-
bool modeStoresAllHistory() const;
809-
bool modeStoresAnyHistory() const;
805+
bool modeStoresHistory() const;
810806
void logBasicInfo() const;
811807
bool parallelLedgerClose() const;
812808
void setNoListen();

‎src/main/test/ApplicationUtilsTests.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class SimulationHelper
9191
mTestCfg.FORCE_SCP = false;
9292
mTestCfg.INVARIANT_CHECKS = {};
9393
mTestCfg.MODE_AUTO_STARTS_OVERLAY = false;
94-
mTestCfg.MODE_STORES_HISTORY_LEDGERHEADERS = true;
9594
mTestCfg.USE_CONFIG_FOR_GENESIS = false;
9695
mTestCfg.TESTING_UPGRADE_DATETIME = VirtualClock::from_time_t(0);
9796

0 commit comments

Comments
 (0)
Please sign in to comment.