Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

#include "LedgerManagerImpl.h"
#include <chrono>
#include <future>
#include <memory>
#include <optional>
#include <regex>
Expand Down Expand Up @@ -317,7 +318,8 @@ LedgerManagerImpl::ApplyState::updateInMemorySorobanState(
std::vector<LedgerKey> const& deadEntries, LedgerHeader const& lh,
std::optional<SorobanNetworkConfig const> const& sorobanConfig)
{
assertWritablePhase();
releaseAssert(mPhase == Phase::SETTING_UP_STATE ||
mPhase == Phase::COMMITTING);
mInMemorySorobanState.updateState(initEntries, liveEntries, deadEntries, lh,
sorobanConfig,
getMetrics().mSorobanMetrics);
Expand Down Expand Up @@ -2971,6 +2973,11 @@ LedgerManagerImpl::finalizeLedgerTxnChanges(
// `ledgerApplied` protects this call with a mutex
std::vector<LedgerEntry> initEntries, liveEntries;
std::vector<LedgerKey> deadEntries;

EvictedStateVectors evictedState;
std::vector<LedgerKey> restoredHotArchiveKeys;
std::future<void> hotArchiveBatchFuture;

// Any V20 features must be behind initialLedgerVers check, see comment
// in LedgerManagerImpl::ledgerApplied
if (protocolVersionStartsFrom(initialLedgerVers, SOROBAN_PROTOCOL_VERSION))
Expand All @@ -2980,16 +2987,13 @@ LedgerManagerImpl::finalizeLedgerTxnChanges(
// `getAllTTLKeysWithoutSealing` must be called at the right time
// _after_ all operations have been applied, but _before_ evictions.
auto sorobanConfig = SorobanNetworkConfig::loadFromLedger(ltx);
auto evictedState =
mApp.getBucketManager().resolveBackgroundEvictionScan(
lclApplyView, ltx, ltx.getAllKeysWithoutSealing());
evictedState = mApp.getBucketManager().resolveBackgroundEvictionScan(
lclApplyView, ltx, ltx.getAllKeysWithoutSealing());

if (protocolVersionStartsFrom(
initialLedgerVers,
LiveBucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION))
{
std::vector<LedgerKey> restoredHotArchiveKeys;

auto const& restoredHotArchiveKeyMap =
ltx.getRestoredHotArchiveKeys();
for (auto const& [key, entry] : restoredHotArchiveKeyMap)
Expand Down Expand Up @@ -3019,9 +3023,14 @@ LedgerManagerImpl::finalizeLedgerTxnChanges(
}
else
{
mApp.getBucketManager().addHotArchiveBatch(
mApp, lh, evictedState.archivedEntries,
restoredHotArchiveKeys);
hotArchiveBatchFuture =
std::async(std::launch::async, [this, lh, &evictedState,
&restoredHotArchiveKeys]() {
mApp.getBucketManager().addHotArchiveBatch(
mApp, lh, evictedState.archivedEntries,
restoredHotArchiveKeys);
});
Comment thread
dmkozh marked this conversation as resolved.

// Validate evicted entries against Protocol 23 corruption
// data if configured
if (mApp.getProtocol23CorruptionDataVerifier())
Expand Down Expand Up @@ -3061,12 +3070,27 @@ LedgerManagerImpl::finalizeLedgerTxnChanges(
}
// NB: getAllEntries seals the ltx.
ltx.getAllEntries(initEntries, liveEntries, deadEntries);

// Launch async task to update in-memory Soroban state. This is independent
// from both addHotArchiveBatch and addLiveBatch, so all can run in
// parallel.
auto inMemoryStateUpdateFuture = std::async(
std::launch::async, [this, &initEntries, &liveEntries, &deadEntries, lh,
&finalSorobanConfig]() {
mApplyState.updateInMemorySorobanState(
initEntries, liveEntries, deadEntries, lh, finalSorobanConfig);
});

mApplyState.addAnyContractsToModuleCache(lh.ledgerVersion, initEntries);
mApplyState.addAnyContractsToModuleCache(lh.ledgerVersion, liveEntries);
mApp.getBucketManager().addLiveBatch(mApp, lh, initEntries, liveEntries,
deadEntries);
Comment thread
dmkozh marked this conversation as resolved.
mApplyState.updateInMemorySorobanState(initEntries, liveEntries,
deadEntries, lh, finalSorobanConfig);
// Wait for all async operations to complete before returning.
if (hotArchiveBatchFuture.valid())
{
hotArchiveBatchFuture.get();
}
inMemoryStateUpdateFuture.get();
return finalSorobanConfig;
}

Expand Down
Loading