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

State Object Management

Each account is managed as a stateObject, which wraps the base types.StateAccount and tracks execution-time changes.

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

Storage Schemes: Hash vs Path

StableNet supports two trie storage schemes. 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.

Snapshot System

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

Snapshot Layers

Snapshot access order is diff → disk → trie fallback.

Snapshot Configuration

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