1#![warn(missing_debug_implementations, missing_docs, bare_trait_objects)]
5#![warn(clippy::all, clippy::pedantic)]
6#![allow(
7 clippy::must_use_candidate,
8 clippy::module_name_repetitions,
9 clippy::doc_markdown )]
11
12use std::{cell::RefCell, collections::HashMap, fmt, rc::Rc};
13
14use zksync_types::{
15 get_known_code_key,
16 storage::{StorageKey, StorageValue},
17 H256,
18};
19
20pub use self::{
21 cache::sequential_cache::SequentialCache,
22 catchup::{AsyncCatchupTask, RocksdbCell},
23 in_memory::InMemoryStorage,
25 in_memory::IN_MEMORY_STORAGE_DEFAULT_NETWORK_ID,
26 postgres::{PostgresStorage, PostgresStorageCaches, PostgresStorageCachesTask},
27 rocksdb::{
28 RocksdbStorage, RocksdbStorageBuilder, RocksdbStorageOptions, StateKeeperColumnFamily,
29 },
30 shadow_storage::ShadowStorage,
31 storage_factory::{BatchDiff, PgOrRocksdbStorage, ReadStorageFactory, RocksdbWithMemory},
32 storage_view::{StorageView, StorageViewCache, StorageViewMetrics},
33 witness::WitnessStorage,
34};
35
36mod cache;
37mod catchup;
38mod in_memory;
39mod postgres;
40mod rocksdb;
41mod shadow_storage;
42mod storage_factory;
43mod storage_view;
44#[cfg(test)]
45mod test_utils;
46mod witness;
47
48pub trait ReadStorage: fmt::Debug {
50 fn read_value(&mut self, key: &StorageKey) -> StorageValue;
52
53 fn is_write_initial(&mut self, key: &StorageKey) -> bool;
58
59 fn load_factory_dep(&mut self, hash: H256) -> Option<Vec<u8>>;
61
62 fn is_bytecode_known(&mut self, bytecode_hash: &H256) -> bool {
64 let code_key = get_known_code_key(bytecode_hash);
65 self.read_value(&code_key) != H256::zero()
66 }
67
68 fn get_enumeration_index(&mut self, key: &StorageKey) -> Option<u64>;
70}
71
72pub trait WriteStorage: ReadStorage {
76 fn read_storage_keys(&self) -> &HashMap<StorageKey, StorageValue>;
78
79 fn set_value(&mut self, key: StorageKey, value: StorageValue) -> StorageValue;
81
82 fn modified_storage_keys(&self) -> &HashMap<StorageKey, StorageValue>;
84
85 fn missed_storage_invocations(&self) -> usize;
88}
89
90pub type StoragePtr<S> = Rc<RefCell<S>>;