pub struct Vm<A> {
pub state: Arc<RwLock<State>>,
pub app_sender: Option<A>,
pub mempool: Arc<RwLock<VecDeque<Vec<u8>>>>,
}
Expand description
Implements snowman.block.ChainVM
interface.
Fields§
§state: Arc<RwLock<State>>
Maintains the Vm-specific states.
app_sender: Option<A>
§mempool: Arc<RwLock<VecDeque<Vec<u8>>>>
A queue of data that have not been put into a block and proposed yet. Mempool is not persistent, so just keep in memory via Vm.
Implementations§
Source§impl<A> Vm<A>
impl<A> Vm<A>
pub fn new() -> Self
pub async fn is_bootstrapped(&self) -> bool
Sourcepub async fn notify_block_ready(&self)
pub async fn notify_block_ready(&self)
Signals the consensus engine that a new block is ready to be created.
Sourcepub async fn propose_block(&self, d: Vec<u8>) -> Result<()>
pub async fn propose_block(&self, d: Vec<u8>) -> Result<()>
Proposes arbitrary data to mempool and notifies that a block is ready for builds. Other VMs may optimize mempool with more complicated batching mechanisms.
§Errors
Can fail if the data size exceeds PROPOSE_LIMIT_BYTES
.
Sourcepub async fn last_accepted(&self) -> Result<Id>
pub async fn last_accepted(&self) -> Result<Id>
Returns the last accepted block Id.
§Errors
Will fail if there’s no state or if the db can’t be accessed
Trait Implementations§
Source§impl<A> BatchedChainVm for Vm<A>
impl<A> BatchedChainVm for Vm<A>
type Block = Block
Source§fn get_ancestors<'life0, 'async_trait>(
&'life0 self,
_block_id: Id,
_max_block_num: i32,
_max_block_size: i32,
_max_block_retrival_time: Duration,
) -> Pin<Box<dyn Future<Output = Result<Vec<Bytes>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_ancestors<'life0, 'async_trait>(
&'life0 self,
_block_id: Id,
_max_block_num: i32,
_max_block_size: i32,
_max_block_retrival_time: Duration,
) -> Pin<Box<dyn Future<Output = Result<Vec<Bytes>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl<A> ChainVm for Vm<A>
impl<A> ChainVm for Vm<A>
Source§fn build_block<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<<Self as ChainVm>::Block>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn build_block<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<<Self as ChainVm>::Block>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Builds a block from mempool data.
type Block = Block
Source§fn set_preference<'life0, 'async_trait>(
&'life0 self,
id: Id,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_preference<'life0, 'async_trait>(
&'life0 self,
id: Id,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn last_accepted<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Id>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn last_accepted<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Id>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn issue_tx<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<<Self as ChainVm>::Block>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn issue_tx<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<<Self as ChainVm>::Block>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn verify_height_index<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn verify_height_index<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn get_block_id_at_height<'life0, 'async_trait>(
&'life0 self,
_height: u64,
) -> Pin<Box<dyn Future<Output = Result<Id>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_block_id_at_height<'life0, 'async_trait>(
&'life0 self,
_height: u64,
) -> Pin<Box<dyn Future<Output = Result<Id>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl<A> CommonVm for Vm<A>
impl<A> CommonVm for Vm<A>
Source§fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Called when the node is shutting down.
Source§fn create_static_handlers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, HttpHandler<Self::StaticHandler>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create_static_handlers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, HttpHandler<Self::StaticHandler>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates static handlers.
Source§fn create_handlers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, HttpHandler<Self::ChainHandler>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create_handlers<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, HttpHandler<Self::ChainHandler>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates VM-specific handlers.
type DatabaseManager = DatabaseManager
type AppSender = A
type ChainHandler = ChainHandler<ChainService<A>>
type StaticHandler = StaticHandler
type ValidatorState = ValidatorStateClient
fn initialize<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 mut self,
ctx: Option<Context<Self::ValidatorState>>,
db_manager: Self::DatabaseManager,
genesis_bytes: &'life1 [u8],
_upgrade_bytes: &'life2 [u8],
_config_bytes: &'life3 [u8],
to_engine: Sender<Message>,
_fxs: &'life4 [Fx],
app_sender: Self::AppSender,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn set_state<'life0, 'async_trait>(
&'life0 self,
snow_state: State,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn version<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl<A> Connector for Vm<A>
impl<A> Connector for Vm<A>
fn connected<'life0, 'life1, 'async_trait>(
&'life0 self,
_id: &'life1 Id,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn disconnected<'life0, 'life1, 'async_trait>(
&'life0 self,
_id: &'life1 Id,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<A> CrossChainAppHandler for Vm<A>
impl<A> CrossChainAppHandler for Vm<A>
Source§fn cross_chain_app_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_chain_id: &'life1 Id,
_request_id: u32,
_deadline: DateTime<Utc>,
_request: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn cross_chain_app_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_chain_id: &'life1 Id,
_request_id: u32,
_deadline: DateTime<Utc>,
_request: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Currently, no cross chain specific messages, so returning Ok.
Source§fn cross_chain_app_request_failed<'life0, 'life1, 'async_trait>(
&'life0 self,
_chain_id: &'life1 Id,
_request_id: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn cross_chain_app_request_failed<'life0, 'life1, 'async_trait>(
&'life0 self,
_chain_id: &'life1 Id,
_request_id: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Currently, no cross chain specific messages, so returning Ok.
Source§fn cross_chain_app_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_chain_id: &'life1 Id,
_request_id: u32,
_response: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn cross_chain_app_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_chain_id: &'life1 Id,
_request_id: u32,
_response: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Currently, no cross chain specific messages, so returning Ok.
Source§impl<A> NetworkAppHandler for Vm<A>
impl<A> NetworkAppHandler for Vm<A>
Source§fn app_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_request_id: u32,
_deadline: DateTime<Utc>,
_request: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn app_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_request_id: u32,
_deadline: DateTime<Utc>,
_request: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Currently, no app-specific messages, so returning Ok.
Source§fn app_request_failed<'life0, 'life1, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_request_id: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn app_request_failed<'life0, 'life1, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_request_id: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Currently, no app-specific messages, so returning Ok.
Source§fn app_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_request_id: u32,
_response: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn app_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_request_id: u32,
_response: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Currently, no app-specific messages, so returning Ok.
Source§fn app_gossip<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_msg: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn app_gossip<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_node_id: &'life1 Id,
_msg: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Currently, no app-specific messages, so returning Ok.
impl<A> AppHandler for Vm<A>
Auto Trait Implementations§
impl<A> Freeze for Vm<A>where
A: Freeze,
impl<A> !RefUnwindSafe for Vm<A>
impl<A> Send for Vm<A>where
A: Send,
impl<A> Sync for Vm<A>where
A: Sync,
impl<A> Unpin for Vm<A>where
A: Unpin,
impl<A> !UnwindSafe for Vm<A>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request