pub struct EngineState<S> { /* private fields */ }
Expand description

Main implementation of an execution engine state.

Takes an engine’s configuration and a provider of a state (aka the global state) to operate on. Methods implemented on this structure are the external API intended to be used by the users such as the node, test framework, and others.

Implementations§

source§

impl EngineState<ScratchGlobalState>

source

pub fn into_inner(self) -> ScratchGlobalState

Returns the inner state

source§

impl EngineState<LmdbGlobalState>

source

pub fn get_state(&self) -> &LmdbGlobalState

Gets underlyng LmdbGlobalState

source

pub fn flush_environment(&self) -> Result<(), Error>

Flushes the LMDB environment to disk when manual sync is enabled in the config.toml.

source

pub fn get_scratch_engine_state(&self) -> EngineState<ScratchGlobalState>

Provide a local cached-only version of engine-state.

source

pub fn write_scratch_to_db( &self, state_root_hash: Digest, scratch_global_state: ScratchGlobalState ) -> Result<Digest, Error>

Writes state cached in an EngineState<ScratchEngineState> to LMDB.

source§

impl<S> EngineState<S>where S: StateProvider + CommitProvider, S::Error: Into<Error>,

source

pub fn new(state: S, config: EngineConfig) -> EngineState<S>

Creates new engine state.

source

pub fn config(&self) -> &EngineConfig

Returns engine config.

source

pub fn update_config(&mut self, new_config: EngineConfig)

Updates current engine config with a new instance.

source

pub fn commit_genesis( &self, correlation_id: CorrelationId, genesis_config_hash: Digest, protocol_version: ProtocolVersion, ee_config: &ExecConfig, chainspec_registry: ChainspecRegistry ) -> Result<GenesisSuccess, Error>

Commits genesis process.

This process is run only once per network to initiate the system. By definition users are unable to execute smart contracts on a network without a genesis.

Takes genesis configuration passed through ExecConfig and creates the system contracts, sets up the genesis accounts, and sets up the auction state based on that. At the end of the process, SystemContractRegistry is persisted under the special global state space Key::SystemContractRegistry.

Returns a GenesisSuccess for a successful operation, or an error otherwise.

source

pub fn commit_upgrade( &self, correlation_id: CorrelationId, upgrade_config: UpgradeConfig ) -> Result<UpgradeSuccess, Error>

Commits upgrade.

This process applies changes to the global state.

Returns UpgradeSuccess.

source

pub fn commit_prune( &self, correlation_id: CorrelationId, prune_config: PruneConfig ) -> Result<PruneResult, Error>

Commit a prune of leaf nodes from the tip of the merkle trie.

source

pub fn tracking_copy( &self, hash: Digest ) -> Result<Option<TrackingCopy<S::Reader>>, Error>

Creates a new tracking copy instance.

source

pub fn run_query( &self, correlation_id: CorrelationId, query_request: QueryRequest ) -> Result<QueryResult, Error>

Executes a query.

For a given root Key it does a path lookup through the named keys.

Returns the value stored under a URef wrapped in a QueryResult.

source

pub fn run_execute( &self, correlation_id: CorrelationId, exec_request: ExecuteRequest ) -> Result<ExecutionResults, Error>

Runs a deploy execution request.

For each deploy stored in the request it will execute it.

Currently a special shortcut is taken to distinguish a native transfer, from a deploy.

Return execution results which contains results from each deploy ran.

source

pub fn get_purse_balance( &self, correlation_id: CorrelationId, state_hash: Digest, purse_uref: URef ) -> Result<BalanceResult, Error>

Get the balance of a passed purse referenced by its URef.

source

pub fn transfer( &self, correlation_id: CorrelationId, executor: &Executor, protocol_version: ProtocolVersion, prestate_hash: Digest, blocktime: BlockTime, deploy_item: DeployItem, proposer: PublicKey ) -> Result<ExecutionResult, Error>

Executes a native transfer.

Native transfers do not involve WASM at all, and also skip executing payment code. Therefore this is the fastest and cheapest way to transfer tokens from account to account.

Returns an ExecutionResult for a successful native transfer.

source

pub fn deploy( &self, correlation_id: CorrelationId, executor: &Executor, protocol_version: ProtocolVersion, prestate_hash: Digest, blocktime: BlockTime, deploy_item: DeployItem, proposer: PublicKey ) -> Result<ExecutionResult, Error>

Executes a deploy.

A deploy execution consists of running the payment code, which is expected to deposit funds into the payment purse, and then running the session code with a specific gas limit. For running payment code, we lock MAX_PAYMENT amount of motes from the user as collateral. If both the payment code and the session code execute successfully, a fraction of the unspent collateral will be transferred back to the proposer of the deploy, as specified in the request.

Returns ExecutionResult, or an error condition.

source

pub fn apply_effect( &self, correlation_id: CorrelationId, pre_state_hash: Digest, effects: AdditiveMap<Key, Transform> ) -> Result<Digest, Error>

Apply effects of the execution.

This is also referred to as “committing” the effects into the global state. This method has to be run after an execution has been made to persists the effects of it.

Returns new state root hash.

source

pub fn get_trie_full( &self, correlation_id: CorrelationId, trie_key: Digest ) -> Result<Option<TrieRaw>, Error>where Error: From<S::Error>,

Gets a trie object for given state root hash.

source

pub fn put_trie_if_all_children_present( &self, correlation_id: CorrelationId, trie_bytes: &[u8] ) -> Result<Digest, Error>where Error: From<S::Error>,

Puts a trie if no children are missing from the global state; otherwise reports the missing children hashes via the Error enum.

source

pub fn get_era_validators( &self, correlation_id: CorrelationId, system_contract_registry: Option<SystemContractRegistry>, get_era_validators_request: GetEraValidatorsRequest ) -> Result<EraValidators, GetEraValidatorsError>

Obtains validator weights for given era.

This skips execution of auction’s get_era_validator entry point logic to avoid creating an executor instance, and going through the execution flow. It follows the same process but uses queries rather than execution to get the snapshot.

source

pub fn get_bids( &self, correlation_id: CorrelationId, get_bids_request: GetBidsRequest ) -> Result<GetBidsResult, Error>

Gets current bids from the auction system.

source

pub fn commit_step( &self, correlation_id: CorrelationId, step_request: StepRequest ) -> Result<StepSuccess, StepError>

Executes a step request.

source

pub fn get_balance( &self, correlation_id: CorrelationId, state_hash: Digest, public_key: PublicKey ) -> Result<BalanceResult, Error>

Gets the balance of a given public key.

source

pub fn get_system_contract_registry( &self, correlation_id: CorrelationId, state_root_hash: Digest ) -> Result<SystemContractRegistry, Error>

Obtains an instance of a system contract registry for a given state root hash.

source

pub fn get_system_mint_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>

Returns mint system contract hash.

source

pub fn get_system_auction_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>

Returns auction system contract hash.

source

pub fn get_handle_payment_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>

Returns handle payment system contract hash.

source

pub fn get_standard_payment_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>

Returns standard payment system contract hash.

source

pub fn get_checksum_registry( &self, correlation_id: CorrelationId, state_root_hash: Digest ) -> Result<Option<ChecksumRegistry>, Error>

Returns the checksum registry at the given state root hash.

source

pub fn get_checksum_registry_proof( &self, correlation_id: CorrelationId, state_root_hash: Digest ) -> Result<TrieMerkleProof<Key, StoredValue>, Error>

Returns the Merkle proof for the checksum registry at the given state root hash.

Trait Implementations§

source§

impl<S: Debug> Debug for EngineState<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for EngineState<S>where S: RefUnwindSafe,

§

impl<S> Send for EngineState<S>where S: Send,

§

impl<S> Sync for EngineState<S>where S: Sync,

§

impl<S> Unpin for EngineState<S>where S: Unpin,

§

impl<S> UnwindSafe for EngineState<S>where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

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