stratus/eth/storage/permanent/rocks/
mod.rs1use std::fmt::Debug;
4
5use anyhow::Context;
6pub use rocks_permanent::RocksPermanentStorage;
7pub use rocks_state::RocksStorageState;
8use serde::Deserialize;
9use serde::Serialize;
10
11use crate::eth::storage::permanent::rocks::types::AddressRocksdb;
12use crate::eth::storage::permanent::rocks::types::BlockNumberRocksdb;
13use crate::eth::storage::permanent::rocks::types::SlotIndexRocksdb;
14
15mod rocks_permanent;
17
18pub mod rocks_state;
20
21pub mod cf_versions;
23
24mod rocks_cf;
26
27pub mod rocks_config;
29
30pub mod rocks_db;
32
33pub mod types;
35
36impl SerializeDeserializeWithContext for (AddressRocksdb, BlockNumberRocksdb) {}
38impl SerializeDeserializeWithContext for (AddressRocksdb, SlotIndexRocksdb) {}
39impl SerializeDeserializeWithContext for (AddressRocksdb, SlotIndexRocksdb, BlockNumberRocksdb) {}
40
41pub trait SerializeDeserializeWithContext {
42 fn deserialize_with_context(bytes: &[u8]) -> anyhow::Result<Self>
43 where
44 Self: for<'de> Deserialize<'de> + bincode::Decode<()>,
45 {
46 use crate::rocks_bincode_config;
47 let (result, _) = bincode::decode_from_slice(bytes, rocks_bincode_config())
48 .with_context(|| format!("failed to deserialize '{}'", hex_fmt::HexFmt(bytes)))
49 .with_context(|| format!("failed to deserialize to type '{}'", std::any::type_name::<Self>()))?;
50 Ok(result)
51 }
52
53 fn serialize_with_context(input: &Self) -> anyhow::Result<Vec<u8>>
54 where
55 Self: Serialize + Debug + bincode::Encode,
56 {
57 use crate::rocks_bincode_config;
58 bincode::encode_to_vec(input, rocks_bincode_config()).with_context(|| format!("failed to serialize '{input:?}'"))
59 }
60}