diff --git a/chain/chain/src/chain.rs b/chain/chain/src/chain.rs index 515473c397f..b5345eb2d41 100644 --- a/chain/chain/src/chain.rs +++ b/chain/chain/src/chain.rs @@ -13,8 +13,8 @@ use crate::state_snapshot_actor::SnapshotCallbacks; use crate::store::{ChainStore, ChainStoreAccess, ChainStoreUpdate}; use crate::types::{ - AcceptedBlock, ApplyTransactionResult, ApplyTransactionsBlockContext, BlockEconomicsConfig, - ChainConfig, RuntimeAdapter, StorageDataSource, + AcceptedBlock, ApplyChunkBlockContext, ApplyChunkResult, BlockEconomicsConfig, ChainConfig, + RuntimeAdapter, StorageDataSource, }; use crate::update_shard::{ apply_new_chunk, process_missing_chunks_range, process_shard_update, NewChunkData, @@ -2878,12 +2878,12 @@ impl Chain { /// For given pair of block headers and shard id, return information about /// block necessary for processing shard update. - fn get_apply_transactions_block_context( + fn get_apply_chunk_block_context( &self, block_header: &BlockHeader, prev_block_header: &BlockHeader, is_new_chunk: bool, - ) -> Result { + ) -> Result { let epoch_id = block_header.epoch_id(); let protocol_version = self.epoch_manager.get_epoch_protocol_version(epoch_id)?; // Before `FixApplyChunks` feature, gas price was taken from current @@ -2896,7 +2896,7 @@ impl Chain { prev_block_header.next_gas_price() }; - Ok(ApplyTransactionsBlockContext::from_header(block_header, gas_price)) + Ok(ApplyChunkBlockContext::from_header(block_header, gas_price)) } fn block_catch_up_postprocess( @@ -3296,7 +3296,7 @@ impl Chain { let cares_about_shard_next_epoch = self.shard_tracker.will_care_about_shard(me.as_ref(), prev_hash, shard_id, true); let will_shard_layout_change = self.epoch_manager.will_shard_layout_change(prev_hash)?; - let should_apply_transactions = get_should_apply_transactions( + let should_apply_chunk = get_should_apply_chunk( mode, cares_about_shard_this_epoch, cares_about_shard_next_epoch, @@ -3307,7 +3307,7 @@ impl Chain { shard_uid, cares_about_shard_this_epoch, will_shard_layout_change, - should_apply_transactions, + should_apply_chunk, need_to_reshard, }) } @@ -3330,16 +3330,16 @@ impl Chain { let shard_context = self.get_shard_context(me, block.header(), shard_id, mode)?; // We can only perform resharding when states are ready, i.e., mode != ApplyChunksMode::NotCaughtUp - // 1) if should_apply_transactions == true && resharding_state_roots.is_some(), + // 1) if should_apply_chunk == true && resharding_state_roots.is_some(), // that means children shards are ready. // `apply_resharding_state_changes` will apply updates to the children shards - // 2) if should_apply_transactions == true && resharding_state_roots.is_none(), + // 2) if should_apply_chunk == true && resharding_state_roots.is_none(), // that means children shards are not ready yet. // `apply_resharding_state_changes` will return `state_changes_for_resharding`, // which will be stored to the database in `process_apply_chunks` - // 3) if should_apply_transactions == false && resharding_state_roots.is_some() + // 3) if should_apply_chunk == false && resharding_state_roots.is_some() // This implies mode == CatchingUp and cares_about_shard_this_epoch == true, - // otherwise should_apply_transactions will be true + // otherwise should_apply_chunk will be true // That means transactions have already been applied last time when apply_chunks are // called with mode NotCaughtUp, therefore `state_changes_for_resharding` have been // stored in the database. Then we can safely read that and apply that to the split @@ -3352,8 +3352,8 @@ impl Chain { }; let is_new_chunk = chunk_header.height_included() == block.header().height(); - let shard_update_reason = if shard_context.should_apply_transactions { - let block_context = self.get_apply_transactions_block_context( + let shard_update_reason = if shard_context.should_apply_chunk { + let block_context = self.get_apply_chunk_block_context( block.header(), prev_block.header(), is_new_chunk, @@ -3490,11 +3490,10 @@ impl Chain { shard_id: ShardId, mode: ApplyChunksMode, return_chunk_extra: bool, - ) -> Result<(Vec<(ApplyTransactionsBlockContext, ShardContext)>, Option), Error> - { + ) -> Result<(Vec<(ApplyChunkBlockContext, ShardContext)>, Option), Error> { let blocks_to_execute = self.get_blocks_until_height(chunk_prev_hash, prev_chunk_height_included, false)?; - let mut execution_contexts: Vec<(ApplyTransactionsBlockContext, ShardContext)> = vec![]; + let mut execution_contexts: Vec<(ApplyChunkBlockContext, ShardContext)> = vec![]; for block_hash in blocks_to_execute { let block_header = self.get_block_header(&block_hash)?; let prev_block_header = self.get_previous_header(&block_header)?; @@ -3505,11 +3504,7 @@ impl Chain { ))); } execution_contexts.push(( - self.get_apply_transactions_block_context( - &block_header, - &prev_block_header, - false, - )?, + self.get_apply_chunk_block_context(&block_header, &prev_block_header, false)?, shard_context, )); } @@ -3565,7 +3560,7 @@ impl Chain { let is_new_chunk = chunk_header.height_included() == block.header().height(); // If we don't track a shard or there is no chunk, there is nothing to validate. - if !last_shard_context.should_apply_transactions || !is_new_chunk { + if !last_shard_context.should_apply_chunk || !is_new_chunk { return Ok(None); } @@ -3667,7 +3662,7 @@ impl Chain { return Ok(None); } ( - self.get_apply_transactions_block_context(&block_header, &prev_block_header, true)?, + self.get_apply_chunk_block_context(&block_header, &prev_block_header, true)?, shard_context, ) }; @@ -3729,7 +3724,7 @@ impl Chain { epoch_manager.as_ref(), )?; let (outcome_root, _) = - ApplyTransactionResult::compute_outcomes_proof(&apply_result.outcomes); + ApplyChunkResult::compute_outcomes_proof(&apply_result.outcomes); current_chunk_extra = ChunkExtra::new( &apply_result.new_root, outcome_root, @@ -3865,7 +3860,7 @@ fn sync_hash_not_first_hash(sync_hash: CryptoHash) -> Error { /// ApplyChunksMode::NotCaughtUp once with ApplyChunksMode::CatchingUp. Note /// that it does not guard whether the children shards are ready or not, see the /// comments before `need_to_reshard` -fn get_should_apply_transactions( +fn get_should_apply_chunk( mode: ApplyChunksMode, cares_about_shard_this_epoch: bool, cares_about_shard_next_epoch: bool, diff --git a/chain/chain/src/chain_update.rs b/chain/chain/src/chain_update.rs index fb58a31559b..c4bf3643ad8 100644 --- a/chain/chain/src/chain_update.rs +++ b/chain/chain/src/chain_update.rs @@ -4,8 +4,8 @@ use crate::metrics::{SHARD_LAYOUT_NUM_SHARDS, SHARD_LAYOUT_VERSION}; use crate::store::{ChainStore, ChainStoreAccess, ChainStoreUpdate}; use crate::types::{ - ApplyTransactionResult, ApplyTransactionsBlockContext, ApplyTransactionsChunkContext, - ReshardingResults, RuntimeAdapter, RuntimeStorageConfig, + ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, ReshardingResults, + RuntimeAdapter, RuntimeStorageConfig, }; use crate::update_shard::{ NewChunkResult, OldChunkResult, ReshardingResult, ShardBlockUpdateResult, ShardUpdateResult, @@ -330,7 +330,7 @@ impl<'a> ChainUpdate<'a> { resharding_results, }) => { let (outcome_root, outcome_paths) = - ApplyTransactionResult::compute_outcomes_proof(&apply_result.outcomes); + ApplyChunkResult::compute_outcomes_proof(&apply_result.outcomes); let shard_id = shard_uid.shard_id(); // Save state root after applying transactions. @@ -732,16 +732,16 @@ impl<'a> ChainUpdate<'a> { // TODO(nikurt): Determine the value correctly. let is_first_block_with_chunk_of_version = false; - let apply_result = self.runtime_adapter.apply_transactions( + let apply_result = self.runtime_adapter.apply_chunk( RuntimeStorageConfig::new(chunk_header.prev_state_root(), true), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, gas_limit, last_validator_proposals: chunk_header.prev_validator_proposals(), is_first_block_with_chunk_of_version, is_new_chunk: true, }, - ApplyTransactionsBlockContext { + ApplyChunkBlockContext { height: chunk_header.height_included(), block_hash: *block_header.hash(), prev_block_hash: *chunk_header.prev_block_hash(), @@ -755,7 +755,7 @@ impl<'a> ChainUpdate<'a> { )?; let (outcome_root, outcome_proofs) = - ApplyTransactionResult::compute_outcomes_proof(&apply_result.outcomes); + ApplyChunkResult::compute_outcomes_proof(&apply_result.outcomes); self.chain_store_update.save_chunk(chunk); @@ -829,19 +829,16 @@ impl<'a> ChainUpdate<'a> { let chunk_extra = self.chain_store_update.get_chunk_extra(prev_block_header.hash(), &shard_uid)?; - let apply_result = self.runtime_adapter.apply_transactions( + let apply_result = self.runtime_adapter.apply_chunk( RuntimeStorageConfig::new(*chunk_extra.state_root(), true), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_extra.validator_proposals(), gas_limit: chunk_extra.gas_limit(), is_new_chunk: false, is_first_block_with_chunk_of_version: false, }, - ApplyTransactionsBlockContext::from_header( - &block_header, - prev_block_header.next_gas_price(), - ), + ApplyChunkBlockContext::from_header(&block_header, prev_block_header.next_gas_price()), &[], &[], )?; diff --git a/chain/chain/src/test_utils/kv_runtime.rs b/chain/chain/src/test_utils/kv_runtime.rs index 95b61af0029..da8cbe196c4 100644 --- a/chain/chain/src/test_utils/kv_runtime.rs +++ b/chain/chain/src/test_utils/kv_runtime.rs @@ -1,7 +1,7 @@ use super::ValidatorSchedule; use crate::types::{ - ApplyResultForResharding, ApplyTransactionResult, ApplyTransactionsBlockContext, - ApplyTransactionsChunkContext, RuntimeAdapter, RuntimeStorageConfig, + ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, ApplyResultForResharding, + RuntimeAdapter, RuntimeStorageConfig, }; use crate::BlockHeader; use borsh::{BorshDeserialize, BorshSerialize}; @@ -1040,14 +1040,14 @@ impl RuntimeAdapter for KeyValueRuntime { Ok(res) } - fn apply_transactions( + fn apply_chunk( &self, storage_config: RuntimeStorageConfig, - chunk: ApplyTransactionsChunkContext, - block: ApplyTransactionsBlockContext, + chunk: ApplyChunkShardContext, + block: ApplyChunkBlockContext, receipts: &[Receipt], transactions: &[SignedTransaction], - ) -> Result { + ) -> Result { assert!(!storage_config.record_storage); let mut tx_results = vec![]; let shard_id = chunk.shard_id; @@ -1181,7 +1181,7 @@ impl RuntimeAdapter for KeyValueRuntime { self.state.write().unwrap().insert(state_root, state); self.state_size.write().unwrap().insert(state_root, state_size); - Ok(ApplyTransactionResult { + Ok(ApplyChunkResult { trie_changes: WrappedTrieChanges::new( self.get_tries(), ShardUId { version: 0, shard_id: shard_id as u32 }, diff --git a/chain/chain/src/types.rs b/chain/chain/src/types.rs index b7fc024f4b6..790dc2cf9f5 100644 --- a/chain/chain/src/types.rs +++ b/chain/chain/src/types.rs @@ -100,7 +100,7 @@ pub enum ReshardingResults { } #[derive(Debug)] -pub struct ApplyTransactionResult { +pub struct ApplyChunkResult { pub trie_changes: WrappedTrieChanges, pub new_root: StateRoot, pub outcomes: Vec, @@ -112,7 +112,7 @@ pub struct ApplyTransactionResult { pub processed_delayed_receipts: Vec, } -impl ApplyTransactionResult { +impl ApplyChunkResult { /// Returns root and paths for all the outcomes in the result. pub fn compute_outcomes_proof( outcomes: &[ExecutionOutcomeWithId], @@ -279,7 +279,7 @@ impl RuntimeStorageConfig { } #[derive(Clone)] -pub struct ApplyTransactionsBlockContext { +pub struct ApplyChunkBlockContext { pub height: BlockHeight, pub block_hash: CryptoHash, pub prev_block_hash: CryptoHash, @@ -289,7 +289,7 @@ pub struct ApplyTransactionsBlockContext { pub random_seed: CryptoHash, } -impl ApplyTransactionsBlockContext { +impl ApplyChunkBlockContext { pub fn from_header(header: &BlockHeader, gas_price: Balance) -> Self { Self { height: header.height(), @@ -303,7 +303,7 @@ impl ApplyTransactionsBlockContext { } } -pub struct ApplyTransactionsChunkContext<'a> { +pub struct ApplyChunkShardContext<'a> { pub shard_id: ShardId, pub last_validator_proposals: ValidatorStakeIter<'a>, pub gas_limit: Gas, @@ -387,16 +387,17 @@ pub trait RuntimeAdapter: Send + Sync { /// Get the block height for which garbage collection should not go over fn get_gc_stop_height(&self, block_hash: &CryptoHash) -> BlockHeight; - /// Apply transactions to given state root and return store update and new state root. + /// Apply transactions and receipts to given state root and return store update + /// and new state root. /// Also returns transaction result for each transaction and new receipts. - fn apply_transactions( + fn apply_chunk( &self, storage: RuntimeStorageConfig, - chunk: ApplyTransactionsChunkContext, - block: ApplyTransactionsBlockContext, + chunk: ApplyChunkShardContext, + block: ApplyChunkBlockContext, receipts: &[Receipt], transactions: &[SignedTransaction], - ) -> Result; + ) -> Result; /// Query runtime with given `path` and `data`. fn query( @@ -548,7 +549,7 @@ mod tests { }, }; let outcomes = vec![outcome1, outcome2]; - let (outcome_root, paths) = ApplyTransactionResult::compute_outcomes_proof(&outcomes); + let (outcome_root, paths) = ApplyChunkResult::compute_outcomes_proof(&outcomes); for (outcome_with_id, path) in outcomes.into_iter().zip(paths.into_iter()) { assert!(verify_path(outcome_root, &path, &outcome_with_id.to_hashes())); } diff --git a/chain/chain/src/update_shard.rs b/chain/chain/src/update_shard.rs index a4aca5d4d60..54ec7f18453 100644 --- a/chain/chain/src/update_shard.rs +++ b/chain/chain/src/update_shard.rs @@ -1,8 +1,7 @@ use crate::crypto_hash_timer::CryptoHashTimer; use crate::types::{ - ApplyResultForResharding, ApplyTransactionResult, ApplyTransactionsBlockContext, - ApplyTransactionsChunkContext, ReshardingResults, RuntimeAdapter, RuntimeStorageConfig, - StorageDataSource, + ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, ApplyResultForResharding, + ReshardingResults, RuntimeAdapter, RuntimeStorageConfig, StorageDataSource, }; use near_chain_primitives::Error; use near_epoch_manager::EpochManagerAdapter; @@ -21,7 +20,7 @@ use std::collections::HashMap; pub struct NewChunkResult { pub(crate) shard_uid: ShardUId, pub(crate) gas_limit: Gas, - pub(crate) apply_result: ApplyTransactionResult, + pub(crate) apply_result: ApplyChunkResult, pub(crate) resharding_results: Option, } @@ -32,7 +31,7 @@ pub struct OldChunkResult { pub(crate) shard_uid: ShardUId, /// Note that despite the naming, no transactions are applied in this case. /// TODO(logunov): exclude receipts/txs context from all related types. - pub(crate) apply_result: ApplyTransactionResult, + pub(crate) apply_result: ApplyChunkResult, pub(crate) resharding_results: Option, } @@ -71,7 +70,7 @@ pub(crate) struct NewChunkData { pub chunk: ShardChunk, pub receipts: Vec, pub resharding_state_roots: Option, - pub block: ApplyTransactionsBlockContext, + pub block: ApplyChunkBlockContext, pub is_first_block_with_chunk_of_version: bool, pub storage_context: StorageContext, } @@ -79,7 +78,7 @@ pub(crate) struct NewChunkData { pub(crate) struct OldChunkData { pub prev_chunk_extra: ChunkExtra, pub resharding_state_roots: Option, - pub block: ApplyTransactionsBlockContext, + pub block: ApplyChunkBlockContext, pub storage_context: StorageContext, } @@ -113,7 +112,7 @@ pub(crate) struct ShardContext { /// Whether shard layout changes in the next epoch. pub will_shard_layout_change: bool, /// Whether transactions should be applied. - pub should_apply_transactions: bool, + pub should_apply_chunk: bool, /// See comment in `get_update_shard_job`. pub need_to_reshard: bool, } @@ -165,7 +164,7 @@ pub(crate) fn process_missing_chunks_range( mut current_chunk_extra: ChunkExtra, runtime: &dyn RuntimeAdapter, epoch_manager: &dyn EpochManagerAdapter, - execution_contexts: Vec<(ApplyTransactionsBlockContext, ShardContext)>, + execution_contexts: Vec<(ApplyChunkBlockContext, ShardContext)>, ) -> Result, Error> { let mut result = vec![]; for (block_context, shard_context) in execution_contexts { @@ -224,9 +223,9 @@ pub(crate) fn apply_new_chunk( state_patch: storage_context.state_patch, record_storage: false, }; - match runtime.apply_transactions( + match runtime.apply_chunk( storage_config, - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_inner.prev_validator_proposals(), gas_limit, @@ -286,9 +285,9 @@ fn apply_old_chunk( state_patch: storage_context.state_patch, record_storage: false, }; - match runtime.apply_transactions( + match runtime.apply_chunk( storage_config, - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: prev_chunk_extra.validator_proposals(), gas_limit: prev_chunk_extra.gas_limit(), @@ -351,7 +350,7 @@ fn apply_resharding( Ok(ReshardingResult { shard_uid, results }) } -/// Process ApplyTransactionResult to apply changes to children shards. When +/// Process ApplyChunkResult to apply changes to children shards. When /// shards will change next epoch, /// - if `resharding_state_roots` is not None, that means states for the /// children shards are ready this function updates these states and returns @@ -362,8 +361,8 @@ fn apply_resharding( fn apply_resharding_state_changes( epoch_manager: &dyn EpochManagerAdapter, runtime_adapter: &dyn RuntimeAdapter, - block: ApplyTransactionsBlockContext, - apply_result: &ApplyTransactionResult, + block: ApplyChunkBlockContext, + apply_result: &ApplyChunkResult, resharding_state_roots: Option, ) -> Result { let state_changes = StateChangesForResharding::from_raw_state_changes( diff --git a/nearcore/src/runtime/mod.rs b/nearcore/src/runtime/mod.rs index 5e6a2482337..c0cf5d8c6ad 100644 --- a/nearcore/src/runtime/mod.rs +++ b/nearcore/src/runtime/mod.rs @@ -5,8 +5,8 @@ use crate::NearConfig; use borsh::BorshDeserialize; use errors::FromStateViewerErrors; use near_chain::types::{ - ApplyResultForResharding, ApplyTransactionResult, ApplyTransactionsBlockContext, - ApplyTransactionsChunkContext, RuntimeAdapter, RuntimeStorageConfig, StorageDataSource, Tip, + ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, ApplyResultForResharding, + RuntimeAdapter, RuntimeStorageConfig, StorageDataSource, Tip, }; use near_chain::Error; use near_chain_configs::{ @@ -274,14 +274,14 @@ impl NightshadeRuntime { fn process_state_update( &self, trie: Trie, - chunk: ApplyTransactionsChunkContext, - block: ApplyTransactionsBlockContext, + chunk: ApplyChunkShardContext, + block: ApplyChunkBlockContext, receipts: &[Receipt], transactions: &[SignedTransaction], state_patch: SandboxStatePatch, - ) -> Result { + ) -> Result { let _span = tracing::debug_span!(target: "runtime", "process_state_update").entered(); - let ApplyTransactionsBlockContext { + let ApplyChunkBlockContext { height: block_height, block_hash, ref prev_block_hash, @@ -290,7 +290,7 @@ impl NightshadeRuntime { challenges_result, random_seed, } = block; - let ApplyTransactionsChunkContext { + let ApplyChunkShardContext { shard_id, last_validator_proposals, gas_limit, @@ -458,7 +458,7 @@ impl NightshadeRuntime { let shard_uid = self.get_shard_uid_from_prev_hash(shard_id, prev_block_hash)?; - let result = ApplyTransactionResult { + let result = ApplyChunkResult { trie_changes: WrappedTrieChanges::new( self.get_tries(), shard_uid, @@ -835,14 +835,14 @@ impl RuntimeAdapter for NightshadeRuntime { } } - fn apply_transactions( + fn apply_chunk( &self, storage_config: RuntimeStorageConfig, - chunk: ApplyTransactionsChunkContext, - block: ApplyTransactionsBlockContext, + chunk: ApplyChunkShardContext, + block: ApplyChunkBlockContext, receipts: &[Receipt], transactions: &[SignedTransaction], - ) -> Result { + ) -> Result { let shard_id = chunk.shard_id; let _timer = metrics::APPLYING_CHUNKS_TIME.with_label_values(&[&shard_id.to_string()]).start_timer(); diff --git a/nearcore/src/runtime/tests.rs b/nearcore/src/runtime/tests.rs index 7cf57744f96..a59fc0d6149 100644 --- a/nearcore/src/runtime/tests.rs +++ b/nearcore/src/runtime/tests.rs @@ -67,16 +67,16 @@ impl NightshadeRuntime { challenges_result: &ChallengesResult, ) -> (StateRoot, Vec, Vec) { let mut result = self - .apply_transactions( + .apply_chunk( RuntimeStorageConfig::new(*state_root, true), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals, gas_limit, is_new_chunk: true, is_first_block_with_chunk_of_version: false, }, - ApplyTransactionsBlockContext { + ApplyChunkBlockContext { height, block_hash: *block_hash, prev_block_hash: *prev_block_hash, diff --git a/tools/state-viewer/src/apply_chain_range.rs b/tools/state-viewer/src/apply_chain_range.rs index de2cbd445d7..9f65d5a18be 100644 --- a/tools/state-viewer/src/apply_chain_range.rs +++ b/tools/state-viewer/src/apply_chain_range.rs @@ -1,8 +1,8 @@ use near_chain::chain::collect_receipts_from_response; use near_chain::migrations::check_if_block_is_first_with_chunk_of_version; use near_chain::types::{ - ApplyTransactionResult, ApplyTransactionsBlockContext, ApplyTransactionsChunkContext, - RuntimeAdapter, RuntimeStorageConfig, + ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, RuntimeAdapter, + RuntimeStorageConfig, }; use near_chain::{ChainStore, ChainStoreAccess, ChainStoreUpdate}; use near_chain_configs::Genesis; @@ -230,16 +230,16 @@ fn apply_block_from_range( } } runtime_adapter - .apply_transactions( + .apply_chunk( RuntimeStorageConfig::new(*chunk_inner.prev_state_root(), use_flat_storage), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_inner.prev_validator_proposals(), gas_limit: chunk_inner.gas_limit(), is_new_chunk: true, is_first_block_with_chunk_of_version, }, - ApplyTransactionsBlockContext::from_header( + ApplyChunkBlockContext::from_header( block.header(), prev_block.header().next_gas_price(), ), @@ -254,16 +254,16 @@ fn apply_block_from_range( prev_chunk_extra = Some(chunk_extra.clone()); runtime_adapter - .apply_transactions( + .apply_chunk( RuntimeStorageConfig::new(*chunk_extra.state_root(), use_flat_storage), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_extra.validator_proposals(), gas_limit: chunk_extra.gas_limit(), is_new_chunk: false, is_first_block_with_chunk_of_version: false, }, - ApplyTransactionsBlockContext::from_header( + ApplyChunkBlockContext::from_header( block.header(), block.header().next_gas_price(), ), @@ -273,7 +273,7 @@ fn apply_block_from_range( .unwrap() }; - let (outcome_root, _) = ApplyTransactionResult::compute_outcomes_proof(&apply_result.outcomes); + let (outcome_root, _) = ApplyChunkResult::compute_outcomes_proof(&apply_result.outcomes); let chunk_extra = ChunkExtra::new( &apply_result.new_root, outcome_root, diff --git a/tools/state-viewer/src/apply_chunk.rs b/tools/state-viewer/src/apply_chunk.rs index c7bd0582253..cdf06d37f67 100644 --- a/tools/state-viewer/src/apply_chunk.rs +++ b/tools/state-viewer/src/apply_chunk.rs @@ -3,8 +3,8 @@ use borsh::BorshDeserialize; use near_chain::chain::collect_receipts_from_response; use near_chain::migrations::check_if_block_is_first_with_chunk_of_version; use near_chain::types::{ - ApplyTransactionResult, ApplyTransactionsBlockContext, ApplyTransactionsChunkContext, - RuntimeAdapter, RuntimeStorageConfig, + ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, RuntimeAdapter, + RuntimeStorageConfig, }; use near_chain::{ChainStore, ChainStoreAccess}; use near_epoch_manager::{EpochManagerAdapter, EpochManagerHandle}; @@ -86,7 +86,7 @@ pub(crate) fn apply_chunk( target_height: Option, rng: Option, use_flat_storage: bool, -) -> anyhow::Result<(ApplyTransactionResult, Gas)> { +) -> anyhow::Result<(ApplyChunkResult, Gas)> { let chunk = chain_store.get_chunk(&chunk_hash)?; let chunk_header = chunk.cloned_header(); @@ -131,16 +131,16 @@ pub(crate) fn apply_chunk( )?; Ok(( - runtime.apply_transactions( + runtime.apply_chunk( RuntimeStorageConfig::new(prev_state_root, use_flat_storage), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_header.prev_validator_proposals(), gas_limit: chunk_header.gas_limit(), is_first_block_with_chunk_of_version, is_new_chunk: true, }, - ApplyTransactionsBlockContext { + ApplyChunkBlockContext { height: target_height, block_timestamp: prev_timestamp + 1_000_000_000, challenges_result: vec![], @@ -201,7 +201,7 @@ fn apply_tx_in_block( tx_hash: &CryptoHash, block_hash: CryptoHash, use_flat_storage: bool, -) -> anyhow::Result { +) -> anyhow::Result { match find_tx_or_receipt(tx_hash, &block_hash, epoch_manager, chain_store)? { Some((hash_type, shard_id)) => { match hash_type { @@ -230,7 +230,7 @@ fn apply_tx_in_chunk( chain_store: &mut ChainStore, tx_hash: &CryptoHash, use_flat_storage: bool, -) -> anyhow::Result> { +) -> anyhow::Result> { if chain_store.get_transaction(tx_hash)?.is_none() { return Err(anyhow!("tx with hash {} not known", tx_hash)); } @@ -298,7 +298,7 @@ pub(crate) fn apply_tx( store: Store, tx_hash: CryptoHash, use_flat_storage: bool, -) -> anyhow::Result> { +) -> anyhow::Result> { let mut chain_store = ChainStore::new(store.clone(), genesis_height, false); let outcomes = chain_store.get_outcomes_by_id(&tx_hash)?; @@ -330,7 +330,7 @@ fn apply_receipt_in_block( id: &CryptoHash, block_hash: CryptoHash, use_flat_storage: bool, -) -> anyhow::Result { +) -> anyhow::Result { match find_tx_or_receipt(id, &block_hash, epoch_manager, chain_store)? { Some((hash_type, shard_id)) => { match hash_type { @@ -360,7 +360,7 @@ fn apply_receipt_in_chunk( chain_store: &mut ChainStore, id: &CryptoHash, use_flat_storage: bool, -) -> anyhow::Result> { +) -> anyhow::Result> { if chain_store.get_receipt(id)?.is_none() { // TODO: handle local/delayed receipts return Err(anyhow!("receipt with ID {} not known. Is it a local or delayed receipt?", id)); @@ -453,7 +453,7 @@ pub(crate) fn apply_receipt( store: Store, id: CryptoHash, use_flat_storage: bool, -) -> anyhow::Result> { +) -> anyhow::Result> { let mut chain_store = ChainStore::new(store.clone(), genesis_height, false); let outcomes = chain_store.get_outcomes_by_id(&id)?; if let Some(outcome) = outcomes.first() { diff --git a/tools/state-viewer/src/commands.rs b/tools/state-viewer/src/commands.rs index ad5a8d1cf75..c187e3966d0 100644 --- a/tools/state-viewer/src/commands.rs +++ b/tools/state-viewer/src/commands.rs @@ -11,9 +11,9 @@ use itertools::GroupBy; use itertools::Itertools; use near_chain::chain::collect_receipts_from_response; use near_chain::migrations::check_if_block_is_first_with_chunk_of_version; -use near_chain::types::ApplyTransactionResult; -use near_chain::types::ApplyTransactionsBlockContext; -use near_chain::types::ApplyTransactionsChunkContext; +use near_chain::types::ApplyChunkBlockContext; +use near_chain::types::ApplyChunkResult; +use near_chain::types::ApplyChunkShardContext; use near_chain::types::RuntimeAdapter; use near_chain::types::RuntimeStorageConfig; use near_chain::{ChainStore, ChainStoreAccess, ChainStoreUpdate, Error}; @@ -58,7 +58,7 @@ pub(crate) fn apply_block( runtime: &dyn RuntimeAdapter, chain_store: &mut ChainStore, use_flat_storage: bool, -) -> (Block, ApplyTransactionResult) { +) -> (Block, ApplyChunkResult) { let block = chain_store.get_block(&block_hash).unwrap(); let height = block.header().height(); let shard_uid = epoch_manager.shard_id_to_uid(shard_id, block.header().epoch_id()).unwrap(); @@ -89,16 +89,16 @@ pub(crate) fn apply_block( .unwrap(); runtime - .apply_transactions( + .apply_chunk( RuntimeStorageConfig::new(*chunk_inner.prev_state_root(), use_flat_storage), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_inner.prev_validator_proposals(), gas_limit: chunk_inner.gas_limit(), is_new_chunk: true, is_first_block_with_chunk_of_version, }, - ApplyTransactionsBlockContext::from_header( + ApplyChunkBlockContext::from_header( block.header(), prev_block.header().next_gas_price(), ), @@ -111,16 +111,16 @@ pub(crate) fn apply_block( chain_store.get_chunk_extra(block.header().prev_hash(), &shard_uid).unwrap(); runtime - .apply_transactions( + .apply_chunk( RuntimeStorageConfig::new(*chunk_extra.state_root(), use_flat_storage), - ApplyTransactionsChunkContext { + ApplyChunkShardContext { shard_id, last_validator_proposals: chunk_extra.validator_proposals(), gas_limit: chunk_extra.gas_limit(), is_new_chunk: false, is_first_block_with_chunk_of_version: false, }, - ApplyTransactionsBlockContext::from_header( + ApplyChunkBlockContext::from_header( block.header(), block.header().next_gas_price(), ), @@ -523,7 +523,7 @@ fn chunk_extras_equal(l: &ChunkExtra, r: &ChunkExtra) -> bool { pub(crate) fn check_apply_block_result( block: &Block, - apply_result: &ApplyTransactionResult, + apply_result: &ApplyChunkResult, epoch_manager: &EpochManagerHandle, chain_store: &ChainStore, shard_id: ShardId, @@ -712,8 +712,8 @@ pub(crate) fn replay_chain( } } -pub(crate) fn resulting_chunk_extra(result: &ApplyTransactionResult, gas_limit: Gas) -> ChunkExtra { - let (outcome_root, _) = ApplyTransactionResult::compute_outcomes_proof(&result.outcomes); +pub(crate) fn resulting_chunk_extra(result: &ApplyChunkResult, gas_limit: Gas) -> ChunkExtra { + let (outcome_root, _) = ApplyChunkResult::compute_outcomes_proof(&result.outcomes); ChunkExtra::new( &result.new_root, outcome_root,