stellar-core icon indicating copy to clipboard operation
stellar-core copied to clipboard

WIP Add LedgerStateCache

Open ThomasBrady opened this issue 1 year ago • 0 comments

Adds LedgerStateCache to store all Soroban entries:

  • Populates (LedgerStateCache::addEntry) the cache in PopulateLedgerCacheWork (executed in LedgerManagerImpl::loadLastKnownLedger).
  • Updates the cache (LedgerStateCache:::addEntries) each ledger from LedgerManagerImpl::transferLedgerEntriesToBucketList.
  • Reads the cache (LedgerStateCache::readEntry) in LedgerTxnRoot::Impl:::getNewestVersion.

Notes:

  • LedgerStateCache lives in an optional shared pointer and is created at startup, originally in the LedgerManagerImpl
  • LedgerTxnRoot takes an std::optional<LedgerStateCache> in its constructor, and PopulateLedgerCacheWork access it with LedgerManager::getLedgerStateCache.
  • addEntry and addEntries are private and only accessible from friend classes LedgerManagerImpl and PopulateLedgerCacheWork
  • addEntry and addEntries acquire a unique lock on the cache
  • Currently, the LedgerStateCache only supports contract entries. To access them in the index, I've added Bucket / Index::getContractEntryRange.
  • The LedgerStateCache is enabled via Config::IN_MEMORY_SOROBAN_STATE_FOR_TESTING (default true).

Description

Resolves https://github.com/stellar/stellar-core/issues/4556

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

ThomasBrady avatar Feb 06 '25 07:02 ThomasBrady