Skip to content

Add phase invariants to LedgerManager::ApplyState - #4819

Merged
marta-lokhova merged 1 commit into
stellar:masterfrom
SirTyson:ledger-apply-invariants
Jul 10, 2025
Merged

marta-lokhova merged 1 commit into
stellar:masterfrom
SirTyson:ledger-apply-invariants

Conversation

@SirTyson

@SirTyson SirTyson commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

Description

Adds additional invariant to LedgerManager::ApplyState. Now that there are multiple apply threads accessing ApplyState, sometimes the state is expected to be an immutable snapshot (i.e. during transaction execution), and other times ApplyState is modified by the apply thread to commit state changes and advance the ledger. This codifies these invariants. There's still some room for further hardening. For example, getNetworkConfig isn't protected by these invariants yet, as that's a larger overhaul that probably also requires changes to the LedgerStateSnapshot interface.

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 requested review from dmkozh and marta-lokhova July 8, 2025 02:41
Comment thread src/ledger/LedgerManagerImpl.h Resolved
Comment thread src/ledger/LedgerManagerImpl.h Resolved
Comment thread src/ledger/LedgerManagerImpl.h Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
@SirTyson
SirTyson force-pushed the ledger-apply-invariants branch from b71c7f5 to eed6dcf Compare July 8, 2025 18:11
@SirTyson

SirTyson commented Jul 8, 2025

Copy link
Copy Markdown
Contributor Author

I've cleaned up the thread asserts and fixed a phase transition issue in the genesis ledger path that was causing an init -> init transition.

Comment thread src/ledger/LedgerManagerImpl.cpp Resolved

@marta-lokhova marta-lokhova 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.

A couple of suggestions, mostly around consistent commentary, and avoiding unnecessary asserts in const functions.

Comment thread src/ledger/LedgerManagerImpl.h Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.h Resolved
@SirTyson
SirTyson force-pushed the ledger-apply-invariants branch from 2ccb363 to 8e77b0b Compare July 10, 2025 01:04
@SirTyson
SirTyson force-pushed the ledger-apply-invariants branch from 8e77b0b to b568cab Compare July 10, 2025 01:07

@marta-lokhova marta-lokhova 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.

LGTM!

Comment thread src/ledger/LedgerManagerImpl.h Resolved
@marta-lokhova
marta-lokhova enabled auto-merge July 10, 2025 16:24
@marta-lokhova
marta-lokhova added this pull request to the merge queue Jul 10, 2025
Merged via the queue into stellar:master with commit e595a79 Jul 10, 2025
pull Bot pushed a commit to mikeyhodl/stellar-core that referenced this pull request May 28, 2026
This does a little simplification on the arithmetic we were doing to
track thresholds of module cache rebuilding, as well as clarifying when
we're measuring _input_ vs. _output_ values in the cost model. Also it
moves the module cache tests to a separate file, as part of my long term
dream to split InvokeHostFunctionTests.cpp into multiple files.

One disappointing part about this is that the tweak above reveals that
the `ApplyState` state-invariant-checking that @SirTyson put in back in
stellar#4819 was actually
_slightly_ incorrect: the `finishPendingCompilation` method does
actually write to `ApplyState` when it's in `READY_TO_APPLY` (it did
back then too, it just didn't happen to _occur_ in tests before). I
can't think of any really great way to avoid this (the whole point is to
defer the implied variable-update/stall until the last moment before
we'll need it) besides I guess we could like add in another state? I
don't know if that would win much, but I'd be willing to if that's your
preference @SirTyson ?
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