Struct cfx_executor::state::State

source ·
pub struct State {
    pub cache: RwLock<HashMap<AddressWithSpace, AccountEntryWithWarm>>,
    pub committed_cache: HashMap<AddressWithSpace, AccountEntry>,
    /* private fields */
}
Expand description

A caching and checkpoint layer built upon semantically meaningful database interfaces, providing interfaces and logics for managing accounts and global statistics to the execution engine.

Fields§

§cache: RwLock<HashMap<AddressWithSpace, AccountEntryWithWarm>>

Caches for the account entries

WARNING: Don’t delete cache entries outside of State::commit, unless you are familiar with checkpoint maintenance.

§committed_cache: HashMap<AddressWithSpace, AccountEntry>

Implementations§

source§

impl State

source

pub fn new_contract_with_admin( &mut self, contract: &AddressWithSpace, admin: &Address, balance: U256, storage_layout: Option<StorageLayout>, cip107: bool ) -> DbResult<()>

source

pub fn remove_contract(&mut self, address: &AddressWithSpace) -> DbResult<()>

Kill a contract

source

pub fn genesis_special_remove_account( &mut self, address: &Address ) -> DbResult<()>

A special implementation to achieve the backward compatible for the genesis (incorrect) behaviour.

source§

impl State

source

pub fn exists(&self, address: &AddressWithSpace) -> DbResult<bool>

source

pub fn touch(&self, address: &AddressWithSpace) -> DbResult<()>

Touch an account to mark it as warm

source

pub fn exists_and_not_null(&self, address: &AddressWithSpace) -> DbResult<bool>

source

pub fn balance(&self, address: &AddressWithSpace) -> DbResult<U256>

source

pub fn add_balance( &mut self, address: &AddressWithSpace, by: &U256 ) -> DbResult<()>

source

pub fn sub_balance( &mut self, address: &AddressWithSpace, by: &U256 ) -> DbResult<()>

source

pub fn transfer_balance( &mut self, from: &AddressWithSpace, to: &AddressWithSpace, by: &U256 ) -> DbResult<()>

source

pub fn nonce(&self, address: &AddressWithSpace) -> DbResult<U256>

source

pub fn inc_nonce(&mut self, address: &AddressWithSpace) -> DbResult<bool>

source

pub fn set_nonce( &mut self, address: &AddressWithSpace, nonce: &U256 ) -> DbResult<()>

source

pub fn is_contract_with_code( &self, address: &AddressWithSpace ) -> DbResult<bool>

source

pub fn is_eip684_empty(&self, address: &AddressWithSpace) -> DbResult<bool>

source

pub fn is_eip158_empty(&self, address: &AddressWithSpace) -> DbResult<bool>

source

pub fn code_hash(&self, address: &AddressWithSpace) -> DbResult<H256>

source

pub fn has_no_code(&self, address: &AddressWithSpace) -> DbResult<bool>

source

pub fn code_size(&self, address: &AddressWithSpace) -> DbResult<usize>

source

pub fn code_owner(&self, address: &AddressWithSpace) -> DbResult<Address>

source

pub fn code(&self, address: &AddressWithSpace) -> DbResult<Option<Arc<Vec<u8>>>>

source

pub fn code_with_hash_on_call( &self, address: &AddressWithSpace ) -> DbResult<(Option<Arc<Vec<u8>>>, H256)>

source

pub fn init_code( &mut self, address: &AddressWithSpace, code: Bytes, owner: Address, transaction_hash: H256 ) -> DbResult<()>

source

pub fn created_at_transaction( &self, address: &AddressWithSpace, transaction_hash: H256 ) -> DbResult<bool>

source

pub fn set_authorization( &mut self, authority: &AddressWithSpace, address: &Address ) -> DbResult<()>

source

pub fn admin(&self, address: &Address) -> DbResult<Address>

source

pub fn set_admin( &mut self, contract_address: &Address, admin: &Address ) -> DbResult<()>

source§

impl State

source

pub fn write_account_lock( &self, address: &AddressWithSpace ) -> DbResult<MappedRwLockWriteGuard<'_, OverlayAccount>>

A convenience function of write_account_ext_lock

source§

impl State

source

pub fn no_checkpoint(&self) -> bool

source§

impl State

source

pub fn collateral_for_storage(&self, address: &Address) -> DbResult<U256>

source

pub fn token_collateral_for_storage(&self, address: &Address) -> DbResult<U256>

source

pub fn available_storage_points_for_collateral( &self, address: &Address ) -> DbResult<U256>

source

pub fn add_collateral_for_storage( &mut self, address: &Address, by: &U256 ) -> DbResult<U256>

Caller should make sure that staking_balance for this account is sufficient enough.

source

pub fn sub_collateral_for_storage( &mut self, address: &Address, by: &U256 ) -> DbResult<U256>

source

pub fn check_storage_limit( &self, original_sender: &Address, storage_limit: &U256, dry_run: bool ) -> DbResult<Result<(), CollateralCheckError>>

source

pub fn storage_point_prop(&self) -> DbResult<U256>

source§

impl State

source

pub fn commit( self, epoch_id: EpochId, debug_record: Option<&mut ComputeEpochDebugRecord> ) -> DbResult<StateCommitResult>

Commit everything to the storage.

source

pub fn compute_state_root_for_genesis( &mut self, debug_record: Option<&mut ComputeEpochDebugRecord> ) -> DbResult<StateRootWithAuxInfo>

Commit to the statedb and compute state root. Only called in the genesis

source

pub fn apply_changes_to_statedb( &mut self, debug_record: Option<&mut ComputeEpochDebugRecord> ) -> DbResult<Vec<Account>>

Apply changes for the accounts and global variables to the statedb.

source§

impl State

source

pub fn commit_cache(&mut self, retain_transient_storage: bool)

source§

impl State

source

pub fn total_issued_tokens(&self) -> U256

source

pub fn add_total_issued(&mut self, v: U256)

Maintain total_issued_tokens.

source

pub fn sub_total_issued(&mut self, v: U256)

Maintain total_issued_tokens. This is only used in the extremely unlikely case that there are a lot of partial invalid blocks.

source

pub fn add_total_pos_staking(&mut self, v: U256)

source

pub fn add_total_evm_tokens(&mut self, v: U256)

source

pub fn sub_total_evm_tokens(&mut self, v: U256)

source

pub fn total_staking_tokens(&self) -> U256

source

pub fn total_storage_tokens(&self) -> U256

source

pub fn total_espace_tokens(&self) -> U256

source

pub fn used_storage_points(&self) -> U256

source

pub fn converted_storage_points(&self) -> U256

source

pub fn total_pos_staking_tokens(&self) -> U256

source

pub fn sub_total_pos_staking(&mut self, v: U256)

source

pub fn total_circulating_tokens(&self) -> DbResult<U256>

source

pub fn add_converted_storage_point( &mut self, from_balance: U256, from_collateral: U256 )

source§

impl State

source

pub fn is_warm_account(&self, address: &AddressWithSpace) -> bool

source

pub fn is_warm_storage_entry( &self, address: &AddressWithSpace, key: &H256 ) -> DbResult<bool>

source

pub fn set_tx_access_list( &mut self, space: Space, access_list: &[AccessListItem] )

source

pub fn touch_tx_addresses(&self, params: &ActionParams) -> DbResult<()>

source

pub fn clear_tx_access_list(&mut self)

source

pub fn update_state_post_tx_execution(&mut self, retain_transient_storage: bool)

source§

impl State

source

pub fn inc_distributable_pos_interest( &mut self, current_block_number: u64 ) -> DbResult<()>

source

pub fn pos_locked_staking(&self, address: &Address) -> DbResult<U256>

source

pub fn add_pos_interest( &mut self, address: &Address, interest: &U256 ) -> DbResult<()>

source§

impl State

source

pub fn save(&mut self) -> SavedState

source

pub fn restore(&mut self, saved: SavedState)

source§

impl State

source

pub fn sponsor_info(&self, address: &Address) -> DbResult<Option<SponsorInfo>>

source

pub fn sponsor_for_gas(&self, address: &Address) -> DbResult<Option<Address>>

source

pub fn set_sponsor_for_gas( &self, address: &Address, sponsor: &Address, sponsor_balance: &U256, upper_bound: &U256 ) -> DbResult<()>

source

pub fn sponsor_balance_for_gas(&self, address: &Address) -> DbResult<U256>

source

pub fn add_sponsor_balance_for_gas( &mut self, address: &Address, by: &U256 ) -> DbResult<()>

source

pub fn sub_sponsor_balance_for_gas( &mut self, address: &Address, by: &U256 ) -> DbResult<()>

source

pub fn sponsor_gas_bound(&self, address: &Address) -> DbResult<U256>

source

pub fn sponsor_for_collateral( &self, address: &Address ) -> DbResult<Option<Address>>

source

pub fn set_sponsor_for_collateral( &mut self, address: &Address, sponsor: &Address, sponsor_balance: &U256, is_cip107: bool ) -> DbResult<U256>

source

pub fn sponsor_balance_for_collateral( &self, address: &Address ) -> DbResult<U256>

source

pub fn add_sponsor_balance_for_collateral( &mut self, address: &Address, by: &U256 ) -> DbResult<()>

source

pub fn sub_sponsor_balance_for_collateral( &mut self, address: &Address, by: &U256 ) -> DbResult<()>

source

pub fn check_contract_whitelist( &self, contract_address: &Address, user: &Address ) -> DbResult<bool>

source

pub fn add_to_contract_whitelist( &mut self, contract_address: Address, storage_owner: Address, user: Address, substate: &mut Substate ) -> DbResult<()>

source

pub fn remove_from_contract_whitelist( &mut self, contract_address: Address, storage_owner: Address, user: Address, substate: &mut Substate ) -> DbResult<()>

source

pub fn record_storage_and_whitelist_entries_release( &mut self, address: &Address, substate: &mut Substate, cip131: bool ) -> DbResult<()>

source§

impl State

source

pub fn staking_balance(&self, address: &Address) -> DbResult<U256>

source

pub fn withdrawable_staking_balance( &self, address: &Address, current_block_number: u64 ) -> DbResult<U256>

source

pub fn locked_staking_balance_at_block_number( &self, address: &Address, block_number: u64 ) -> DbResult<U256>

source

pub fn vote_stake_list_length(&self, address: &Address) -> DbResult<usize>

source

pub fn vote_lock( &mut self, address: &Address, amount: &U256, unlock_block_number: u64 ) -> DbResult<()>

source

pub fn remove_expired_vote_stake_info( &mut self, address: &Address, current_block_number: u64 ) -> DbResult<()>

source

pub fn deposit_list_length(&self, address: &Address) -> DbResult<usize>

source

pub fn deposit( &mut self, address: &Address, amount: &U256, current_block_number: u64, cip_97: bool ) -> DbResult<()>

source

pub fn withdraw( &mut self, address: &Address, amount: &U256, cip_97: bool ) -> DbResult<U256>

source§

impl State

source

pub fn get_system_storage(&self, key: &[u8]) -> DbResult<U256>

source

pub fn set_system_storage(&mut self, key: Vec<u8>, value: U256) -> DbResult<()>

source

pub fn set_eip2935_storage( &mut self, block_height: u64, block_hash: H256 ) -> DbResult<()>

source

pub fn storage_at( &self, address: &AddressWithSpace, key: &[u8] ) -> DbResult<U256>

source

pub fn origin_storage_at( &self, address: &AddressWithSpace, key: &[u8] ) -> DbResult<Option<U256>>

source

pub fn transient_storage_at( &self, address: &AddressWithSpace, key: &[u8] ) -> DbResult<U256>

source

pub fn storage_entry_at( &self, address: &AddressWithSpace, key: &[u8] ) -> DbResult<StorageValue>

source

pub fn set_storage( &mut self, address: &AddressWithSpace, key: Vec<u8>, value: U256, owner: Address, substate: &mut Substate ) -> DbResult<()>

source

pub fn transient_set_storage( &mut self, address: &AddressWithSpace, key: Vec<u8>, value: U256 ) -> DbResult<()>

source

pub fn is_fresh_storage(&self, address: &AddressWithSpace) -> DbResult<bool>

source§

impl State

source

pub fn bump_block_number_accumulate_interest(&mut self)

Calculate the secondary reward for the next block number.

source

pub fn secondary_reward(&self) -> U256

source

pub fn pow_base_reward(&self) -> U256

source

pub fn distributable_pos_interest(&self) -> U256

source

pub fn last_distribute_block(&self) -> u64

source

pub fn reset_pos_distribute_info(&mut self, current_block_number: u64)

source

pub fn burn_by_cip1559(&mut self, by: U256)

source

pub fn get_base_price_prop(&self) -> U256

source

pub fn set_base_fee_prop(&mut self, val: U256)

source

pub fn burnt_gas_price(&self, base_price: U256) -> U256

source§

impl State

Apply the state override to the state object, only used for rpc call eg eth_call, eth_estimateGas etc.

source

pub fn new_with_override( db: StateDb, state_override: &StateOverride, space: Space ) -> DbResult<Self>

source§

impl State

source

pub fn new(db: StateDb) -> DbResult<Self>

source

pub fn prefetch_accounts( &mut self, addresses: BTreeSet<AddressWithSpace>, pool: &ThreadPool ) -> DbResult<()>

Auto Trait Implementations§

§

impl !Freeze for State

§

impl !RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl !UnwindSafe for State

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
source§

impl<T> ElementSatisfy<ElementNoConstrain> for T

§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
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 T
where 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.

§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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 T
where 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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T

§

impl<T> UnsafeAny for T
where T: Any,