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
impl State
pub fn new_contract_with_admin( &mut self, contract: &AddressWithSpace, admin: &Address, balance: U256, storage_layout: Option<StorageLayout>, cip107: bool, ) -> DbResult<()>
Sourcepub fn remove_contract(&mut self, address: &AddressWithSpace) -> DbResult<()>
pub fn remove_contract(&mut self, address: &AddressWithSpace) -> DbResult<()>
Kill a contract
Sourcepub fn genesis_special_remove_account(
&mut self,
address: &Address,
) -> DbResult<()>
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
impl State
pub fn exists(&self, address: &AddressWithSpace) -> DbResult<bool>
Sourcepub fn touch(&self, address: &AddressWithSpace) -> DbResult<()>
pub fn touch(&self, address: &AddressWithSpace) -> DbResult<()>
Touch an account to mark it as warm
pub fn exists_and_not_null(&self, address: &AddressWithSpace) -> DbResult<bool>
pub fn balance(&self, address: &AddressWithSpace) -> DbResult<U256>
pub fn add_balance( &mut self, address: &AddressWithSpace, by: &U256, ) -> DbResult<()>
pub fn sub_balance( &mut self, address: &AddressWithSpace, by: &U256, ) -> DbResult<()>
pub fn transfer_balance( &mut self, from: &AddressWithSpace, to: &AddressWithSpace, by: &U256, ) -> DbResult<()>
pub fn nonce(&self, address: &AddressWithSpace) -> DbResult<U256>
pub fn inc_nonce(&mut self, address: &AddressWithSpace) -> DbResult<bool>
pub fn set_nonce( &mut self, address: &AddressWithSpace, nonce: &U256, ) -> DbResult<()>
pub fn is_contract_with_code( &self, address: &AddressWithSpace, ) -> DbResult<bool>
pub fn is_eip684_empty(&self, address: &AddressWithSpace) -> DbResult<bool>
pub fn is_eip158_empty(&self, address: &AddressWithSpace) -> DbResult<bool>
pub fn code_hash(&self, address: &AddressWithSpace) -> DbResult<H256>
pub fn has_no_code(&self, address: &AddressWithSpace) -> DbResult<bool>
pub fn code_size(&self, address: &AddressWithSpace) -> DbResult<usize>
pub fn code_owner(&self, address: &AddressWithSpace) -> DbResult<Address>
pub fn code(&self, address: &AddressWithSpace) -> DbResult<Option<Arc<Vec<u8>>>>
pub fn code_with_hash_on_call( &self, address: &AddressWithSpace, ) -> DbResult<(Option<Arc<Vec<u8>>>, H256)>
pub fn init_code( &mut self, address: &AddressWithSpace, code: Bytes, owner: Address, transaction_hash: H256, ) -> DbResult<()>
pub fn created_at_transaction( &self, address: &AddressWithSpace, transaction_hash: H256, ) -> DbResult<bool>
pub fn admin(&self, address: &Address) -> DbResult<Address>
pub fn set_admin( &mut self, contract_address: &Address, admin: &Address, ) -> DbResult<()>
Source§impl State
impl State
Sourcepub fn write_account_lock(
&self,
address: &AddressWithSpace,
) -> DbResult<MappedRwLockWriteGuard<'_, OverlayAccount>>
pub fn write_account_lock( &self, address: &AddressWithSpace, ) -> DbResult<MappedRwLockWriteGuard<'_, OverlayAccount>>
A convenience function of write_account_ext_lock
Source§impl State
impl State
pub fn collateral_for_storage(&self, address: &Address) -> DbResult<U256>
pub fn token_collateral_for_storage(&self, address: &Address) -> DbResult<U256>
pub fn available_storage_points_for_collateral( &self, address: &Address, ) -> DbResult<U256>
Sourcepub fn add_collateral_for_storage(
&mut self,
address: &Address,
by: &U256,
) -> DbResult<U256>
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.
pub fn sub_collateral_for_storage( &mut self, address: &Address, by: &U256, ) -> DbResult<U256>
pub fn check_storage_limit( &self, original_sender: &Address, storage_limit: &U256, dry_run: bool, ) -> DbResult<Result<(), CollateralCheckError>>
pub fn storage_point_prop(&self) -> DbResult<U256>
Source§impl State
impl State
Sourcepub fn commit(
self,
epoch_id: EpochId,
debug_record: Option<&mut ComputeEpochDebugRecord>,
) -> DbResult<StateCommitResult>
pub fn commit( self, epoch_id: EpochId, debug_record: Option<&mut ComputeEpochDebugRecord>, ) -> DbResult<StateCommitResult>
Commit everything to the storage.
Sourcepub fn compute_state_root_for_genesis(
&mut self,
debug_record: Option<&mut ComputeEpochDebugRecord>,
) -> DbResult<StateRootWithAuxInfo>
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
Sourcepub fn apply_changes_to_statedb(
&mut self,
debug_record: Option<&mut ComputeEpochDebugRecord>,
) -> DbResult<Vec<Account>>
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
impl State
pub fn total_issued_tokens(&self) -> U256
Sourcepub fn add_total_issued(&mut self, v: U256)
pub fn add_total_issued(&mut self, v: U256)
Maintain total_issued_tokens.
Sourcepub fn sub_total_issued(&mut self, v: U256)
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.
pub fn add_total_pos_staking(&mut self, v: U256)
pub fn add_total_evm_tokens(&mut self, v: U256)
pub fn sub_total_evm_tokens(&mut self, v: U256)
pub fn total_staking_tokens(&self) -> U256
pub fn total_storage_tokens(&self) -> U256
pub fn total_espace_tokens(&self) -> U256
pub fn used_storage_points(&self) -> U256
pub fn converted_storage_points(&self) -> U256
pub fn total_pos_staking_tokens(&self) -> U256
pub fn sub_total_pos_staking(&mut self, v: U256)
pub fn total_circulating_tokens(&self) -> DbResult<U256>
pub fn add_converted_storage_point( &mut self, from_balance: U256, from_collateral: U256, )
Source§impl State
impl State
pub fn is_warm_account(&self, address: &AddressWithSpace) -> bool
pub fn is_warm_storage_entry( &self, address: &AddressWithSpace, key: &H256, ) -> DbResult<bool>
Sourcepub fn set_tx_access_list(
&mut self,
space: Space,
access_list: &[AccessListItem],
cip176: bool,
)
pub fn set_tx_access_list( &mut self, space: Space, access_list: &[AccessListItem], cip176: bool, )
Pre-warms the addresses and storage keys carried by the transaction’s access list.
EIP-2930 permits the same address to appear in more than one entry, in which case the warmed storage keys are the union over all of its entries. Before CIP-176 a later entry replaced the storage keys recorded by an earlier one, leaving the earlier keys cold even though the transaction was charged for them.
pub fn touch_tx_addresses(&self, params: &ActionParams) -> DbResult<()>
pub fn clear_tx_access_list(&mut self)
pub fn update_state_post_tx_execution(&mut self, retain_transient_storage: bool)
Source§impl State
impl State
pub fn inc_distributable_pos_interest( &mut self, current_block_number: u64, ) -> DbResult<()>
pub fn pos_locked_staking(&self, address: &Address) -> DbResult<U256>
pub fn add_pos_interest( &mut self, address: &Address, interest: &U256, ) -> DbResult<()>
Source§impl State
impl State
pub fn sponsor_info(&self, address: &Address) -> DbResult<Option<SponsorInfo>>
pub fn sponsor_for_gas(&self, address: &Address) -> DbResult<Option<Address>>
pub fn set_sponsor_for_gas( &self, address: &Address, sponsor: &Address, sponsor_balance: &U256, upper_bound: &U256, ) -> DbResult<()>
pub fn sponsor_balance_for_gas(&self, address: &Address) -> DbResult<U256>
pub fn add_sponsor_balance_for_gas( &mut self, address: &Address, by: &U256, ) -> DbResult<()>
pub fn sub_sponsor_balance_for_gas( &mut self, address: &Address, by: &U256, ) -> DbResult<()>
pub fn sponsor_gas_bound(&self, address: &Address) -> DbResult<U256>
pub fn sponsor_for_collateral( &self, address: &Address, ) -> DbResult<Option<Address>>
pub fn set_sponsor_for_collateral( &mut self, address: &Address, sponsor: &Address, sponsor_balance: &U256, is_cip107: bool, ) -> DbResult<U256>
pub fn sponsor_balance_for_collateral( &self, address: &Address, ) -> DbResult<U256>
pub fn add_sponsor_balance_for_collateral( &mut self, address: &Address, by: &U256, ) -> DbResult<()>
pub fn sub_sponsor_balance_for_collateral( &mut self, address: &Address, by: &U256, ) -> DbResult<()>
pub fn check_contract_whitelist( &self, contract_address: &Address, user: &Address, ) -> DbResult<bool>
pub fn add_to_contract_whitelist( &mut self, contract_address: Address, storage_owner: Address, user: Address, substate: &mut Substate, ) -> DbResult<()>
pub fn remove_from_contract_whitelist( &mut self, contract_address: Address, storage_owner: Address, user: Address, substate: &mut Substate, ) -> DbResult<()>
pub fn record_storage_and_whitelist_entries_release( &mut self, address: &Address, substate: &mut Substate, cip131: bool, ) -> DbResult<()>
Source§impl State
impl State
pub fn staking_balance(&self, address: &Address) -> DbResult<U256>
pub fn withdrawable_staking_balance( &self, address: &Address, current_block_number: u64, ) -> DbResult<U256>
pub fn locked_staking_balance_at_block_number( &self, address: &Address, block_number: u64, ) -> DbResult<U256>
pub fn vote_stake_list_length(&self, address: &Address) -> DbResult<usize>
pub fn vote_lock( &mut self, address: &Address, amount: &U256, unlock_block_number: u64, ) -> DbResult<()>
pub fn remove_expired_vote_stake_info( &mut self, address: &Address, current_block_number: u64, ) -> DbResult<()>
pub fn deposit_list_length(&self, address: &Address) -> DbResult<usize>
pub fn deposit( &mut self, address: &Address, amount: &U256, current_block_number: u64, cip_97: bool, ) -> DbResult<()>
pub fn withdraw( &mut self, address: &Address, amount: &U256, cip_97: bool, ) -> DbResult<U256>
Source§impl State
impl State
pub fn get_system_storage(&self, key: &[u8]) -> DbResult<U256>
pub fn set_system_storage(&mut self, key: Vec<u8>, value: U256) -> DbResult<()>
pub fn set_eip2935_storage( &mut self, block_height: u64, block_hash: H256, ) -> DbResult<()>
pub fn storage_at( &self, address: &AddressWithSpace, key: &[u8], ) -> DbResult<U256>
pub fn origin_storage_at( &self, address: &AddressWithSpace, key: &[u8], ) -> DbResult<Option<U256>>
pub fn transient_storage_at( &self, address: &AddressWithSpace, key: &[u8], ) -> DbResult<U256>
pub fn storage_entry_at( &self, address: &AddressWithSpace, key: &[u8], ) -> DbResult<StorageValue>
pub fn set_storage( &mut self, address: &AddressWithSpace, key: Vec<u8>, value: U256, owner: Address, substate: &mut Substate, ) -> DbResult<()>
pub fn transient_set_storage( &mut self, address: &AddressWithSpace, key: Vec<u8>, value: U256, ) -> DbResult<()>
pub fn is_fresh_storage(&self, address: &AddressWithSpace) -> DbResult<bool>
Source§impl State
impl State
Sourcepub fn bump_block_number_accumulate_interest(&mut self)
pub fn bump_block_number_accumulate_interest(&mut self)
Calculate the secondary reward for the next block number.
pub fn secondary_reward(&self) -> U256
pub fn pow_base_reward(&self) -> U256
pub fn distributable_pos_interest(&self) -> U256
pub fn last_distribute_block(&self) -> u64
pub fn reset_pos_distribute_info(&mut self, current_block_number: u64)
pub fn burn_by_cip1559(&mut self, by: U256)
pub fn get_base_price_prop(&self) -> U256
pub fn set_base_fee_prop(&mut self, val: U256)
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.
impl State
Apply the state override to the state object, only used for rpc call eg eth_call, eth_estimateGas etc.
pub fn new_with_override( db: StateDb, state_override: &StateOverride, space: Space, ) -> DbResult<Self>
Auto Trait Implementations§
impl !Freeze for State
impl !RefUnwindSafe for State
impl !UnwindSafe for State
impl Forget for State
impl Move for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
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> Conv for T
impl<T> Conv for T
Source§impl<T> ElementSatisfy<ElementNoConstrain> for T
impl<T> ElementSatisfy<ElementNoConstrain> for T
fn to_constrain_object(&self) -> &ElementNoConstrain
fn to_constrain_object_mut(&mut self) -> &mut ElementNoConstrain
impl<T> ErasedDestructor for Twhere
T: 'static,
§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.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSend for Twhere
T: Send,
impl<T> MaybeSendSync for T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§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,
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) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
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
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
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
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
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
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.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
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.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
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.