Skip to main content

VM

Struct VM 

Source
pub struct VM<N, C>
where N: Network, C: ConsensusStorage<N>,
{ /* private fields */ }

Implementations§

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn start_sequential_queue( &self, request_rx: Receiver<SequentialOperationRequest<N>>, ) -> JoinHandle<()>

Launches a thread dedicated to the sequential processing of storage-related operations.

Source

pub fn run_sequential_operation( &self, op: SequentialOperation<N>, ) -> Option<SequentialOperationResult<N>>

Sends the given operation to the thread used for sequential processing.

Source

pub fn ensure_sequential_processing(&self)

A safeguard used to ensure that the given operation is processed in the thread enforcing sequential processing of operations.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn authorize<R>( &self, private_key: &PrivateKey<N>, program_id: impl TryInto<ProgramID<N>>, function_name: impl TryInto<Identifier<N>>, inputs: impl IntoIterator<IntoIter = impl ExactSizeIterator<Item = impl TryInto<Value<N>>>>, rng: &mut R, ) -> Result<Authorization<N>, VmAuthError>
where R: Rng + CryptoRng,

Authorizes a call to the program function for the given inputs.

Source

pub fn authorize_fee_private<R>( &self, private_key: &PrivateKey<N>, credits: Record<N, Plaintext<N>>, base_fee_in_microcredits: u64, priority_fee_in_microcredits: u64, deployment_or_execution_id: Field<N>, rng: &mut R, ) -> Result<Authorization<N>, Error>
where R: Rng + CryptoRng,

Authorizes the fee given the credits record, the fee amount (in microcredits), and the deployment or execution ID.

Source

pub fn authorize_fee_public<R>( &self, private_key: &PrivateKey<N>, base_fee_in_microcredits: u64, priority_fee_in_microcredits: u64, deployment_or_execution_id: Field<N>, rng: &mut R, ) -> Result<Authorization<N>, Error>
where R: Rng + CryptoRng,

Authorizes the fee given the the fee amount (in microcredits) and the deployment or execution ID.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn deploy<R>( &self, private_key: &PrivateKey<N>, program: &ProgramCore<N>, fee_record: Option<Record<N, Plaintext<N>>>, priority_fee_in_microcredits: u64, query: Option<&dyn QueryTrait<N>>, rng: &mut R, ) -> Result<Transaction<N>, VmDeployError>
where R: Rng + CryptoRng,

Returns a new deploy transaction.

If a fee_record is provided, then a private fee will be included in the transaction; otherwise, a public fee will be included in the transaction.

The priority_fee_in_microcredits is an additional fee on top of the deployment fee.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn execute<R>( &self, private_key: &PrivateKey<N>, _: (impl TryInto<ProgramID<N>>, impl TryInto<Identifier<N>>), inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>, fee_record: Option<Record<N, Plaintext<N>>>, priority_fee_in_microcredits: u64, query: Option<&dyn QueryTrait<N>>, rng: &mut R, ) -> Result<Transaction<N>, VmExecError>
where R: Rng + CryptoRng,

Returns a new execute transaction.

If a fee_record is provided, then a private fee will be included in the transaction; otherwise, a public fee will be included in the transaction.

The priority_fee_in_microcredits is an additional fee on top of the execution fee.

Source

pub fn execute_with_response<R>( &self, private_key: &PrivateKey<N>, _: (impl TryInto<ProgramID<N>>, impl TryInto<Identifier<N>>), inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>, fee_record: Option<Record<N, Plaintext<N>>>, priority_fee_in_microcredits: u64, query: Option<&dyn QueryTrait<N>>, rng: &mut R, ) -> Result<(Transaction<N>, Response<N>), VmExecError>
where R: Rng + CryptoRng,

Returns a new execute transaction and response.

If a fee_record is provided, then a private fee will be included in the transaction; otherwise, a public fee will be included in the transaction.

The priority_fee_in_microcredits is an additional fee on top of the execution fee.

Source

pub fn execute_authorization<R>( &self, execute_authorization: Authorization<N>, fee_authorization: Option<Authorization<N>>, query: Option<&dyn QueryTrait<N>>, rng: &mut R, ) -> Result<Transaction<N>, Error>
where R: Rng + CryptoRng,

Returns a new execute transaction for the given authorization.

This is identical to execute_authorization_with_response except that it discards the Response.

Source

pub fn execute_authorization_with_response<R>( &self, execute_authorization: Authorization<N>, fee_authorization: Option<Authorization<N>>, query: Option<&dyn QueryTrait<N>>, rng: &mut R, ) -> Result<(Transaction<N>, Response<N>), Error>
where R: Rng + CryptoRng,

Returns a new execute transaction and response for the given authorization.

Source

pub fn execute_fee_authorization<R>( &self, authorization: Authorization<N>, query: Option<&dyn QueryTrait<N>>, rng: &mut R, ) -> Result<Fee<N>, VmExecError>
where R: Rng + CryptoRng,

Returns a new fee for the given authorization.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn speculate<'a, R>( &self, state: FinalizeGlobalState, time_since_last_block: i64, coinbase_reward: Option<u64>, candidate_ratifications: Vec<Ratify<N>>, candidate_solutions: &Solutions<N>, candidate_transactions: impl ExactSizeIterator<Item = &'a Transaction<N>>, rng: &mut R, ) -> Result<(Ratifications<N>, Transactions<N>, Vec<<N as Network>::TransactionID>, Vec<FinalizeOperation<N>>), Error>
where R: Rng + CryptoRng,

Speculates on the given list of transactions in the VM. This function aborts all transactions that are not are well-formed or unique.

Returns the confirmed transactions, aborted transaction IDs, and finalize operations from pre-ratify and post-ratify.

§Note

This method is used to create a new block (including the genesis block).

  • If coinbase_reward = None, then the ratifications will not be modified.
  • If coinbase_reward = Some(coinbase_reward), then the method will append a Ratify::BlockReward(block_reward) and Ratify::PuzzleReward(puzzle_reward) to the front of the ratifications list.
§Panics

This function panics if called from an async context.

Source

pub fn check_speculate<R>( &self, state: FinalizeGlobalState, time_since_last_block: i64, ratifications: &Ratifications<N>, solutions: &Solutions<N>, transactions: &Transactions<N>, rng: &mut R, ) -> Result<Vec<FinalizeOperation<N>>, Error>
where R: Rng + CryptoRng,

Checks the speculation on the given transactions in the VM. This function also ensure that the given transactions are well-formed and unique.

Returns the finalize operations from pre-ratify and post-ratify.

§Panics

This function panics if called from an async context.

Source

pub fn finalize( &self, state: FinalizeGlobalState, ratifications: &Ratifications<N>, solutions: &Solutions<N>, transactions: &Transactions<N>, ) -> Result<Vec<FinalizeOperation<N>>, Error>

Finalizes the given transactions into the VM.

Returns the finalize operations from pre-ratify and post-ratify.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub const MAXIMUM_CONFIRMED_TRANSACTIONS: usize = Transactions<N>::MAX_TRANSACTIONS

The maximum number of confirmed transactions allowed in a block.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub const MAX_PARALLEL_DEPLOY_VERIFICATIONS: usize = 5

The maximum number of deployments that the VM can verify in parallel.

Source

pub const MAX_PARALLEL_EXECUTE_VERIFICATIONS: usize = 1000

The maximum number of executions to verify in parallel.

Source

pub fn check_transactions<R>( &self, transactions: &[(&Transaction<N>, Option<Field<N>>)], rng: &mut R, ) -> Result<(), Error>
where R: CryptoRng + Rng,

Verifies the list of transactions in the VM. On failure, returns an error.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn check_transaction<R>( &self, transaction: &Transaction<N>, rejected_id: Option<Field<N>>, rng: &mut R, ) -> Result<(), Error>
where R: CryptoRng + Rng,

Verifies the transaction in the VM. On failure, returns an error.

Source

pub fn check_fee( &self, transaction: &Transaction<N>, rejected_id: Option<Field<N>>, is_partially_verified: bool, ) -> Result<(), Error>

Verifies the fee in the given transaction. On failure, returns an error.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn from(store: ConsensusStore<N, C>) -> Result<VM<N, C>, Error>

Initializes the VM from storage.

Source

pub fn contains_program(&self, program_id: &ProgramID<N>) -> bool

Returns true if a program with the given program ID exists.

Source

pub fn process(&self) -> Arc<RwLock<RawRwLock, Process<N>>>

Returns the process.

Source

pub const fn puzzle(&self) -> &Puzzle<N>

Returns the puzzle.

Source

pub fn partially_verified_transactions( &self, ) -> Arc<RwLock<RawRwLock, LruCache<(<N as Network>::TransactionID, Vec<Integer<N, u16>>), <N as Network>::TransmissionChecksum>>>

Returns the partially-verified transactions.

Source

pub const fn restrictions(&self) -> &Restrictions<N>

Returns the restrictions.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn finalize_store( &self, ) -> &FinalizeStore<N, <C as ConsensusStorage<N>>::FinalizeStorage>

Returns the finalize store.

Source

pub fn block_store( &self, ) -> &BlockStore<N, <C as ConsensusStorage<N>>::BlockStorage>

Returns the block store.

Source

pub fn transaction_store( &self, ) -> &TransactionStore<N, <C as ConsensusStorage<N>>::TransactionStorage>

Returns the transaction store.

Source

pub fn transition_store( &self, ) -> &TransitionStore<N, <C as ConsensusStorage<N>>::TransitionStorage>

Returns the transition store.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn new_puzzle() -> Result<Puzzle<N>, Error>

Returns a new instance of the puzzle.

Source§

impl<N, C> VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source

pub fn genesis_beacon<R>( &self, private_key: &PrivateKey<N>, rng: &mut R, ) -> Result<Block<N>, Error>
where R: Rng + CryptoRng,

Returns a new genesis block for a beacon chain with the default size (four validators).

Source

pub fn genesis_beacon_with_size<R>( &self, private_key: &PrivateKey<N>, num_validators: usize, rng: &mut R, ) -> Result<Block<N>, Error>
where R: Rng + CryptoRng,

Returns a new genesis block for a beacon chain.

Source

pub fn genesis_quorum<R>( &self, private_key: &PrivateKey<N>, committee: Committee<N>, public_balances: IndexMap<Address<N>, u64>, bonded_balances: IndexMap<Address<N>, (Address<N>, Address<N>, u64)>, rng: &mut R, ) -> Result<Block<N>, Error>
where R: Rng + CryptoRng,

Returns a new genesis block for a quorum chain.

§Panics

This function panics if called from an async context.

Source

pub fn add_next_block(&self, block: &Block<N>) -> Result<(), Error>

Adds the given block into the VM.

§Panics

This function panics if called from an async context.

Trait Implementations§

Source§

impl<N, C> Clone for VM<N, C>

Source§

fn clone(&self) -> VM<N, C>

Returns a duplicate 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<N, C> Drop for VM<N, C>
where N: Network, C: ConsensusStorage<N>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<N, C> Freeze for VM<N, C>
where C: Freeze, <N as Environment>::Field: Freeze,

§

impl<N, C> !RefUnwindSafe for VM<N, C>

§

impl<N, C> Send for VM<N, C>

§

impl<N, C> Sync for VM<N, C>

§

impl<N, C> Unpin for VM<N, C>
where C: Unpin, N: Unpin, <N as Environment>::Field: Unpin, <N as Environment>::Projective: Unpin, <N as Environment>::Scalar: Unpin,

§

impl<N, C> UnsafeUnpin for VM<N, C>

§

impl<N, C> !UnwindSafe for VM<N, C>

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<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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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