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<ScratchEngineState>
to LMDB.
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,
chainspec_registry: ChainspecRegistry
) -> Result<GenesisSuccess, Error>
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.
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 commit_prune(
&self,
correlation_id: CorrelationId,
prune_config: PruneConfig
) -> Result<PruneResult, Error>
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.
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_full(
&self,
correlation_id: CorrelationId,
trie_key: Digest
) -> Result<Option<TrieRaw>, Error>where
Error: From<S::Error>,
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.
sourcepub fn put_trie_if_all_children_present(
&self,
correlation_id: CorrelationId,
trie_bytes: &[u8]
) -> Result<Digest, Error>where
Error: From<S::Error>,
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.
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.
sourcepub fn get_checksum_registry(
&self,
correlation_id: CorrelationId,
state_root_hash: Digest
) -> Result<Option<ChecksumRegistry>, Error>
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.
sourcepub fn get_checksum_registry_proof(
&self,
correlation_id: CorrelationId,
state_root_hash: Digest
) -> Result<TrieMerkleProof<Key, StoredValue>, Error>
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§
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> 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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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.