Struct near_chain::chain::Chain [−][src]
pub struct Chain {
pub runtime_adapter: Arc<dyn RuntimeAdapter>,
pub blocks_with_missing_chunks: MissingChunksPool<Orphan>,
pub transaction_validity_period: NumBlocks,
pub epoch_length: BlockHeightDelta,
pub block_economics_config: BlockEconomicsConfig,
pub doomslug_threshold_mode: DoomslugThresholdMode,
// some fields omitted
}
Expand description
Facade to the blockchain block processing and storage. Provides current view on the state according to the chain state.
Fields
runtime_adapter: Arc<dyn RuntimeAdapter>
blocks_with_missing_chunks: MissingChunksPool<Orphan>
transaction_validity_period: NumBlocks
epoch_length: BlockHeightDelta
block_economics_config: BlockEconomicsConfig
Block economics, relevant to changes when new block must be produced.
doomslug_threshold_mode: DoomslugThresholdMode
Implementations
pub fn new_for_view_client(
runtime_adapter: Arc<dyn RuntimeAdapter>,
chain_genesis: &ChainGenesis,
doomslug_threshold_mode: DoomslugThresholdMode
) -> Result<Chain, Error>
pub fn new(
runtime_adapter: Arc<dyn RuntimeAdapter>,
chain_genesis: &ChainGenesis,
doomslug_threshold_mode: DoomslugThresholdMode
) -> Result<Chain, Error>
pub fn compute_bp_hash(
runtime_adapter: &dyn RuntimeAdapter,
epoch_id: EpochId,
last_known_hash: &CryptoHash
) -> Result<CryptoHash, Error>
pub fn create_light_client_block(
header: &BlockHeader,
runtime_adapter: &dyn RuntimeAdapter,
chain_store: &mut dyn ChainStoreAccess
) -> Result<LightClientBlockView, Error>
pub fn create_light_client_block(
header: &BlockHeader,
runtime_adapter: &dyn RuntimeAdapter,
chain_store: &mut dyn ChainStoreAccess
) -> Result<LightClientBlockView, Error>
Creates a light client block for the last final block from perspective of some other block
Arguments
header
- the last finalized block seen fromheader
(not pushed back) will be used to compute the light client block
pub fn clear_data(
&mut self,
tries: ShardTries,
gc_blocks_limit: NumBlocks
) -> Result<(), Error>
pub fn clear_forks_data(
&mut self,
tries: ShardTries,
height: BlockHeight,
gc_blocks_remaining: &mut NumBlocks
) -> Result<(), Error>
Do Basic validation of a block upon receiving it. Check that header is valid and block is well-formed (various roots match).
pub fn process_block_header<F>(
&mut self,
header: &BlockHeader,
on_challenge: F
) -> Result<(), Error> where
F: FnMut(ChallengeBody),
pub fn process_block_header<F>(
&mut self,
header: &BlockHeader,
on_challenge: F
) -> Result<(), Error> where
F: FnMut(ChallengeBody),
Process a block header received during “header first” propagation.
pub fn mark_block_as_challenged(
&mut self,
block_hash: &CryptoHash,
challenger_hash: &CryptoHash
) -> Result<(), Error>
pub fn process_block<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
block: Block,
provenance: Provenance,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) -> Result<Option<Tip>, Error> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
pub fn process_block<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
block: Block,
provenance: Provenance,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) -> Result<Option<Tip>, Error> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
Process a received or produced block, and unroll any orphans that may depend on it.
Changes current state, and calls block_accepted
callback in case block was successfully applied.
Process challenge to invalidate chain. This is done between blocks to unroll the chain as soon as possible and allow next block producer to skip invalid blocks.
pub fn sync_block_headers<F>(
&mut self,
headers: Vec<BlockHeader>,
on_challenge: F
) -> Result<(), Error> where
F: Copy + FnMut(ChallengeBody),
pub fn sync_block_headers<F>(
&mut self,
headers: Vec<BlockHeader>,
on_challenge: F
) -> Result<(), Error> where
F: Copy + FnMut(ChallengeBody),
Processes headers and adds them to store for syncing.
Returns if given block header is on the current chain.
Finds first of the given hashes that is known on the main chain.
pub fn reset_heads_post_state_sync<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
sync_hash: CryptoHash,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) -> Result<(), Error> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
pub fn reset_heads_post_state_sync<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
sync_hash: CryptoHash,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) -> Result<(), Error> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
Set the new head after state sync was completed if it is indeed newer. Check for potentially unlocked orphans after this update.
pub fn prev_block_is_caught_up(
&self,
prev_prev_hash: &CryptoHash,
prev_hash: &CryptoHash
) -> Result<bool, Error>
pub fn check_blocks_with_missing_chunks<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
pub fn check_blocks_with_missing_chunks<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
Check if any block with missing chunk is ready to be processed
pub fn check_orphans<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
prev_hash: CryptoHash,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) -> Option<Tip> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
pub fn check_orphans<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
prev_hash: CryptoHash,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3
) -> Option<Tip> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
Check for orphans, once a block is successfully added.
pub fn get_outgoing_receipts_for_shard(
&mut self,
prev_block_hash: CryptoHash,
shard_id: ShardId,
last_height_included: BlockHeight
) -> Result<Vec<Receipt>, Error>
pub fn get_state_response_header(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash
) -> Result<ShardStateSyncResponseHeader, Error>
pub fn get_state_response_part(
&mut self,
shard_id: ShardId,
part_id: u64,
sync_hash: CryptoHash
) -> Result<Vec<u8>, Error>
pub fn set_state_header(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash,
shard_state_header: ShardStateSyncResponseHeader
) -> Result<(), Error>
pub fn get_state_header(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash
) -> Result<ShardStateSyncResponseHeader, Error>
pub fn set_state_part(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash,
part_id: u64,
num_parts: u64,
data: &Vec<u8>
) -> Result<(), Error>
pub fn schedule_apply_state_parts(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash,
num_parts: u64,
state_parts_task_scheduler: &dyn Fn(ApplyStatePartsRequest)
) -> Result<(), Error>
pub fn set_state_finalize(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash,
apply_result: Result<(), Error>
) -> Result<(), Error>
pub fn build_state_for_split_shards_preprocessing(
&mut self,
sync_hash: &CryptoHash,
shard_id: ShardId,
state_split_scheduler: &dyn Fn(StateSplitRequest)
) -> Result<(), Error>
pub fn build_state_for_split_shards_postprocessing(
&mut self,
sync_hash: &CryptoHash,
state_roots: Result<HashMap<ShardUId, StateRoot>, Error>
) -> Result<(), Error>
pub fn clear_downloaded_parts(
&mut self,
shard_id: ShardId,
sync_hash: CryptoHash,
num_parts: u64
) -> Result<(), Error>
pub fn catchup_blocks_step(
&mut self,
me: &Option<AccountId>,
sync_hash: &CryptoHash,
blocks_catch_up_state: &mut BlocksCatchUpState,
block_catch_up_scheduler: &dyn Fn(BlockCatchUpRequest)
) -> Result<(), Error>
pub fn finish_catchup_blocks<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
epoch_first_block: &CryptoHash,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3,
affected_blocks: &Vec<CryptoHash>
) -> Result<(), Error> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
pub fn finish_catchup_blocks<F, F2, F3>(
&mut self,
me: &Option<AccountId>,
epoch_first_block: &CryptoHash,
block_accepted: F,
block_misses_chunks: F2,
on_challenge: F3,
affected_blocks: &Vec<CryptoHash>
) -> Result<(), Error> where
F: Copy + FnMut(AcceptedBlock),
F2: Copy + FnMut(Vec<ShardChunkHeader>),
F3: Copy + FnMut(ChallengeBody),
Apply transactions in chunks for the next epoch in blocks that were blocked on the state sync
pub fn get_transaction_execution_result(
&mut self,
id: &CryptoHash
) -> Result<Vec<ExecutionOutcomeWithIdView>, Error>
pub fn get_final_transaction_result(
&mut self,
transaction_hash: &CryptoHash
) -> Result<FinalExecutionOutcomeView, Error>
pub fn get_final_transaction_result_with_receipt(
&mut self,
final_outcome: FinalExecutionOutcomeView
) -> Result<FinalExecutionOutcomeWithReceiptView, Error>
pub fn find_chunk_producer_for_forwarding(
&self,
epoch_id: &EpochId,
shard_id: ShardId,
horizon: BlockHeight
) -> Result<AccountId, Error>
pub fn find_chunk_producer_for_forwarding(
&self,
epoch_id: &EpochId,
shard_id: ShardId,
horizon: BlockHeight
) -> Result<AccountId, Error>
Find a validator to forward transactions to
Find a validator that is responsible for a given shard to forward requests to
pub fn check_block_final_and_canonical(
&mut self,
block_hash: &CryptoHash
) -> Result<(), Error>
pub fn get_block_execution_outcomes(
&mut self,
block_hash: &CryptoHash
) -> Result<HashMap<ShardId, Vec<ExecutionOutcomeWithIdAndProof>>, Error>
pub fn get_block_execution_outcomes(
&mut self,
block_hash: &CryptoHash
) -> Result<HashMap<ShardId, Vec<ExecutionOutcomeWithIdAndProof>>, Error>
Get all execution outcomes generated when the chunk are applied
Implement block merkle proof retrieval.
pub fn get_block_proof(
&mut self,
block_hash: &CryptoHash,
head_block_hash: &CryptoHash
) -> Result<MerklePath, Error>
pub fn get_block_proof(
&mut self,
block_hash: &CryptoHash,
head_block_hash: &CryptoHash
) -> Result<MerklePath, Error>
Get merkle proof for block with hash block_hash
in the merkle tree of head_block_hash
.
Various chain getters.
Gets chain header head.
Header of the block at the head of the block chain (not the same thing as header_head).
Get final head of the chain.
Gets a chunk from hash.
pub fn get_chunk_clone_from_header(
&mut self,
header: &ShardChunkHeader
) -> Result<ShardChunk, Error>
pub fn get_chunk_clone_from_header(
&mut self,
header: &ShardChunkHeader
) -> Result<ShardChunk, Error>
Gets a chunk from header.
Gets a block from the current chain by height.
Gets a block header by hash.
Returns block header from the canonical chain for given height if present.
pub fn get_header_on_chain_by_height(
&mut self,
sync_hash: &CryptoHash,
height: BlockHeight
) -> Result<&BlockHeader, Error>
pub fn get_header_on_chain_by_height(
&mut self,
sync_hash: &CryptoHash,
height: BlockHeight
) -> Result<&BlockHeader, Error>
Returns block header from the current chain defined by sync_hash
for given height if present.
Get previous block header.
Returns hash of the first available block after genesis.
Check if block exists.
Get block extra that was computer after applying previous block.
pub fn get_chunk_extra(
&mut self,
block_hash: &CryptoHash,
shard_uid: &ShardUId
) -> Result<&ChunkExtra, Error>
pub fn get_chunk_extra(
&mut self,
block_hash: &CryptoHash,
shard_uid: &ShardUId
) -> Result<&ChunkExtra, Error>
Get chunk extra that was computed after applying chunk with given hash.
pub fn get_shard_id_for_receipt_id(
&mut self,
receipt_id: &CryptoHash
) -> Result<&ShardId, Error>
pub fn get_shard_id_for_receipt_id(
&mut self,
receipt_id: &CryptoHash
) -> Result<&ShardId, Error>
Get destination shard id for a given receipt id.
pub fn get_next_block_hash_with_new_chunk(
&mut self,
block_hash: &CryptoHash,
shard_id: ShardId
) -> Result<Option<&CryptoHash>, Error>
pub fn get_next_block_hash_with_new_chunk(
&mut self,
block_hash: &CryptoHash,
shard_id: ShardId
) -> Result<Option<&CryptoHash>, Error>
Get next block hash for which there is a new chunk for the shard.
Returns underlying ChainStore.
Returns mutable ChainStore.
Returns underlying RuntimeAdapter.
Returns genesis block.
Returns genesis block header.
Returns number of orphans currently in the orphan pool.
Returns number of orphans currently in the orphan pool.
Returns number of evicted orphans.
Check if hash is for a known chunk orphan.
Check if can sync with sync_hash
pub fn get_execution_outcome(
&mut self,
id: &CryptoHash
) -> Result<ExecutionOutcomeWithIdAndProof, Error>
pub fn get_execution_outcome(
&mut self,
id: &CryptoHash
) -> Result<ExecutionOutcomeWithIdAndProof, Error>
Get transaction result for given hash of transaction or receipt id on the canonical chain
pub fn get_prev_chunk_headers(
runtime_adapter: &dyn RuntimeAdapter,
prev_block: &Block
) -> Result<Vec<ShardChunkHeader>, Error>
pub fn get_prev_chunk_headers(
runtime_adapter: &dyn RuntimeAdapter,
prev_block: &Block
) -> Result<Vec<ShardChunkHeader>, Error>
Returns a vector of chunk headers, each of which corresponds to the previous chunk of
a chunk in the block after prev_block
This function is important when the block after prev_block
has different number of chunks
from prev_block
.
In block production and processing, often we need to get the previous chunks of chunks
in the current block, this function provides a way to do so while handling sharding changes
correctly.
For example, if prev_block
has two shards 0, 1 and the block after prev_block
will have
4 shards 0, 1, 2, 3, 0 and 1 split from shard 0 and 2 and 3 split from shard 1.
get_prev_chunks(runtime_adapter, prev_block)
will return
[prev_block.chunks()[0], prev_block.chunks()[0], prev_block.chunks()[1], prev_block.chunks()[1]]
pub fn get_prev_chunk_header(
runtime_adapter: &dyn RuntimeAdapter,
prev_block: &Block,
shard_id: ShardId
) -> Result<ShardChunkHeader, Error>
Auto Trait Implementations
impl !RefUnwindSafe for Chain
impl !UnwindSafe for Chain
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