Struct Vm

Source
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>
where A: Send + Sync + Clone + 'static,

Source

pub fn new() -> Self

Source

pub async fn is_bootstrapped(&self) -> bool

Source

pub async fn notify_block_ready(&self)

Signals the consensus engine that a new block is ready to be created.

Source

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.

Source

pub async fn set_state(&self, snow_state: State) -> Result<()>

Sets the state of the Vm.

§Errors

Will fail if the snow::State is syncing

Source

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>
where A: Send + Sync + Clone + 'static,

Source§

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,

Attempts to obtain the ancestors of a block.
Source§

fn batched_parse_block<'life0, 'life1, 'async_trait>( &'life0 self, _blocks: &'life1 [Vec<u8>], ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Block>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Attempts to batch parse_block requests.
Source§

impl<A> ChainVm for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

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,

Builds a block from mempool data.

Source§

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,

Notify the Vm of the currently preferred block.
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,

Returns the ID of the last accepted block. If no blocks have been accepted, this should return the genesis block
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,

Issues a transaction to the chain
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,

Returns empty if the height index is available. Returns ErrIndexIncomplete if the height index is not currently available. TODO: Remove after v1.11.x activates.
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,

Returns the ID of the block that was accepted with [height]. Returns ErrNotFound if the [height] index is unknown.
Source§

fn state_sync_enabled<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns whether state sync is enabled.
Source§

impl<A> Checkable for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

Source§

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<A: Clone> Clone for Vm<A>

Source§

fn clone(&self) -> Vm<A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A> CommonVm for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

Source§

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,

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,

Creates VM-specific handlers.

Source§

type DatabaseManager = DatabaseManager

Source§

type AppSender = A

Source§

type ChainHandler = ChainHandler<ChainService<A>>

Source§

type StaticHandler = StaticHandler

Source§

type ValidatorState = ValidatorStateClient

Source§

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,

Source§

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,

Source§

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>
where A: AppSender + Send + Sync + Clone + 'static,

Source§

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,

Source§

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>
where A: AppSender + Send + Sync + Clone + 'static,

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,

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,

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,

Currently, no cross chain specific messages, so returning Ok.

Source§

impl<A> Default for Vm<A>
where A: Send + Sync + Clone + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A> Getter for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

Source§

type Block = Block

Source§

fn get_block<'life0, 'async_trait>( &'life0 self, blk_id: Id, ) -> Pin<Box<dyn Future<Output = Result<<Self as Getter>::Block>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<A> NetworkAppHandler for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

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,

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,

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,

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,

Currently, no app-specific messages, so returning Ok.

Source§

impl<A> Parser for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

Source§

type Block = Block

Source§

fn parse_block<'life0, 'life1, 'async_trait>( &'life0 self, bytes: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<<Self as Parser>::Block>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<A> AppHandler for Vm<A>
where A: AppSender + Send + Sync + Clone + 'static,

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more