Skip to content

Commit 368063a

Browse files
authored
Merge pull request #4162 from marta-lokhova/networkConfigLod
Fix startup race condition Reviewed-by: dmkozh
2 parents 3076c13 + 574241b commit 368063a

6 files changed

+20
-22
lines changed

Diff for: src/ledger/LedgerManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class LedgerManager
128128
// Ledger txn here is needed for the sake of lazy load; it won't be
129129
// used most of the time.
130130
virtual SorobanNetworkConfig const& getSorobanNetworkConfig() = 0;
131+
virtual bool hasSorobanNetworkConfig() const = 0;
131132

132133
#ifdef BUILD_TESTS
133134
virtual SorobanNetworkConfig& getMutableSorobanNetworkConfig() = 0;

Diff for: src/ledger/LedgerManagerImpl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@ LedgerManagerImpl::getSorobanNetworkConfig()
540540
return getSorobanNetworkConfigInternal();
541541
}
542542

543+
bool
544+
LedgerManagerImpl::hasSorobanNetworkConfig() const
545+
{
546+
return mSorobanNetworkConfig.has_value();
547+
}
548+
543549
#ifdef BUILD_TESTS
544550
SorobanNetworkConfig&
545551
LedgerManagerImpl::getMutableSorobanNetworkConfig()

Diff for: src/ledger/LedgerManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class LedgerManagerImpl : public LedgerManager
146146
uint32_t getLastTxFee() const override;
147147
uint32_t getLastClosedLedgerNum() const override;
148148
SorobanNetworkConfig const& getSorobanNetworkConfig() override;
149+
bool hasSorobanNetworkConfig() const override;
149150

150151
#ifdef BUILD_TESTS
151152
SorobanNetworkConfig& getMutableSorobanNetworkConfig() override;

Diff for: src/main/ApplicationImpl.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ ApplicationImpl::getJsonInfo(bool verbose)
471471
info["ledger"]["baseFee"] = lcl.header.baseFee;
472472
info["ledger"]["baseReserve"] = lcl.header.baseReserve;
473473
info["ledger"]["maxTxSetSize"] = lcl.header.maxTxSetSize;
474-
if (protocolVersionStartsFrom(lcl.header.ledgerVersion,
475-
SOROBAN_PROTOCOL_VERSION))
474+
if (lm.hasSorobanNetworkConfig())
476475
{
477476
info["ledger"]["maxSorobanTxSetSize"] =
478477
static_cast<Json::Int64>(lm.maxLedgerResources(/* isSoroban */ true)
@@ -551,13 +550,15 @@ ApplicationImpl::getJsonInfo(bool verbose)
551550
void
552551
ApplicationImpl::reportInfo(bool verbose)
553552
{
554-
mLedgerManager->loadLastKnownLedger(nullptr);
555-
LedgerTxn ltx(getLedgerTxnRoot());
556-
if (protocolVersionStartsFrom(ltx.loadHeader().current().ledgerVersion,
557-
SOROBAN_PROTOCOL_VERSION))
558-
{
559-
getLedgerManager().updateNetworkConfig(ltx);
560-
}
553+
auto loadConfig = [this]() {
554+
LedgerTxn ltx(getLedgerTxnRoot());
555+
if (protocolVersionStartsFrom(ltx.loadHeader().current().ledgerVersion,
556+
SOROBAN_PROTOCOL_VERSION))
557+
{
558+
getLedgerManager().updateNetworkConfig(ltx);
559+
}
560+
};
561+
mLedgerManager->loadLastKnownLedger(loadConfig);
561562
LOG_INFO(DEFAULT_LOG, "Reporting application info");
562563
std::cout << getJsonInfo(verbose).toStyledString() << std::endl;
563564
}

Diff for: src/main/CommandHandler.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,7 @@ CommandHandler::sorobanInfo(std::string const& params, std::string& retStr)
740740
ZoneScoped;
741741
auto& lm = mApp.getLedgerManager();
742742

743-
if (protocolVersionStartsFrom(
744-
lm.getLastClosedLedgerHeader().header.ledgerVersion,
745-
SOROBAN_PROTOCOL_VERSION))
743+
if (lm.hasSorobanNetworkConfig())
746744
{
747745
std::map<std::string, std::string> retMap;
748746
http::server::server::parseParams(params, retMap);

Diff for: src/main/test/ApplicationUtilsTests.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -630,16 +630,7 @@ TEST_CASE("application setup", "[applicationutils]")
630630
Config cfg2 = getTestConfig(2);
631631
cfg2.setInMemoryMode();
632632
cfg2.DATABASE = SecretValue{minimalDBForInMemoryMode(cfg2)};
633-
634-
SECTION("BucketListDB")
635-
{
636-
cfg2.EXPERIMENTAL_BUCKETLIST_DB = true;
637-
testInMemoryMode(cfg1, cfg2);
638-
}
639-
SECTION("SQL DB")
640-
{
641-
testInMemoryMode(cfg1, cfg2);
642-
}
633+
testInMemoryMode(cfg1, cfg2);
643634
}
644635
}
645636

0 commit comments

Comments
 (0)