Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-existent entries should not be metered #4428

Merged
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
18 changes: 0 additions & 18 deletions src/bucket/BucketSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,6 @@ BucketSnapshot::loadKeysWithLimits(std::set<LedgerKey, LedgerEntryIdCmp>& keys,
auto indexIter = index.begin();
while (currKeyIt != keys.end() && indexIter != index.end())
{
if (lkMeter)
{
auto keySize = xdr::xdr_size(*currKeyIt);
if (!lkMeter->canLoad(*currKeyIt, keySize))
{
// If the transactions containing this key have a remaining
// quota less than the size of the key, we cannot load the
// entry, as xdr_size(key) <= xdr_size(entry). Here we consume
// keySize bytes from the quotas of transactions containing the
// key so that they will have zero remaining quota and
// additional entries belonging to only those same transactions
// will not be loaded even if they would fit in the remaining
// quota before this update.
lkMeter->updateReadQuotasForKey(*currKeyIt, keySize);
currKeyIt = keys.erase(currKeyIt);
continue;
}
}
auto [offOp, newIndexIter] = index.scan(indexIter, *currKeyIt);
indexIter = newIndexIter;
if (offOp)
Expand Down
13 changes: 13 additions & 0 deletions src/ledger/test/LedgerTxnTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2975,6 +2975,19 @@ TEST_CASE("LedgerTxnRoot prefetch soroban entries", "[ledgertxn]")
expectedSuccessKeys.emplace(LedgerEntryKey(classicEntry));
checkPrefetch(expectedSuccessKeys);
}
SECTION("non existent entries should not affect quota")
{
// Prefetch an entry which has not been added to the database.
auto nonExistentEntry =
LedgerTestUtils::generateValidLedgerEntryOfType(CONTRACT_DATA);
// Both should succeed, as the non-existent entry is not metered and
// should result in a null entry in the cache.
addTxn(false /* not enough */, {contractDataEntry, nonExistentEntry});
std::set<LedgerKey> expectedSuccessKeys{
LedgerEntryKey(contractDataEntry),
LedgerEntryKey(nonExistentEntry)};
checkPrefetch(expectedSuccessKeys);
}
}

TEST_CASE("LedgerKeyMeter tests")
Expand Down
Loading