Struct casper_execution_engine::core::engine_state::EngineState
source · 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>
impl EngineState<ScratchGlobalState>
sourcepub fn into_inner(self) -> ScratchGlobalState
pub fn into_inner(self) -> ScratchGlobalState
Returns the inner state
source§impl EngineState<LmdbGlobalState>
impl EngineState<LmdbGlobalState>
sourcepub fn get_state(&self) -> &LmdbGlobalState
pub fn get_state(&self) -> &LmdbGlobalState
Gets underlyng LmdbGlobalState
sourcepub fn flush_environment(&self) -> Result<(), Error>
pub fn flush_environment(&self) -> Result<(), Error>
Flushes the LMDB environment to disk when manual sync is enabled in the config.toml.
sourcepub fn get_scratch_engine_state(&self) -> EngineState<ScratchGlobalState>
pub fn get_scratch_engine_state(&self) -> EngineState<ScratchGlobalState>
Provide a local cached-only version of engine-state.
sourcepub fn write_scratch_to_db(
&self,
state_root_hash: Digest,
scratch_global_state: ScratchGlobalState
) -> Result<Digest, Error>
pub fn write_scratch_to_db( &self, state_root_hash: Digest, scratch_global_state: ScratchGlobalState ) -> Result<Digest, Error>
Writes state cached in an EngineState
source§impl<S> EngineState<S>where
S: StateProvider + CommitProvider,
S::Error: Into<Error>,
impl<S> EngineState<S>where S: StateProvider + CommitProvider, S::Error: Into<Error>,
sourcepub fn new(state: S, config: EngineConfig) -> EngineState<S>
pub fn new(state: S, config: EngineConfig) -> EngineState<S>
Creates new engine state.
sourcepub fn config(&self) -> &EngineConfig
pub fn config(&self) -> &EngineConfig
Returns engine config.
sourcepub fn update_config(&mut self, new_config: EngineConfig)
pub fn update_config(&mut self, new_config: EngineConfig)
Updates current engine config with a new instance.
sourcepub fn commit_genesis(
&self,
correlation_id: CorrelationId,
genesis_config_hash: Digest,
protocol_version: ProtocolVersion,
ee_config: &ExecConfig
) -> Result<GenesisSuccess, Error>
pub fn commit_genesis( &self, correlation_id: CorrelationId, genesis_config_hash: Digest, protocol_version: ProtocolVersion, ee_config: &ExecConfig ) -> 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.
sourcepub fn commit_upgrade(
&self,
correlation_id: CorrelationId,
upgrade_config: UpgradeConfig
) -> Result<UpgradeSuccess, Error>
pub fn commit_upgrade( &self, correlation_id: CorrelationId, upgrade_config: UpgradeConfig ) -> Result<UpgradeSuccess, Error>
sourcepub fn tracking_copy(
&self,
hash: Digest
) -> Result<Option<TrackingCopy<S::Reader>>, Error>
pub fn tracking_copy( &self, hash: Digest ) -> Result<Option<TrackingCopy<S::Reader>>, Error>
Creates a new tracking copy instance.
sourcepub fn run_query(
&self,
correlation_id: CorrelationId,
query_request: QueryRequest
) -> Result<QueryResult, Error>
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.
sourcepub fn run_execute(
&self,
correlation_id: CorrelationId,
exec_request: ExecuteRequest
) -> Result<ExecutionResults, Error>
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.
sourcepub fn get_purse_balance(
&self,
correlation_id: CorrelationId,
state_hash: Digest,
purse_uref: URef
) -> Result<BalanceResult, Error>
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.
sourcepub fn transfer(
&self,
correlation_id: CorrelationId,
executor: &Executor,
protocol_version: ProtocolVersion,
prestate_hash: Digest,
blocktime: BlockTime,
deploy_item: DeployItem,
proposer: PublicKey
) -> Result<ExecutionResult, Error>
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.
sourcepub fn deploy(
&self,
correlation_id: CorrelationId,
executor: &Executor,
protocol_version: ProtocolVersion,
prestate_hash: Digest,
blocktime: BlockTime,
deploy_item: DeployItem,
proposer: PublicKey
) -> Result<ExecutionResult, Error>
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.
sourcepub fn apply_effect(
&self,
correlation_id: CorrelationId,
pre_state_hash: Digest,
effects: AdditiveMap<Key, Transform>
) -> Result<Digest, Error>
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.
sourcepub fn get_trie(
&self,
correlation_id: CorrelationId,
trie_key: Digest
) -> Result<Option<Trie<Key, StoredValue>>, Error>where
Error: From<S::Error>,
pub fn get_trie( &self, correlation_id: CorrelationId, trie_key: Digest ) -> Result<Option<Trie<Key, StoredValue>>, Error>where Error: From<S::Error>,
Gets a trie object for given state root hash.
sourcepub fn put_trie_and_find_missing_descendant_trie_keys(
&self,
correlation_id: CorrelationId,
trie: &Trie<Key, StoredValue>
) -> Result<Vec<Digest>, Error>where
Error: From<S::Error>,
pub fn put_trie_and_find_missing_descendant_trie_keys( &self, correlation_id: CorrelationId, trie: &Trie<Key, StoredValue> ) -> Result<Vec<Digest>, Error>where Error: From<S::Error>,
Puts a trie and finds missing descendant trie keys.
sourcepub fn missing_trie_keys(
&self,
correlation_id: CorrelationId,
trie_keys: Vec<Digest>
) -> Result<Vec<Digest>, Error>where
Error: From<S::Error>,
pub fn missing_trie_keys( &self, correlation_id: CorrelationId, trie_keys: Vec<Digest> ) -> Result<Vec<Digest>, Error>where Error: From<S::Error>,
Performs a lookup for a list of missing root hashes.
sourcepub fn get_era_validators(
&self,
correlation_id: CorrelationId,
system_contract_registry: Option<SystemContractRegistry>,
get_era_validators_request: GetEraValidatorsRequest
) -> Result<EraValidators, GetEraValidatorsError>
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.
sourcepub fn get_bids(
&self,
correlation_id: CorrelationId,
get_bids_request: GetBidsRequest
) -> Result<GetBidsResult, Error>
pub fn get_bids( &self, correlation_id: CorrelationId, get_bids_request: GetBidsRequest ) -> Result<GetBidsResult, Error>
Gets current bids from the auction system.
sourcepub fn commit_step(
&self,
correlation_id: CorrelationId,
step_request: StepRequest
) -> Result<StepSuccess, StepError>
pub fn commit_step( &self, correlation_id: CorrelationId, step_request: StepRequest ) -> Result<StepSuccess, StepError>
Executes a step request.
sourcepub fn get_balance(
&self,
correlation_id: CorrelationId,
state_hash: Digest,
public_key: PublicKey
) -> Result<BalanceResult, Error>
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.
sourcepub fn get_system_contract_registry(
&self,
correlation_id: CorrelationId,
state_root_hash: Digest
) -> Result<SystemContractRegistry, Error>
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.
sourcepub fn get_system_mint_hash(
&self,
correlation_id: CorrelationId,
state_hash: Digest
) -> Result<ContractHash, Error>
pub fn get_system_mint_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>
Returns mint system contract hash.
sourcepub fn get_system_auction_hash(
&self,
correlation_id: CorrelationId,
state_hash: Digest
) -> Result<ContractHash, Error>
pub fn get_system_auction_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>
Returns auction system contract hash.
sourcepub fn get_handle_payment_hash(
&self,
correlation_id: CorrelationId,
state_hash: Digest
) -> Result<ContractHash, Error>
pub fn get_handle_payment_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>
Returns handle payment system contract hash.
sourcepub fn get_standard_payment_hash(
&self,
correlation_id: CorrelationId,
state_hash: Digest
) -> Result<ContractHash, Error>
pub fn get_standard_payment_hash( &self, correlation_id: CorrelationId, state_hash: Digest ) -> Result<ContractHash, Error>
Returns standard payment system contract hash.
Trait Implementations§
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§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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 + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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>
§impl<T> Pipe for T
impl<T> Pipe for T
§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
§impl<T> PipeDeref for T
impl<T> PipeDeref for T
§impl<T> PipeRef for T
impl<T> PipeRef for T
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
§fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere F: FnOnce(&Self) -> R,
§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere F: FnOnce(&Self) -> R,
tap in debug builds, and does nothing in release builds.§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere F: FnOnce(&mut Self) -> R,
§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere F: FnOnce(&mut Self) -> R,
tap_mut in debug builds, and does nothing in release builds.§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere U: ?Sized,
§fn tap_ref<F, R>(self, func: F) -> Selfwhere
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref<F, R>(self, func: F) -> Selfwhere Self: AsRef<T>, F: FnOnce(&T) -> R,
§fn tap_ref_dbg<F, R>(self, func: F) -> Selfwhere
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref_dbg<F, R>(self, func: F) -> Selfwhere Self: AsRef<T>, F: FnOnce(&T) -> R,
tap_ref in debug builds, and does nothing in release builds.§fn tap_ref_mut<F, R>(self, func: F) -> Selfwhere
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut<F, R>(self, func: F) -> Selfwhere Self: AsMut<T>, F: FnOnce(&mut T) -> R,
§fn tap_ref_mut_dbg<F, R>(self, func: F) -> Selfwhere
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Selfwhere Self: AsMut<T>, F: FnOnce(&mut T) -> R,
tap_ref_mut in debug builds, and does nothing in release builds.§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere U: ?Sized,
§fn tap_borrow<F, R>(self, func: F) -> Selfwhere
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow<F, R>(self, func: F) -> Selfwhere Self: Borrow<T>, F: FnOnce(&T) -> R,
§fn tap_borrow_dbg<F, R>(self, func: F) -> Selfwhere
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow_dbg<F, R>(self, func: F) -> Selfwhere Self: Borrow<T>, F: FnOnce(&T) -> R,
tap_borrow in debug builds, and does nothing in release builds.§fn tap_borrow_mut<F, R>(self, func: F) -> Selfwhere
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut<F, R>(self, func: F) -> Selfwhere Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,
§fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Selfwhere
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Selfwhere Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,
tap_borrow_mut in debug builds, and does nothing in release
builds.§impl<T> TapDeref for T
impl<T> TapDeref for T
§fn tap_deref<F, R>(self, func: F) -> Selfwhere
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref<F, R>(self, func: F) -> Selfwhere Self: Deref, F: FnOnce(&Self::Target) -> R,
self for inspection.§fn tap_deref_dbg<F, R>(self, func: F) -> Selfwhere
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref_dbg<F, R>(self, func: F) -> Selfwhere Self: Deref, F: FnOnce(&Self::Target) -> R,
tap_deref in debug builds, and does nothing in release builds.§fn tap_deref_mut<F, R>(self, func: F) -> Selfwhere
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut<F, R>(self, func: F) -> Selfwhere Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,
self for modification.§fn tap_deref_mut_dbg<F, R>(self, func: F) -> Selfwhere
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Selfwhere Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,
tap_deref_mut in debug builds, and does nothing in release
builds.