massa_pool_exports/
controller_traits.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use massa_models::{
4    block_id::BlockId,
5    denunciation::{Denunciation, DenunciationPrecursor},
6    endorsement::EndorsementId,
7    operation::OperationId,
8    slot::Slot,
9};
10use massa_storage::Storage;
11use massa_time::MassaTime;
12
13use crate::error::PoolError;
14
15/// Trait defining a pool controller
16#[cfg_attr(feature = "test-exports", mockall_wrap::wrap, mockall::automock)]
17pub trait PoolController: Send + Sync {
18    /// Asynchronously add operations to pool.
19    /// Returns an error if the operations could not be queued for insertion.
20    fn add_operations(&mut self, ops: Storage) -> Result<(), PoolError>;
21
22    /// Asynchronously add endorsements to pool. Simply print a warning on failure.
23    fn add_endorsements(&mut self, endorsements: Storage);
24
25    /// Add denunciation precursor to pool
26    fn add_denunciation_precursor(&self, denunciation_precursor: DenunciationPrecursor);
27
28    /// Asynchronously notify of new consensus final periods. Simply print a warning on failure.
29    fn notify_final_cs_periods(&mut self, final_cs_periods: &[u64]);
30
31    /// Get operations for block creation.
32    fn get_block_operations(
33        &self,
34        slot: &Slot,
35        timeout: Option<MassaTime>,
36    ) -> Result<(Vec<OperationId>, Storage), PoolError>;
37
38    /// Get endorsements for a block.
39    fn get_block_endorsements(
40        &self,
41        target_block: &BlockId,
42        slot: &Slot,
43        timeout: Option<MassaTime>,
44    ) -> Result<(Vec<Option<EndorsementId>>, Storage), PoolError>;
45
46    /// Get denunciations for a block header.
47    fn get_block_denunciations(
48        &self,
49        target_slot: &Slot,
50        timeout: Option<MassaTime>,
51    ) -> Result<Vec<Denunciation>, PoolError>;
52
53    /// Get the number of endorsements in the pool
54    fn get_endorsement_count(&self, timeout: Option<MassaTime>) -> Result<usize, PoolError>;
55
56    /// Get the number of operations in the pool
57    fn get_operation_count(&self, timeout: Option<MassaTime>) -> Result<usize, PoolError>;
58
59    /// Check if the pool contains a list of endorsements. Returns one boolean per item.
60    fn contains_endorsements(
61        &self,
62        endorsements: &[EndorsementId],
63        timeout: Option<MassaTime>,
64    ) -> Result<Vec<bool>, PoolError>;
65
66    /// Check if the pool contains a list of operations. Returns one boolean per item.
67    fn contains_operations(
68        &self,
69        operations: &[OperationId],
70        timeout: Option<MassaTime>,
71    ) -> Result<Vec<bool>, PoolError>;
72
73    /// Get the number of denunciations in the pool
74    fn get_denunciation_count(&self, timeout: Option<MassaTime>) -> Result<usize, PoolError>;
75
76    /// Returns a boxed clone of self.
77    /// Useful to allow cloning `Box<dyn PoolController>`.
78    fn clone_box(&self) -> Box<dyn PoolController>;
79
80    /// Get final cs periods (updated regularly from consensus)
81    fn get_final_cs_periods(&self) -> Vec<u64>;
82}
83
84/// Allow cloning `Box<dyn PoolController>`
85/// Uses `PoolController::clone_box` internally
86impl Clone for Box<dyn PoolController> {
87    fn clone(&self) -> Box<dyn PoolController> {
88        self.clone_box()
89    }
90}
91
92/// Pool manager trait
93pub trait PoolManager: Send + Sync {
94    /// Stops the worker
95    fn stop(&mut self);
96}