Skip to content

Commit

Permalink
Merge pull request #4162 from marta-lokhova/networkConfigLod
Browse files Browse the repository at this point in the history
Fix startup race condition

Reviewed-by: dmkozh
  • Loading branch information
latobarita authored Jan 26, 2024
2 parents 3076c13 + 574241b commit 368063a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class LedgerManager
// Ledger txn here is needed for the sake of lazy load; it won't be
// used most of the time.
virtual SorobanNetworkConfig const& getSorobanNetworkConfig() = 0;
virtual bool hasSorobanNetworkConfig() const = 0;

#ifdef BUILD_TESTS
virtual SorobanNetworkConfig& getMutableSorobanNetworkConfig() = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ LedgerManagerImpl::getSorobanNetworkConfig()
return getSorobanNetworkConfigInternal();
}

bool
LedgerManagerImpl::hasSorobanNetworkConfig() const
{
return mSorobanNetworkConfig.has_value();
}

#ifdef BUILD_TESTS
SorobanNetworkConfig&
LedgerManagerImpl::getMutableSorobanNetworkConfig()
Expand Down
1 change: 1 addition & 0 deletions src/ledger/LedgerManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class LedgerManagerImpl : public LedgerManager
uint32_t getLastTxFee() const override;
uint32_t getLastClosedLedgerNum() const override;
SorobanNetworkConfig const& getSorobanNetworkConfig() override;
bool hasSorobanNetworkConfig() const override;

#ifdef BUILD_TESTS
SorobanNetworkConfig& getMutableSorobanNetworkConfig() override;
Expand Down
19 changes: 10 additions & 9 deletions src/main/ApplicationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ ApplicationImpl::getJsonInfo(bool verbose)
info["ledger"]["baseFee"] = lcl.header.baseFee;
info["ledger"]["baseReserve"] = lcl.header.baseReserve;
info["ledger"]["maxTxSetSize"] = lcl.header.maxTxSetSize;
if (protocolVersionStartsFrom(lcl.header.ledgerVersion,
SOROBAN_PROTOCOL_VERSION))
if (lm.hasSorobanNetworkConfig())
{
info["ledger"]["maxSorobanTxSetSize"] =
static_cast<Json::Int64>(lm.maxLedgerResources(/* isSoroban */ true)
Expand Down Expand Up @@ -551,13 +550,15 @@ ApplicationImpl::getJsonInfo(bool verbose)
void
ApplicationImpl::reportInfo(bool verbose)
{
mLedgerManager->loadLastKnownLedger(nullptr);
LedgerTxn ltx(getLedgerTxnRoot());
if (protocolVersionStartsFrom(ltx.loadHeader().current().ledgerVersion,
SOROBAN_PROTOCOL_VERSION))
{
getLedgerManager().updateNetworkConfig(ltx);
}
auto loadConfig = [this]() {
LedgerTxn ltx(getLedgerTxnRoot());
if (protocolVersionStartsFrom(ltx.loadHeader().current().ledgerVersion,
SOROBAN_PROTOCOL_VERSION))
{
getLedgerManager().updateNetworkConfig(ltx);
}
};
mLedgerManager->loadLastKnownLedger(loadConfig);
LOG_INFO(DEFAULT_LOG, "Reporting application info");
std::cout << getJsonInfo(verbose).toStyledString() << std::endl;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,7 @@ CommandHandler::sorobanInfo(std::string const& params, std::string& retStr)
ZoneScoped;
auto& lm = mApp.getLedgerManager();

if (protocolVersionStartsFrom(
lm.getLastClosedLedgerHeader().header.ledgerVersion,
SOROBAN_PROTOCOL_VERSION))
if (lm.hasSorobanNetworkConfig())
{
std::map<std::string, std::string> retMap;
http::server::server::parseParams(params, retMap);
Expand Down
11 changes: 1 addition & 10 deletions src/main/test/ApplicationUtilsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,16 +630,7 @@ TEST_CASE("application setup", "[applicationutils]")
Config cfg2 = getTestConfig(2);
cfg2.setInMemoryMode();
cfg2.DATABASE = SecretValue{minimalDBForInMemoryMode(cfg2)};

SECTION("BucketListDB")
{
cfg2.EXPERIMENTAL_BUCKETLIST_DB = true;
testInMemoryMode(cfg1, cfg2);
}
SECTION("SQL DB")
{
testInMemoryMode(cfg1, cfg2);
}
testInMemoryMode(cfg1, cfg2);
}
}

Expand Down

0 comments on commit 368063a

Please sign in to comment.