Introducing a new way to review your PRs.

Read the announcement

near / nearcore

Reference client for NEAR Protocol

View on GitHub

20 documents · Updated Nov 23, 2026

docs / persistent-storage-and-flat-state

Persistent storage and flat state

Persistent storage is the durable base for the node's chain data and shard state. It gives chain, runtime, synchronization, archival, and query services one store interface while using a verifiable trie for canonical state, fast flat reads, and optional in-memory and prefetch paths for node operation.

Parent: Storage and state · Related: State sync and state parts, Cloud archival storage, Chain data processing

Storage foundation

Store abstraction

The Store in core/…/store.rs is the common access layer over the node database. It reads serialized records, supports ordered scans, and turns a group of changes into one atomic database write. StoreUpdate keeps these changes together until commit, so related records can move forward as one unit.

The adapter layer gives each major data area a focused view of the same store. Chain, chunk, epoch, trie, and flat-state adapters can also share one pending update. This keeps domain code separate while preserving the database transaction boundary. The lower database interface also supports zero-copy reads where the backend can pin its data, while callers can request owned bytes when they need them.

The in-memory TestDB implements the same database contract for tests and storage-cost estimates. Its ordered columns keep scans deterministic, and its writes apply the same reference-count rules as the on-disk backend.

References: core/…/store.rs• L18-40 core/…/store.rs• L129-180 core/…/store.rs• L307-329 core/…/store.rs• L454-463 core/…/mod.rs• L87-153 core/…/mod.rs• L84-127 core/…/mod.rs• L207-323 core/…/slice.rs• L28-105 core/…/rocks.rs• L14-49 core/…/testdb.rs• L8-20 core/…/testdb.rs• L45-125

Logical data groups

The database is divided into named logical columns. Each column has a key shape and a write policy that describes whether records are immutable, reference counted, or freely updated. This policy protects shared data such as trie values and lets cleanup remove old chain records without changing live records. Store and trie configuration assign memory limits and database tuning by workload, so state-heavy columns can use different resources from less active records.

The important groups are:

GroupPurpose
Chain recordsBlocks, headers, heads, height indexes, forks, receipts, outcomes, and Merkle data
Shard execution recordsChunks, chunk results, chunk metadata, and state-change records
State recordsTrie nodes and values, state roots, trie changes, and shard-prefix mappings
Flat-state recordsThe current flat key view, per-block deltas, delta metadata, and readiness status
State-transfer recordsState parts, state-part progress, and state-sync metadata used during bootstrap
Operational recordsDatabase metadata, sync markers, archival progress, caches, and other node-local progress

Reference-counted groups represent shared values as one durable value with a count. A read hides entries whose count is no longer positive, and the RocksDB backend removes zero-count entries during compaction. The in-memory backend removes them during the write. This allows several trie versions to share data without copying it for every version.

References: core/…/columns.rs• L4-18 core/…/columns.rs• L45-121 core/…/columns.rs• L189-277 core/…/columns.rs• L249-421 core/…/columns.rs• L463-512 core/…/columns.rs• L515-563 core/…/mod.rs• L42-72 core/…/refcount.rs• L1-19 core/…/refcount.rs• L25-145 core/…/rocksdb.rs• L780-793 core/…/rocksdb.rs• L927-946 core/…/testdb.rs• L88-125 core/…/config.rs• L9-19 core/…/config.rs• L312-413

Chain persistence

Chain records

The ChainStoreAdapter in core/…/chain_store.rs is the durable record of chain progress. It connects block hashes and heights with headers, full blocks, fork information, receipt flow, execution outcomes, and the several heads that describe what the node knows, follows, and considers final.

These records are not only a block archive. They are the indexes that let the node find a block by hash or height, follow parent and next-block links, recover receipt proofs, and restore chain progress after a restart. The store also keeps separate execution-progress heads for work that has been executed and work that has reached finality. These heads advance forward so execution progress does not move back when a fork is revisited.

For the SPICE execution path, the store also records the block that certifies a chunk and keeps execution heads forward-only. This preserves the highest known execution point when blocks arrive out of order or a fork is processed again.

Epoch light-client blocks use a versioned stored form that is separate from the RPC view. This keeps old epoch records readable when the view changes and converts them back to the view only when the node reads them.

References: core/…/chain_store.rs• L27-42 core/…/chain_store.rs• L56-132 core/…/chain_store.rs• L132-212 core/…/chain_store.rs• L213-297 core/…/chain_store.rs• L326-335 core/…/chain_store.rs• L367-374 core/…/chain_store.rs• L425-451 core/…/chain_store.rs• L669-751 core/…/light_client_block.rs• L1-9 core/…/light_client_block.rs• L19-49 core/…/light_client_block.rs• L75-97

Epoch and chunk records

Epoch and chunk data extend chain persistence into the shard and protocol timelines. The epoch adapter stores epoch starts, block information, epoch context, validator-era summaries, and epoch sync proofs. It also stores chunk-producer selections when the related protocol feature is active.

Together these records let the node reconstruct the protocol context for a block and connect a shard's execution result to the chain record that carries it. Block information is read through the store's committed-record cache, so epoch consumers share storage-layer caching instead of maintaining a separate block-information cache. EarlyKickout chunk-producer records use the anchor block and shard as their key, so historical lookup can use the sampled producer for that chunk. Continuous epoch sync stores its proof in compressed form and decodes it when the node reads it. These records provide durable inputs for recovery and synchronization without putting those concerns into the generic store API.

The chunk adapter provides the matching durable view for partial and full chunks. It also keeps chunk execution metadata, invalid-chunk records, state witnesses, and contract-access data available to later validation and replay work.

References: core/…/epoch_store.rs• L18-95 core/…/epoch_store.rs• L97-147 core/…/epoch_store.rs• L150-175 core/…/chunk_store.rs• L21-124 core/…/chunk_store.rs• L127-200

Canonical state

Persistent trie state

The canonical shard state is a persistent Merkle-Patricia trie. A state root identifies a complete version of the state, and unchanged trie nodes can be shared by later versions. This gives the node durable access to state at a block or fork while retaining a hash-based way to detect missing or altered trie data.

The trie store is the database-facing boundary for trie bytes. It also records trie changes for later cleanup and maintains reference counts for shared nodes and values. During resharding, a shard can temporarily read through a mapping to the database prefix that still owns its state. Resharding can apply new references without applying old-state deletions, which protects shared data until the source state is no longer needed.

References: docs/…/trie_storage.md• L1-7 docs/…/trie_storage.md• L24-41 docs/…/trie_storage.md• L93-123 core/…/trie_store.rs• L12-79 core/…/trie_store.rs• L123-208 core/…/mod.rs• L446-530 core/…/shard_tries.rs• L291-337 core/…/columns.rs• L314-319

State access boundary

Trie state is the source that preserves full historical and fork-specific state. The flat representation is a derived read aid. It stores a direct mapping from a shard and trie key to a value reference or a small inlined value, while the value data remains available in trie state when it is not inlined.

This split gives reads a small, ordered index without changing the state root model. A flat entry alone is not the proof of state correctness; the trie and its hashes remain the canonical representation. A lookup can prefer an in-memory trie, use the flat view, or walk the persistent trie according to its access mode. Proof recording still uses the canonical trie data needed to prove the result. View reads avoid the normal in-memory trie path so they can use historical state without adding contention to block processing.

References: docs/…/flat_storage.md• L3-15 docs/…/flat_storage.md• L43-52 core/…/columns.rs• L262-277 core/…/mod.rs• L94-150 core/…/mod.rs• L248-280 core/…/mod.rs• L1223-1313 core/…/shard_tries.rs• L145-220 core/…/chunk_view.rs• L34-43

Trie iteration

Trie iteration provides one ordered traversal model for both durable tries and in-memory tries. It supports prefix and range seeks, subtree pruning, and state-part intervals, while seek operations avoid recording reads that are not part of the returned data.

Trie updates use the same ordered view when they scan a key range. The iterator merges committed and prospective changes over the durable trie, so a caller sees pending values and deletions in the same key order as committed state.

References: core/…/iterator.rs• L12-105 core/…/iter.rs• L61-166 core/…/iter.rs• L398-469 core/…/iterator.rs• L36-140

Trie access utilities

The storage utilities provide the shared read and write boundary for objects held in trie state. They serialize values consistently, turn malformed data into storage errors, and support reads that either record access for normal execution or avoid side effects when a caller only needs information.

TrieUpdate keeps new changes separate from committed changes until the caller accepts them. Reads see these pending changes before they consult the base trie. Finalization then turns the accepted changes into a new trie root, state-change records, and contract-update records for the store and downstream distribution paths.

The same utility layer handles common account, access-key, receipt, promise-yield, and genesis metadata operations. Persistent receipt queues use cached indexes with typed push, pop, update, and iteration operations. The queue helpers require one active view of a queue so cached indexes and trie records do not diverge. This keeps state-key rules in one place and lets execution code work with typed state objects instead of raw trie keys.

TrieUpdate also records local and global contract deployments before the final state write. A contract deployed during the current chunk is visible to later reads in that chunk. Finalization keeps local deployment updates separate from global-contract distribution, while rollback removes only deployments that were not committed. Contract reads that arrive after the tracker is finalized fall back to durable trie storage; any pipeline work still running at that point is not used.

References: core/…/mod.rs• L25-63 core/…/mod.rs• L93-118 core/…/mod.rs• L120-179 core/…/mod.rs• L355-454 core/…/mod.rs• L504-601 core/…/receipts_column_helper.rs• L8-79 core/…/receipts_column_helper.rs• L81-249 core/…/update.rs• L20-45 core/…/update.rs• L115-138 core/…/update.rs• L180-220 core/…/update.rs• L275-322 core/…/iterator.rs• L36-140 core/…/contract.rs• L19-31 core/…/contract.rs• L141-200 core/…/contract.rs• L203-262

Genesis state initialization

Genesis initialization creates the first state root for each shard and records the roots with the genesis height. It can load a prepared state dump, use roots supplied by genesis, or build the trie from genesis records. Before it commits the roots, it checks that the number of roots matches the shard layout so the node cannot start with a state that belongs to a different shard shape.

When records build the state, the initializer assigns records and validators to shards. The state applier writes accounts, contract data, keys, receipts, and related state through the trie access boundary. It computes account storage use and applies the resulting trie changes to both canonical state and the initial flat view. Large genesis loads flush bounded groups of writes, while one final state root is returned for each shard.

References: core/…/initialization.rs• L29-70 core/…/initialization.rs• L83-114 core/…/initialization.rs• L129-215 core/…/state_applier.rs• L26-99 core/…/state_applier.rs• L101-169 core/…/state_applier.rs• L172-374

State part exchange

State parts are bounded pieces of one shard's state used when a node builds or receives state from scratch. The partition follows trie traversal order so parts are disjoint and contiguous. Each part also carries the boundary paths and sibling data needed to verify its position against the state root.

Flat state makes part creation faster by supplying key-value entries through an ordered scan. Inlined values come from the flat view, while referenced values are read from canonical trie storage. The resulting entries are assembled into a partial trie before the part is returned for verification or transfer.

When a valid part is applied, the node produces both canonical trie changes and a flat-state delta. It also extracts contract code so state transfer can update the state views and distribute code through the paths that need it.

State-part decoding also limits the number of entries before it allocates the full part. The limit complements the byte-size limit and protects validation from inputs with many small entries.

The relationship between the two state views is:

flowchart LR
    A[Canonical state root] --> B[Trie boundary paths]
    C[Flat key view] --> D[State-part key-value entries]
    E[Trie value records] --> D
    B --> F[Verified partial state part]
    D --> F

References: core/…/state_parts.rs• L1-18 core/…/state_parts.rs• L90-116 core/…/state_parts.rs• L158-225 core/…/state_parts.rs• L227-299 core/…/state_parts.rs• L399-480 core/…/state_part.rs• L19-37 core/…/state_part.rs• L76-112 core/…/mod.rs• L532-540

Flat-state facilities

Flat storage model

FlatStorage represents the flat state for one shard over a range of blocks. It keeps a durable base snapshot at its flat head and keeps later block changes as deltas. A delta is a set of key updates or deletions plus enough block metadata to connect it to a parent or fork.

This model avoids copying the whole key map for every block. It also lets a read ask for state after a non-head block. The read walks the relevant deltas from that block back to the flat head, then falls back to the durable flat snapshot for keys not changed in those deltas.

The following diagram shows how a state change becomes a flat read view while the trie remains the canonical state source.

flowchart LR
    A[Applied chunk state changes] --> B[Flat state delta]
    B --> C[Durable delta records]
    C --> D[Flat storage for a shard]
    D --> E[Block-specific chunk view]
    E --> F[Fast key lookup]
    G[Trie state and value records] --> D
    G --> H[Canonical state root and proof data]

References: core/…/delta.rs• L12-16 core/…/delta.rs• L26-42 core/…/delta.rs• L58-69 core/…/storage.rs• L19-52 core/…/storage.rs• L287-337

Flat-state coordination

The FlatStorageManager owns the per-shard flat views used by the runtime. It receives state changes after chunk processing, saves the delta with the other block changes, and later advances the flat head by applying reachable deltas in chain order.

The manager also coordinates startup, shard tracking, resharding, and state snapshots. Each shard has its own flat view because normal processing and catch-up can cover different block ranges. A flat head hold freezes movement while a snapshot or another state task needs a stable view. Multiple holds can coexist, and movement resumes only after all holders release them. The manager can report the highest flat-head height across its active shard views so snapshot and sync coordination can compare shard progress.

Flat-state status records whether a shard is disabled, empty, ready, or in a resharding phase, so restart code can resume from a known boundary. If a shard is created while a snapshot is active, the manager also holds its flat head so the new shard joins the same stable snapshot view. It can mark a shard that finished catch-up as ready before it creates the in-memory view needed by snapshot work.

References: core/…/manager.rs• L18-47 core/…/manager.rs• L59-102 core/…/manager.rs• L142-223 core/…/manager.rs• L230-276 core/…/manager.rs• L300-345 core/…/types.rs• L36-115 core/…/types.rs• L153-219

Flat-state lifecycle

Flat state follows the chain rather than replacing it. The lifecycle has four broad stages:

  1. The node records the genesis flat head for each tracked shard and writes the initial flat values while it builds genesis state from records.
  2. Chunk processing records a delta for each accepted block, including empty deltas that preserve the block path.
  3. A flat head update applies deltas to the durable flat map and removes deltas that are no longer needed.
  4. A block-specific view reads the durable map plus the remaining deltas for that block or fork.

The node initializes views for the current epoch and may prepare views for the next shard layout. If a required block is not reachable from the current flat head, the view reports that the block is not supported. A missing delta or other broken storage link is an internal storage error because the view can no longer guarantee correct state.

References: chain/…/flat_storage_init.rs• L8-30 chain/…/flat_storage_init.rs• L34-90 core/…/state_applier.rs• L141-161 core/…/storage.rs• L287-317 core/…/storage.rs• L340-425 core/…/types.rs• L35-57

State snapshots

A state snapshot is a read-only checkpoint of the flat-state data at an epoch boundary. It gives state-part generation and other state work a stable block view while the live node continues to process blocks.

The snapshot records its block identity and included shards. Creation keeps only the database columns needed for the checkpoint, opens the checkpoint in read-only mode after restart, and positions each included shard's flat view for state-part reads. A lock prevents deletion or replacement while a reader uses the snapshot.

References: core/…/state_snapshot.rs• L24-80 core/…/state_snapshot.rs• L82-136 core/…/state_snapshot.rs• L185-194 core/…/state_snapshot.rs• L196-220 core/…/disk.rs• L15-78 core/…/disk.rs• L80-123

Storage tiers and utilities

Hot and cold storage

NodeStorage presents the node's hot database and optional cold database as separate roles. A normal node uses hot storage. An archival node can use cold storage for old durable records and a split view that reads hot data first, then cold data for columns that belong in the archive.

Cold storage keeps archival records and does not behave like a writable working store. Reference counts are normalized there, and destructive operations are rejected or filtered. Resharding-aware migration copies the state records and shard-prefix mappings needed to keep old state readable after a shard split. At a resharding boundary it also handles rows whose keys use the next shard layout, so old chunk-producer and state records are not lost during migration.

Cloud storage is an optional archival role. Builds without the RocksDB feature keep the storage API available but cannot construct a cloud store, while in-memory test storage remains available.

References: core/…/mod.rs• L11-21 core/…/mod.rs• L35-43 core/…/mod.rs• L60-124 core/…/mod.rs• L150-185 core/…/colddb.rs• L7-16 core/…/colddb.rs• L39-96 core/…/splitdb.rs• L8-18 core/…/splitdb.rs• L56-100 core/…/cold_storage.rs• L41-76 core/…/cold_storage.rs• L144-169 core/…/cold_storage.rs• L196-305 core/…/mod.rs• L1-10 core/…/Cargo.toml• L94-103

Cloud archival

Cloud archival is an external durable tier for long-term chain and shard data. It packages block records, shard records, and epoch context into versioned compressed files. It also publishes state snapshot headers and parts so a reader can rebuild retained state without keeping the full local working database.

The archive uses progress heads for block data and for each shard. Local metadata tracks the writer's safe range and the reader's rebuilt range. Retrieval uses whole block or shard batches rather than repeated single-record requests. A batch contains one entry per height and uses an empty entry for a skipped slot. A shard batch can start after or end before the requested height when resharding adds or retires that shard.

Block batches carry the block context needed to rebuild chain indexes. Shard batches distinguish a new chunk from carried shard data and carry execution results, receipts, state changes, and chunk metadata. For the defined resharding gap, they can also carry the prior value of each changed key so a reader can restore the earlier state. The reader checks batch shape and archive configuration before it writes data locally.

The cloud connection context carries the archive location, credentials, and chain identifier. The current opener supports filesystem and GCS locations and rejects S3 locations until that backend is added.

The main archive objects are:

ObjectRole
Epoch dataEpoch context and the shard layout needed to interpret later records
Block batchBlock, header-related, Merkle, chain-link, chunk-producer, and chunk-hash data for a height range
Shard batchNew or carried chunk data, receipts, outcomes, state changes, chunk metadata, and optional inverse state changes for a shard and height range
State header and partsState-sync material for a shard at an epoch boundary
Archive heads and configurationShared completeness markers and the contract for the bucket

The cloud reader has an explicit set of retained database columns that it rebuilds from these objects and state snapshots. It skips node-local metadata and work records that a reader does not need. This classification keeps a new retained column from silently disappearing during cloud bootstrap.

When a reader advances its archive position, it updates the chain, final, and header heads to the same tip in one store update. Queries therefore resolve against data that the reader has already written as a complete unit.

References: core/…/cloud_archival_store.rs• L13-86 core/…/cloud_archival_store.rs• L138-148 core/…/config.rs• L10-45 core/…/opener.rs• L8-49 core/…/mod.rs• L30-110 core/…/mod.rs• L112-191 core/…/blocks.rs• L19-45 core/…/blocks.rs• L47-107 core/…/shards.rs• L23-86 core/…/shards.rs• L96-175 core/…/shards.rs• L253-287 core/…/shards.rs• L364-413 core/…/retrieve.rs• L12-31 core/…/retrieve.rs• L71-163

Database lifecycle

The storage opener makes database state safe to use across node starts and software upgrades. It checks whether the database exists, verifies its kind and version, keeps hot and cold versions aligned, and runs migrations only when the store is opened for writing. Read-only opens fail instead of changing an incompatible database.

The database kind distinguishes a garbage-collected working store, a full archive, and the hot or cold half of split archival storage. The current supported database version is 52, with versions 45 and newer accepted by this binary. The same lifecycle tools support checkpoints and state snapshots. A checkpoint can keep only selected logical columns, which makes a smaller working database for recovery or state work. Flush, compaction, statistics, and external sorted-file ingestion support the operational work needed to keep a large node store usable.

State snapshot databases use the same opener and migration path with a flag that lets migrations skip chain data that the reduced snapshot does not contain. This keeps snapshot restart and upgrade behavior separate from the full node database without creating a second storage lifecycle.

References: core/…/metadata.rs• L1-11 core/…/metadata.rs• L28-59 core/…/opener.rs• L58-163 core/…/opener.rs• L208-237 core/…/opener.rs• L311-441 core/…/opener.rs• L547-669 core/…/opener.rs• L795-875 core/…/mod.rs• L272-323 core/…/rocksdb.rs• L437-606 core/…/rocksdb.rs• L703-749

Read performance support

The store uses two complementary read aids. The database provides ordered column scans and per-column block caches. The store also caches deserialized records and invalidates affected entries when a write starts, so repeated chain and epoch reads do not repeatedly decode the same bytes.

Trie reads add a bounded per-shard cache for small nodes and values. The cache delays some evictions so fork processing can still find recently used old roots. Operators can also load selected shard tries into memory from flat state, then apply newer flat deltas while a flat-head hold keeps the base stable. In-memory tries retain roots for active blocks and can share frozen nodes across resharding views. Historical view reads use separate caches and do not use the normal block-processing memtries.

Receipt prefetching moves selected trie reads to bounded background I/O threads. The runtime submits keys through a shared API, while the prefetch staging area prevents duplicate reads and caps staged memory. A normal cache miss uses staged data when available and otherwise reads the database, so prefetching changes timing rather than state results.

Trie recording captures the nodes used by a read so the same access can run from partial storage. A recording budget can stop a read before a value that would exceed the limit. This supports state witnesses and bounded proof work without changing the canonical state root.

The database can keep returned values pinned in its own read buffer until the caller releases them. This reduces copying on hot read paths. Flat state improves the layout of common key lookups, while trie caching still supports canonical state reads and proof work. The two paths serve different needs: flat state favors frequent direct reads, and trie state preserves versioned and verifiable state.

The store also measures database operation latency and iterator lifetime. It can collect backend statistics for both hot and cold stores, and it supports bulk ingestion for sorted on-disk data. These facilities help operators find slow reads, long-lived iterators, compaction pressure, and large write preparation costs.

References: core/…/store.rs• L46-123 core/…/store.rs• L231-273 core/…/rocksdb.rs• L283-345 core/…/rocksdb.rs• L437-606 core/…/rocksdb.rs• L753-778 core/…/slice.rs• L48-105 core/…/rocks.rs• L14-49 core/…/config.rs• L33-63 core/…/config.rs• L254-273 core/…/config.rs• L19-65 core/…/trie_storage.rs• L53-80 core/…/trie_storage.rs• L137-187 core/…/trie_storage.rs• L241-290 core/…/trie_storage.rs• L415-605 core/…/prefetching_trie_storage.rs• L27-43 core/…/prefetching_trie_storage.rs• L93-119 core/…/prefetching_trie_storage.rs• L206-280 core/…/prefetching_trie_storage.rs• L382-475 core/…/shard_tries.rs• L137-220 core/…/shard_tries.rs• L260-289 core/…/shard_tries.rs• L491-649 core/…/loading.rs• L21-60 core/…/loading.rs• L101-202 core/…/memtries.rs• L23-81 core/…/memtries.rs• L101-182 core/…/memtries.rs• L268-331 core/…/trie_recording.rs• L16-41 core/…/trie_recording.rs• L116-229 core/…/trie_recording.rs• L231-271 core/…/update.rs• L153-164 core/…/mod.rs• L681-787 core/…/mod.rs• L1-15 docs/…/flat_storage.md• L71-101 core/…/finalize_bench.rs• L1-12 core/…/finalize_bench.rs• L36-83

Storage observability

Storage metrics expose the health and work level of the main persistence paths. They cover database operation latency, live backend iterators, hot and cold database statistics, flat-head distance and holds, resharding progress, state snapshots, state-part creation, trie-cache use, prefetch staging, and background memtrie loading.

The metrics loop exports backend statistics for the stores that a node has enabled. Flat-state and snapshot metrics show whether derived state can keep pace with chain processing and whether a stable checkpoint is holding resources. Trie cache, prefetch, and memtrie signals show whether memory and background I/O are reducing database work or adding pressure.

References: core/…/mod.rs• L16-25 core/…/mod.rs• L203-255 core/…/mod.rs• L369-467 core/…/mod.rs• L503-557 core/…/prefetching_trie_storage.rs• L121-133 core/…/trie_storage.rs• L83-90 core/…/trie_storage.rs• L438-450 core/…/shard_tries.rs• L10-13 core/…/shard_tries.rs• L612-643

Change checklist

When these files or sections are changed, remember to consider these:

  • A new or renamed database column needs matching key-shape, write-policy, garbage-collection, cold-storage, cloud-reader, and migration rules. A renamed enum variant must preserve the existing column-family name or provide a migration path.
  • A state write must keep trie records, trie changes, reference counts, and any flat-state delta in the same update boundary.
  • Genesis state roots must remain consistent with the shard layout and must not be committed before that check succeeds.
  • Genesis state application must keep account storage usage, receipt indexes, initial flat values, and per-shard state roots aligned.
  • A change to an epoch light-client view must add a stored-data version and migration path instead of changing the layout of existing rows.
  • Epoch sync proof changes must keep compressed storage compatible with the read path and preserve the proof's role as a durable sync boundary.
  • Epoch block-information reads must preserve the store cache's committed-row boundary and invalidation behavior when records are written or deleted.
  • EarlyKickout chunk-producer changes must keep the anchor-block and shard key aligned with historical resolver lookups and the feature activation boundary.
  • A change to hot, cold, or cloud placement must preserve split-store read precedence, archive completeness heads, and the set of columns that archival readers can rebuild.
  • A flat-head, delta, or snapshot change must preserve restart recovery, fork reachability, resharding status, state-part reads, and snapshot holds.
  • Flat-head hold changes must keep independent snapshot, background memtrie, and other task holds from releasing movement before every holder is finished.
  • A state-part format or validation change must keep byte and entry limits aligned with trie memory accounting before full decode or allocation.
  • A persistent receipt queue change must keep its cached indices, item keys, and single-active-view rule aligned for every queue type.
  • A contract deployment path must record local and global deployments for same-chunk reads while preserving their distinct final distribution paths. Late reads after tracker finalization must still use durable trie state, and discarded pipeline results must not affect the chunk.
  • A shard-prefix or resharding mapping change must cover both reads and cleanup so that live descendant state is not removed.
  • A cloud block or shard blob schema or batch-range change must preserve versioning, skipped-height handling, deterministic ordering, compression, validation, and inverse-state-change coverage for resharding gaps.
  • A SPICE execution-head or chunk-certification change must preserve forward-only progress and the link between a chunk and its certifying block.
  • A database version or kind change must keep hot and cold metadata aligned and must define whether a state snapshot contains enough columns for the migration.
  • A feature-gated RocksDB or cloud-storage change must keep the in-memory store build usable without those features.
  • A database read-path change must preserve reference-count stripping, pinned-slice lifetimes, ordered iteration, and iterator release behavior.
  • A change to the in-memory database must preserve the database contract, deterministic ordering, and the same reference-count visibility as the RocksDB backend.
  • A trie cache or prefetch change must preserve per-shard memory bounds, fork-safe eviction, duplicate-read suppression, and the ordering needed before a staged value is released.
  • A memtrie loading change must keep the flat-head hold alive through delta catch-up and keep parent-to-child views valid across resharding.
  • A state-witness recording change must keep disk, flat, memtrie, and recorded-storage reads within the same budget and access result.

Important failure modes

TriggerConsequenceGuard
Hot and cold stores have different versions or incompatible kindsThe node refuses to open the pairStore opening checks metadata and migrates both stores in lockstep
Genesis roots do not match the shard layoutThe node could start with a state assigned to the wrong shard shapeValidate the root count before committing genesis metadata
A block view is not reachable from the flat headThe read cannot use flat state for that blockReturn a block-not-supported error and let chain processing handle the fork case
A required flat delta is missingFlat state correctness is no longer guaranteedTreat it as an internal storage error rather than serving a guessed value
Flat values and the flat-head status are committed separatelyA restart can load a map and head that describe different statesCommit state changes, deltas, and head status as one database update
One flat-head holder releases while another task still needs a stable viewThe flat head can move during a snapshot or background state operationCount independent holds and advance only when the count reaches zero
A state part boundary or referenced trie value is missingThe node cannot make a state part that matches the state rootKeep boundary proof nodes and resolve referenced values from canonical trie state
A state part has too many entries even though its bytes fit the size limitValidation can use excessive memory before it rejects the partCheck the entry count before full deserialization and keep the limit tied to trie memory cost
An epoch light-client row uses an old or changed layout without a stored versionA read can fail to decode durable data from an earlier node versionStore a frozen versioned type and migrate old rows before normal reads
A required EarlyKickout chunk-producer row is absent or uses a mismatched anchor keyHistorical chunk-producer resolution cannot use the stored authoritative sampleWrite the row by anchor block and shard only when the feature's data is valid
A persistent queue index points to a missing itemReceipt or buffer processing sees inconsistent stateReturn a storage inconsistency error instead of silently skipping the item
Two mutable views update the same persistent queueCached indexes can disagree with queue itemsKeep one active queue view and use the scoped shard buffer access
A cloud bucket has a different configuration or an invalid batch shapeUpload or retrieval stops instead of creating an inconsistent archiveValidate the bucket configuration and batch length before use
A cloud reader advances its position without moving query heads with the written dataQueries can resolve against a head whose records are incompleteCommit reader progress and all chain heads in one store update
An out-of-order SPICE update lowers an execution headLater chain work can appear to be unexecuted or uncertifiedAdvance execution heads only when the new height is higher
A shard batch does not cover the requested height after a shard is added or retiredThe reader cannot provide shard data for that heightTreat the range as no shard data and require callers to handle resharding boundaries
A retained database column is neither rebuilt nor marked as skipped for cloud bootstrapA cloud reader can open without data needed for its retained-store contractClassify each retained column in exactly one cloud-reader category
A delete or reference-count operation uses the wrong column policyThe node can panic or corrupt shared dataUse adapter update methods that enforce insert-only and reference-count rules
A pinned database slice outlives its database or a long-lived iterator remains openReads can become invalid or old files can stay live and disk use can growKeep slice ownership and iterator lifetimes within the database scope
A read-only open finds an unsupported database versionThe node cannot safely use the storeRequire a compatible version or perform migration in read-write mode
RocksDB direct I/O is enabled on a file system that does not support itThe database fails to open or operateDisable direct I/O for flush and compaction in the matching store configuration
A trie cache exceeds its intended value or memory boundsLarge values or fork activity can displace useful state and increase database readsDo not cache oversized values and apply per-shard limits with delayed eviction
A prefetch slot is released before the value enters the shard cacheAnother reader can start a duplicate fetch or wait on a slot that no longer owns the valueRelease a staged value only after the main read inserts it into the cache
Background memtrie loading finishes without retaining its flat-head hold through catch-upThe in-memory view can miss deltas written during the loadHold the flat head until catch-up and activation finish
A recording budget counts flat or in-memory reads differently from trie replayA witness producer and validator can stop at different readsRecord canonical paths and apply the same budget checks before value fetches
A contract tracker is finalized while a pipeline task tries to use its temporary deployment viewThe late task could read a stale temporary deployment, but its result is not part of the completed chunkFall back to durable trie storage after finalization and discard pipeline work that finishes after chunk apply

Key files

FileWhy to read it
core/…/Cargo.tomlUnderstand which builds provide on-disk RocksDB and cloud archival versus in-memory storage
core/…/lib.rsSee the public storage surface shared by node components and embedders
core/…/config.rsUnderstand store, cache, prefetch, and database tuning controls
core/…/store.rsUnderstand the common read, update, cache, flush, and compaction boundary
core/…/mod.rsSee how domain adapters share one store and one pending update
core/…/columns.rsSee the logical data groups and the policies that govern their lifetime and archival placement
core/…/mod.rsUnderstand the database contract, atomic operations, scans, checkpoints, and bulk loading boundary
core/…/refcount.rsUnderstand shared-value lifetime and how reference-counted reads hide dead values
core/…/slice.rsUnderstand the byte-slice boundary returned by database reads
core/…/rocks.rsSee how on-disk reads retain backend-owned buffers without an immediate copy
core/…/rocksdb.rsUnderstand ordered reads, write batches, caches, compaction, and backend statistics
core/…/testdb.rsUnderstand the deterministic in-memory database used to exercise storage behavior without disk I/O
core/…/finalize_bench.rsSee the performance boundary for preparing large chunk writes before commit
core/…/chain_store.rsFollow durable block, head, receipt, outcome, and execution-progress records
core/…/light_client_block.rsSee the versioned durable form used for epoch light-client records
core/…/epoch_store.rsFollow epoch context, cached block information, epoch-sync proof, and EarlyKickout chunk-producer storage
core/…/chunk_store.rsFollow durable chunks, chunk execution metadata, witnesses, and contract-access records
core/…/trie_store.rsFollow canonical trie bytes, state roots, reference counts, and shard mappings
core/…/mod.rsUnderstand trie lookup modes, proof-aware reads, and the state-change boundary
core/…/iterator.rsCompare ordered traversal over disk tries and memtries
core/…/iter.rsUnderstand seeks, pruning, and state-part traversal over trie nodes
core/…/config.rsSee how store settings become trie cache and prefetch behavior
core/…/trie_storage.rsUnderstand trie caches, direct reads, staged values, and new-node overlays
core/…/prefetching_trie_storage.rsUnderstand bounded background trie reads and staging coordination
core/…/shard_tries.rsFollow per-shard trie selection, memtrie loading, resharding views, and trie change application
core/…/loading.rsFollow flat-state loading and delta catch-up for in-memory tries
core/…/memtries.rsUnderstand in-memory roots, sharing, expiry, and root pins
core/…/trie_recording.rsUnderstand state-witness capture, proof size accounting, and replay storage
core/…/update.rsFollow pending state changes from reads and writes to finalized trie changes
core/…/iterator.rsSee how pending trie updates overlay ordered committed-state iteration
core/…/mod.rsSee the typed trie access, queue, account, receipt, and update helpers used by execution state
core/…/receipts_column_helper.rsUnderstand persistent delayed-receipt and outgoing-receipt queues
core/…/initialization.rsUnderstand genesis state sources, shard-layout checks, and root persistence
core/…/state_applier.rsUnderstand how genesis records become trie and initial flat-state changes
core/…/state_parts.rsUnderstand how canonical and flat state become verifiable state parts
core/…/state_part.rsUnderstand state-part size and entry limits before decoding
core/…/storage.rsUnderstand flat heads, fork-aware reads, delta application, holds, and atomic movement
core/…/manager.rsUnderstand per-shard coordination, startup, snapshot holds, progress reporting, and resharding
core/…/delta.rsUnderstand the state-change unit used to advance a flat view
core/…/types.rsUnderstand flat-state readiness and resharding progress
core/…/flat_store.rsSee how flat values, deltas, and status cross the database boundary
core/…/contract.rsUnderstand same-chunk contract reads, temporary deployment tracking, finalization fallback, rollback, and distribution
core/…/state_snapshot.rsUnderstand stable flat-state checkpoints used for state work
core/…/disk.rsUnderstand snapshot checkpoint creation, selected columns, and restart opening
core/…/mod.rsUnderstand hot, cold, split, cloud, and recovery store roles
core/…/opener.rsUnderstand version checks, lockstep migrations, checkpoints, and state snapshots
core/…/cold_storage.rsUnderstand migration of old records and state across cold-storage boundaries
core/…/mod.rsUnderstand the feature boundary for cloud archival
core/…/config.rsUnderstand cloud archive location, credentials, chain identity, and role configuration
core/…/opener.rsUnderstand supported external archive locations and connection setup
core/…/mod.rsUnderstand the external archive boundary, batch access, and the columns a cloud reader rebuilds
core/…/blocks.rsUnderstand the chain records and skipped heights packaged in block batches
core/…/shards.rsUnderstand new versus carried shard data and inverse state changes
core/…/archive.rsUnderstand archive packaging, progress publication, and bucket checks
core/…/retrieve.rsUnderstand archive listing, batch retrieval, decompression, and validation
core/…/file_id.rsUnderstand the stable layout of archive objects
core/…/metadata.rsUnderstand database kind, supported versions, and metadata invariants
core/…/mod.rsUnderstand storage health signals for databases, flat state, snapshots, state parts, and trie read aids
core/…/test_utils.rsSee the in-memory store and flat-state fixtures used to validate storage behavior
core/…/archive.rsSee the test setups for hot, cold, split, and cloud archival roles
chain/…/flat_storage_init.rsSee how chain startup restores flat views for current and next shard layouts