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

Switch read-only LedgerTxn to BucketList snapshots #4431

Merged
merged 9 commits into from
Sep 11, 2024

Conversation

marta-lokhova
Copy link
Contributor

@marta-lokhova marta-lokhova commented Aug 15, 2024

Resolves #4315 and #3800 This PR automatically switches overlay/herder to using BucketListDB snapshots instead of LedgerTxn.

This change introduces a single "read-only ledger state snapshot" interface, which supports both SQL (via LedgerTxn) and BucketListDB snapshots. A unified interface avoids invasive changes to the rest of the codebase to support both snapshot types, and allows to have a centralized validation flow for both overlay and apply time.

A notable change is the removal of nested LegderTxn in validation paths, and using loadWithoutRecord instead in newer protocols. This creates a stronger invariant that validation flow is only meant to be accessing read-only version of the ledger, and prevents it from making modifications by accident. Note that nested LedgerTxn is preserved for older buggy versions of the protocol (making the code a bit uglier than I would have preferred, I'm open to ideas on simplifying/refactoring old protocol logic out of the critical path).

@marta-lokhova marta-lokhova force-pushed the removeReadOnlyLedgerTxn branch 5 times, most recently from ec3d1ce to 8540866 Compare August 19, 2024 21:17
Copy link
Contributor

@sisuresh sisuresh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I'm still reviewing, but here are a couple comments.

src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
Copy link
Contributor

@SirTyson SirTyson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a very helpful change! A few comments about hardening some asserts around BucketList based load access. Other than that, I think moving the snapshot logic into more of the domain of the LedgerManager will help us consolidate the snapshotting logic, as well as prevent potential footguns in the future.

src/bucket/BucketListSnapshot.cpp Show resolved Hide resolved
src/bucket/BucketListSnapshot.h Outdated Show resolved Hide resolved
src/bucket/BucketListSnapshot.h Outdated Show resolved Hide resolved
src/bucket/BucketListSnapshot.h Outdated Show resolved Hide resolved
src/bucket/BucketListSnapshot.h Outdated Show resolved Hide resolved
src/transactions/TransactionFrameBase.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.cpp Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.cpp Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
Copy link
Contributor

@dmkozh dmkozh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RO ltx had caused us a lot of pain, I'm really happy to see this change!

src/ledger/LedgerStateSnapshot.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.cpp Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Show resolved Hide resolved
src/herder/Upgrades.h Outdated Show resolved Hide resolved
src/test/TestAccount.cpp Outdated Show resolved Hide resolved
src/transactions/OperationFrame.cpp Outdated Show resolved Hide resolved
src/transactions/OperationFrame.cpp Outdated Show resolved Hide resolved
@marta-lokhova marta-lokhova force-pushed the removeReadOnlyLedgerTxn branch 4 times, most recently from d1c7816 to 71b5f89 Compare September 6, 2024 21:52
@marta-lokhova
Copy link
Contributor Author

I believe all the comments are addressed now, and parallel catchup on both testnet and pubnet passed. PTAL. I haven't squashed newer commits so it's easier to review, but I can do so once the PR is approved.

SirTyson
SirTyson previously approved these changes Sep 9, 2024
Copy link
Contributor

@SirTyson SirTyson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about the snapshotting in assumeState, but otherwise LGTM

@SirTyson
Copy link
Contributor

SirTyson commented Sep 9, 2024

One question about the snapshotting in assumeState, but otherwise LGTM

Thanks for the change, LGTM!

Copy link
Contributor

@dmkozh dmkozh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. Just a few minor cleanups (mostly const-related).

src/transactions/TransactionFrame.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/ledger/LedgerStateSnapshot.h Outdated Show resolved Hide resolved
src/herder/HerderImpl.cpp Show resolved Hide resolved
@marta-lokhova marta-lokhova force-pushed the removeReadOnlyLedgerTxn branch 7 times, most recently from 4315f1c to f4f04b0 Compare September 11, 2024 01:14
@marta-lokhova
Copy link
Contributor Author

@dmkozh @sisuresh @SirTyson I ended up fixing the getHeader issue in f4f04b0, so the unsafe header access has been removed from the API. The PR is ready to merge now.

@dmkozh dmkozh added this pull request to the merge queue Sep 11, 2024
Merged via the queue into stellar:master with commit fbb53d8 Sep 11, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LedgerTxn is not thread-safe: switch read-only paths to BucketList snapshots
4 participants