Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/bucket/BucketListSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ class SearchableLiveBucketListSnapshot
LedgerEntryType type,
std::function<Loop(BucketEntry const&)> callback) const;

friend class BucketSnapshotState;
friend class CompleteConstLedgerState;
friend class LedgerStateSnapshot;
};
Expand Down
10 changes: 5 additions & 5 deletions src/bucket/BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ BucketManager::startBackgroundEvictionScan(ApplyLedgerStateSnapshot lclSnapshot,

// Start the eviction scan for then _next_ ledger
auto ledgerSeq = lclSnapshot.getLedgerSeq() + 1;
auto ledgerVers = lclSnapshot.getLedgerHeader().ledgerVersion;
auto ledgerVers = lclSnapshot.getLedgerHeader().current().ledgerVersion;

auto const& sas = cfg.stateArchivalSettings();

Expand Down Expand Up @@ -1185,10 +1185,10 @@ BucketManager::resolveBackgroundEvictionScan(
ZoneScoped;
releaseAssert(mEvictionStatistics);
auto timer = mBucketListEvictionMetrics.blockingTime.TimeScope();
auto ls = LedgerSnapshot(ltx);
auto ledgerSeq = ls.getLedgerHeader().current().ledgerSeq;
auto ledgerVers = ls.getLedgerHeader().current().ledgerVersion;
auto networkConfig = SorobanNetworkConfig::loadFromLedger(ls);
LedgerTxnReadOnly ltxSnap(ltx);
auto ledgerSeq = ltxSnap.getLedgerHeader().current().ledgerSeq;
auto ledgerVers = ltxSnap.getLedgerHeader().current().ledgerVersion;
auto networkConfig = SorobanNetworkConfig::loadFromLedger(ltxSnap);
releaseAssert(ledgerSeq == lclSnapshot.getLedgerSeq() + 1);

if (!mEvictionFuture.valid())
Expand Down
6 changes: 3 additions & 3 deletions src/bucket/test/BucketListTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,15 +1112,15 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist][archival][soroban]")
LedgerKey stateArchivalKey(CONFIG_SETTING);
stateArchivalKey.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_STATE_ARCHIVAL;
LedgerSnapshot ls(*app);
auto stateArchivalEntry = ls.load(stateArchivalKey).current();
LedgerReadView lrv(*app);
auto stateArchivalEntry = lrv.load(stateArchivalKey).current();
modifyStateArchivalFn(stateArchivalEntry.data.configSetting()
.stateArchivalSettings());

LedgerKey evictionIterKey(CONFIG_SETTING);
evictionIterKey.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_EVICTION_ITERATOR;
auto evictionIterEntry = ls.load(evictionIterKey).current();
auto evictionIterEntry = lrv.load(evictionIterKey).current();
modifyEvictionIteratorFn(
evictionIterEntry.data.configSetting().evictionIterator());

Expand Down
18 changes: 12 additions & 6 deletions src/bucket/test/BucketTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,18 @@ LedgerManagerForBucketTests::finalizeLedgerTxnChanges(
if (protocolVersionStartsFrom(lh.ledgerVersion,
SOROBAN_PROTOCOL_VERSION))
{
auto liveData =
std::make_shared<BucketListSnapshotData<LiveBucket>>(
mApp.getBucketManager().getLiveBucketList());
LedgerSnapshot ls(mApp.getMetrics(), std::move(liveData), lh);
finalSorobanConfig =
std::make_optional(SorobanNetworkConfig::loadFromLedger(ls));
// Tests may inject config upgrades directly into the BucketList, so
// we need to construct a temp dummy snapshot to load the injected
// config.
LedgerHeaderHistoryEntry tempLcl;
tempLcl.header = lh;
HistoryArchiveState tempHas;
tempHas.currentLedger = lh.ledgerSeq;
auto& bm = mApp.getBucketManager();
auto tempState = CompleteConstLedgerState::createAndMaybeLoadConfig(
bm.getLiveBucketList(), bm.getHotArchiveBucketList(), tempLcl,
tempHas, mApp.getMetrics(), nullptr, 0);
finalSorobanConfig = tempState->getSorobanConfig();
}

mApplyState.updateInMemorySorobanState(
Expand Down
8 changes: 4 additions & 4 deletions src/herder/HerderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,8 +1587,8 @@ HerderImpl::triggerNextLedger(uint32_t ledgerSeqToTrigger,
// see if we need to include some upgrades
std::vector<LedgerUpgrade> upgrades;
{
LedgerSnapshot ls(mApp);
upgrades = mUpgrades.createUpgradesFor(lcl.header, ls);
LedgerReadView lrv(mApp);
upgrades = mUpgrades.createUpgradesFor(lcl.header, lrv);
}
for (auto const& upgrade : upgrades)
{
Expand Down Expand Up @@ -1655,8 +1655,8 @@ HerderImpl::setUpgrades(Upgrades::UpgradeParameters const& upgrades)
std::string
HerderImpl::getUpgradesJson()
{
auto ls = LedgerSnapshot(mApp);
return mUpgrades.getParameters().toDebugJson(ls);
auto lrv = LedgerReadView(mApp);
return mUpgrades.getParameters().toDebugJson(lrv);
}

void
Expand Down
20 changes: 11 additions & 9 deletions src/herder/TransactionQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ TransactionQueue::canAdd(
}
}

LedgerSnapshot ls(mApp);
LedgerReadView lrv(mApp);
// Subtle: transactions are rejected based on the source account limit
// prior to this point. This is safe because we can't evict transactions
// from the same source account, so a newer transaction won't replace an
Expand All @@ -464,11 +464,12 @@ TransactionQueue::canAdd(
auto closeTime = mApp.getLedgerManager()
.getLastClosedLedgerHeader()
.header.scpValue.closeTime;
// Validate minSeqLedgerGap and LedgerBounds against the next ledgerSeq,
// which is what will be used at apply time.
std::optional<uint32_t> validationLedgerSeq;
if (protocolVersionStartsFrom(ledgerVersion, ProtocolVersion::V_19))
{
// This is done so minSeqLedgerGap is validated against the next
// ledgerSeq, which is what will be used at apply time
ls.getLedgerHeader().currentToModify().ledgerSeq =
validationLedgerSeq =
mApp.getLedgerManager().getLastClosedLedgerNum() + 1;
}

Expand All @@ -478,9 +479,10 @@ TransactionQueue::canAdd(
if (!isLoadgenTx)
#endif
{
auto validationResult = tx->checkValid(
mApp.getAppConnector(), ls, 0, 0,
getUpperBoundCloseTimeOffset(mApp, closeTime), diagnosticEvents);
auto validationResult =
tx->checkValid(mApp.getAppConnector(), lrv, 0, 0,
getUpperBoundCloseTimeOffset(mApp, closeTime),
diagnosticEvents, validationLedgerSeq);
if (!validationResult->isSuccess())
{
return AddResult(TransactionQueue::AddResultCode::ADD_STATUS_ERROR,
Expand All @@ -497,12 +499,12 @@ TransactionQueue::canAdd(
if (!isLoadgenTx && !mApp.getRunInOverlayOnlyMode())
#endif
{
auto const feeSource = ls.getAccount(tx->getFeeSourceID());
auto const feeSource = lrv.getAccount(tx->getFeeSourceID());
auto feeStateIter = mAccountStates.find(tx->getFeeSourceID());
int64_t totalFees = feeStateIter == mAccountStates.end()
? 0
: feeStateIter->second.mTotalFees;
if (getAvailableBalance(ls.getLedgerHeader().current(),
if (getAvailableBalance(lrv.getLedgerHeader().current(),
feeSource.current()) -
newFullFee <
totalFees)
Expand Down
25 changes: 15 additions & 10 deletions src/herder/TxSetUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ TxSetUtils::getInvalidTxListWithErrors(
{
ZoneScoped;
releaseAssert(threadIsMain());
LedgerSnapshot ls(app);
// This is done so minSeqLedgerGap is validated against the next
// ledgerSeq, which is what will be used at apply time
ls.getLedgerHeader().currentToModify().ledgerSeq =
app.getLedgerManager().getLastClosedLedgerNum() + 1;
LedgerReadView lrv(app);
// Validate minSeqLedgerGap and LedgerBounds against the next ledgerSeq,
// which is what will be used at apply time.
std::optional<uint32_t> validationLedgerSeq;
if (protocolVersionStartsFrom(lrv.getLedgerHeader().current().ledgerVersion,
ProtocolVersion::V_19))
{
validationLedgerSeq =
app.getLedgerManager().getLastClosedLedgerNum() + 1;
}

TxFrameListWithErrors invalidTxsWithError;
auto& invalidTxs = invalidTxsWithError.first;
Expand All @@ -186,9 +191,9 @@ TxSetUtils::getInvalidTxListWithErrors(
auto diagnostics = DiagnosticEventManager::createDisabled();
for (auto const& tx : txs)
{
auto txResult = tx->checkValid(app.getAppConnector(), ls, 0,
lowerBoundCloseTimeOffset,
upperBoundCloseTimeOffset, diagnostics);
auto txResult = tx->checkValid(
app.getAppConnector(), lrv, 0, lowerBoundCloseTimeOffset,
upperBoundCloseTimeOffset, diagnostics, validationLedgerSeq);
if (!txResult->isSuccess())
{
invalidTxs.emplace_back(tx);
Expand All @@ -209,7 +214,7 @@ TxSetUtils::getInvalidTxListWithErrors(
}
}

auto header = ls.getLedgerHeader().current();
auto header = lrv.getLedgerHeader().current();
for (auto const& tx : txs)
{
// Already added invalid tx
Expand All @@ -219,7 +224,7 @@ TxSetUtils::getInvalidTxListWithErrors(
}

auto feeSourceID = tx->getFeeSourceID();
auto feeSource = ls.getAccount(feeSourceID);
auto feeSource = lrv.getAccount(feeSourceID);
// feeSource should exist since we've already run checkValid, log
// internal bug
if (!feeSource)
Expand Down
Loading
Loading