stratus/eth/storage/permanent/rocks/
mod.rs1use std::fmt::Debug;
4
5use anyhow::Context;
6pub use rocks_cf_cache_config::RocksCfCacheConfig;
7pub use rocks_permanent::RocksPermanentStorage;
8pub use rocks_state::RocksStorageState;
9use serde::Deserialize;
10use serde::Serialize;
11
12use crate::eth::storage::permanent::rocks::types::AddressRocksdb;
13use crate::eth::storage::permanent::rocks::types::BlockNumberRocksdb;
14use crate::eth::storage::permanent::rocks::types::SlotIndexRocksdb;
15
16mod rocks_permanent;
18
19pub mod rocks_state;
21
22pub mod cf_versions;
24
25mod rocks_cf;
27
28pub mod rocks_config;
30
31pub mod rocks_cf_cache_config;
33
34pub mod rocks_db;
36
37pub mod types;
39
40#[cfg(test)]
42pub mod test_utils;
43
44impl SerializeDeserializeWithContext for (AddressRocksdb, BlockNumberRocksdb) {}
46impl SerializeDeserializeWithContext for (AddressRocksdb, SlotIndexRocksdb) {}
47impl SerializeDeserializeWithContext for (AddressRocksdb, SlotIndexRocksdb, BlockNumberRocksdb) {}
48
49pub trait SerializeDeserializeWithContext {
50 fn deserialize_with_context(bytes: &[u8]) -> anyhow::Result<Self>
51 where
52 Self: for<'de> Deserialize<'de> + bincode::Decode<()>,
53 {
54 use crate::rocks_bincode_config;
55 let (result, _) = bincode::decode_from_slice(bytes, rocks_bincode_config())
56 .with_context(|| format!("failed to deserialize '{}'", hex_fmt::HexFmt(bytes)))
57 .with_context(|| format!("failed to deserialize to type '{}'", std::any::type_name::<Self>()))?;
58 Ok(result)
59 }
60
61 fn serialize_with_context(input: &Self) -> anyhow::Result<Vec<u8>>
62 where
63 Self: Serialize + Debug + bincode::Encode,
64 {
65 use crate::rocks_bincode_config;
66 bincode::encode_to_vec(input, rocks_bincode_config()).with_context(|| format!("failed to serialize '{input:?}'"))
67 }
68}