Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Dec 11, 2024
1 parent 37892ad commit 34bbcb8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 122 deletions.
7 changes: 2 additions & 5 deletions src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,10 @@ class LedgerManager
virtual void startNewLedger() = 0;

// loads the last ledger information from the database with the following
// parameters:
// parameter:
// * restoreBucketlist indicates whether to restore the bucket list fully,
// and restart merges
// * isLedgerStateReady indicates whether the ledger state is ready or is
// still being rebuilt (in which case we can't yet load ledger entries)
virtual void loadLastKnownLedger(bool restoreBucketlist,
bool isLedgerStateReady) = 0;
virtual void loadLastKnownLedger(bool restoreBucketlist) = 0;

// Return true if core is currently rebuilding in-memory state via local
// catchup
Expand Down
24 changes: 5 additions & 19 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ setLedgerTxnHeader(LedgerHeader const& lh, Application& app)
}

void
LedgerManagerImpl::loadLastKnownLedger(bool restoreBucketlist,
bool isLedgerStateReady)
LedgerManagerImpl::loadLastKnownLedger(bool restoreBucketlist)
{
ZoneScoped;

Expand Down Expand Up @@ -397,23 +396,10 @@ LedgerManagerImpl::loadLastKnownLedger(bool restoreBucketlist,
if (protocolVersionStartsFrom(latestLedgerHeader->ledgerVersion,
SOROBAN_PROTOCOL_VERSION))
{
if (isLedgerStateReady)
{
// Step 5. If ledger state is ready and core is in v20, load network
// configs right away
LedgerTxn ltx(mApp.getLedgerTxnRoot());
updateNetworkConfig(ltx);
}
else
{
// In some modes, e.g. in-memory, core's state is rebuilt
// asynchronously via catchup. In this case, we're not able to load
// the network config at this time, and instead must let catchup do
// it when ready.
CLOG_INFO(Ledger,
"Ledger state is being rebuilt, network config will "
"be loaded once the rebuild is done");
}
// Step 5. If ledger state is ready and core is in v20, load network
// configs right away
LedgerTxn ltx(mApp.getLedgerTxnRoot());
updateNetworkConfig(ltx);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/ledger/LedgerManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ class LedgerManagerImpl : public LedgerManager

void startNewLedger(LedgerHeader const& genesisLedger);
void startNewLedger() override;
void loadLastKnownLedger(bool restoreBucketlist,
bool isLedgerStateReady) override;
void loadLastKnownLedger(bool restoreBucketlist) override;
virtual bool rebuildingInMemoryState() override;
virtual void setupInMemoryStateRebuild() override;

Expand Down
6 changes: 2 additions & 4 deletions src/main/ApplicationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,7 @@ ApplicationImpl::getJsonInfo(bool verbose)
void
ApplicationImpl::reportInfo(bool verbose)
{
mLedgerManager->loadLastKnownLedger(/* restoreBucketlist */ false,
/* isLedgerStateReady */ true);
mLedgerManager->loadLastKnownLedger(/* restoreBucketlist */ false);
LOG_INFO(DEFAULT_LOG, "Reporting application info");
std::cout << getJsonInfo(verbose).toStyledString() << std::endl;
}
Expand Down Expand Up @@ -918,8 +917,7 @@ ApplicationImpl::start()
CLOG_INFO(Ledger, "Starting up application");
mStarted = true;

mLedgerManager->loadLastKnownLedger(/* restoreBucketlist */ true,
/* isLedgerStateReady */ true);
mLedgerManager->loadLastKnownLedger(/* restoreBucketlist */ true);
startServices();
}

Expand Down
23 changes: 5 additions & 18 deletions src/main/ApplicationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,7 @@ setupApp(Config& cfg, VirtualClock& clock)
return nullptr;
}

// With in-memory testing mode, ledger state is not yet ready during this
// setup step
app->getLedgerManager().loadLastKnownLedger(
/* restoreBucketlist */ false,
#ifdef BUILD_TESTS
/* isLedgerStateReady */ !cfg.MODE_USES_IN_MEMORY_LEDGER
#else
/* isLedgerStateReady */ true
#endif
);
app->getLedgerManager().loadLastKnownLedger(/* restoreBucketlist */ false);
auto lcl = app->getLedgerManager().getLastClosedLedgerHeader();

if (
Expand Down Expand Up @@ -328,8 +319,7 @@ selfCheck(Config cfg)

// We run self-checks from a "loaded but dormant" state where the
// application is not started, but the LM has loaded the LCL.
app->getLedgerManager().loadLastKnownLedger(/* restoreBucketlist */ false,
/* isLedgerStateReady */ true);
app->getLedgerManager().loadLastKnownLedger(/* restoreBucketlist */ false);

// First we schedule the cheap, asynchronous "online" checks that get run by
// the HTTP "self-check" endpoint, and crank until they're done.
Expand Down Expand Up @@ -410,8 +400,7 @@ mergeBucketList(Config cfg, std::string const& outputDir)
auto& lm = app->getLedgerManager();
auto& bm = app->getBucketManager();

lm.loadLastKnownLedger(/* restoreBucketlist */ false,
/* isLedgerStateReady */ true);
lm.loadLastKnownLedger(/* restoreBucketlist */ false);
HistoryArchiveState has = lm.getLastClosedLedgerHAS();
auto bucket = bm.mergeBuckets(has);

Expand Down Expand Up @@ -514,8 +503,7 @@ dumpStateArchivalStatistics(Config cfg)
VirtualClock clock;
cfg.setNoListen();
Application::pointer app = Application::create(clock, cfg, false);
app->getLedgerManager().loadLastKnownLedger(/* restoreBucketlist */ false,
/* isLedgerStateReady */ true);
app->getLedgerManager().loadLastKnownLedger(/* restoreBucketlist */ false);
auto& lm = app->getLedgerManager();
auto& bm = app->getBucketManager();
HistoryArchiveState has = lm.getLastClosedLedgerHAS();
Expand Down Expand Up @@ -628,8 +616,7 @@ dumpLedger(Config cfg, std::string const& outputFile,
Application::pointer app = Application::create(clock, cfg, false);
auto& lm = app->getLedgerManager();

lm.loadLastKnownLedger(/* restoreBucketlist */ false,
/* isLedgerStateReady */ true);
lm.loadLastKnownLedger(/* restoreBucketlist */ false);
HistoryArchiveState has = lm.getLastClosedLedgerHAS();
std::optional<uint32_t> minLedger;
if (lastModifiedLedgerCount)
Expand Down
62 changes: 0 additions & 62 deletions src/main/test/ApplicationUtilsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "bucket/test/BucketTestUtils.h"
#include "crypto/Random.h"
#include "history/HistoryArchiveManager.h"
#include "history/HistoryManagerImpl.h"
#include "history/test/HistoryTestsUtils.h"
#include "invariant/BucketListIsConsistentWithDatabase.h"
#include "ledger/LedgerTxn.h"
#include "ledger/test/LedgerTestUtils.h"
#include "lib/catch.hpp"
#include "main/Application.h"
#include "main/ApplicationUtils.h"
#include "main/CommandHandler.h"
#include "main/Config.h"
#include "overlay/OverlayManager.h"
#include "simulation/Simulation.h"
#include "test/TestUtils.h"
#include "test/TxTests.h"
#include "test/test.h"
#include "transactions/TransactionUtils.h"
#include "util/Logging.h"
#include <filesystem>
#include <fstream>

Expand Down Expand Up @@ -54,54 +48,6 @@ class TemporaryFileDamager
}
};

// Logic to check the state of the bucket list with the state of the DB
static bool
checkState(Application& app)
{
BucketListIsConsistentWithDatabase blc(app);
bool blcOk = true;
try
{
blc.checkEntireBucketlist();
}
catch (std::runtime_error& e)
{
LOG_ERROR(DEFAULT_LOG, "Error during bucket-list consistency check: {}",
e.what());
blcOk = false;
}

if (!app.getConfig().MODE_USES_IN_MEMORY_LEDGER)
{
auto checkBucket = [&blcOk](auto b) {
if (!b->isEmpty() && !b->isIndexed())
{
LOG_ERROR(DEFAULT_LOG,
"Error during bucket-list consistency check: "
"unindexed bucket in BucketList");
blcOk = false;
}
};

auto& bm = app.getBucketManager();
for (uint32_t i = 0; i < bm.getLiveBucketList().kNumLevels && blcOk;
++i)
{
auto& level = bm.getLiveBucketList().getLevel(i);
checkBucket(level.getCurr());
checkBucket(level.getSnap());
auto& nextFuture = level.getNext();
if (nextFuture.hasOutputHash())
{
auto hash = hexToBin256(nextFuture.getOutputHash());
checkBucket(bm.getBucketByHash<LiveBucket>(hash));
}
}
}

return blcOk;
}

// Sets up a network with a main validator node that publishes checkpoints to
// a test node. Tests startup behavior of the test node when up to date with
// validator and out of sync.
Expand Down Expand Up @@ -377,14 +323,6 @@ TEST_CASE("offline self-check works", "[applicationutils][selfcheck]")
}
}

TEST_CASE("application setup", "[applicationutils]")
{
VirtualClock clock;
auto cfg = getTestConfig();
auto app = setupApp(cfg, clock);
REQUIRE(checkState(*app));
}

TEST_CASE("application major version numbers", "[applicationutils]")
{
CHECK(getStellarCoreMajorReleaseVersion("v19.0.0") ==
Expand Down
17 changes: 5 additions & 12 deletions src/simulation/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,16 @@ Simulation::addNode(SecretKey nodeKey, SCPQuorumSet qSet, Config const* cfg2,
}

Application::pointer app;
if (newDB)
if (mMode == OVER_LOOPBACK)
{
if (mMode == OVER_LOOPBACK)
{
app =
createTestApplication<ApplicationLoopbackOverlay, Simulation&>(
*clock, *cfg, *this, newDB, false);
}
else
{
app = createTestApplication(*clock, *cfg, newDB, false);
}
app = createTestApplication<ApplicationLoopbackOverlay, Simulation&>(
*clock, *cfg, *this, newDB, false);
}
else
{
app = setupApp(*cfg, *clock);
app = createTestApplication(*clock, *cfg, newDB, false);
}

mNodes.emplace(nodeKey.getPublicKey(), Node{clock, app});

mPeerMap.emplace(app->getConfig().PEER_PORT,
Expand Down

0 comments on commit 34bbcb8

Please sign in to comment.