Trait near_chain::types::RuntimeAdapter[][src]

pub trait RuntimeAdapter: Send + Sync {
Show 61 methods fn genesis_state(&self) -> (Arc<Store>, Vec<StateRoot>);
fn get_tries(&self) -> ShardTries;
fn get_store(&self) -> Arc<Store>;
fn get_trie_for_shard(
        &self,
        shard_id: ShardId,
        prev_hash: &CryptoHash
    ) -> Result<Trie, Error>;
fn get_view_trie_for_shard(
        &self,
        shard_id: ShardId,
        prev_hash: &CryptoHash
    ) -> Result<Trie, Error>;
fn verify_block_vrf(
        &self,
        epoch_id: &EpochId,
        block_height: BlockHeight,
        prev_random_value: &CryptoHash,
        vrf_value: &Value,
        vrf_proof: &Proof
    ) -> Result<(), Error>;
fn validate_tx(
        &self,
        gas_price: Balance,
        state_root: Option<StateRoot>,
        transaction: &SignedTransaction,
        verify_signature: bool,
        epoch_id: &EpochId,
        current_protocol_version: ProtocolVersion
    ) -> Result<Option<InvalidTxError>, Error>;
fn prepare_transactions(
        &self,
        gas_price: Balance,
        gas_limit: Gas,
        epoch_id: &EpochId,
        shard_id: ShardId,
        state_root: StateRoot,
        next_block_height: BlockHeight,
        pool_iterator: &mut dyn PoolIterator,
        chain_validate: &mut dyn FnMut(&SignedTransaction) -> bool,
        current_protocol_version: ProtocolVersion
    ) -> Result<Vec<SignedTransaction>, Error>;
fn verify_validator_signature(
        &self,
        epoch_id: &EpochId,
        last_known_block_hash: &CryptoHash,
        account_id: &AccountId,
        data: &[u8],
        signature: &Signature
    ) -> Result<bool, Error>;
fn verify_validator_or_fisherman_signature(
        &self,
        epoch_id: &EpochId,
        last_known_block_hash: &CryptoHash,
        account_id: &AccountId,
        data: &[u8],
        signature: &Signature
    ) -> Result<bool, Error>;
fn verify_header_signature(
        &self,
        header: &BlockHeader
    ) -> Result<bool, Error>;
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>;
fn verify_approval(
        &self,
        prev_block_hash: &CryptoHash,
        prev_block_height: BlockHeight,
        block_height: BlockHeight,
        approvals: &[Option<Signature>]
    ) -> Result<bool, Error>;
fn get_epoch_block_producers_ordered(
        &self,
        epoch_id: &EpochId,
        last_known_block_hash: &CryptoHash
    ) -> Result<Vec<(ValidatorStake, bool)>, Error>;
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_chunk_producer(
        &self,
        epoch_id: &EpochId,
        height: BlockHeight,
        shard_id: ShardId
    ) -> Result<AccountId, Error>;
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 num_shards(&self, epoch_id: &EpochId) -> Result<ShardId, Error>;
fn num_total_parts(&self) -> usize;
fn num_data_parts(&self) -> usize;
fn account_id_to_shard_id(
        &self,
        account_id: &AccountId,
        epoch_id: &EpochId
    ) -> Result<ShardId, Error>;
fn get_part_owner(
        &self,
        parent_hash: &CryptoHash,
        part_id: u64
    ) -> Result<AccountId, Error>;
fn get_shard_layout(&self, epoch_id: &EpochId) -> Result<ShardLayout, Error>;
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 shard_id_to_uid(
        &self,
        shard_id: ShardId,
        epoch_id: &EpochId
    ) -> Result<ShardUId, Error>;
fn will_shard_layout_change_next_epoch(
        &self,
        parent_hash: &CryptoHash
    ) -> Result<bool, Error>;
fn cares_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;
fn is_next_block_epoch_start(
        &self,
        parent_hash: &CryptoHash
    ) -> Result<bool, Error>;
fn get_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>;
fn get_epoch_start_height(
        &self,
        block_hash: &CryptoHash
    ) -> Result<BlockHeight, Error>;
fn get_gc_stop_height(&self, block_hash: &CryptoHash) -> BlockHeight;
fn epoch_exists(&self, epoch_id: &EpochId) -> bool;
fn get_epoch_minted_amount(
        &self,
        epoch_id: &EpochId
    ) -> Result<Balance, Error>;
fn get_epoch_sync_data(
        &self,
        prev_epoch_last_block_hash: &CryptoHash,
        epoch_id: &EpochId,
        next_epoch_id: &EpochId
    ) -> Result<(BlockInfo, BlockInfo, BlockInfo, EpochInfo, EpochInfo, EpochInfo), Error>;
fn get_epoch_sync_data_hash(
        &self,
        prev_epoch_last_block_hash: &CryptoHash,
        epoch_id: &EpochId,
        next_epoch_id: &EpochId
    ) -> Result<CryptoHash, Error>;
fn get_epoch_protocol_version(
        &self,
        epoch_id: &EpochId
    ) -> Result<ProtocolVersion, Error>;
fn epoch_sync_init_epoch_manager(
        &self,
        prev_epoch_first_block_info: BlockInfo,
        prev_epoch_prev_last_block_info: BlockInfo,
        prev_epoch_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 add_validator_proposals(
        &self,
        block_header_info: BlockHeaderInfo
    ) -> Result<StoreUpdate, Error>;
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_result: &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_result: &ChallengesResult,
        random_value: CryptoHash,
        is_new_chunk: bool,
        is_first_block_with_chunk_of_version: bool
    ) -> Result<ApplyTransactionResult, Error>;
fn query(
        &self,
        shard_uid: 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 get_validator_info(
        &self,
        epoch_id: ValidatorInfoIdentifier
    ) -> Result<EpochValidatorInfo, Error>;
fn obtain_state_part(
        &self,
        shard_id: ShardId,
        block_hash: &CryptoHash,
        state_root: &StateRoot,
        part_id: u64,
        num_parts: u64
    ) -> Result<Vec<u8>, Error>;
fn validate_state_part(
        &self,
        state_root: &StateRoot,
        part_id: u64,
        num_parts: u64,
        data: &Vec<u8>
    ) -> bool;
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>;
fn apply_state_part(
        &self,
        shard_id: ShardId,
        state_root: &StateRoot,
        part_id: u64,
        num_parts: u64,
        part: &[u8],
        epoch_id: &EpochId
    ) -> Result<(), Error>;
fn get_state_root_node(
        &self,
        shard_id: ShardId,
        block_hash: &CryptoHash,
        state_root: &StateRoot
    ) -> Result<StateRootNode, Error>;
fn validate_state_root_node(
        &self,
        state_root_node: &StateRootNode,
        state_root: &StateRoot
    ) -> bool;
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>;
fn get_protocol_config(
        &self,
        epoch_id: &EpochId
    ) -> Result<ProtocolConfig, Error>;
fn get_prev_epoch_id_from_prev_block(
        &self,
        prev_block_hash: &CryptoHash
    ) -> Result<EpochId, Error>; fn verify_chunk_header_signature(
        &self,
        header: &ShardChunkHeader
    ) -> Result<bool, 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> { ... }
fn build_receipts_hashes(
        &self,
        receipts: &[Receipt],
        shard_layout: &ShardLayout
    ) -> Vec<CryptoHash> { ... }
}
Expand description

Bridge between the chain and the runtime. Main function is to update state given transactions. Additionally handles validators.

Required methods

Get store and genesis state roots

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.

Returns trie with view cache

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.

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.

Verify validator signature for the given epoch. Note: doesnt’t account for slashed accounts within given epoch. USE WITH CAUTION.

Verify signature for validator or fisherman. Used for validating challenges.

Verify header signature.

Verify aggregated bls signature

Epoch block producers ordered by their order in the proposals. Returns error if height is outside of known boundaries.

Block producers for given height for the main block. Return error if outside of known boundaries.

Chunk producer for given height for given shard. Return error if outside of known boundaries.

Get current number of shards.

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.

Get shard layout given hash of previous block.

Returns true if the shard layout will change in the next epoch Current epoch is the epoch of the block after parent_hash

Whether the client cares about some shard right now.

  • If account_id is None, is_me is not checked and the result indicates whether the client is tracking the shard
  • If account_id is not None, it is supposed to be a validator account and is_me indicates whether we check what shards the client tracks.

Whether the client cares about some shard in the next epoch.

  • If account_id is None, is_me is not checked and the result indicates whether the client will track the shard
  • If account_id is not None, it is supposed to be a validator account and is_me indicates whether we check what shards the client will track.

Returns true, if given hash is last block in it’s epoch.

Get epoch id given hash of previous block.

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.

Epoch Manager init procedure that is necessary after Epoch Sync.

Add proposals for validators.

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

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.

Should be executed after accepting all the parts to set up a new state.

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

Validate StateRootNode of a state.

Get previous epoch id by hash of previous block.

Provided methods

Verify chunk header signature.

Apply transactions to given state root and return store update and new state root. Also returns transaction result for each transaction and new receipts.

Build receipts hashes.

Implementors