pos_ledger_db/schema/
mod.rs1use anyhow::{ensure, Result};
15
16use schemadb::ColumnFamilyName;
17
18pub(crate) mod block_by_epoch_and_round;
19pub(crate) mod committed_block;
20pub(crate) mod committed_block_by_view;
21pub(crate) mod epoch_by_version;
22pub(crate) mod event;
23pub(crate) mod event_accumulator;
24pub(crate) mod ledger_info;
25pub(crate) mod ledger_info_by_block;
26pub(crate) mod ledger_info_by_voted_block;
27pub(crate) mod pos_state;
28pub(crate) mod reward_event;
29pub(crate) mod transaction;
30pub(crate) mod transaction_accumulator;
31pub(crate) mod transaction_info;
32
33pub const EPOCH_BY_VERSION_CF_NAME: ColumnFamilyName = "epoch_by_version";
34pub const EVENT_ACCUMULATOR_CF_NAME: ColumnFamilyName = "event_accumulator";
35pub const EVENT_CF_NAME: ColumnFamilyName = "event";
36pub const TRANSACTION_CF_NAME: ColumnFamilyName = "transaction";
37pub const TRANSACTION_ACCUMULATOR_CF_NAME: ColumnFamilyName =
38 "transaction_accumulator";
39pub const EVENT_BY_KEY_CF_NAME: ColumnFamilyName = "event_by_key";
43pub const EVENT_BY_VERSION_CF_NAME: ColumnFamilyName = "event_by_version";
44pub const JELLYFISH_MERKLE_NODE_CF_NAME: ColumnFamilyName =
45 "jellyfish_merkle_node";
46pub const LEDGER_COUNTERS_CF_NAME: ColumnFamilyName = "ledger_counters";
47pub const STALE_NODE_INDEX_CF_NAME: ColumnFamilyName = "stale_node_index";
48pub const TRANSACTION_BY_ACCOUNT_CF_NAME: ColumnFamilyName =
49 "transaction_by_account";
50pub const TRANSACTION_INFO_CF_NAME: ColumnFamilyName = "transaction_info";
51pub const LEDGER_INFO_BY_BLOCK_CF_NAME: ColumnFamilyName =
52 "ledger_info_by_block";
53pub const POS_STATE_CF_NAME: ColumnFamilyName = "pos_state";
54pub const REWARD_EVENT_CF_NAME: ColumnFamilyName = "reward_event";
55pub const COMMITTED_BLOCK_CF_NAME: ColumnFamilyName = "committed_block";
56pub const COMMITTED_BLOCK_BY_VIEW_CF_NAME: ColumnFamilyName =
57 "committed_block_by_view";
58pub const LEDGER_INFO_BY_VOTED_BLOCK_CF_NAME: ColumnFamilyName =
59 "ledger_info_by_voted_block";
60pub const BLOCK_BY_EPOCH_AND_ROUND_CF_NAME: ColumnFamilyName =
61 "block_by_epoch_and_round";
62
63fn ensure_slice_len_eq(data: &[u8], len: usize) -> Result<()> {
64 ensure!(
65 data.len() == len,
66 "Unexpected data len {}, expected {}.",
67 data.len(),
68 len,
69 );
70 Ok(())
71}
72
73#[cfg(feature = "fuzzing")]
74pub mod fuzzing {
75 use schemadb::schema::{KeyCodec, Schema, ValueCodec};
76
77 macro_rules! decode_key_value {
78 ($schema_type: ty, $data: ident) => {
79 <<$schema_type as Schema>::Key as KeyCodec<$schema_type>>::decode_key($data);
80 <<$schema_type as Schema>::Value as ValueCodec<$schema_type>>::decode_value($data);
81 };
82 }
83
84 pub fn fuzz_decode(data: &[u8]) {
85 #[allow(unused_must_use)]
86 {
87 decode_key_value!(
88 super::epoch_by_version::EpochByVersionSchema,
89 data
90 );
91 decode_key_value!(super::event::EventSchema, data);
92 decode_key_value!(
93 super::event_accumulator::EventAccumulatorSchema,
94 data
95 );
96 decode_key_value!(super::ledger_info::LedgerInfoSchema, data);
97 decode_key_value!(super::transaction::TransactionSchema, data);
98 decode_key_value!(
99 super::transaction_accumulator::TransactionAccumulatorSchema,
100 data
101 );
102 decode_key_value!(
103 super::transaction_info::TransactionInfoSchema,
104 data
105 );
106 }
107 }
108}