Skip to main content

Purpose and Scope

This document describes the persistent and in-memory storage architecture used by StableNet to maintain blockchain state, blocks, and receipts.
It covers the layered storage structure from the high-level StateDB caching layer down to the raw database backends, including the Merkle Patricia Trie, caching strategies, and the snapshot system.
For state transitions and EVM execution, see State Transitions and Gas.
For blockchain management and canonical chain maintenance, see Blockchain Management.
For detailed information on the ancient store and data lifecycle, see Ancient Store and Data Lifecycle.

Storage Layer Hierarchy

StableNet’s storage architecture is composed of multiple layers, each providing a different level of abstraction and performance optimization.

StateDB: State Caching Layer

StateDB is the core interface for reading and modifying blockchain state.
It is an advanced caching layer that provides journaling-based atomicity guarantees and snapshot-based rollback capabilities.

StateDB Structure

ComponentTypePurpose
dbDatabaseTrie database interface
trieTrieAccount trie root
snaps*snapshot.TreeSnapshot tree for fast access
snapsnapshot.SnapshotCurrently active snapshot
stateObjectsmap[common.Address]*stateObjectActive account objects
stateObjectsPendingmap[common.Address]struct{}Finalized but uncommitted objects
stateObjectsDirtymap[common.Address]struct{}Objects modified during execution
stateObjectsDestructmap[common.Address]*types.StateAccountDestructed objects
accountsmap[common.Hash][]byteModified account data
storagesmap[common.Hash]map[common.Hash][]byteModified storage slots
accountsOriginmap[common.Address][]byteOriginal account values
storagesOriginmap[common.Address]map[common.Hash][]byteOriginal storage values
journal*journalState change log
validRevisions[]revisionSnapshot revisions
refunduint64Gas refund counter

State Object Management

Each account is managed as a stateObject, which wraps the base types.StateAccount and tracks execution-time changes.
FieldTypePurpose
addresscommon.AddressAccount address
addrHashcommon.HashKeccak256(address)
origin*types.StateAccountOriginal account data
datatypes.StateAccountCurrent account data
trieTrieStorage trie
codeCodeContract bytecode
originStorageStorageOriginal storage
pendingStorageStoragePending storage (awaiting commit)
dirtyStorageStorageModified storage during execution
dirtyCodeboolCode modification flag
selfDestructedboolSelf-destruct marker
deletedboolDeletion marker
createdboolCreated in current transaction

Journaling and Snapshots

StateDB records all state changes in a journal to guarantee rollback capability.
Each journal entry implements a revert() method and includes the following change types:
  • balanceChange
  • nonceChange
  • storageChange
  • codeChange
  • extraChange
  • createObjectChange
  • selfDestructChange
  • touchChange
  • addLogChange

Merkle Patricia Trie Implementation

The Merkle Patricia Trie (MPT) is the core cryptographic data structure used to store state.
StableNet supports both hash-based and path-based storage schemes.

Trie Node Types

Node TypePurposeStructure
fullNode16-way branchingChildren [17]node
shortNodePath compressionKey []byte, Val node
valueNodeLeaf value[]byte
hashNodeHash reference[]byte

Storage Schemes: Hash vs Path

StableNet supports two trie storage schemes.
SchemeKey FormatPurpose
Hash SchemeNode hashContent-addressed storage
Path SchemeTrie pathHistory and pruning support
The path scheme enables state history, efficient pruning, and historical state queries.
The hash scheme is simpler but does not embed history.

BlockChain Caching Strategy

BlockChain minimizes database access by using multiple LRU caches.
CacheSizePurpose
bodyCache256Block bodies
blockCache256Full blocks
receiptsCache32Receipts
txLookupCache1024Transaction lookup
headerCache512Block headers
tdCache1024Total difficulty
numberCache2048Hash → block number

Snapshot System

Snapshots provide a flattened view of state, enabling fast access to accounts and storage without traversing the state trie.

Snapshot Layers

LayerPurposeStorage
difflayerRecent changesMemory
disklayerBase stateDisk
Snapshot access order is diff → disk → trie fallback.

Snapshot Configuration

FieldDefaultPurpose
SnapshotLimit256MBSnapshot cache size
SnapshotNoBuildfalseDisable background building
SnapshotWaittrueWait on startup

State Commit and Finalization

State changes proceed through modification → finalization → trie update → commit stages.
The final result is returned as a new state root hash.

Raw Database and Ancient Store

At the lowest level, a key-value database is used, and old data is migrated to the ancient store.

Ancient Store Characteristics

  • Reduced active database size
  • Fast sequential access to historical data
  • Enables pruning of the active database
  • Supports Era1 archive generation

Cache Configuration Summary

ConfigurationDefaultPurpose
TrieCleanLimit256MBClean trie cache
TrieDirtyLimit256MBDirty trie cache
TrieTimeLimit5 minutesFlush delay
SnapshotLimit256MBSnapshot cache
StateHistory0State history
bodyCacheLimit256Block bodies
blockCacheLimit256Full blocks
receiptsCacheLimit32Receipts
txLookupCacheLimit1024Transaction lookup