Struct near_chain::test_utils::KeyValueRuntime [−][src]
pub struct KeyValueRuntime { /* fields omitted */ }Expand description
Simple key value runtime for tests.
Implementations
Trait Implementations
fn get_trie_for_shard(
&self,
shard_id: ShardId,
_block_hash: &CryptoHash
) -> Result<Trie, Error>
fn get_trie_for_shard(
&self,
shard_id: ShardId,
_block_hash: &CryptoHash
) -> Result<Trie, Error>
Returns trie. Since shard layout may change from epoch to epoch, shard_id itself is
not enough to identify the trie. prev_hash is used to identify the epoch the given
shard_id is at. Read more
fn get_view_trie_for_shard(
&self,
shard_id: ShardId,
_block_hash: &CryptoHash
) -> Result<Trie, Error>
fn get_view_trie_for_shard(
&self,
shard_id: ShardId,
_block_hash: &CryptoHash
) -> Result<Trie, Error>
Returns trie with view cache
fn verify_block_vrf(
&self,
_epoch_id: &EpochId,
_block_height: BlockHeight,
_prev_random_value: &CryptoHash,
_vrf_value: &Value,
_vrf_proof: &Proof
) -> Result<(), Error>
Verify validator signature for the given epoch. Note: doesnt’t account for slashed accounts within given epoch. USE WITH CAUTION. Read more
Verify header signature.
fn verify_chunk_signature_with_header_parts(
&self,
_chunk_hash: &ChunkHash,
_signature: &Signature,
_prev_block_hash: &CryptoHash,
_height_created: BlockHeight,
_shard_id: ShardId
) -> Result<bool, Error>
Verify aggregated bls signature
fn get_epoch_block_producers_ordered(
&self,
epoch_id: &EpochId,
_last_known_block_hash: &CryptoHash
) -> Result<Vec<(ValidatorStake, bool)>, Error>
fn get_epoch_block_producers_ordered(
&self,
epoch_id: &EpochId,
_last_known_block_hash: &CryptoHash
) -> Result<Vec<(ValidatorStake, bool)>, Error>
Epoch block producers ordered by their order in the proposals. Returns error if height is outside of known boundaries. Read more
fn get_epoch_block_approvers_ordered(
&self,
parent_hash: &CryptoHash
) -> Result<Vec<(ApprovalStake, bool)>, Error>
fn get_block_producer(
&self,
epoch_id: &EpochId,
height: BlockHeight
) -> Result<AccountId, Error>
fn get_block_producer(
&self,
epoch_id: &EpochId,
height: BlockHeight
) -> Result<AccountId, Error>
Block producers for given height for the main block. Return error if outside of known boundaries.
fn get_chunk_producer(
&self,
epoch_id: &EpochId,
height: BlockHeight,
shard_id: ShardId
) -> Result<AccountId, Error>
fn get_chunk_producer(
&self,
epoch_id: &EpochId,
height: BlockHeight,
shard_id: ShardId
) -> Result<AccountId, Error>
Chunk producer for given height for given shard. Return error if outside of known boundaries.
Get current number of shards.
fn get_prev_shard_ids(
&self,
_prev_hash: &CryptoHash,
shard_ids: Vec<ShardId>
) -> Result<Vec<ShardId>, Error>
fn get_shard_layout_from_prev_block(
&self,
_parent_hash: &CryptoHash
) -> Result<ShardLayout, Error>
fn get_shard_layout_from_prev_block(
&self,
_parent_hash: &CryptoHash
) -> Result<ShardLayout, Error>
Get shard layout given hash of previous block.
fn account_id_to_shard_id(
&self,
account_id: &AccountId,
_epoch_id: &EpochId
) -> Result<ShardId, Error>
fn account_id_to_shard_id(
&self,
account_id: &AccountId,
_epoch_id: &EpochId
) -> Result<ShardId, Error>
Account Id to Shard Id mapping, given current number of shards.
Returns account_id that suppose to have the part_id of all chunks given previous block hash.
fn cares_about_shard(
&self,
account_id: Option<&AccountId>,
parent_hash: &CryptoHash,
shard_id: ShardId,
_is_me: bool
) -> bool
fn cares_about_shard(
&self,
account_id: Option<&AccountId>,
parent_hash: &CryptoHash,
shard_id: ShardId,
_is_me: bool
) -> bool
Whether the client cares about some shard right now. Read more
fn will_care_about_shard(
&self,
account_id: Option<&AccountId>,
parent_hash: &CryptoHash,
shard_id: ShardId,
_is_me: bool
) -> bool
fn will_care_about_shard(
&self,
account_id: Option<&AccountId>,
parent_hash: &CryptoHash,
shard_id: ShardId,
_is_me: bool
) -> bool
Whether the client cares about some shard in the next epoch. Read more
fn validate_tx(
&self,
_gas_price: Balance,
_state_update: Option<StateRoot>,
_transaction: &SignedTransaction,
_verify_signature: bool,
_epoch_id: &EpochId,
_current_protocol_version: ProtocolVersion
) -> Result<Option<InvalidTxError>, Error>
fn validate_tx(
&self,
_gas_price: Balance,
_state_update: Option<StateRoot>,
_transaction: &SignedTransaction,
_verify_signature: bool,
_epoch_id: &EpochId,
_current_protocol_version: ProtocolVersion
) -> Result<Option<InvalidTxError>, Error>
Validates a given signed transaction.
If the state root is given, then the verification will use the account. Otherwise it will
only validate the transaction math, limits and signatures.
Returns an option of InvalidTxError, it contains Some(InvalidTxError) if there is
a validation error, or None in case the transaction succeeded.
Throws an Error with ErrorKind::StorageError in case the runtime throws
RuntimeError::StorageError. Read more
fn prepare_transactions(
&self,
_gas_price: Balance,
_gas_limit: Gas,
_epoch_id: &EpochId,
_shard_id: ShardId,
_state_root: StateRoot,
_next_block_height: BlockHeight,
transactions: &mut dyn PoolIterator,
_chain_validate: &mut dyn FnMut(&SignedTransaction) -> bool,
_current_protocol_version: ProtocolVersion
) -> Result<Vec<SignedTransaction>, Error>
fn prepare_transactions(
&self,
_gas_price: Balance,
_gas_limit: Gas,
_epoch_id: &EpochId,
_shard_id: ShardId,
_state_root: StateRoot,
_next_block_height: BlockHeight,
transactions: &mut dyn PoolIterator,
_chain_validate: &mut dyn FnMut(&SignedTransaction) -> bool,
_current_protocol_version: ProtocolVersion
) -> Result<Vec<SignedTransaction>, Error>
Returns an ordered list of valid transactions from the pool up the given limits.
Pulls transactions from the given pool iterators one by one. Validates each transaction
against the given chain_validate closure and runtime’s transaction verifier.
If the transaction is valid for both, it’s added to the result and the temporary state
update is preserved for validation of next transactions.
Throws an Error with ErrorKind::StorageError in case the runtime throws
RuntimeError::StorageError. Read more
fn epoch_sync_init_epoch_manager(
&self,
_prev_epoch_first_block_info: BlockInfo,
_prev_epoch_last_block_info: BlockInfo,
_prev_epoch_prev_last_block_info: BlockInfo,
_prev_epoch_id: &EpochId,
_prev_epoch_info: EpochInfo,
_epoch_id: &EpochId,
_epoch_info: EpochInfo,
_next_epoch_id: &EpochId,
_next_epoch_info: EpochInfo
) -> Result<(), Error>
fn epoch_sync_init_epoch_manager(
&self,
_prev_epoch_first_block_info: BlockInfo,
_prev_epoch_last_block_info: BlockInfo,
_prev_epoch_prev_last_block_info: BlockInfo,
_prev_epoch_id: &EpochId,
_prev_epoch_info: EpochInfo,
_epoch_id: &EpochId,
_epoch_info: EpochInfo,
_next_epoch_id: &EpochId,
_next_epoch_info: EpochInfo
) -> Result<(), Error>
Epoch Manager init procedure that is necessary after Epoch Sync.
fn add_validator_proposals(
&self,
_block_header_info: BlockHeaderInfo
) -> Result<StoreUpdate, Error>
fn add_validator_proposals(
&self,
_block_header_info: BlockHeaderInfo
) -> Result<StoreUpdate, Error>
Add proposals for validators.
fn apply_transactions_with_optional_storage_proof(
&self,
shard_id: ShardId,
state_root: &StateRoot,
_height: BlockHeight,
_block_timestamp: u64,
_prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
receipts: &[Receipt],
transactions: &[SignedTransaction],
_last_validator_proposals: ValidatorStakeIter<'_>,
gas_price: Balance,
_gas_limit: Gas,
_challenges: &ChallengesResult,
_random_seed: CryptoHash,
generate_storage_proof: bool,
_is_new_chunk: bool,
_is_first_block_with_chunk_of_version: bool,
states_to_patch: Option<Vec<StateRecord>>
) -> Result<ApplyTransactionResult, Error>
fn check_state_transition(
&self,
_partial_storage: PartialStorage,
_shard_id: ShardId,
_state_root: &StateRoot,
_height: BlockHeight,
_block_timestamp: u64,
_prev_block_hash: &CryptoHash,
_block_hash: &CryptoHash,
_receipts: &[Receipt],
_transactions: &[SignedTransaction],
_last_validator_proposals: ValidatorStakeIter<'_>,
_gas_price: Balance,
_gas_limit: Gas,
_challenges: &ChallengesResult,
_random_value: CryptoHash,
_is_new_chunk: bool,
_is_first_block_with_chunk_of_version: bool
) -> Result<ApplyTransactionResult, Error>
fn query(
&self,
_shard_id: ShardUId,
state_root: &StateRoot,
block_height: BlockHeight,
_block_timestamp: u64,
_prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
_epoch_id: &EpochId,
request: &QueryRequest
) -> Result<QueryResponse, QueryError>
fn query(
&self,
_shard_id: ShardUId,
state_root: &StateRoot,
block_height: BlockHeight,
_block_timestamp: u64,
_prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
_epoch_id: &EpochId,
request: &QueryRequest
) -> Result<QueryResponse, QueryError>
Query runtime with given path and data.
Get the part of the state from given state root.
block_hash is a block whose prev_state_root is state_root Read more
Validate state part that expected to be given state root with provided data. Returns false if the resulting part doesn’t match the expected one. Read more
Should be executed after accepting all the parts to set up a new state.
fn get_state_root_node(
&self,
_shard_id: ShardId,
_block_hash: &CryptoHash,
state_root: &StateRoot
) -> Result<StateRootNode, Error>
fn get_state_root_node(
&self,
_shard_id: ShardId,
_block_hash: &CryptoHash,
state_root: &StateRoot
) -> Result<StateRootNode, Error>
Returns StateRootNode of a state.
block_hash is a block whose prev_state_root is state_root
Panics if requested hash is not in storage.
Never returns Error Read more
fn validate_state_root_node(
&self,
_state_root_node: &StateRootNode,
_state_root: &StateRoot
) -> bool
fn validate_state_root_node(
&self,
_state_root_node: &StateRootNode,
_state_root: &StateRoot
) -> bool
Validate StateRootNode of a state.
Returns true, if given hash is last block in it’s epoch.
Get epoch id given hash of previous block.
fn get_next_epoch_id_from_prev_block(
&self,
parent_hash: &CryptoHash
) -> Result<EpochId, Error>
fn get_next_epoch_id_from_prev_block(
&self,
parent_hash: &CryptoHash
) -> Result<EpochId, Error>
Get next epoch id given hash of previous block.
Get epoch start for given block hash.
Get the block height for which garbage collection should not go over
Check if epoch exists.
Amount of tokens minted in given epoch.
Data that is necessary for prove Epochs in Epoch Sync.
Hash that is necessary for prove Epochs in Epoch Sync.
Epoch active protocol version.
fn get_validator_info(
&self,
_epoch_id: ValidatorInfoIdentifier
) -> Result<EpochValidatorInfo, Error>
fn compare_epoch_id(
&self,
epoch_id: &EpochId,
other_epoch_id: &EpochId
) -> Result<Ordering, Error>
fn chunk_needs_to_be_fetched_from_archival(
&self,
_chunk_prev_block_hash: &CryptoHash,
_header_head: &CryptoHash
) -> Result<bool, Error>
Verify signature for validator or fisherman. Used for validating challenges.
fn get_validator_by_account_id(
&self,
epoch_id: &EpochId,
_last_known_block_hash: &CryptoHash,
account_id: &AccountId
) -> Result<(ValidatorStake, bool), Error>
fn get_fisherman_by_account_id(
&self,
_epoch_id: &EpochId,
_last_known_block_hash: &CryptoHash,
_account_id: &AccountId
) -> Result<(ValidatorStake, bool), Error>
fn get_prev_epoch_id_from_prev_block(
&self,
prev_block_hash: &CryptoHash
) -> Result<EpochId, Error>
fn get_prev_epoch_id_from_prev_block(
&self,
prev_block_hash: &CryptoHash
) -> Result<EpochId, Error>
Get previous epoch id by hash of previous block.
fn will_shard_layout_change_next_epoch(
&self,
_parent_hash: &CryptoHash
) -> Result<bool, Error>
fn will_shard_layout_change_next_epoch(
&self,
_parent_hash: &CryptoHash
) -> Result<bool, Error>
Returns true if the shard layout will change in the next epoch
Current epoch is the epoch of the block after parent_hash Read more
fn apply_update_to_split_states(
&self,
_block_hash: &CryptoHash,
_state_roots: HashMap<ShardUId, StateRoot>,
_next_shard_layout: &ShardLayout,
_state_changes: StateChangesForSplitStates
) -> Result<Vec<ApplySplitStateResult>, Error>
fn build_state_for_split_shards(
&self,
_shard_uid: ShardUId,
_state_root: &StateRoot,
_next_epoch_shard_layout: &ShardLayout
) -> Result<HashMap<ShardUId, StateRoot>, Error>
Verify chunk header signature.
fn apply_transactions(
&self,
shard_id: ShardId,
state_root: &StateRoot,
height: BlockHeight,
block_timestamp: u64,
prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
receipts: &[Receipt],
transactions: &[SignedTransaction],
last_validator_proposals: ValidatorStakeIter<'_>,
gas_price: Balance,
gas_limit: Gas,
challenges_result: &ChallengesResult,
random_seed: CryptoHash,
is_new_chunk: bool,
is_first_block_with_chunk_of_version: bool,
states_to_patch: Option<Vec<StateRecord>>
) -> Result<ApplyTransactionResult, Error>
fn apply_transactions(
&self,
shard_id: ShardId,
state_root: &StateRoot,
height: BlockHeight,
block_timestamp: u64,
prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
receipts: &[Receipt],
transactions: &[SignedTransaction],
last_validator_proposals: ValidatorStakeIter<'_>,
gas_price: Balance,
gas_limit: Gas,
challenges_result: &ChallengesResult,
random_seed: CryptoHash,
is_new_chunk: bool,
is_first_block_with_chunk_of_version: bool,
states_to_patch: Option<Vec<StateRecord>>
) -> Result<ApplyTransactionResult, Error>
Apply transactions to given state root and return store update and new state root. Also returns transaction result for each transaction and new receipts. Read more
fn build_receipts_hashes(
&self,
receipts: &[Receipt],
shard_layout: &ShardLayout
) -> Vec<CryptoHash>
fn build_receipts_hashes(
&self,
receipts: &[Receipt],
shard_layout: &ShardLayout
) -> Vec<CryptoHash>
Build receipts hashes.
Auto Trait Implementations
impl !RefUnwindSafe for KeyValueRuntime
impl Send for KeyValueRuntime
impl Sync for KeyValueRuntime
impl Unpin for KeyValueRuntime
impl !UnwindSafe for KeyValueRuntime
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more