massa_final_state/
controller_trait.rs

1use massa_async_pool::AsyncPool;
2use massa_db_exports::{DBBatch, ShareableMassaDBController};
3use massa_deferred_calls::DeferredCallRegistry;
4use massa_executed_ops::ExecutedDenunciations;
5use massa_hash::Hash;
6use massa_ledger_exports::LedgerController;
7use massa_models::{operation::OperationId, slot::Slot};
8use massa_pos_exports::{PoSFinalState, PosError};
9use massa_versioning::versioning::MipStore;
10
11use crate::{FinalStateError, StateChanges};
12
13/// Trait for final state controller.
14#[cfg_attr(feature = "test-exports", mockall::automock)]
15pub trait FinalStateController: Send + Sync {
16    /// Get the fingerprint (hash) of the final state.
17    /// Note that only one atomic write per final slot occurs, so this can be safely queried at any time.
18    fn get_fingerprint(&self) -> Hash;
19
20    /// Get the slot at the end of which the final state is attached
21    fn get_slot(&self) -> Slot;
22
23    /// Gets the hash of the execution trail
24    fn get_execution_trail_hash(&self) -> Hash;
25
26    /// Reset the final state to the initial state.
27    ///
28    /// USED ONLY FOR BOOTSTRAP
29    fn reset(&mut self);
30
31    /// Performs the initial draws.
32    fn compute_initial_draws(&mut self) -> Result<(), FinalStateError>;
33
34    /// Applies changes to the execution state at a given slot, and settles that slot forever.
35    /// Once this is called, the state is attached at the output of the provided slot.
36    ///
37    /// Panics if the new slot is not the one coming just after the current one.
38    fn finalize(
39        &mut self,
40        slot: Slot,
41        changes: StateChanges,
42        network_versions: Option<(u32, Option<u32>)>,
43    );
44
45    /// After bootstrap or load from disk, recompute all the caches.
46    fn recompute_caches(&mut self);
47
48    /// Deserialize the entire DB and check the data. Useful to check after bootstrap.
49    fn is_db_valid(&self) -> bool;
50
51    /// Initialize the execution trail hash to zero.
52    fn init_execution_trail_hash_to_batch(&mut self, batch: &mut DBBatch);
53
54    /// Get ledger
55    #[allow(clippy::borrowed_box)]
56    fn get_ledger(&self) -> &Box<dyn LedgerController>;
57
58    /// Get ledger mut
59    fn get_ledger_mut(&mut self) -> &mut Box<dyn LedgerController>;
60
61    /// Get async pool
62    fn get_async_pool(&self) -> &AsyncPool;
63
64    /// Get pos state
65    fn get_pos_state(&self) -> &PoSFinalState;
66
67    /// Get pos state mut
68    fn get_pos_state_mut(&mut self) -> &mut PoSFinalState;
69
70    /// Load initial deferred credits from file, using the ledger to skip credits
71    /// that could not be applied at execution time.
72    fn load_initial_deferred_credits(&mut self, batch: &mut DBBatch) -> Result<(), PosError>;
73
74    /// check if an operation is in the executed ops
75    fn executed_ops_contains(&self, op_id: &OperationId) -> bool;
76
77    /// Get the executed status ops
78    fn get_ops_exec_status(&self, batch: &[OperationId]) -> Vec<Option<bool>>;
79
80    /// Get executed denunciations
81    fn get_executed_denunciations(&self) -> &ExecutedDenunciations;
82
83    /// Get the database
84    fn get_database(&self) -> &ShareableMassaDBController;
85
86    /// Get last start period
87    fn get_last_start_period(&self) -> u64;
88
89    /// Set last start period
90    fn set_last_start_period(&mut self, last_start_period: u64);
91
92    /// Get last slot before downtime
93    fn get_last_slot_before_downtime(&self) -> &Option<Slot>;
94
95    /// Set last slot before downtime
96    fn set_last_slot_before_downtime(&mut self, last_slot_before_downtime: Option<Slot>);
97
98    /// Get MIP Store
99    fn get_mip_store(&self) -> &MipStore;
100
101    /// Get mutable reference to MIP Store
102    fn get_mip_store_mut(&mut self) -> &mut MipStore;
103
104    /// Get deferred call registry
105    fn get_deferred_call_registry(&self) -> &DeferredCallRegistry;
106}