diff --git a/chain/chain/src/blocks_delay_tracker.rs b/chain/chain/src/blocks_delay_tracker.rs index fa0803718fa..bf048c1765e 100644 --- a/chain/chain/src/blocks_delay_tracker.rs +++ b/chain/chain/src/blocks_delay_tracker.rs @@ -150,7 +150,7 @@ impl BlocksDelayTracker { let height = block.header().height(); let chunks = block .chunks() - .iter() + .iter_deprecated() .map(|chunk| { if chunk.height_included() == height { let chunk_hash = chunk.chunk_hash(); diff --git a/chain/chain/src/chain.rs b/chain/chain/src/chain.rs index 9b199c5ff3c..7fe175178dd 100644 --- a/chain/chain/src/chain.rs +++ b/chain/chain/src/chain.rs @@ -47,7 +47,7 @@ use near_chain_configs::{MutableConfigValue, MutableValidatorSigner}; use near_chain_primitives::error::{BlockKnownError, Error, LogTransientStorageError}; use near_epoch_manager::shard_tracker::ShardTracker; use near_epoch_manager::EpochManagerAdapter; -use near_primitives::block::{genesis_chunks, Block, BlockValidityError, Tip}; +use near_primitives::block::{genesis_chunks, Block, BlockValidityError, MaybeNew, Tip}; use near_primitives::block_header::BlockHeader; use near_primitives::challenge::{ BlockDoubleSign, Challenge, ChallengeBody, ChallengesResult, ChunkProofs, ChunkState, @@ -664,7 +664,8 @@ impl Chain { epoch_manager: &dyn EpochManagerAdapter, store_update: &mut ChainStoreUpdate, ) -> Result<(), Error> { - for (chunk_header, state_root) in genesis.chunks().iter().zip(state_roots.iter()) { + for (chunk_header, state_root) in genesis.chunks().iter_deprecated().zip(state_roots.iter()) + { let congestion_info = if ProtocolFeature::CongestionControl.enabled(chain_genesis.protocol_version) { genesis @@ -835,7 +836,7 @@ impl Chain { let epoch_id = block.header().epoch_id(); let shard_layout = epoch_manager.get_shard_layout(&epoch_id)?; - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); if chunk_header.height_created() == genesis_block.header().height() { // Special case: genesis chunks can be in non-genesis blocks and don't have a signature @@ -1240,34 +1241,33 @@ impl Chain { for (chunk_header, prev_chunk_header) in block.chunks().iter().zip(prev_chunk_headers.iter()) { - if chunk_header.height_included() == block.header().height() { - // new chunk - if chunk_header.prev_block_hash() != block.header().prev_hash() { - return Err(Error::InvalidChunk(format!( - "Invalid prev_block_hash, chunk hash {:?}, chunk prev block hash {}, block prev block hash {}", - chunk_header.chunk_hash(), - chunk_header.prev_block_hash(), - block.header().prev_hash() - ))); + match chunk_header { + MaybeNew::New(chunk_header) => { + if chunk_header.prev_block_hash() != block.header().prev_hash() { + return Err(Error::InvalidChunk(format!( + "Invalid prev_block_hash, chunk hash {:?}, chunk prev block hash {}, block prev block hash {}", + chunk_header.chunk_hash(), + chunk_header.prev_block_hash(), + block.header().prev_hash() + ))); + } } - } else { - // old chunk - if prev_chunk_header != chunk_header { - return Err(Error::InvalidChunk(format!( - "Invalid chunk header, prev chunk hash {:?}, chunk hash {:?}", - prev_chunk_header.chunk_hash(), - chunk_header.chunk_hash() - ))); + MaybeNew::Old(chunk_header) => { + if prev_chunk_header != chunk_header { + return Err(Error::InvalidChunk(format!( + "Invalid chunk header, prev chunk hash {:?}, chunk hash {:?}", + prev_chunk_header.chunk_hash(), + chunk_header.chunk_hash() + ))); + } } } } // Verify that proposals from chunks match block header proposals. - let block_height = block.header().height(); for pair in block .chunks() - .iter() - .filter(|chunk| chunk.is_new_chunk(block_height)) + .iter_new_chunks() .flat_map(|chunk| chunk.prev_validator_proposals()) .zip_longest(block.header().prev_validator_proposals()) { @@ -1329,13 +1329,14 @@ impl Chain { let epoch_id = block.header().epoch_id(); let shard_layout = self.epoch_manager.get_shard_layout(&epoch_id)?; - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); // Check if any chunks are invalid in this block. if let Some(encoded_chunk) = self.chain_store.is_invalid_chunk(&chunk_header.chunk_hash())? { - let merkle_paths = Block::compute_chunk_headers_root(block.chunks().iter()).1; + let merkle_paths = + Block::compute_chunk_headers_root(block.chunks().iter_deprecated()).1; let merkle_proof = merkle_paths.get(shard_index).ok_or_else(|| Error::InvalidShardId(shard_id))?; let chunk_proof = ChunkProofs { @@ -1419,7 +1420,7 @@ impl Chain { let block_height = block.header().height(); let mut receipt_proofs_by_shard_id = HashMap::new(); - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { if !chunk_header.is_new_chunk(block_height) { continue; } @@ -1698,8 +1699,12 @@ impl Chain { // sync hash block. The logic below adjusts the new_tail so that every // shard is guaranteed to have at least one new chunk in the blocks // leading to the sync hash block. - let min_height_included = - prev_block.chunks().iter().map(|chunk| chunk.height_included()).min().unwrap(); + let min_height_included = prev_block + .chunks() + .iter_deprecated() + .map(|chunk| chunk.height_included()) + .min() + .unwrap(); tracing::debug!(target: "sync", ?min_height_included, ?new_tail, "adjusting tail for missing chunks"); new_tail = std::cmp::min(new_tail, min_height_included.saturating_sub(1)); @@ -1707,8 +1712,12 @@ impl Chain { // In order to find the right new_chunk_tail we need to find the minimum // of chunk height_created for chunks in the new tail block. let new_tail_block = self.get_block_by_height(new_tail)?; - let new_chunk_tail = - new_tail_block.chunks().iter().map(|chunk| chunk.height_created()).min().unwrap(); + let new_chunk_tail = new_tail_block + .chunks() + .iter_deprecated() + .map(|chunk| chunk.height_created()) + .min() + .unwrap(); let tip = Tip::from_header(prev_block.header()); let final_head = Tip::from_header(self.genesis.header()); @@ -2107,7 +2116,7 @@ impl Chain { let last_final_block_chunks = last_final_block.chunks(); let chunk_header = last_final_block_chunks - .iter() + .iter_deprecated() .find(|chunk| chunk.shard_id() == shard_id) .ok_or_else(|| Error::InvalidShardId(shard_id))?; let new_flat_head = *chunk_header.prev_block_hash(); @@ -2521,7 +2530,7 @@ impl Chain { let (chunk_headers_root, chunk_proofs) = merklize( &sync_prev_block .chunks() - .iter() + .iter_deprecated() .map(|shard_chunk| { ChunkHashHeight(shard_chunk.chunk_hash(), shard_chunk.height_included()) }) @@ -2550,7 +2559,7 @@ impl Chain { let (prev_chunk_headers_root, prev_chunk_proofs) = merklize( &prev_block .chunks() - .iter() + .iter_deprecated() .map(|shard_chunk| { ChunkHashHeight(shard_chunk.chunk_hash(), shard_chunk.height_included()) }) @@ -2597,7 +2606,7 @@ impl Chain { let (block_receipts_root, block_receipts_proofs) = merklize( &block .chunks() - .iter() + .iter_deprecated() .map(|chunk| chunk.prev_outgoing_receipts_root()) .collect::>(), ); @@ -3140,7 +3149,8 @@ impl Chain { chunk: &ShardChunk, ) -> Result<(), Error> { if !validate_transactions_order(chunk.transactions()) { - let merkle_paths = Block::compute_chunk_headers_root(block.chunks().iter()).1; + let merkle_paths = + Block::compute_chunk_headers_root(block.chunks().iter_deprecated()).1; let epoch_id = block.header().epoch_id(); let shard_layout = self.epoch_manager.get_shard_layout(&epoch_id)?; let shard_id = chunk.shard_id(); @@ -3468,8 +3478,9 @@ impl Chain { let shard_layout = self.epoch_manager.get_shard_layout(&epoch_id)?; let shard_id = chunk_header.shard_id(); let shard_index = shard_layout.get_shard_index(shard_id); - let prev_merkle_proofs = Block::compute_chunk_headers_root(prev_block.chunks().iter()).1; - let merkle_proofs = Block::compute_chunk_headers_root(block.chunks().iter()).1; + let prev_merkle_proofs = + Block::compute_chunk_headers_root(prev_block.chunks().iter_deprecated()).1; + let merkle_proofs = Block::compute_chunk_headers_root(block.chunks().iter_deprecated()).1; let prev_chunk = self.get_chunk_clone_from_header(&prev_block.chunks()[shard_index].clone()).unwrap(); @@ -3606,7 +3617,7 @@ impl Chain { let mut maybe_jobs = vec![]; for (shard_index, (chunk_header, prev_chunk_header)) in - block.chunks().iter().zip(prev_chunk_headers.iter()).enumerate() + block.chunks().iter_deprecated().zip(prev_chunk_headers.iter()).enumerate() { // XXX: This is a bit questionable -- sandbox state patching works // only for a single shard. This so far has been enough. diff --git a/chain/chain/src/garbage_collection.rs b/chain/chain/src/garbage_collection.rs index 690f1d5467e..79647667313 100644 --- a/chain/chain/src/garbage_collection.rs +++ b/chain/chain/src/garbage_collection.rs @@ -331,7 +331,7 @@ impl ChainStore { let prev_block = self.get_block(&prev_hash); if let Ok(prev_block) = prev_block { let min_height_included = - prev_block.chunks().iter().map(|chunk| chunk.height_included()).min(); + prev_block.chunks().iter_deprecated().map(|chunk| chunk.height_included()).min(); if let Some(min_height_included) = min_height_included { tracing::debug!(target: "sync", ?min_height_included, ?gc_height, "adjusting gc_height for missing chunks"); gc_height = std::cmp::min(gc_height, min_height_included - 1); @@ -650,7 +650,7 @@ impl<'a> ChainStoreUpdate<'a> { // 6. Canonical Chain only clearing // Delete chunks, chunk-indexed data and block headers let mut min_chunk_height = self.tail()?; - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { if min_chunk_height > chunk_header.height_created() { min_chunk_height = chunk_header.height_created(); } @@ -832,8 +832,10 @@ impl<'a> ChainStoreUpdate<'a> { fn gc_outcomes(&mut self, block: &Block) -> Result<(), Error> { let block_hash = block.hash(); let store_update = self.store().store_update(); - for chunk_header in - block.chunks().iter().filter(|h| h.height_included() == block.header().height()) + for chunk_header in block + .chunks() + .iter_deprecated() + .filter(|h| h.height_included() == block.header().height()) { // It is ok to use the shard id from the header because it is a new // chunk. An old chunk may have the shard id from the parent shard. diff --git a/chain/chain/src/stateless_validation/chunk_endorsement.rs b/chain/chain/src/stateless_validation/chunk_endorsement.rs index 71d3a9a1cbe..60c49f71681 100644 --- a/chain/chain/src/stateless_validation/chunk_endorsement.rs +++ b/chain/chain/src/stateless_validation/chunk_endorsement.rs @@ -44,7 +44,9 @@ pub fn validate_chunk_endorsements_in_block( let epoch_id = epoch_manager.get_epoch_id_from_prev_block(block.header().prev_hash())?; let shard_layout = epoch_manager.get_shard_layout(&epoch_id)?; - for (chunk_header, signatures) in block.chunks().iter().zip(block.chunk_endorsements()) { + for (chunk_header, signatures) in + block.chunks().iter_deprecated().zip(block.chunk_endorsements()) + { // For old chunks, we optimize the block by not including the chunk endorsements. if chunk_header.height_included() != block.header().height() { if !signatures.is_empty() { diff --git a/chain/chain/src/stateless_validation/chunk_validation.rs b/chain/chain/src/stateless_validation/chunk_validation.rs index 144fe758ad0..7220af34699 100644 --- a/chain/chain/src/stateless_validation/chunk_validation.rs +++ b/chain/chain/src/stateless_validation/chunk_validation.rs @@ -372,7 +372,7 @@ fn validate_source_receipt_proofs( // Collect all receipts coming from this block. let mut block_receipt_proofs = Vec::new(); - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { if !chunk.is_new_chunk(block.header().height()) { continue; } diff --git a/chain/chain/src/stateless_validation/state_transition_data.rs b/chain/chain/src/stateless_validation/state_transition_data.rs index f87412bab82..9ca6440c920 100644 --- a/chain/chain/src/stateless_validation/state_transition_data.rs +++ b/chain/chain/src/stateless_validation/state_transition_data.rs @@ -25,7 +25,7 @@ impl Chain { let final_block = chain_store.get_block(&final_block_hash)?; let final_block_chunk_created_heights = final_block .chunks() - .iter() + .iter_deprecated() .map(|chunk| (chunk.shard_id(), chunk.height_created())) .collect::>(); clear_before_last_final_block(chain_store, &final_block_chunk_created_heights)?; diff --git a/chain/chain/src/store/mod.rs b/chain/chain/src/store/mod.rs index 40c38a55a00..43fc2ac4830 100644 --- a/chain/chain/src/store/mod.rs +++ b/chain/chain/src/store/mod.rs @@ -770,7 +770,7 @@ impl ChainStore { block_hash: &CryptoHash, ) -> Result>, Error> { let block = self.get_block(block_hash)?; - let chunk_headers = block.chunks().iter().cloned().collect::>(); + let chunk_headers = block.chunks().iter_deprecated().cloned().collect::>(); let mut res = HashMap::new(); for chunk_header in chunk_headers { @@ -2181,7 +2181,7 @@ impl<'a> ChainStoreUpdate<'a> { source_store.get_chunk_extra(block_hash, &shard_uid)?.clone(), ); } - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); let chunk_hash = chunk_header.chunk_hash(); chain_store_update diff --git a/chain/chain/src/store_validator/validate.rs b/chain/chain/src/store_validator/validate.rs index 8de071ee000..2f7950ed11e 100644 --- a/chain/chain/src/store_validator/validate.rs +++ b/chain/chain/src/store_validator/validate.rs @@ -367,7 +367,7 @@ pub(crate) fn block_chunks_exist( // for single-shard, no-missing-chunks state sync or epoch sync tests. return Ok(()); } - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { if chunk_header.height_included() == block.header().height() { if let Some(me) = &sv.me { let cares_about_shard = sv.shard_tracker.care_about_shard( @@ -419,7 +419,7 @@ pub(crate) fn block_chunks_height_validity( _block_hash: &CryptoHash, block: &Block, ) -> Result<(), StoreValidatorError> { - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { if chunk_header.height_created() > block.header().height() { err!( "Invalid ShardChunk included, chunk_header = {:?}, block = {:?}", @@ -704,7 +704,7 @@ pub(crate) fn outcome_indexed_by_block_hash( "Can't get Block {} from DB", block_hash ); - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { if chunk_header.height_included() == block.header().height() { let shard_uid = sv .epoch_manager diff --git a/chain/chain/src/test_utils.rs b/chain/chain/src/test_utils.rs index 566cfe9831a..ac8928a12e7 100644 --- a/chain/chain/src/test_utils.rs +++ b/chain/chain/src/test_utils.rs @@ -229,7 +229,7 @@ pub fn display_chain(me: &Option, chain: &mut Chain, tail: bool) { } ); if let Some(block) = maybe_block { - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { let chunk_producer = epoch_manager .get_chunk_producer( &epoch_id, diff --git a/chain/chain/src/tests/simple_chain.rs b/chain/chain/src/tests/simple_chain.rs index e347b4e678a..fc81923455e 100644 --- a/chain/chain/src/tests/simple_chain.rs +++ b/chain/chain/src/tests/simple_chain.rs @@ -74,7 +74,7 @@ fn build_chain_with_orphans() { last_block.header(), 10, last_block.header().block_ordinal() + 1, - last_block.chunks().iter().cloned().collect(), + last_block.chunks().iter_deprecated().cloned().collect(), vec![vec![]; last_block.chunks().len()], *last_block.header().epoch_id(), *last_block.header().next_epoch_id(), @@ -268,7 +268,7 @@ fn block_chunk_headers_iter() { let chunks = block.chunks(); let new_headers: Vec<&ShardChunkHeader> = chunks - .iter_annotated() + .iter() .filter_map(|chunk| match chunk { MaybeNew::New(chunk) => Some(chunk), _ => None, @@ -276,13 +276,16 @@ fn block_chunk_headers_iter() { .collect(); let old_headers: Vec<&ShardChunkHeader> = chunks - .iter_annotated() + .iter() .filter_map(|chunk| match chunk { MaybeNew::Old(chunk) => Some(chunk), _ => None, }) .collect(); + let raw_headers: Vec<&ShardChunkHeader> = chunks.iter_raw().collect(); + assert_eq!(old_headers.len(), 8); assert_eq!(new_headers.len(), 8); + assert_eq!(raw_headers.len(), old_headers.len() + new_headers.len()); } diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs index 0efeec2054f..f86d8a68e80 100644 --- a/chain/client/src/client.rs +++ b/chain/client/src/client.rs @@ -422,7 +422,7 @@ impl Client { ) -> Result<(), Error> { let epoch_id = self.epoch_manager.get_epoch_id(block.hash())?; let shard_layout = self.epoch_manager.get_shard_layout(&epoch_id)?; - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); let shard_uid = self.epoch_manager.shard_id_to_uid(shard_id, &epoch_id)?; if block.header().height() == chunk_header.height_included() { @@ -454,7 +454,7 @@ impl Client { let epoch_id = self.epoch_manager.get_epoch_id(block.hash())?; let shard_layout = self.epoch_manager.get_shard_layout(&epoch_id)?; - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); let shard_uid = self.epoch_manager.shard_id_to_uid(shard_id, &epoch_id)?; diff --git a/chain/client/src/client_actor.rs b/chain/client/src/client_actor.rs index 610249b2097..3f5ef59fcbd 100644 --- a/chain/client/src/client_actor.rs +++ b/chain/client/src/client_actor.rs @@ -1382,7 +1382,7 @@ impl ClientActorInner { fn send_chunks_metrics(&mut self, block: &Block) { let chunks = block.chunks(); - for (chunk, &included) in chunks.iter().zip(block.header().chunk_mask().iter()) { + for (chunk, &included) in chunks.iter_deprecated().zip(block.header().chunk_mask().iter()) { if included { self.info_helper.chunk_processed( chunk.shard_id(), @@ -1397,7 +1397,8 @@ impl ClientActorInner { fn send_block_metrics(&mut self, block: &Block) { let chunks_in_block = block.header().chunk_mask().iter().filter(|&&m| m).count(); - let gas_used = Block::compute_gas_used(block.chunks().iter(), block.header().height()); + let gas_used = + Block::compute_gas_used(block.chunks().iter_deprecated(), block.header().height()); let last_final_hash = block.header().last_final_block(); let last_final_ds_hash = block.header().last_ds_final_block(); @@ -1851,7 +1852,8 @@ impl ClientActorInner { return vec![]; }; - let min_height_included = block.chunks().iter().map(|chunk| chunk.height_included()).min(); + let min_height_included = + block.chunks().iter_deprecated().map(|chunk| chunk.height_included()).min(); let Some(min_height_included) = min_height_included else { tracing::warn!(target: "sync", ?block_hash, "get_extra_sync_block_hashes: Cannot find the min block height"); return vec![]; diff --git a/chain/client/src/debug.rs b/chain/client/src/debug.rs index c3c59579848..8773b725760 100644 --- a/chain/client/src/debug.rs +++ b/chain/client/src/debug.rs @@ -239,7 +239,7 @@ impl ClientActorInner { let shards_size_and_parts: Vec<(u64, u64)> = block .chunks() - .iter() + .iter_deprecated() .enumerate() .map(|(shard_index, chunk)| { let shard_id = shard_layout.get_shard_id(shard_index); @@ -477,7 +477,7 @@ impl ClientActorInner { let chunks = match &block { Some(block) => block .chunks() - .iter() + .iter_deprecated() .map(|chunk| { let endorsement_ratio = chunk_endorsements .as_ref() @@ -700,7 +700,9 @@ impl ClientActorInner { return None; }; // Iterate all shards and compute the endorsed stake from the endorsement signatures. - for (chunk_header, signatures) in block.chunks().iter().zip(block.chunk_endorsements()) { + for (chunk_header, signatures) in + block.chunks().iter_deprecated().zip(block.chunk_endorsements()) + { // Validation checks. if chunk_header.height_included() != block.header().height() { chunk_endorsements.insert(chunk_header.chunk_hash(), 0.0); diff --git a/chain/client/src/stateless_validation/shadow_validate.rs b/chain/client/src/stateless_validation/shadow_validate.rs index 8551c093a62..913d364d5a8 100644 --- a/chain/client/src/stateless_validation/shadow_validate.rs +++ b/chain/client/src/stateless_validation/shadow_validate.rs @@ -19,7 +19,7 @@ impl Client { let prev_block_chunks = prev_block.chunks(); for (shard_index, chunk) in block .chunks() - .iter() + .iter_deprecated() .enumerate() .filter(|(_, chunk)| chunk.is_new_chunk(block.header().height())) { diff --git a/chain/client/src/sync/header.rs b/chain/client/src/sync/header.rs index 3476eb92ed0..52374e14672 100644 --- a/chain/client/src/sync/header.rs +++ b/chain/client/src/sync/header.rs @@ -784,7 +784,7 @@ mod test { last_block.header(), this_height, last_block.header().block_ordinal() + 1, - last_block.chunks().iter().cloned().collect(), + last_block.chunks().iter_deprecated().cloned().collect(), vec![vec![]; last_block.chunks().len()], epoch_id, next_epoch_id, diff --git a/chain/client/src/tests/process_blocks.rs b/chain/client/src/tests/process_blocks.rs index 83d6d33bfb4..f0958900bb3 100644 --- a/chain/client/src/tests/process_blocks.rs +++ b/chain/client/src/tests/process_blocks.rs @@ -64,7 +64,7 @@ fn test_bad_shard_id() { env.process_block(0, prev_block, Provenance::PRODUCED); let mut block = env.clients[0].produce_block(2).unwrap().unwrap(); // modify the block and resign it let validator_signer = create_test_signer("test0"); - let mut chunks: Vec<_> = block.chunks().iter().cloned().collect(); + let mut chunks: Vec<_> = block.chunks().iter_deprecated().cloned().collect(); // modify chunk 0 to have shard_id 1 let chunk = chunks.get(0).unwrap(); let outgoing_receipts_root = chunks.get(1).unwrap().prev_outgoing_receipts_root(); @@ -212,7 +212,7 @@ fn test_bad_congestion_info_impl(mode: BadCongestionInfoMode) { let validator_signer = create_test_signer("test0"); - let chunks: Vec<_> = block.chunks().iter().cloned().collect(); + let chunks: Vec<_> = block.chunks().iter_deprecated().cloned().collect(); let chunk = chunks.get(0).unwrap(); let mut congestion_info = chunk.congestion_info().unwrap_or_default(); diff --git a/chain/client/src/view_client_actor.rs b/chain/client/src/view_client_actor.rs index d91d956a243..81ce61caa8e 100644 --- a/chain/client/src/view_client_actor.rs +++ b/chain/client/src/view_client_actor.rs @@ -1105,7 +1105,7 @@ impl Handler for ViewClientActorInner { .chain .get_block(&h)? .chunks() - .iter() + .iter_deprecated() .map(|header| header.prev_outcome_root()) .collect::>(); if target_shard_index >= outcome_roots.len() { diff --git a/core/primitives/src/block.rs b/core/primitives/src/block.rs index 3fea3b18eac..1abd9bc8261 100644 --- a/core/primitives/src/block.rs +++ b/core/primitives/src/block.rs @@ -445,7 +445,7 @@ impl Block { ) -> bool { let mut balance_burnt = 0; - for chunk in self.chunks().iter() { + for chunk in self.chunks().iter_deprecated() { if chunk.height_included() == self.header().height() { balance_burnt += chunk.prev_balance_burnt(); } @@ -462,8 +462,10 @@ impl Block { max_gas_price: Balance, gas_price_adjustment_rate: Rational32, ) -> bool { - let gas_used = Self::compute_gas_used(self.chunks().iter(), self.header().height()); - let gas_limit = Self::compute_gas_limit(self.chunks().iter(), self.header().height()); + let gas_used = + Self::compute_gas_used(self.chunks().iter_deprecated(), self.header().height()); + let gas_limit = + Self::compute_gas_limit(self.chunks().iter_deprecated(), self.header().height()); let expected_price = Self::compute_next_gas_price( gas_price, gas_used, @@ -655,7 +657,7 @@ impl Block { pub fn block_congestion_info(&self) -> BlockCongestionInfo { let mut result = BTreeMap::new(); - for chunk in self.chunks().iter() { + for chunk in self.chunks().iter_deprecated() { let shard_id = chunk.shard_id(); if let Some(congestion_info) = chunk.congestion_info() { @@ -689,31 +691,32 @@ impl Block { /// Checks that block content matches block hash, with the possible exception of chunk signatures pub fn check_validity(&self) -> Result<(), BlockValidityError> { // Check that state root stored in the header matches the state root of the chunks - let state_root = Block::compute_state_root(self.chunks().iter()); + let state_root = Block::compute_state_root(self.chunks().iter_deprecated()); if self.header().prev_state_root() != &state_root { return Err(InvalidStateRoot); } // Check that chunk receipts root stored in the header matches the state root of the chunks let chunk_receipts_root = - Block::compute_chunk_prev_outgoing_receipts_root(self.chunks().iter()); + Block::compute_chunk_prev_outgoing_receipts_root(self.chunks().iter_deprecated()); if self.header().prev_chunk_outgoing_receipts_root() != &chunk_receipts_root { return Err(InvalidReceiptRoot); } // Check that chunk headers root stored in the header matches the chunk headers root of the chunks - let chunk_headers_root = Block::compute_chunk_headers_root(self.chunks().iter()).0; + let chunk_headers_root = + Block::compute_chunk_headers_root(self.chunks().iter_deprecated()).0; if self.header().chunk_headers_root() != &chunk_headers_root { return Err(InvalidChunkHeaderRoot); } // Check that chunk tx root stored in the header matches the tx root of the chunks - let chunk_tx_root = Block::compute_chunk_tx_root(self.chunks().iter()); + let chunk_tx_root = Block::compute_chunk_tx_root(self.chunks().iter_deprecated()); if self.header().chunk_tx_root() != &chunk_tx_root { return Err(InvalidTransactionRoot); } - let outcome_root = Block::compute_outcome_root(self.chunks().iter()); + let outcome_root = Block::compute_outcome_root(self.chunks().iter_deprecated()); if self.header().outcome_root() != &outcome_root { return Err(InvalidTransactionRoot); } @@ -721,7 +724,7 @@ impl Block { // Check that chunk included root stored in the header matches the chunk included root of the chunks let chunk_mask: Vec = self .chunks() - .iter() + .iter_deprecated() .map(|chunk| chunk.height_included() == self.header().height()) .collect(); if self.header().chunk_mask() != &chunk_mask[..] { @@ -798,7 +801,16 @@ impl<'a> Chunks<'a> { } } - pub fn iter(&'a self) -> Box + 'a> { + /// Deprecated, use `iter` instead. `iter_raw` is available if there is no need to + /// distinguish between old and new headers. + pub fn iter_deprecated(&'a self) -> Box + 'a> { + match &self.chunks { + ChunksCollection::V1(chunks) => Box::new(chunks.iter()), + ChunksCollection::V2(chunks) => Box::new(chunks.iter()), + } + } + + pub fn iter_raw(&'a self) -> Box + 'a> { match &self.chunks { ChunksCollection::V1(chunks) => Box::new(chunks.iter()), ChunksCollection::V2(chunks) => Box::new(chunks.iter()), @@ -806,9 +818,7 @@ impl<'a> Chunks<'a> { } /// Returns an iterator over the shard chunk headers, differentiating between new and old chunks. - pub fn iter_annotated( - &'a self, - ) -> Box> + 'a> { + pub fn iter(&'a self) -> Box> + 'a> { match &self.chunks { ChunksCollection::V1(chunks) => { Box::new(chunks.iter().map(|chunk| annotate_chunk(chunk, self.block_height))) @@ -819,6 +829,13 @@ impl<'a> Chunks<'a> { } } + pub fn iter_new_chunks(&'a self) -> Box + 'a> { + Box::new(self.iter_annotated().filter_map(|chunk| match chunk { + MaybeNew::New(chunk) => Some(chunk), + _ => None, + })) + } + pub fn get(&self, index: ShardIndex) -> Option<&ShardChunkHeader> { match &self.chunks { ChunksCollection::V1(chunks) => chunks.get(index), diff --git a/core/primitives/src/test_utils.rs b/core/primitives/src/test_utils.rs index 3fec1ae975c..39053f260c4 100644 --- a/core/primitives/src/test_utils.rs +++ b/core/primitives/src/test_utils.rs @@ -828,7 +828,7 @@ impl TestBlockBuilder { self.prev.header(), self.height, self.prev.header().block_ordinal() + 1, - self.prev.chunks().iter().cloned().collect(), + self.prev.chunks().iter_deprecated().cloned().collect(), vec![vec![]; self.prev.chunks().len()], self.epoch_id, self.next_epoch_id, diff --git a/core/primitives/src/views.rs b/core/primitives/src/views.rs index 541ee51027d..e4585ae51da 100644 --- a/core/primitives/src/views.rs +++ b/core/primitives/src/views.rs @@ -1049,7 +1049,7 @@ impl BlockView { BlockView { author, header: block.header().clone().into(), - chunks: block.chunks().iter().cloned().map(Into::into).collect(), + chunks: block.chunks().iter_deprecated().cloned().map(Into::into).collect(), } } } diff --git a/core/store/src/cold_storage.rs b/core/store/src/cold_storage.rs index afb75cf04f2..3ab8637272c 100644 --- a/core/store/src/cold_storage.rs +++ b/core/store/src/cold_storage.rs @@ -387,7 +387,7 @@ fn get_keys_from_store( let block: Block = store.get_ser_or_err_for_cold(DBCol::Block, &block_hash_key)?; let chunks = block .chunks() - .iter() + .iter_deprecated() .map(|chunk_header| { store.get_ser_or_err_for_cold(DBCol::Chunks, chunk_header.chunk_hash().as_bytes()) }) diff --git a/genesis-tools/genesis-populate/src/lib.rs b/genesis-tools/genesis-populate/src/lib.rs index 9eaa8a78a60..81a7ad6b35d 100644 --- a/genesis-tools/genesis-populate/src/lib.rs +++ b/genesis-tools/genesis-populate/src/lib.rs @@ -272,7 +272,9 @@ impl GenesisBuilder { store_update.save_block(genesis.clone()); let protocol_version = self.genesis.config.protocol_version; - for (chunk_header, &state_root) in genesis.chunks().iter().zip(self.roots.values()) { + for (chunk_header, &state_root) in + genesis.chunks().iter_deprecated().zip(self.roots.values()) + { let shard_layout = &self.genesis.config.shard_layout; let shard_id = chunk_header.shard_id(); let shard_uid = ShardUId::from_shard_id_and_layout(shard_id, &shard_layout); diff --git a/integration-tests/src/tests/client/block_corruption.rs b/integration-tests/src/tests/client/block_corruption.rs index aad623b2bfa..4b1306eb8a3 100644 --- a/integration-tests/src/tests/client/block_corruption.rs +++ b/integration-tests/src/tests/client/block_corruption.rs @@ -64,7 +64,7 @@ fn change_shard_id_to_invalid() { // 1. Corrupt chunks let bad_shard_id = ShardId::new(100); let mut new_chunks = vec![]; - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { let mut new_chunk = chunk.clone(); match &mut new_chunk { ShardChunkHeader::V1(new_chunk) => new_chunk.inner.shard_id = bad_shard_id, diff --git a/integration-tests/src/tests/client/challenges.rs b/integration-tests/src/tests/client/challenges.rs index 035b42b65bd..d491f388b8e 100644 --- a/integration-tests/src/tests/client/challenges.rs +++ b/integration-tests/src/tests/client/challenges.rs @@ -99,7 +99,7 @@ fn test_verify_block_double_sign_challenge() { genesis.header(), 2, genesis.header().block_ordinal() + 1, - genesis.chunks().iter().cloned().collect(), + genesis.chunks().iter_deprecated().cloned().collect(), vec![vec![]; genesis.chunks().len()], *b1.header().epoch_id(), *b1.header().next_epoch_id(), @@ -316,7 +316,7 @@ fn challenge( let shard_layout = env.clients[0].chain.epoch_manager.get_shard_layout(epoch_id).unwrap(); let shard_index = shard_layout.get_shard_index(shard_id); - let merkle_paths = Block::compute_chunk_headers_root(block.chunks().iter()).1; + let merkle_paths = Block::compute_chunk_headers_root(block.chunks().iter_deprecated()).1; let valid_challenge = Challenge::produce( ChallengeBody::ChunkProofs(ChunkProofs { block_header: borsh::to_vec(&block.header()).unwrap(), @@ -448,8 +448,9 @@ fn test_verify_chunk_invalid_state_challenge() { let challenge_body = client.chain.create_chunk_state_challenge(&last_block, &block, &block.chunks()[0]).unwrap(); { - let prev_merkle_proofs = Block::compute_chunk_headers_root(last_block.chunks().iter()).1; - let merkle_proofs = Block::compute_chunk_headers_root(block.chunks().iter()).1; + let prev_merkle_proofs = + Block::compute_chunk_headers_root(last_block.chunks().iter_deprecated()).1; + let merkle_proofs = Block::compute_chunk_headers_root(block.chunks().iter_deprecated()).1; assert_eq!(prev_merkle_proofs[0], challenge_body.prev_merkle_proof); assert_eq!(merkle_proofs[0], challenge_body.merkle_proof); // TODO (#6316): enable storage proof generation diff --git a/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs b/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs index fe0362ab20d..ed7f8e34206 100644 --- a/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs +++ b/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs @@ -482,7 +482,7 @@ fn test_processing_chunks_sanity() { let block = env.clients[0].produce_block(i).unwrap().unwrap(); let chunks = block .chunks() - .iter() + .iter_deprecated() .map(|chunk| format!("{:?}", chunk.chunk_hash())) .collect::>(); debug!(target: "chunks", "Block #{} has chunks {:?}", i, chunks.join(", ")); diff --git a/integration-tests/src/tests/client/features/congestion_control.rs b/integration-tests/src/tests/client/features/congestion_control.rs index 4716ecd78ba..4e6048e72ad 100644 --- a/integration-tests/src/tests/client/features/congestion_control.rs +++ b/integration-tests/src/tests/client/features/congestion_control.rs @@ -159,7 +159,7 @@ fn check_congestion_info(env: &TestEnv, check_congested_protocol_upgrade: bool) let protocol_config = client.runtime_adapter.get_protocol_config(&epoch_id).unwrap(); let runtime_config = protocol_config.runtime_config; - for (shard_index, chunk) in block.chunks().iter().enumerate() { + for (shard_index, chunk) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); let prev_state_root = chunk.prev_state_root(); @@ -239,7 +239,7 @@ fn test_protocol_upgrade_simple() { assert!(chunks.len() > 0); let config = head_congestion_control_config(&env); - for chunk_header in chunks.iter() { + for chunk_header in chunks.iter_deprecated() { let congestion_info = chunk_header .congestion_info() .expect("chunk header must have congestion info after upgrade"); @@ -320,7 +320,7 @@ fn test_protocol_upgrade_under_congestion() { // check congestion info is available let block = env.clients[0].chain.get_head_block().unwrap(); let chunks = block.chunks(); - for chunk_header in chunks.iter() { + for chunk_header in chunks.iter_deprecated() { chunk_header .congestion_info() .expect("chunk header must have congestion info after upgrade"); @@ -403,7 +403,7 @@ fn check_old_protocol(env: &TestEnv) { let block = env.clients[0].chain.get_head_block().unwrap(); let chunks = block.chunks(); assert!(chunks.len() > 0, "no chunks in block"); - for chunk_header in chunks.iter() { + for chunk_header in chunks.iter_deprecated() { assert!( chunk_header.congestion_info().is_none(), "old protocol should not have congestion info but found {:?}", diff --git a/integration-tests/src/tests/client/features/in_memory_tries.rs b/integration-tests/src/tests/client/features/in_memory_tries.rs index 15a56945fc6..38a07135162 100644 --- a/integration-tests/src/tests/client/features/in_memory_tries.rs +++ b/integration-tests/src/tests/client/features/in_memory_tries.rs @@ -227,7 +227,7 @@ fn get_block_producer(env: &TestEnv, head: &Tip, height_offset: u64) -> AccountI } fn check_block_does_not_have_missing_chunks(block: &Block) { - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { if !chunk.is_new_chunk(block.header().height()) { panic!( "Block at height {} is produced without all chunks; the test setup is faulty", @@ -356,7 +356,7 @@ fn run_chain_for_some_blocks_while_sending_money_around( } } - for chunk in block_processed.chunks().iter() { + for chunk in block_processed.chunks().iter_deprecated() { let mut chunks_found = 0; for i in 0..env.clients.len() { let client = &env.clients[i]; diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 7d2e466f311..df10a95f2b4 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -686,7 +686,7 @@ fn invalid_blocks_common(is_requested: bool) { // Send block with invalid chunk signature let mut block = valid_block.clone(); - let mut chunks: Vec<_> = block.chunks().iter().cloned().collect(); + let mut chunks: Vec<_> = block.chunks().iter_deprecated().cloned().collect(); let some_signature = Signature::from_parts(KeyType::ED25519, &[1; 64]).unwrap(); match &mut chunks[0] { ShardChunkHeader::V1(chunk) => { @@ -1259,7 +1259,7 @@ fn test_bad_chunk_mask() { { let mut chunk_header = shard_chunk.cloned_header(); *chunk_header.height_included_mut() = height; - let mut chunk_headers: Vec<_> = block.chunks().iter().cloned().collect(); + let mut chunk_headers: Vec<_> = block.chunks().iter_deprecated().cloned().collect(); chunk_headers[0] = chunk_header; block.set_chunks(chunk_headers.clone()); block @@ -1418,7 +1418,7 @@ fn test_archival_save_trie_changes() { // Go through chunks and test that trie changes were correctly saved to the store. let chunks = block.chunks(); - for chunk in chunks.iter() { + for chunk in chunks.iter_deprecated() { let shard_id = chunk.shard_id(); let version = shard_layout.version(); @@ -2283,7 +2283,7 @@ fn test_validate_chunk_extra() { block .mut_header() .set_chunk_endorsements(ChunkEndorsementsBitmap::from_endorsements(vec![vec![true]])); - let outcome_root = Block::compute_outcome_root(block.chunks().iter()); + let outcome_root = Block::compute_outcome_root(block.chunks().iter_deprecated()); block.mut_header().set_prev_outcome_root(outcome_root); let endorsement = ChunkEndorsementV1::new(chunk_header.chunk_hash(), &validator_signer); block.set_chunk_endorsements(vec![vec![Some(Box::new(endorsement.signature))]]); diff --git a/nearcore/benches/store.rs b/nearcore/benches/store.rs index e1e906cd4a2..c03e3e6620c 100644 --- a/nearcore/benches/store.rs +++ b/nearcore/benches/store.rs @@ -49,7 +49,7 @@ fn read_trie_items(bench: &mut Bencher, shard_index: ShardIndex, shard_id: Shard let head = chain_store.head().unwrap(); let last_block = chain_store.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); let header = last_block.header(); let trie = runtime diff --git a/nearcore/src/metrics.rs b/nearcore/src/metrics.rs index a8db65cc675..966509f723d 100644 --- a/nearcore/src/metrics.rs +++ b/nearcore/src/metrics.rs @@ -120,7 +120,7 @@ fn export_postponed_receipt_count(near_config: &NearConfig, store: &Store) -> an let block = chain_store.get_block(&head.last_block_hash)?; let shard_layout = epoch_manager.get_shard_layout(block.header().epoch_id())?; - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { let shard_id = chunk_header.shard_id(); if chunk_header.height_included() != block.header().height() { tracing::trace!(target: "metrics", "trie-stats - chunk for shard {shard_id} is missing, skipping it."); diff --git a/test-utils/testlib/src/process_blocks.rs b/test-utils/testlib/src/process_blocks.rs index 4d41fb047e8..0c5304ac9d0 100644 --- a/test-utils/testlib/src/process_blocks.rs +++ b/test-utils/testlib/src/process_blocks.rs @@ -8,7 +8,7 @@ use std::sync::Arc; pub fn set_no_chunk_in_block(block: &mut Block, prev_block: &Block) { let chunk_headers = vec![prev_block.chunks()[0].clone()]; let mut balance_burnt = 0; - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { if chunk.height_included() == block.header().height() { balance_burnt += chunk.prev_balance_burnt(); } diff --git a/tools/chainsync-loadtest/src/fetch_chain.rs b/tools/chainsync-loadtest/src/fetch_chain.rs index 9314b180afc..8216008ee79 100644 --- a/tools/chainsync-loadtest/src/fetch_chain.rs +++ b/tools/chainsync-loadtest/src/fetch_chain.rs @@ -55,7 +55,7 @@ pub async fn run( let h = *h.hash(); s.spawn(async move { let block = network.fetch_block(h).await?; - for ch in block.chunks().iter() { + for ch in block.chunks().iter_deprecated() { s.spawn(network.fetch_chunk(ch.clone())); } anyhow::Ok(()) diff --git a/tools/cold-store/src/cli.rs b/tools/cold-store/src/cli.rs index 6c6b33f99f2..12803573082 100644 --- a/tools/cold-store/src/cli.rs +++ b/tools/cold-store/src/cli.rs @@ -494,7 +494,7 @@ impl StateRootSelector { .get_ser::(DBCol::Block, &hash_key)? .ok_or_else(|| anyhow::anyhow!("Failed to find Block: {:?}", hash_key))?; let mut hashes = vec![]; - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { hashes.push( cold_store .get_ser::( diff --git a/tools/database/src/analyse_gas_usage.rs b/tools/database/src/analyse_gas_usage.rs index 35534d6361b..981a8f9d94b 100644 --- a/tools/database/src/analyse_gas_usage.rs +++ b/tools/database/src/analyse_gas_usage.rs @@ -225,7 +225,7 @@ fn get_gas_usage_in_block( let mut result = GasUsageStats::new(); // Go over every chunk in this block and gather data - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { let shard_id = chunk_header.shard_id(); let shard_uid = ShardUId::from_shard_id_and_layout(shard_id, &shard_layout); diff --git a/tools/database/src/analyse_high_load.rs b/tools/database/src/analyse_high_load.rs index 9d553cd7f6d..9f8ce595a1c 100644 --- a/tools/database/src/analyse_high_load.rs +++ b/tools/database/src/analyse_high_load.rs @@ -161,7 +161,7 @@ impl HighLoadStatsCommand { let mut tx_by_account = vec![0; 4]; let mut receipts_by_account = vec![0; 4]; - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { // Note that this doesn't work if there are missing chunks and resharding. let shard_id = chunk_header.shard_id(); // let mut gas_usage_in_shard = GasUsageInShard::new(); diff --git a/tools/database/src/analyze_delayed_receipt.rs b/tools/database/src/analyze_delayed_receipt.rs index b425dbb812a..0a3345b258e 100644 --- a/tools/database/src/analyze_delayed_receipt.rs +++ b/tools/database/src/analyze_delayed_receipt.rs @@ -96,7 +96,7 @@ impl AnalyzeDelayedReceiptCommand { last_analysed_block = Some((block.header().height(), *block.hash())); let shard_layout = epoch_manager.get_shard_layout(block.header().epoch_id()).unwrap(); - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { let state_root = chunk_header.prev_state_root(); let trie_update = shard_tries.get_trie_for_shard( ShardUId::from_shard_id_and_layout(chunk_header.shard_id(), &shard_layout), diff --git a/tools/mirror/src/offline.rs b/tools/mirror/src/offline.rs index bf5b70e2611..e92b4d8d1fa 100644 --- a/tools/mirror/src/offline.rs +++ b/tools/mirror/src/offline.rs @@ -118,7 +118,7 @@ impl crate::ChainAccess for ChainAccess { .with_context(|| format!("Can't get block {} at height {}", &block_hash, height))?; let mut chunks = Vec::new(); - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { let chunk = match self.chain.get_chunk(&chunk.chunk_hash()) { Ok(c) => c, Err(e) => { diff --git a/tools/mock-node/src/lib.rs b/tools/mock-node/src/lib.rs index 4f30854d60b..7a705419245 100644 --- a/tools/mock-node/src/lib.rs +++ b/tools/mock-node/src/lib.rs @@ -107,7 +107,7 @@ fn retrieve_starting_chunk_hash( .chain_store() .get_block_hash_by_height(height) .and_then(|hash| chain.chain_store().get_block(&hash)) - .map(|block| block.chunks().iter().next().unwrap().chunk_hash()) + .map(|block| block.chunks().iter_deprecated().next().unwrap().chunk_hash()) { Ok(hash) => return Ok(hash), Err(e) => { diff --git a/tools/mock-node/src/setup.rs b/tools/mock-node/src/setup.rs index a0b145c2ff0..f9857b09459 100644 --- a/tools/mock-node/src/setup.rs +++ b/tools/mock-node/src/setup.rs @@ -187,7 +187,7 @@ pub fn setup_mock_node( let prev_hash = *block.header().prev_hash(); let epoch_id = block.header().epoch_id(); let shard_layout = client_epoch_manager.get_shard_layout(epoch_id).unwrap(); - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); let state_root = chunk_header.prev_state_root(); let state_root_node = diff --git a/tools/replay-archive/src/cli.rs b/tools/replay-archive/src/cli.rs index d2f827e3fd7..d6a0192b9ae 100644 --- a/tools/replay-archive/src/cli.rs +++ b/tools/replay-archive/src/cli.rs @@ -451,7 +451,7 @@ impl ReplayController { let block_height = block.header().height(); let block_hash = block.header().hash(); let mut receipt_proofs_by_shard_id: HashMap> = HashMap::new(); - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { if !chunk_header.is_new_chunk(block_height) { continue; } diff --git a/tools/state-viewer/src/apply_chunk.rs b/tools/state-viewer/src/apply_chunk.rs index 3e2d15f81d0..5a44bea2ebc 100644 --- a/tools/state-viewer/src/apply_chunk.rs +++ b/tools/state-viewer/src/apply_chunk.rs @@ -183,7 +183,7 @@ fn find_tx_or_receipt( chain_store: &ChainStore, ) -> anyhow::Result> { let block = chain_store.get_block(block_hash)?; - let chunk_hashes = block.chunks().iter().map(|c| c.chunk_hash()).collect::>(); + let chunk_hashes = block.chunks().iter_deprecated().map(|c| c.chunk_hash()).collect::>(); let epoch_id = block.header().epoch_id(); let shard_layout = epoch_manager.get_shard_layout(epoch_id)?; @@ -560,7 +560,8 @@ mod test { let block = env.clients[0].produce_block(height).unwrap().unwrap(); let hash = *block.hash(); - let chunk_hashes = block.chunks().iter().map(|c| c.chunk_hash()).collect::>(); + let chunk_hashes = + block.chunks().iter_deprecated().map(|c| c.chunk_hash()).collect::>(); let epoch_id = *block.header().epoch_id(); let shard_layout = epoch_manager.get_shard_layout(&epoch_id).unwrap(); @@ -649,7 +650,8 @@ mod test { let block = env.clients[0].produce_block(height).unwrap().unwrap(); let hash = *block.hash(); - let chunk_hashes = block.chunks().iter().map(|c| c.chunk_hash()).collect::>(); + let chunk_hashes = + block.chunks().iter_deprecated().map(|c| c.chunk_hash()).collect::>(); let epoch_id = *block.header().epoch_id(); let shard_layout = epoch_manager.get_shard_layout(&epoch_id).unwrap(); diff --git a/tools/state-viewer/src/commands.rs b/tools/state-viewer/src/commands.rs index 16ad543b4cd..067bc238152 100644 --- a/tools/state-viewer/src/commands.rs +++ b/tools/state-viewer/src/commands.rs @@ -724,7 +724,7 @@ pub(crate) fn view_chain( let mut chunk_extras = vec![]; let mut chunks = vec![]; - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { if chunk_header.height_included() == block.header().height() { let shard_id = shard_layout.get_shard_id(shard_index); let shard_uid = ShardUId::from_shard_id_and_layout(shard_id, &shard_layout); @@ -843,7 +843,7 @@ fn read_genesis_from_store( let genesis_hash = chain_store.get_block_hash_by_height(genesis_height)?; let genesis_block = chain_store.get_block(&genesis_hash)?; let mut genesis_chunks = vec![]; - for chunk_header in genesis_block.chunks().iter() { + for chunk_header in genesis_block.chunks().iter_deprecated() { if chunk_header.height_included() == genesis_height { genesis_chunks.push(chain_store.get_chunk(&chunk_header.chunk_hash())?); } @@ -858,7 +858,7 @@ pub(crate) fn check_block_chunk_existence(near_config: NearConfig, store: Store) let head = chain_store.head().unwrap(); let mut cur_block = chain_store.get_block(&head.last_block_hash).unwrap(); while cur_block.header().height() > genesis_height { - for chunk_header in cur_block.chunks().iter() { + for chunk_header in cur_block.chunks().iter_deprecated() { if chunk_header.height_included() == cur_block.header().height() && chain_store.get_chunk(&chunk_header.chunk_hash()).is_err() { diff --git a/tools/state-viewer/src/congestion_control.rs b/tools/state-viewer/src/congestion_control.rs index e0d8c46b5dd..b7dbdc9cbda 100644 --- a/tools/state-viewer/src/congestion_control.rs +++ b/tools/state-viewer/src/congestion_control.rs @@ -58,7 +58,7 @@ impl PrintCmd { let head = chain_store.head().unwrap(); let block = chain_store.get_block(&head.last_block_hash).unwrap(); - for chunk_header in block.chunks().iter() { + for chunk_header in block.chunks().iter_deprecated() { let congestion_info = chunk_header.congestion_info(); println!( "{:?} - {:?} - {:?}", diff --git a/tools/state-viewer/src/replay_headers.rs b/tools/state-viewer/src/replay_headers.rs index 96e3897cc5c..cfdbb71a226 100644 --- a/tools/state-viewer/src/replay_headers.rs +++ b/tools/state-viewer/src/replay_headers.rs @@ -239,7 +239,7 @@ fn get_block_info( let height = header.height(); let prev_block_epoch_id = epoch_manager.get_epoch_id_from_prev_block(header.prev_hash())?; - for (shard_index, chunk_header) in chunks.iter().enumerate() { + for (shard_index, chunk_header) in chunks.iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); let endorsements = &endorsement_signatures[shard_index]; if !chunk_header.is_new_chunk(height) { diff --git a/tools/state-viewer/src/state_dump.rs b/tools/state-viewer/src/state_dump.rs index af8da45677f..519e7224459 100644 --- a/tools/state-viewer/src/state_dump.rs +++ b/tools/state-viewer/src/state_dump.rs @@ -440,7 +440,7 @@ mod test { ); let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = @@ -518,7 +518,7 @@ mod test { ); let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = @@ -582,7 +582,7 @@ mod test { ); let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = @@ -625,7 +625,7 @@ mod test { let head = env.clients[0].chain.head().unwrap(); let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = @@ -680,7 +680,7 @@ mod test { let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = @@ -777,8 +777,11 @@ mod test { .unwrap(); let last_block = blocks.pop().unwrap(); - let state_roots = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect::>(); + let state_roots = last_block + .chunks() + .iter_deprecated() + .map(|chunk| chunk.prev_state_root()) + .collect::>(); let records_file = tempfile::NamedTempFile::new().unwrap(); let _ = state_dump( @@ -860,7 +863,7 @@ mod test { ); let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = @@ -918,7 +921,7 @@ mod test { let last_block = env.clients[0].chain.get_block(&head.last_block_hash).unwrap(); let state_roots: Vec = - last_block.chunks().iter().map(|chunk| chunk.prev_state_root()).collect(); + last_block.chunks().iter_deprecated().map(|chunk| chunk.prev_state_root()).collect(); initialize_genesis_state(store.clone(), &genesis, None); let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config); let runtime = diff --git a/tools/state-viewer/src/trie_iteration_benchmark.rs b/tools/state-viewer/src/trie_iteration_benchmark.rs index 03ca6e6bac5..eac07f7f8d5 100644 --- a/tools/state-viewer/src/trie_iteration_benchmark.rs +++ b/tools/state-viewer/src/trie_iteration_benchmark.rs @@ -117,14 +117,14 @@ impl TrieIterationBenchmarkCmd { EpochManager::new_from_genesis_config(store.clone(), &genesis_config).unwrap(); let shard_layout = epoch_manager.get_shard_layout(block.header().epoch_id()).unwrap(); - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); if chunk_header.height_included() != block.header().height() { println!("chunk for shard {shard_id} is missing and will be skipped"); } } - for (shard_index, chunk_header) in block.chunks().iter().enumerate() { + for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() { let shard_id = shard_layout.get_shard_id(shard_index); if chunk_header.height_included() != block.header().height() { println!("chunk for shard {shard_id} is missing, skipping it"); diff --git a/tools/state-viewer/src/tx_dump.rs b/tools/state-viewer/src/tx_dump.rs index 291f18f7f5c..f9212378a74 100644 --- a/tools/state-viewer/src/tx_dump.rs +++ b/tools/state-viewer/src/tx_dump.rs @@ -12,7 +12,7 @@ pub fn dump_tx_from_block( ) -> Vec { let chunks = block.chunks(); let mut res = vec![]; - for (_, chunk_header) in chunks.iter().enumerate() { + for (_, chunk_header) in chunks.iter_deprecated().enumerate() { res.extend( chain_store .get_chunk(&chunk_header.chunk_hash()) diff --git a/tools/state-viewer/src/util.rs b/tools/state-viewer/src/util.rs index 8084e72fb19..dc7dffecd57 100644 --- a/tools/state-viewer/src/util.rs +++ b/tools/state-viewer/src/util.rs @@ -58,7 +58,7 @@ pub fn load_trie_stop_at_height( }; let shard_layout = epoch_manager.get_shard_layout(&block.header().epoch_id()).unwrap(); let mut state_roots = vec![]; - for chunk in block.chunks().iter() { + for chunk in block.chunks().iter_deprecated() { let shard_uid = ShardUId::from_shard_id_and_layout(chunk.shard_id(), &shard_layout); let chunk_extra = chain_store.get_chunk_extra(&head.last_block_hash, &shard_uid).unwrap(); let state_root = *chunk_extra.state_root();