Skip to content

Commit

Permalink
Merge pull request #4213 from sisuresh/revert
Browse files Browse the repository at this point in the history
Revert "Enforce pre and post load invariants for LedgerTxnRoot::Impl:getNewestVersion for both BucketsDB and SQL path."

Reviewed-by: anupsdf
  • Loading branch information
latobarita committed Feb 24, 2024
2 parents d8cbaff + 9c6ec14 commit 0f0c4d6
Showing 1 changed file with 2 additions and 48 deletions.
50 changes: 2 additions & 48 deletions src/ledger/LedgerTxn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,7 @@

namespace stellar
{
namespace
{
void
enforceBucketListPreLoadInvariants(LedgerKey const& key, uint32_t ledgerVersion)
{
if (key.type() == TRUSTLINE)
{
validateTrustLineKey(ledgerVersion, key);
}
// Note: There are additional invariants that are enforced when
// loading offers by account and asset. This type of query is only
// performed on the SQL backend, so we do not enforce those invariants here.
// See LedgerTxnOfferSQL.cpp::loadOffersByAccountAndAsset.
}
void
enforceBucketListPostLoadInvariants(
LedgerKey const& key, std::shared_ptr<LedgerEntry const> const& entry)
{
if (!entry)
{
return;
}
releaseAssert(key.type() == entry->data.type());
if (key.type() == ACCOUNT)
{
// LedgerTxnRoot::loadAccount SQL enforces
// invariants post-load.
// It decodes the result of the query and ensures
// the account signers are sorted in ascending order.
releaseAssert(
std::adjacent_find(entry->data.account().signers.begin(),
entry->data.account().signers.end(),
[](Signer const& lhs, Signer const& rhs) {
return !(lhs.key < rhs.key);
}) == entry->data.account().signers.end());
}
};
}

LedgerEntryPtr
LedgerEntryPtr::Init(std::shared_ptr<InternalLedgerEntry> const& lePtr)
{
Expand Down Expand Up @@ -3022,16 +2985,10 @@ LedgerTxnRoot::Impl::prefetch(UnorderedSet<LedgerKey> const& keys)
for (auto const& key : keys)
{
insertIfNotLoaded(keysToSearch, key);
enforceBucketListPreLoadInvariants(key, mHeader->ledgerVersion);
}

auto blLoad = mApp.getBucketManager().loadKeys(keysToSearch);
auto loadedEntries = populateLoadedEntries(keysToSearch, blLoad);
for (auto const& entry : loadedEntries)
{
enforceBucketListPostLoadInvariants(entry.first, entry.second);
}
cacheResult(loadedEntries);
cacheResult(populateLoadedEntries(keysToSearch, blLoad));
}
else
{
Expand Down Expand Up @@ -3663,14 +3620,11 @@ LedgerTxnRoot::Impl::getNewestVersion(InternalLedgerKey const& gkey) const
}

std::shared_ptr<LedgerEntry const> entry;

try
{
if (mApp.getConfig().isUsingBucketListDB() && key.type() != OFFER)
{
enforceBucketListPreLoadInvariants(key, mHeader->ledgerVersion);
entry = mApp.getBucketManager().getLedgerEntry(key);
enforceBucketListPostLoadInvariants(key, entry);
}
else
{
Expand Down

0 comments on commit 0f0c4d6

Please sign in to comment.