hypercall_db/traits/
validator_rsm.rs1use anyhow::Result;
2use async_trait::async_trait;
3
4use crate::{
5 NewRsmBlockCommand, NewRsmBlockHeader, NewValidatorRsmRootSummary, RsmBlockCommand,
6 RsmBlockData, RsmBlockView, ValidatorRsmCurrentState, ValidatorRsmEnvironment,
7 ValidatorRsmRootSummary,
8};
9
10pub trait ValidatorRsmStateReader: Send + Sync {
11 fn get_validator_rsm_root_summary_sync(
12 &self,
13 environment: ValidatorRsmEnvironment,
14 version: u64,
15 ) -> Result<Option<ValidatorRsmRootSummary>>;
16
17 fn get_validator_rsm_current_state_sync(
18 &self,
19 environment: ValidatorRsmEnvironment,
20 ) -> Result<Option<ValidatorRsmCurrentState>>;
21
22 fn get_validator_rsm_current_root_summary_sync(
23 &self,
24 environment: ValidatorRsmEnvironment,
25 ) -> Result<Option<ValidatorRsmRootSummary>>;
26
27 fn get_rsm_block_by_height_sync(
28 &self,
29 environment: ValidatorRsmEnvironment,
30 height: u64,
31 ) -> Result<Option<RsmBlockView>>;
32
33 fn get_rsm_block_by_hash_sync(
34 &self,
35 environment: ValidatorRsmEnvironment,
36 hash: [u8; 32],
37 ) -> Result<Option<RsmBlockView>>;
38
39 fn get_latest_rsm_block_sync(
40 &self,
41 environment: ValidatorRsmEnvironment,
42 ) -> Result<Option<RsmBlockView>>;
43
44 fn list_rsm_blocks_sync(
45 &self,
46 environment: ValidatorRsmEnvironment,
47 from_height: Option<u64>,
48 limit: u32,
49 ) -> Result<Vec<RsmBlockView>>;
50
51 fn get_rsm_block_commands_sync(
52 &self,
53 environment: ValidatorRsmEnvironment,
54 height: u64,
55 ) -> Result<Vec<RsmBlockCommand>>;
56
57 fn get_rsm_block_data_sync(
58 &self,
59 environment: ValidatorRsmEnvironment,
60 height: u64,
61 ) -> Result<Option<RsmBlockData>> {
62 let Some(block) = self.get_rsm_block_by_height_sync(environment, height)? else {
63 return Ok(None);
64 };
65 let commands = self.get_rsm_block_commands_sync(environment, height)?;
66 Ok(Some(RsmBlockData { block, commands }))
67 }
68}
69
70#[async_trait]
71pub trait ValidatorRsmStateAsyncReader: Send + Sync {
72 async fn get_validator_rsm_root_summary(
73 &self,
74 environment: ValidatorRsmEnvironment,
75 version: u64,
76 ) -> Result<Option<ValidatorRsmRootSummary>>;
77
78 async fn get_validator_rsm_current_state(
79 &self,
80 environment: ValidatorRsmEnvironment,
81 ) -> Result<Option<ValidatorRsmCurrentState>>;
82
83 async fn get_validator_rsm_current_root_summary(
84 &self,
85 environment: ValidatorRsmEnvironment,
86 ) -> Result<Option<ValidatorRsmRootSummary>>;
87
88 async fn get_rsm_block_by_height(
89 &self,
90 environment: ValidatorRsmEnvironment,
91 height: u64,
92 ) -> Result<Option<RsmBlockView>>;
93
94 async fn get_rsm_block_by_hash(
95 &self,
96 environment: ValidatorRsmEnvironment,
97 hash: [u8; 32],
98 ) -> Result<Option<RsmBlockView>>;
99
100 async fn get_latest_rsm_block(
101 &self,
102 environment: ValidatorRsmEnvironment,
103 ) -> Result<Option<RsmBlockView>>;
104
105 async fn list_rsm_blocks(
106 &self,
107 environment: ValidatorRsmEnvironment,
108 from_height: Option<u64>,
109 limit: u32,
110 ) -> Result<Vec<RsmBlockView>>;
111
112 async fn get_rsm_block_commands(
113 &self,
114 environment: ValidatorRsmEnvironment,
115 height: u64,
116 ) -> Result<Vec<RsmBlockCommand>>;
117
118 async fn get_rsm_block_data(
119 &self,
120 environment: ValidatorRsmEnvironment,
121 height: u64,
122 ) -> Result<Option<RsmBlockData>> {
123 let Some(block) = self.get_rsm_block_by_height(environment, height).await? else {
124 return Ok(None);
125 };
126 let commands = self.get_rsm_block_commands(environment, height).await?;
127 Ok(Some(RsmBlockData { block, commands }))
128 }
129}
130
131pub trait ValidatorRsmStateWriter: ValidatorRsmStateReader {
132 fn save_validator_rsm_root_summary_sync(
133 &self,
134 summary: &NewValidatorRsmRootSummary,
135 advance_current: bool,
136 ) -> Result<()>;
137
138 fn save_rsm_block_header_sync(&self, block: &NewRsmBlockHeader) -> Result<()>;
139
140 fn save_rsm_block_commands_sync(&self, commands: &[NewRsmBlockCommand]) -> Result<()>;
141}