-
Notifications
You must be signed in to change notification settings - Fork 989
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
4034 implement sql invariants in bucketdb #4189
4034 implement sql invariants in bucketdb #4189
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few small things but LGTM, thanks!
src/ledger/LedgerTxn.cpp
Outdated
case OFFER: | ||
// Ensure offer is not XLM -- possibly? | ||
// special case for offer loading from allow trust op frame? | ||
// See LedgerTxnOfferSQL.cpp::loadOffersByAccountAndAsset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadOffersByAccountAndAsset
is actually only ever performed on SQL. Even if BucketListDB
is enabled, we still keep the offers table around for this very query. It's very expensive to run on a DB without relational tables. You should be fine omitting the check here, but it might be good to include a comment as to why we don't need that specific invariant for BucketListDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that makes sense, thanks!
src/ledger/LedgerTxn.cpp
Outdated
void | ||
enforcePreLoadInvariants(LedgerKey const& key, uint32_t ledgerVersion) | ||
{ | ||
switch (key.type()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since TRUSTLINE
is the only type here that needs this check, probably cleaner to use and if statement instead of switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I wrote the switch before I realized how little invariants we are actually enforcing 😅
src/ledger/LedgerTxn.cpp
Outdated
@@ -2986,9 +3068,17 @@ LedgerTxnRoot::Impl::prefetch(UnorderedSet<LedgerKey> const& keys) | |||
{ | |||
insertIfNotLoaded(keysToSearch, key); | |||
} | |||
|
|||
for (auto key : keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto const&
src/ledger/LedgerTxn.cpp
Outdated
auto blLoad = mApp.getBucketManager().loadKeys(keysToSearch); | ||
cacheResult(populateLoadedEntries(keysToSearch, blLoad)); | ||
auto loadedEntries = populateLoadedEntries(keysToSearch, blLoad); | ||
for (auto entry : loadedEntries) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto const&
src/ledger/LedgerTxn.cpp
Outdated
return; | ||
} | ||
releaseAssert(key.type() == entry->data.type()); | ||
switch (key.type()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If statement instead of switch.
814895b
to
5b66603
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one small issue. I don't have merge authority, so might want to add @sisuresh as a reviewer as well since he opened the original issue.
src/ledger/LedgerTxn.cpp
Outdated
@@ -2986,9 +3023,17 @@ LedgerTxnRoot::Impl::prefetch(UnorderedSet<LedgerKey> const& keys) | |||
{ | |||
insertIfNotLoaded(keysToSearch, key); | |||
} | |||
|
|||
for (auto const& key : keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this in insertIfNotLoaded
loaded loop, no need to loop twice.
src/ledger/LedgerTxn.cpp
Outdated
// See LedgerTxnOfferSQL.cpp::loadOffersByAccountAndAsset. | ||
} | ||
void | ||
enforcePostLoadInvariants(LedgerKey const& key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Rename to something like enforceBucketListPostLoadInvariants
so it's clear we only use this for BucketListDB loads and not SQL, same goes for the other function as well.
5b66603
to
87a8026
Compare
…stVersion for both BucketsDB and SQL path.
87a8026
to
7180ed7
Compare
r+ 7180ed7 |
Description
Adds functions to LedgerTxn.cpp to enforce pre and post load invariants on key loads, lifted from the various LedgerTxn*SQL.cpp implementations.
Resolves #4034
Checklist
clang-format
v8.0.0 (viamake format
or the Visual Studio extension)