Struct account_state::state::State[][src]

pub struct State<B> { /* fields omitted */ }

Representation of the entire state of all accounts in the system.

State can work together with StateDB to share account cache.

Local cache contains changes made locally and changes accumulated locally from previous commits. Global cache reflects the database state and never contains any changes.

Cache items contains account data, or the flag that account does not exist and modification state (see AccountState)

Account data can be in the following cache states:

  • In global but not local - something that was queried from the database, but never modified
  • In local but not global - something that was just added (e.g. new account)
  • In both with the same value - something that was changed to a new value, but changed back to a previous block in the same block (same State instance)
  • In both with different values - something that was overwritten with a new value.

All read-only state queries check local cache/modifications first, then global state cache. If data is not found in any of the caches it is loaded from the DB to the local cache.

**** IMPORTANT ************************************************************* All the modifications to the account data must set the Dirty state in the AccountEntry. This is done in require and require_or_from. So just use that.


Upon destruction all the local cache data propagated into the global cache. Propagated items might be rejected if current state is non-canonical.

State checkpointing.

A new checkpoint can be created with checkpoint(). checkpoints can be created in a hierarchy. When a checkpoint is active all changes are applied directly into cache and the original value is copied into an active checkpoint. Reverting a checkpoint with revert_to_checkpoint involves copying original values from the latest checkpoint back into cache. The code takes care not to overwrite cached storage while doing that. A checkpoint can be discarded with discard_checkpoint. All of the original backed-up values are moved into a parent checkpoint (if any).

Implementations

impl<B: Backend> State<B>[src]

pub fn new(db: B, account_start_nonce: U256, factories: Factories) -> State<B>[src]

Creates new state with empty state root Used for tests.

pub fn from_existing(
    db: B,
    root: H256,
    account_start_nonce: U256,
    factories: Factories
) -> TrieResult<State<B>>
[src]

Creates new state with existing state root

pub fn vm_factory(&self) -> VmFactory[src]

Get a VM factory that can execute on this state.

pub fn checkpoint(&mut self) -> usize[src]

Create a recoverable checkpoint of this state. Return the checkpoint index.

pub fn discard_checkpoint(&mut self)[src]

Merge last checkpoint with previous.

pub fn revert_to_checkpoint(&mut self)[src]

Revert to the last checkpoint and discard it.

pub fn drop(self) -> (H256, B)[src]

Destroy the current object and return root and database.

pub fn into_account(
    self,
    account: &Address
) -> TrieResult<(Option<Arc<Bytes>>, HashMap<H256, H256>)>
[src]

Destroy the current object and return single account data.

pub fn root(&self) -> &H256[src]

Return reference to root

pub fn new_contract(
    &mut self,
    contract: &Address,
    balance: U256,
    nonce_offset: U256,
    version: U256
) -> TrieResult<()>
[src]

Create a new contract at address contract. If there is already an account at the address it will have its code reset, ready for init_code().

pub fn kill_account(&mut self, account: &Address)[src]

Remove an existing account.

pub fn exists(&self, a: &Address) -> TrieResult<bool>[src]

Determine whether an account exists.

pub fn exists_and_not_null(&self, a: &Address) -> TrieResult<bool>[src]

Determine whether an account exists and if not empty.

pub fn exists_and_has_code_or_nonce(&self, a: &Address) -> TrieResult<bool>[src]

Determine whether an account exists and has code or non-zero nonce.

pub fn balance(&self, a: &Address) -> TrieResult<U256>[src]

Get the balance of account a.

pub fn nonce(&self, a: &Address) -> TrieResult<U256>[src]

Get the nonce of account a.

pub fn is_base_storage_root_unchanged(&self, a: &Address) -> TrieResult<bool>[src]

Whether the base storage root of an account remains unchanged.

pub fn storage_root(&self, a: &Address) -> TrieResult<Option<H256>>[src]

Get the storage root of account a.

pub fn original_storage_root(&self, a: &Address) -> TrieResult<H256>[src]

Get the original storage root since last commit of account a.

pub fn checkpoint_storage_at(
    &self,
    start_checkpoint_index: usize,
    address: &Address,
    key: &H256
) -> TrieResult<Option<H256>>
[src]

Get the value of storage at a specific checkpoint.

pub fn storage_at(&self, address: &Address, key: &H256) -> TrieResult<H256>[src]

Mutate storage of account address so that it is value for key.

pub fn original_storage_at(
    &self,
    address: &Address,
    key: &H256
) -> TrieResult<H256>
[src]

Get the value of storage after last state commitment.

pub fn code(&self, a: &Address) -> TrieResult<Option<Arc<Bytes>>>[src]

Get accounts’ code.

pub fn code_hash(&self, a: &Address) -> TrieResult<Option<H256>>[src]

Get an account’s code hash.

pub fn code_version(&self, a: &Address) -> TrieResult<U256>[src]

Get an account’s code version.

pub fn code_size(&self, a: &Address) -> TrieResult<Option<usize>>[src]

Get accounts’ code size.

pub fn add_balance(
    &mut self,
    a: &Address,
    incr: &U256,
    cleanup_mode: CleanupMode<'_>
) -> TrieResult<()>
[src]

Add incr to the balance of account a.

pub fn sub_balance(
    &mut self,
    a: &Address,
    decr: &U256,
    cleanup_mode: &mut CleanupMode<'_>
) -> TrieResult<()>
[src]

Subtract decr from the balance of account a.

pub fn transfer_balance(
    &mut self,
    from: &Address,
    to: &Address,
    by: &U256,
    cleanup_mode: CleanupMode<'_>
) -> TrieResult<()>
[src]

Subtracts by from the balance of from and adds it to that of to.

pub fn inc_nonce(&mut self, a: &Address) -> TrieResult<()>[src]

Increment the nonce of account a by 1.

pub fn set_storage(
    &mut self,
    a: &Address,
    key: H256,
    value: H256
) -> TrieResult<()>
[src]

Mutate storage of account a so that it is value for key.

pub fn init_code(&mut self, a: &Address, code: Bytes) -> TrieResult<()>[src]

Initialise the code of account a so that it is code. NOTE: Account should have been created with new_contract.

pub fn reset_code(&mut self, a: &Address, code: Bytes) -> TrieResult<()>[src]

Reset the code of account a so that it is code.

pub fn commit(&mut self) -> Result<(), Error>[src]

Commits our cached account changes into the trie.

pub fn clear(&mut self)[src]

Clear state cache

pub fn kill_garbage(
    &mut self,
    touched: &HashSet<Address>,
    remove_empty_touched: bool,
    min_balance: &Option<U256>,
    kill_contracts: bool
) -> TrieResult<()>
[src]

Remove any touched empty or dust accounts.

pub fn populate_from(&mut self, accounts: PodState)[src]

Populate the state from accounts. Used for tests.

pub fn to_pod_full(&self) -> Result<PodState, Error>[src]

Populate a PodAccount map from this state. Warning this is not for real time use. Use of this method requires FatDB mode to be able to iterate on accounts.

pub fn diff_from<X: Backend>(&self, orig: State<X>) -> TrieResult<StateDiff>[src]

Returns a StateDiff describing the difference from orig to self. Consumes self.

pub fn require<'a>(
    &'a self,
    a: &Address,
    require_code: bool
) -> TrieResult<RefMut<'a, Account>>
[src]

Pull account a in our cache from the trie DB. require_code requires that the code be cached, too.

pub fn require_or_from<'a, F, G>(
    &'a self,
    a: &Address,
    require_code: bool,
    default: F,
    not_default: G
) -> TrieResult<RefMut<'a, Account>> where
    F: FnOnce() -> Account,
    G: FnOnce(&mut Account), 
[src]

Pull account a in our cache from the trie DB. require_code requires that the code be cached, too. If it doesn’t exist, make account equal the evaluation of default.

pub fn patch_account(
    &self,
    a: &Address,
    code: Arc<Bytes>,
    storage: HashMap<H256, H256>
) -> TrieResult<()>
[src]

Replace account code and storage. Creates account if it does not exist.

impl<B: Backend> State<B>[src]

pub fn prove_account(
    &self,
    account_key: H256
) -> TrieResult<(Vec<Bytes>, BasicAccount)>
[src]

Prove an account’s existence or nonexistence in the state trie. Returns a merkle proof of the account’s trie node omitted or an encountered trie error. If the account doesn’t exist in the trie, prove that and return defaults. Requires a secure trie to be used for accurate results. account_key == keccak(address)

pub fn prove_storage(
    &self,
    account_key: H256,
    storage_key: H256
) -> TrieResult<(Vec<Bytes>, H256)>
[src]

Prove an account’s storage key’s existence or nonexistence in the state. Returns a merkle proof of the account’s storage trie. Requires a secure trie to be used for correctness. account_key == keccak(address) storage_key == keccak(key)

impl<B: Backend> State<B>[src]

pub fn db(&self) -> &B[src]

Get a reference to the underlying state DB.

Trait Implementations

impl<B: Backend + Clone> Clone for State<B>[src]

impl<B: Backend> Debug for State<B>[src]

impl<B: Backend> StateInfo for State<B>[src]

Auto Trait Implementations

impl<B> !RefUnwindSafe for State<B>

impl<B> Send for State<B> where
    B: Send

impl<B> !Sync for State<B>

impl<B> Unpin for State<B> where
    B: Unpin

impl<B> !UnwindSafe for State<B>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> MaybeDebug for T where
    T: Debug
[src]

impl<T> MaybeDebug for T where
    T: Debug
[src]

impl<T> MaybeDebug for T where
    T: Debug
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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