Struct casper_execution_engine::core::tracking_copy::TrackingCopy
source · pub struct TrackingCopy<R> { /* private fields */ }
Expand description
An interface for the global state that caches all operations (reads and writes) instead of applying them directly to the state. This way the state remains unmodified, while the user can interact with it as if it was being modified in real time.
Implementations§
source§impl<R: StateReader<Key, StoredValue>> TrackingCopy<R>
impl<R: StateReader<Key, StoredValue>> TrackingCopy<R>
sourcepub fn new(reader: R) -> TrackingCopy<R>
pub fn new(reader: R) -> TrackingCopy<R>
Creates a new TrackingCopy
using the reader
as the interface to the state.
sourcepub fn fork(&self) -> TrackingCopy<&TrackingCopy<R>>
pub fn fork(&self) -> TrackingCopy<&TrackingCopy<R>>
Creates a new TrackingCopy, using this one (including its mutations) as
the base state to read against. The intended use case for this
function is to “snapshot” the current TrackingCopy
and produce a
new TrackingCopy
where further changes can be made. This
allows isolating a specific set of changes (those in the new
TrackingCopy
) from existing changes. Note that mutations to state
caused by new changes (i.e. writes and adds) only impact the new
TrackingCopy
, not this one. Note that currently there is no join
/
merge
function to bring changes from a fork back to the main
TrackingCopy
. this means the current usage requires repeated
forking, however we recognize this is sub-optimal and will revisit
in the future.
sourcepub fn get_keys(
&mut self,
correlation_id: CorrelationId,
key_tag: &KeyTag
) -> Result<BTreeSet<Key>, R::Error>
pub fn get_keys( &mut self, correlation_id: CorrelationId, key_tag: &KeyTag ) -> Result<BTreeSet<Key>, R::Error>
Gets the set of keys in the state whose tag is key_tag
.
sourcepub fn read(
&mut self,
correlation_id: CorrelationId,
key: &Key
) -> Result<Option<StoredValue>, R::Error>
pub fn read( &mut self, correlation_id: CorrelationId, key: &Key ) -> Result<Option<StoredValue>, R::Error>
Reads the value stored under key
.
sourcepub fn write(&mut self, key: Key, value: StoredValue)
pub fn write(&mut self, key: Key, value: StoredValue)
Writes value
under key
. Note that the write is only cached, and the global state itself
remains unmodified.
sourcepub fn add(
&mut self,
correlation_id: CorrelationId,
key: Key,
value: StoredValue
) -> Result<AddResult, R::Error>
pub fn add( &mut self, correlation_id: CorrelationId, key: Key, value: StoredValue ) -> Result<AddResult, R::Error>
Ok(None) represents missing key to which we want to “add” some value. Ok(Some(unit)) represents successful operation. Err(error) is reserved for unexpected errors when accessing global state.
sourcepub fn effect(&self) -> ExecutionEffect
pub fn effect(&self) -> ExecutionEffect
Returns the execution effects cached by this instance.
sourcepub fn execution_journal(&self) -> ExecutionJournal
pub fn execution_journal(&self) -> ExecutionJournal
Returns the journal of operations executed on this instance.
sourcepub fn query(
&self,
correlation_id: CorrelationId,
config: &EngineConfig,
base_key: Key,
path: &[String]
) -> Result<TrackingCopyQueryResult, R::Error>
pub fn query( &self, correlation_id: CorrelationId, config: &EngineConfig, base_key: Key, path: &[String] ) -> Result<TrackingCopyQueryResult, R::Error>
Calling query()
avoids calling into self.cache
, so this will not return any values
written or mutated in this TrackingCopy
via previous calls to write()
or add()
, since
these updates are only held in self.cache
.
The intent is that query()
is only used to satisfy QueryRequest
s made to the server.
Other EE internal use cases should call read()
or get()
in order to retrieve cached
values.
Trait Implementations§
source§impl<R: StateReader<Key, StoredValue>> StateReader<Key, StoredValue> for &TrackingCopy<R>
impl<R: StateReader<Key, StoredValue>> StateReader<Key, StoredValue> for &TrackingCopy<R>
The purpose of this implementation is to allow a “snapshot” mechanism for
TrackingCopy. The state of a TrackingCopy (including the effects of
any transforms it has accumulated) can be read using an immutable
reference to that TrackingCopy via this trait implementation. See
TrackingCopy::fork
for more information.
§type Error = <R as StateReader<Key, StoredValue>>::Error
type Error = <R as StateReader<Key, StoredValue>>::Error
source§fn read(
&self,
correlation_id: CorrelationId,
key: &Key
) -> Result<Option<StoredValue>, Self::Error>
fn read( &self, correlation_id: CorrelationId, key: &Key ) -> Result<Option<StoredValue>, Self::Error>
source§fn read_with_proof(
&self,
correlation_id: CorrelationId,
key: &Key
) -> Result<Option<TrieMerkleProof<Key, StoredValue>>, Self::Error>
fn read_with_proof( &self, correlation_id: CorrelationId, key: &Key ) -> Result<Option<TrieMerkleProof<Key, StoredValue>>, Self::Error>
source§fn keys_with_prefix(
&self,
correlation_id: CorrelationId,
prefix: &[u8]
) -> Result<Vec<Key>, Self::Error>
fn keys_with_prefix( &self, correlation_id: CorrelationId, prefix: &[u8] ) -> Result<Vec<Key>, Self::Error>
prefix
.source§impl<R> TrackingCopyExt<R> for TrackingCopy<R>where
R: StateReader<Key, StoredValue>,
R::Error: Into<Error>,
impl<R> TrackingCopyExt<R> for TrackingCopy<R>where R: StateReader<Key, StoredValue>, R::Error: Into<Error>,
source§fn get_contract_wasm(
&mut self,
correlation_id: CorrelationId,
contract_wasm_hash: ContractWasmHash
) -> Result<ContractWasm, Self::Error>
fn get_contract_wasm( &mut self, correlation_id: CorrelationId, contract_wasm_hash: ContractWasmHash ) -> Result<ContractWasm, Self::Error>
Gets a contract wasm by Key
source§fn get_contract(
&mut self,
correlation_id: CorrelationId,
contract_hash: ContractHash
) -> Result<Contract, Self::Error>
fn get_contract( &mut self, correlation_id: CorrelationId, contract_hash: ContractHash ) -> Result<Contract, Self::Error>
Gets a contract header by Key
source§fn get_account(
&mut self,
correlation_id: CorrelationId,
account_hash: AccountHash
) -> Result<Account, Self::Error>
fn get_account( &mut self, correlation_id: CorrelationId, account_hash: AccountHash ) -> Result<Account, Self::Error>
source§fn read_account(
&mut self,
correlation_id: CorrelationId,
account_hash: AccountHash
) -> Result<Account, Self::Error>
fn read_account( &mut self, correlation_id: CorrelationId, account_hash: AccountHash ) -> Result<Account, Self::Error>
source§fn get_purse_balance_key(
&self,
_correlation_id: CorrelationId,
purse_key: Key
) -> Result<Key, Self::Error>
fn get_purse_balance_key( &self, _correlation_id: CorrelationId, purse_key: Key ) -> Result<Key, Self::Error>
source§fn get_purse_balance(
&self,
correlation_id: CorrelationId,
key: Key
) -> Result<Motes, Self::Error>
fn get_purse_balance( &self, correlation_id: CorrelationId, key: Key ) -> Result<Motes, Self::Error>
source§fn get_purse_balance_key_with_proof(
&self,
correlation_id: CorrelationId,
purse_key: Key
) -> Result<(Key, TrieMerkleProof<Key, StoredValue>), Self::Error>
fn get_purse_balance_key_with_proof( &self, correlation_id: CorrelationId, purse_key: Key ) -> Result<(Key, TrieMerkleProof<Key, StoredValue>), Self::Error>
source§fn get_purse_balance_with_proof(
&self,
correlation_id: CorrelationId,
key: Key
) -> Result<(Motes, TrieMerkleProof<Key, StoredValue>), Self::Error>
fn get_purse_balance_with_proof( &self, correlation_id: CorrelationId, key: Key ) -> Result<(Motes, TrieMerkleProof<Key, StoredValue>), Self::Error>
source§fn get_contract_package(
&mut self,
correlation_id: CorrelationId,
contract_package_hash: ContractPackageHash
) -> Result<ContractPackage, Self::Error>
fn get_contract_package( &mut self, correlation_id: CorrelationId, contract_package_hash: ContractPackageHash ) -> Result<ContractPackage, Self::Error>
source§fn get_system_contracts(
&mut self,
correlation_id: CorrelationId
) -> Result<SystemContractRegistry, Self::Error>
fn get_system_contracts( &mut self, correlation_id: CorrelationId ) -> Result<SystemContractRegistry, Self::Error>
source§fn get_checksum_registry(
&mut self,
correlation_id: CorrelationId
) -> Result<Option<ChecksumRegistry>, Self::Error>
fn get_checksum_registry( &mut self, correlation_id: CorrelationId ) -> Result<Option<ChecksumRegistry>, Self::Error>
Auto Trait Implementations§
impl<R> RefUnwindSafe for TrackingCopy<R>where R: RefUnwindSafe,
impl<R> Send for TrackingCopy<R>where R: Send,
impl<R> Sync for TrackingCopy<R>where R: Sync,
impl<R> Unpin for TrackingCopy<R>where R: Unpin,
impl<R> UnwindSafe for TrackingCopy<R>where R: 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.