Skip to main content

tenzro_storage/
lib.rs

1//! State storage layer for Tenzro Network
2//!
3//! This crate provides the storage infrastructure for the Tenzro Network blockchain,
4//! including:
5//!
6//! - **Key-Value Store**: Abstract storage layer with RocksDB and in-memory implementations
7//! - **Merkle Patricia Trie**: Efficient state commitment and proof generation
8//! - **Block Storage**: Indexing and retrieval of blocks by hash and height
9//! - **Account Storage**: Management of account state and balances
10//! - **Snapshots**: State snapshot creation and restoration
11//!
12//! # Architecture
13//!
14//! The storage layer uses RocksDB with multiple column families to organize different
15//! data types. It provides async/await interfaces for all storage operations.
16//!
17//! # Example
18//!
19//! ```rust,no_run
20//! use tenzro_storage::{
21//!     config::StorageConfig,
22//!     kv::{RocksDbStore, MemoryStore},
23//!     block_store::BlockStoreImpl,
24//!     account_store::AccountStoreImpl,
25//!     traits::{BlockStore, AccountStore},
26//! };
27//! use std::sync::Arc;
28//! use std::path::PathBuf;
29//!
30//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
31//! // Create a storage configuration
32//! let config = StorageConfig::new(PathBuf::from("./data/tenzro-db"));
33//!
34//! // Open the RocksDB store
35//! let kv_store = Arc::new(RocksDbStore::open(&config)?);
36//!
37//! // Create block and account stores
38//! let block_store = BlockStoreImpl::new(kv_store.clone())?;
39//! let account_store = AccountStoreImpl::new(kv_store.clone());
40//!
41//! // Use the stores...
42//! # Ok(())
43//! # }
44//! ```
45
46pub mod config;
47pub mod error;
48pub mod traits;
49pub mod kv;
50pub mod merkle;
51pub mod block_store;
52pub mod account_store;
53pub mod snapshot;
54pub mod da;
55
56// Re-export commonly used types
57pub use config::StorageConfig;
58pub use error::{Result, StorageError};
59pub use traits::{AccountStore, BlockStore, StateStore};
60pub use kv::{KvStore, RocksDbStore, MemoryStore, WriteOp, CF_BLOCKS, CF_STATE, CF_ACCOUNTS, CF_TRANSACTIONS, CF_METADATA, CF_SNAPSHOTS, CF_IDENTITIES, CF_DELEGATIONS, CF_CREDENTIALS, CF_CHANNELS, CF_AGENTS, CF_MODELS, CF_PROVIDERS, CF_TASKS, CF_AGENT_TEMPLATES, CF_SKILLS, CF_TOOLS, CF_KNOWLEDGE, CF_WORKFLOW_TEMPLATES, CF_TOKENS, CF_SETTLEMENTS, CF_MODEL_SERVICES, CF_NFTS, CF_EVENTS, CF_WEBHOOKS, CF_COMPLIANCE, CF_TRAINING_RUNS, CF_TRAINING_RECEIPTS, CF_AUDIT, CF_APPROVALS, CF_API_KEYS, CF_MPC_KEYSHARES, CF_CANTON_ANALYTICS, CF_BRIDGE_ANALYTICS, CF_VALIDATOR_MODULES};
61pub use merkle::{MerklePatriciaTrie, MerkleProof, ProofNode};
62pub use block_store::BlockStoreImpl;
63pub use account_store::{AccountStoreImpl, StateStoreImpl};
64pub use snapshot::{Snapshot, SnapshotManager, SnapshotMetadata, CompressionType, SnapshotRestorer, RestoredState, SnapshotEntry, serialize_snapshot_entries};
65pub use da::{
66    compute_commitment, DaBackend, DaBackendId, DaBackendStatus, DaPointer, InlineFallbackBackend,
67    MandateRef, ReceiptEnvelope, ReceiptKind, ReceiptStorageMode, ReceiptSummary,
68};
69#[cfg(feature = "celestia")]
70pub use da::CelestiaBackend;
71
72/// Storage version for compatibility tracking
73pub const STORAGE_VERSION: u32 = 1;
74
75/// Maximum cache size for the storage layer (in bytes)
76pub const MAX_CACHE_SIZE: usize = 1024 * 1024 * 1024; // 1 GB
77
78/// Default snapshot retention count
79pub const DEFAULT_SNAPSHOT_RETENTION: u64 = 100;
80
81#[cfg(test)]
82mod tests {
83    use super::*;
84
85    #[test]
86    fn test_storage_version() {
87        assert_eq!(STORAGE_VERSION, 1);
88    }
89}