Skip to content

Conversation

@SirTyson
Copy link
Contributor

@SirTyson SirTyson commented Dec 3, 2025

Description

Resolves #5004

This PR adds the BucketListStateConsistency invariant. This is a snapshot invariant that checks the following properties:

  • Soroban cache is consistent with the Live BucketList
  • Every live soroban entry has an associated TTL entry in the BL (and by extension the cache)
  • No live soroban entry is also in the Hot Archive (this was already implemented in ArchivedStateConsistency, but it has been refactored over to the new invariant).

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

Copy link

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 introduces a new BucketListStateConsistency invariant that validates the consistency between the in-memory Soroban state cache and the live BucketList. The invariant performs comprehensive checks to ensure data integrity across multiple dimensions:

  • Validates cache-BucketList synchronization for CONTRACT_DATA and CONTRACT_CODE entries
  • Ensures every live Soroban entry has an associated TTL entry
  • Verifies no live entry exists in both the live and hot archive BucketLists (refactored from ArchivedStateConsistency)

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/invariant/BucketListStateConsistency.h Defines the new snapshot invariant interface
src/invariant/BucketListStateConsistency.cpp Implements the 5 key consistency checks between cache and BucketList
src/invariant/ArchivedStateConsistency.h Removes checkSnapshot method declaration (refactored to new invariant)
src/invariant/ArchivedStateConsistency.cpp Changes from snapshot to non-snapshot invariant, removes hot archive overlap check
src/ledger/InMemorySorobanState.h Adds methods to query CONTRACT_DATA and CONTRACT_CODE entry counts
src/ledger/InMemorySorobanState.cpp Implements entry count accessors
src/invariant/test/InvariantTests.cpp Adds comprehensive test suite with 10 test sections covering all invariant properties
src/main/ApplicationImpl.cpp Registers the new invariant during application initialization

@SirTyson SirTyson force-pushed the in-memory-state-invariant branch 2 times, most recently from 3c8cb7b to ceeb145 Compare December 4, 2025 17:08
@SirTyson SirTyson mentioned this pull request Dec 10, 2025
6 tasks
@SirTyson SirTyson force-pushed the in-memory-state-invariant branch from ceeb145 to d67fb41 Compare December 10, 2025 19:37
@SirTyson SirTyson force-pushed the in-memory-state-invariant branch from d67fb41 to 6d03a13 Compare December 12, 2025 00:32
@SirTyson SirTyson requested a review from dmkozh December 18, 2025 18:18
app->getInvariantManager().runStateSnapshotInvariant(
getLedgerState(), lm.getInMemorySorobanStateForTesting()),
InvariantDoesNotHold);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to also verify that only contract data and code entries exist in the hot archive?

// BucketList, along with other important properties. We check these properties:
// 1. Every live entry in the BL is reflected in the in-memory cache
// 2. No entry exists in the cache, but not the BL
// 3. Each live soroban entry also has a live TTL entry associated with it
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We should mention somewhere that we also verify that TTLs in cache match TTLs in BL (currently that's done in step 3)

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.

Thorough in-memory soroban state cache invariant

2 participants