Skip to content

Commit 18314c8

Browse files
authored
docs: add more documentation for the Store API (#55)
* docs: update Store documentation * docs: add more documentation on the storage crate
1 parent ec48acc commit 18314c8

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

crates/storage/src/api/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
//! Storage backend API.
2+
//!
3+
//! This module defines the traits and types for pluggable storage backends.
4+
//!
5+
//! # Traits
6+
//!
7+
//! - [`StorageBackend`]: Main trait for storage implementations. Creates read views and write batches.
8+
//! - [`StorageReadView`]: Read-only access to storage via `get` and `prefix_iterator`.
9+
//! - [`StorageWriteBatch`]: Batched writes with atomic `commit`.
10+
//!
11+
//! # Tables
12+
//!
13+
//! Storage is organized into [`Table`]s, each storing a different type of data.
14+
//! All keys and values are byte slices (`&[u8]` / `Vec<u8>`).
15+
116
mod tables;
217
mod traits;
318

crates/storage/src/api/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ pub type Error = Box<dyn std::error::Error + Send + Sync>;
66
/// Result type for prefix iterator operations.
77
pub type PrefixResult = Result<(Box<[u8]>, Box<[u8]>), Error>;
88

9-
/// A storage backend that can create read views and write batches.
9+
/// A storage backend that can read and write data through views and batches.
1010
pub trait StorageBackend: Send + Sync {
11-
/// Begin a read-only transaction.
11+
/// Begin a read-only view.
1212
fn begin_read(&self) -> Result<Box<dyn StorageReadView + '_>, Error>;
1313

1414
/// Begin a write batch.

crates/storage/src/backend/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Storage backend implementations.
2+
//!
3+
//! This module provides concrete implementations of the [`crate::api::StorageBackend`] trait.
4+
//!
5+
//! # Backends
6+
//!
7+
//! - [`InMemoryBackend`]: Thread-safe in-memory storage using `RwLock<HashMap>`.
8+
//! Suitable for testing and ephemeral nodes. Data is lost on restart.
9+
110
mod in_memory;
211

312
pub use in_memory::InMemoryBackend;

crates/storage/src/store.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ impl ForkCheckpoints {
5252

5353
// ============ Metadata Keys ============
5454

55+
/// Key for "time" field of the Store. Its value has type [`u64`] and it's SSZ-encoded.
5556
const KEY_TIME: &[u8] = b"time";
57+
/// Key for "config" field of the Store. Its value has type [`ChainConfig`] and it's SSZ-encoded.
5658
const KEY_CONFIG: &[u8] = b"config";
59+
/// Key for "head" field of the Store. Its value has type [`H256`] and it's SSZ-encoded.
5760
const KEY_HEAD: &[u8] = b"head";
61+
/// Key for "safe_target" field of the Store. Its value has type [`H256`] and it's SSZ-encoded.
5862
const KEY_SAFE_TARGET: &[u8] = b"safe_target";
63+
/// Key for "latest_justified" field of the Store. Its value has type [`Checkpoint`] and it's SSZ-encoded.
5964
const KEY_LATEST_JUSTIFIED: &[u8] = b"latest_justified";
65+
/// Key for "latest_finalized" field of the Store. Its value has type [`Checkpoint`] and it's SSZ-encoded.
6066
const KEY_LATEST_FINALIZED: &[u8] = b"latest_finalized";
6167

6268
// ============ Key Encoding Helpers ============
@@ -76,20 +82,8 @@ fn decode_signature_key(bytes: &[u8]) -> SignatureKey {
7682
(validator_id, root)
7783
}
7884

79-
/// Forkchoice store tracking chain state and validator attestations.
80-
///
81-
/// This is the "local view" that a node uses to run LMD GHOST. It contains:
82-
///
83-
/// - which blocks and states are known,
84-
/// - which checkpoints are justified and finalized,
85-
/// - which block is currently considered the head,
86-
/// - and, for each validator, their latest attestation that should influence fork choice.
87-
///
88-
/// The `Store` is updated whenever:
89-
/// - a new block is processed,
90-
/// - an attestation is received (via a block or gossip),
91-
/// - an interval tick occurs (activating new attestations),
92-
/// - or when the head is recomputed.
85+
/// Underlying storage of the node.
86+
/// Similar to the spec's `Store`, but backed by a pluggable storage backend.
9387
///
9488
/// All data is stored in the backend. Metadata fields (time, config, head, etc.)
9589
/// are stored in the Metadata table with their field name as the key.

0 commit comments

Comments
 (0)