Skip to content

Simplify the ledger view hierarchy and interfaces. - #5461

Merged
dmkozh merged 1 commit into
stellar:masterfrom
dmkozh:ledger_view_refactor
Oct 14, 2026
Merged

dmkozh merged 1 commit into
stellar:masterfrom
dmkozh:ledger_view_refactor

Conversation

@dmkozh

@dmkozh dmkozh commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Description

  • CheckValidLedgerViewWrapper is gone. It was used only for test compatibility, which is is unnecessary. It was also used outside of tx validation quite a bit, which made it even more confusing.
  • LedgerTxnReadOnly is renamed to LedgerTxnView for clarity, and now it's used more generally anywhere we need an adapter from LTX to ledger view
  • executeWithMaybeInnerSnapshot is gone. We only need the hacky pre-p8 logic in 2 places, and now it's used there explicitly (with LedgerTxnView on the child transaction)
  • All views now provide network config with getSorobanNetworkConfig consistently. We don't use it too broadly at the moment, but it makes sense for views to be able to expose the config (in the same way as it makes sense for them to expose the ledger header).
  • SorobanNetworkConfig is now loaded using a closure in order to avoid a weird circular dependency that the previous step would introduce (as we used to load the config from an AbstractLedgerView)
  • ImmutableLedgerData now always automatically loads the network config, which reduces awkwardness around creating a throw-away view (another symptom of the circular dependency weirdness above)
  • Concrete copyImmutableLedgerView() is only exposed to tests. I still dislike the name (as it's unclear which state does the view represent), but I kept it as is for now to reduce the change amount a bit. All the production users can get by with the new getLCLView() that returns an instance of an abstract ledger view of LCL. Also renamed maybeUpdateImmutableLedgerView to syncWithLCLView for clarity. Consumers also use abstract view, which ties the above changes together.
  • ledgerView.mSkipSeqNumCheck is gone, we just check the overlay-only mode flag directly.
  • Misc minor cleanups and comment updates.

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

@dmkozh
dmkozh force-pushed the ledger_view_refactor branch 3 times, most recently from 7764afe to 7908ade Compare September 17, 2026 20:28
@dmkozh
dmkozh marked this pull request as ready for review September 17, 2026 20:32
Copilot AI balanced review requested due to automatic review settings September 17, 2026 20:32

Copilot AI left a comment

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.

🔵 Needs a closer look

The broad consensus-sensitive refactor spans transaction validation, historical protocol behavior, Soroban configuration, and concurrent snapshots.

Pull request overview

Simplifies ledger-view abstractions while preserving transaction validation, legacy protocol behavior, Soroban configuration access, and thread-local snapshot handling.

Changes:

  • Replaces CheckValidLedgerViewWrapper and renames LedgerTxnReadOnly to LedgerTxnView.
  • Adds consistent Soroban configuration access and abstract LCL snapshot APIs.
  • Migrates transaction, herder, overlay, simulation, utility, and test consumers.
File summaries
File Description
src/transactions/TransactionFrameBase.h Generalizes validation APIs to abstract views.
src/transactions/TransactionFrame.h Updates transaction validation interfaces.
src/transactions/TransactionFrame.cpp Refactors validation and legacy snapshot handling.
src/transactions/test/TransactionTestFrame.h Updates test-frame view interfaces.
src/transactions/test/TransactionTestFrame.cpp Loads missing test network configuration.
src/transactions/test/SorobanTxTestUtils.cpp Uses LCL views in Soroban helpers.
src/transactions/test/SetTrustLineFlagsTests.cpp Adapts validation calls to LedgerTxnView.
src/transactions/test/RevokeSponsorshipTests.cpp Migrates test validation views.
src/transactions/test/PaymentTests.cpp Uses the abstract LCL view.
src/transactions/test/ParallelApplyTest.cpp Migrates parallel-apply snapshot reads.
src/transactions/test/ManageBuyOfferTests.cpp Updates validation-view construction.
src/transactions/test/InvokeHostFunctionTests.cpp Migrates Soroban validation and state reads.
src/transactions/test/FrozenLedgerKeysTests.cpp Migrates frozen-key validation views.
src/transactions/test/FeeBumpTransactionTests.cpp Updates fee-bump validation views.
src/transactions/test/EndSponsoringFutureReservesTests.cpp Uses the LCL validation view.
src/transactions/test/CreateAccountTests.cpp Uses the LCL validation view.
src/transactions/test/ClaimableBalanceTests.cpp Uses LedgerTxnView for pending state.
src/transactions/test/ChangeTrustTests.cpp Uses LedgerTxnView for pending state.
src/transactions/test/BeginSponsoringFutureReservesTests.cpp Migrates validation views.
src/transactions/ParallelApplyUtils.cpp Uses SorobanPreApplyLedgerView directly.
src/transactions/OperationFrame.h Generalizes operation validation APIs.
src/transactions/OperationFrame.cpp Adds explicit legacy nested validation.
src/transactions/FeeBumpTransactionFrame.h Generalizes fee-bump view interfaces.
src/transactions/FeeBumpTransactionFrame.cpp Reads configuration from supplied views.
src/test/TxTests.cpp Preserves pre-v8 test isolation.
src/test/TestAccount.cpp Migrates account queries to LCL views.
src/test/fuzz/targets/TxFuzzTarget.cpp Supplies configuration through LedgerTxnView.
src/simulation/TxGenerator.cpp Migrates generator state reads.
src/simulation/LoadGenerator.cpp Migrates load-generator state reads.
src/simulation/ApplyLoad.cpp Migrates validation and generation views.
src/overlay/test/OverlayTests.cpp Updates overlay validation tests.
src/overlay/Peer.cpp Uses the overlay snapshot directly.
src/overlay/OverlayManagerImpl.h Stores an abstract overlay snapshot.
src/overlay/OverlayManagerImpl.cpp Automatically synchronizes the overlay snapshot.
src/overlay/OverlayManager.h Generalizes the snapshot interface.
src/main/test/CommandHandlerTests.cpp Uses the LCL view in tests.
src/main/CommandHandler.cpp Migrates command ledger reads.
src/main/ApplicationUtils.cpp Uses abstract reads and manager scanning.
src/main/ApplicationImpl.h Makes overlay-only state atomic.
src/main/ApplicationImpl.cpp Adds ledger-view implementation dependency.
src/main/AppConnector.h Removes concrete snapshot APIs.
src/main/AppConnector.cpp Delegates abstract overlay snapshots.
src/ledger/test/ImmutableLedgerViewTests.cpp Tests abstract snapshot ownership and syncing.
src/ledger/NetworkConfig.h Introduces callback-based configuration loading.
src/ledger/NetworkConfig.cpp Loads configuration through entry readers.
src/ledger/LedgerManagerImpl.h Adds abstract LCL and scan APIs.
src/ledger/LedgerManagerImpl.cpp Implements LCL views and synchronization.
src/ledger/LedgerManager.h Defines the revised snapshot interface.
src/ledger/InMemorySorobanState.cpp Reuses configuration embedded in views.
src/ledger/ImmutableLedgerView.h Simplifies the ledger-view hierarchy.
src/ledger/ImmutableLedgerView.cpp Implements views and automatic configuration loading.
src/invariant/BucketListStateConsistency.cpp Reuses snapshot network configuration.
src/herder/Upgrades.h Generalizes upgrade view parameters.
src/herder/Upgrades.cpp Migrates upgrade processing to abstract views.
src/herder/TxSetUtils.cpp Uses LCL views during set validation.
src/herder/TransactionQueue.cpp Uses LCL views for queue admission.
src/herder/test/UpgradesTests.cpp Migrates upgrade tests.
src/herder/test/TxSetTests.cpp Migrates transaction-set tests.
src/herder/test/HerderTests.cpp Migrates herder validation tests.
src/herder/HerderImpl.cpp Uses LCL views for upgrade handling.
src/bucket/test/BucketTestUtils.cpp Uses automatic configuration loading.
src/bucket/test/BucketListTests.cpp Migrates BucketList snapshot reads.
src/bucket/test/BucketIndexTests.cpp Supplies synthetic network configuration.
src/bucket/BucketManager.cpp Loads configuration directly from LedgerTxn.
Review details
  • Files reviewed: 65/65 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/overlay/OverlayManager.h Resolved
@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from 7908ade to dd341a4 Compare September 17, 2026 21:30
Copilot AI review requested due to automatic review settings September 17, 2026 21:30

Copilot AI left a comment

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.

🟡 Changes recommended

LCL synchronization can replace the required in-memory-ledger view with an empty BucketList-backed view.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

src/overlay/OverlayManager.h:218

  • This contract is now stale: getOverlayThreadSnapshot() calls syncWithLCLView() internally on every access, so callers are no longer responsible for refreshing it. Document the automatic refresh to prevent callers from looking for a synchronization API that is no longer exposed here.
    // Get a snapshot of ledger state for use by the overlay thread only. Caller
    // is responsible for updating the snapshot as needed.
    virtual AbstractLedgerView const& getOverlayThreadSnapshot() = 0;
  • Files reviewed: 65/65 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Copilot AI review requested due to automatic review settings September 17, 2026 21:44
@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from dd341a4 to 45c677d Compare September 17, 2026 21:44

Copilot AI left a comment

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.

🟡 Changes recommended

LCL synchronization can replace an in-memory-ledger view with an empty BucketList-backed snapshot.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

src/ledger/LedgerManagerImpl.cpp:2473

  • In test builds this bypasses the MODE_USES_IN_MEMORY_LEDGER handling in getLCLView(): the first sync (or any stale sync) installs an ImmutableLedgerView, even though the BucketList is explicitly not populated in that mode. An overlay-thread snapshot then sees missing accounts/config instead of the state held by the root LedgerTxn. Please make synchronization recreate the same owned-LTX-backed view used by getLCLView() for in-memory mode (while accounting for the existing child view's lifetime).
        ledgerView = std::make_unique<ImmutableLedgerView>(
            mLastClosedLedgerState, mApp.getMetrics());
  • Files reviewed: 65/65 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/ledger/LedgerManager.h Resolved
Copilot AI review requested due to automatic review settings September 17, 2026 22:51
@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from 45c677d to 01c5f1a Compare September 17, 2026 22:51

Copilot AI left a comment

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.

🔵 Needs a closer look

The broad refactor touches consensus-critical transaction validation, ledger snapshots, Soroban configuration, and concurrency contracts, with one documentation contract needing correction.

Review details
  • Files reviewed: 65/65 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/ledger/LedgerManager.h Resolved
Copilot AI review requested due to automatic review settings September 18, 2026 18:48
@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from f1ecbd9 to 283f36f Compare September 18, 2026 18:50

Copilot AI left a comment

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.

🔵 Needs a closer look

The broad consensus-critical ledger and transaction interface refactor warrants final human review despite no specific defect being identified.

Review details
  • Files reviewed: 65/65 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 18, 2026 18:51

Copilot AI left a comment

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.

🔵 Needs a closer look

No new actionable defect was identified, but this broad consensus-critical validation and snapshot refactor warrants final human review.

Review details
  • Files reviewed: 65/65 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from 283f36f to eb1d799 Compare October 12, 2026 22:19
Copilot AI balanced review requested due to automatic review settings October 12, 2026 22:19
Comment thread src/ledger/LedgerManager.h Resolved
Comment thread src/ledger/ImmutableLedgerView.cpp Resolved
Comment thread src/overlay/OverlayManagerImpl.cpp Resolved
Comment thread src/ledger/ImmutableLedgerView.cpp Resolved
Comment thread src/overlay/OverlayManagerImpl.cpp Resolved
Comment thread src/ledger/ImmutableLedgerView.h Resolved

Copilot AI left a comment

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.

🟡 Changes recommended

Pre-apply config lifetime, active-view rollback handling, and incomplete config equality introduce correctness gaps.

3 open findings

🧠 Review effort: Balanced

Comment thread src/ledger/ImmutableLedgerView.cpp Resolved
Comment thread src/transactions/TransactionFrame.cpp Resolved
Comment thread src/ledger/NetworkConfig.h Resolved
Copilot AI balanced review requested due to automatic review settings October 13, 2026 21:06

Copilot AI left a comment

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.

🟡 Changes recommended

The production SorobanNetworkConfig equality implementation calls accessors available only in test builds, preventing a non-test build.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/ledger/NetworkConfig.cpp Resolved
Copilot AI balanced review requested due to automatic review settings October 13, 2026 22:16

Copilot AI left a comment

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.

🔵 Needs a closer look

It changes consensus-critical ledger ownership, validation, and parallel-apply behavior across many subsystems.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 13, 2026 22:21

Copilot AI left a comment

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.

🔵 Needs a closer look

The broad consensus-critical ledger, transaction, and concurrency refactor warrants final human validation despite no confirmed defects found.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 13, 2026 22:50

Copilot AI left a comment

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.

🔵 Needs a closer look

It broadly changes consensus-critical ledger access, transaction validation, snapshot ownership, and concurrency boundaries despite no confirmed defect in the reviewed code.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:02

Copilot AI left a comment

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.

🔵 Needs a closer look

The snapshot stress test’s header check now duplicates its sequence check and no longer validates header consistency.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Header assertion removed, allowing cached sequence mismatches

src/​ledger/​test/​ImmutableLedgerViewTests.cpp:251

headerMatchesExpected() now duplicates seqMatchesExpected() and no longer checks the header at all, so the stress test cannot detect a mismatch between the view's cached sequence and getLedgerHeader(). Keep this assertion on the header sequence as before.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:24

Copilot AI left a comment

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.

🟡 Changes recommended

LedgerTxnView can fail to create when a Soroban configuration entry is already active, contrary to its documented handle-deactivation behavior.

1 open finding

🧠 Review effort: Balanced

Comment thread src/ledger/ImmutableLedgerView.cpp Resolved
@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from b166a35 to 0df7ddd Compare October 14, 2026 17:20
- CheckValidLedgerViewWrapper is gone. It was used only for test compatibility, which is is unnecessary. It was also used outside of tx validation quite a bit, which made it even more confusing.
- LedgerTxnReadOnly is renamed to LedgerTxnView for clarity, and now it's used more generally anywhere we need an adapter from LTX to ledger view. Moreover, LTX views are now guaranteed to be over immutable LTX via runtime enforcement.
- executeWithMaybeInnerSnapshot is gone. We only need the hacky pre-p8 logic in 2 places, and now it's used there explicitly (with LedgerTxnView on the child transaction)
- All views now provide network config with `getSorobanNetworkConfig` consistently. We don't use it too broadly at the moment, but it makes sense for views to be able to expose the config (in the same way as it makes sense for them to expose the ledger header).
- SorobanNetworkConfig is now loaded using a closure in order to avoid a weird circular dependency that the previous step would introduce (as we used to load the config from an AbstractLedgerView)
- ImmutableLedgerData now always automatically loads the network config, which reduces awkwardness around creating a throw-away view (another symptom of the circular dependency weirdness above)
- Concrete `copyImmutableLedgerView()` is only exposed to tests. I still dislike the name (as it's unclear which state does the view represent), but I kept it as is for now to reduce the change amount a bit. All the production users can get by with the new `getLCLView()` that returns an instance of an abstract ledger view of LCL. Also renamed `maybeUpdateImmutableLedgerView` to `syncWithLCLView` for clarity. Consumers also use abstract view, which ties the above changes together.
- `ledgerView.mSkipSeqNumCheck` is gone, we just check the overlay-only mode flag directly.
- Misc minor cleanups and comment updates.
@dmkozh
dmkozh force-pushed the ledger_view_refactor branch from 0df7ddd to dbe95a7 Compare October 14, 2026 20:41
@dmkozh
dmkozh enabled auto-merge October 14, 2026 20:53
@dmkozh
dmkozh added this pull request to the merge queue Oct 14, 2026
Merged via the queue into stellar:master with commit 983b948 Oct 14, 2026
54 of 56 checks passed
@dmkozh
dmkozh deleted the ledger_view_refactor branch October 14, 2026 22:43
SirTyson added a commit to SirTyson/stellar-core that referenced this pull request Nov 9, 2026
Brings overlay-v2-shared up to date with master. The previous master
merge (b90d48e, stellar#5428) was recorded with master's tip 100cc38 missing
from its parents, so this merge used 100cc38 as its base (temporary
graft of b90d48e, removed afterwards).

Notable master changes brought in:
- Protocol 30: CURRENT_LEDGER_PROTOCOL_VERSION follows
  MAX_SUPPORTED_PROTOCOL_VERSION; CAP-0084 and CAP-0087 ungated, p29 and
  p30 Soroban hosts (stellar#5472, stellar#5478, stellar#5484, stellar#5483).
- Millisecond-resolution close times at protocol 30 (stellar#5423):
  ConsensusTime/ApplyTime types, STELLAR_VALUE_SIGNED_MS and
  STELLAR_VALUE_EMPTY_TX_SET_MS.
- Tx set validity hardening (stellar#5481), lower max message size in protocol
  29 (stellar#733), sub-second ledger edge-case fixes.
- Simplified ledger view hierarchy (stellar#5461); the overlay-only-mode
  sequence number skip now lives in TransactionFrame::checkValid.
- Banned accounts deprecated (CAP-0077 is active).
- Apply-path performance work (stellar#5402, stellar#5411, stellar#5414, stellar#5415, stellar#5418, stellar#5421,
  stellar#5436, stellar#5286), apply-load tx set construction mode (stellar#5448), --check-lcm
  (stellar#5435), v29.0.0 release merge.

Conflict resolution:
- Files overlay-v2-shared deleted and master modified (the C++ overlay,
  TransactionQueue, TransactionQueueTests, UpgradesTests, private/Horizon/RPC
  workflows): kept deleted. Master's changes to them are C++ overlay
  peer/flow-control logic, tx queue admission and tests for those.
- Herder: kept the Rust-overlay submission path (recvTransaction returns
  TxSubmitStatus) and dropped the deprecated `force` parameter as master did.
  triggerNextLedger keeps the prepared/built tx set path from the Rust
  mempool, now with ConsensusTime close times and master's apply-time
  close-time offset. The early tx set preparation path (prepareTxSet,
  buildTxSet, setupTriggerNextLedger) takes ConsensusTime. Kept master's
  mNominatedTxSetOverride test hook (applied before the tx set is cached in
  the Rust overlay) and the herder.txset.build timer (now timing
  buildTxSet). Dropped the banned-accounts setup and tx queue maintenance.
- AppConnector: dropped both ov2's maybeUpdateImmutableLedgerView and
  master's C++-overlay getOverlayThreadSnapshot.
- LoadGenerator: master's CachedTestAccountPtr with ov2's TxSubmitStatus.
- Tests: kept ov2's removal of tests that need the C++ overlay, standalone
  mode or the tx queue (standalone, manualclose, flooding, tx queue limits,
  far-future slot cleanup, herderExternalizesValuesWithProtocol, MAX_SAC_TPS,
  custom token, soroswap and noisy binary search apply-load tests). Added
  master's ms close time HerderTests and the non-canonical empty tx set test
  on ov2's Rust-overlay topologies. The tx set size test checks against
  overlay-v2's own tx set allowance. The sub-second
  getUpperBoundCloseTimeOffset test checks the offset directly, since there
  is no C++ tx queue admission. Tests that used CheckValidLedgerViewWrapper
  now use getLCLView().
- Cargo.lock: master's lockfile plus the overlay crate's packages,
  regenerated by cargo; semver-compatible duplicates take the newer
  version.
- Build: Makefile.am keeps the Rust overlay rules and adds tracy
  import-chrome; ci-build.sh keeps ASAN off and takes master's -g1.
- Needed to compile: PendingEnvelopes.cpp includes LedgerManager.h
  (master got it through the C++ OverlayManager.h); ov2's early-nomination
  and checkpoint-slot tests use ConsensusTime/ApplyTimeOffset; OverlayIPC
  tests take ledger views from the LedgerManager.
@SirTyson SirTyson mentioned this pull request Nov 9, 2026
5 of 6 tasks
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