Skip to content

Cleanup historical ledger query#5221

Open
SirTyson wants to merge 3 commits intostellar:masterfrom
SirTyson:cleanup-historical-ledger-query
Open

Cleanup historical ledger query#5221
SirTyson wants to merge 3 commits intostellar:masterfrom
SirTyson:cleanup-historical-ledger-query

Conversation

@SirTyson
Copy link
Copy Markdown
Contributor

Description

This is another follow up in the ledger state refactor.

Currently, CompleteConstLedgerState manages historical snapshots. These are only used by captive-core for the RPC query server, but add complexity to the core LedgerState interface. This PR makes it such that the QueryServer is responsible for maintaining it's own historical states, so CompleteConstLedgerState is simplified to just containing the minimum LCL state.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

@SirTyson SirTyson force-pushed the cleanup-historical-ledger-query branch 2 times, most recently from 66a30bb to 3cc6f16 Compare April 10, 2026 22:31
@SirTyson SirTyson force-pushed the cleanup-historical-ledger-query branch from 3cc6f16 to b01b1a3 Compare April 27, 2026 06:24
@SirTyson SirTyson marked this pull request as ready for review April 27, 2026 08:39
Copilot AI review requested due to automatic review settings April 27, 2026 08:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the ledger state refactor by removing historical snapshot management from ImmutableLedgerData/ImmutableLedgerView and shifting responsibility for retaining historical queryable snapshots to QueryServer (primarily used by captive-core/RPC query server).

Changes:

  • Move historical snapshot retention from ImmutableLedgerData/BucketListSnapshot into QueryServer, with a shared snapshot map plus per-thread ImmutableLedgerView caches.
  • Wire snapshot publication from LedgerManagerImplCommandHandlerQueryServer on ledger close.
  • Update/add tests to exercise QueryServer snapshot window behavior and concurrent snapshot access.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/test/QueryServerTests.cpp Switch tests to use CommandHandler’s QueryServer and add snapshot-window coverage (0 snapshots + eviction behavior).
src/main/QueryServer.h Add shared snapshot store (mStates), per-thread snapshot cache, and test hooks (registerThread, resetForTesting).
src/main/QueryServer.cpp Implement addSnapshot() and getSnapshotForLedger() and route query lookups through retained snapshots.
src/main/Config.h Add QUERY_SERVER_FOR_TESTING (tests-only) to allow direct QueryServer usage without network IO.
src/main/CommandHandler.h / src/main/CommandHandler.cpp Add addSnapshot() forwarding and a test-only QueryServer instantiation path; expose getQueryServer() in tests.
src/main/ApplicationImpl.cpp Construct CommandHandler earlier so ledger loading can publish snapshots; add test-only QueryServer reset to avoid duplicate-seq assertions.
src/ledger/test/ImmutableLedgerViewTests.cpp Update stress test to use QueryServer-provided snapshots and register worker threads for per-thread caching.
src/ledger/LedgerManagerImpl.h / src/ledger/LedgerManagerImpl.cpp Remove historical snapshot plumbing from ledger state construction and publish snapshots to CommandHandler after advancing LCL.
src/ledger/ImmutableLedgerView.h / src/ledger/ImmutableLedgerView.cpp Remove historical snapshot APIs and historical snapshot storage from ImmutableLedgerData.
src/bucket/test/BucketTestUtils.cpp Update ImmutableLedgerData::createAndMaybeLoadConfig call signature.
src/bucket/test/BucketIndexTests.cpp Remove historical snapshot test that depended on the removed historical snapshot API.
src/bucket/BucketListSnapshot.h / src/bucket/BucketListSnapshot.cpp Remove historical snapshot routing/storage from SearchableBucketListSnapshot; simplify constructors and loads.

Comment thread src/main/QueryServer.cpp
Comment thread src/main/QueryServer.cpp
dmkozh
dmkozh previously approved these changes Apr 27, 2026
Comment thread src/bucket/BucketListSnapshot.cpp Outdated

auto keys = inKeys;
std::vector<LedgerEntry> entries;
auto loadKeysLoop = [&](std::shared_ptr<LiveBucket const> const& bucket) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Can we dedup this with SearchableHotArchiveBucketListSnapshot::loadKeys with a helper?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@SirTyson SirTyson force-pushed the cleanup-historical-ledger-query branch from b01b1a3 to 64f0279 Compare April 29, 2026 22:51
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.

3 participants