From 1cacbad43dd842a26c4908ad3ff87d315eedbf10 Mon Sep 17 00:00:00 2001 From: Anton Puhach Date: Fri, 8 Nov 2024 13:15:17 +0100 Subject: [PATCH] refactor: remove EpochManager get_chunk_producer (#12414) Replace all usages with `get_chunk_producer_info`, follow-up to #12409. --- chain/chain/src/blocks_delay_tracker.rs | 9 ++- chain/chain/src/test_utils.rs | 14 ++-- chain/chain/src/validate.rs | 13 ++-- chain/chunks/src/shards_manager_actor.rs | 62 +++++++++++------ chain/chunks/src/test_utils.rs | 11 ++- chain/client/src/client.rs | 68 ++++++++++++++----- chain/client/src/debug.rs | 29 +++++--- .../partial_witness/partial_witness_actor.rs | 6 +- chain/client/src/test_utils/test_env.rs | 10 ++- chain/client/src/view_client_actor.rs | 19 ++++-- chain/epoch-manager/src/adapter.rs | 11 --- .../client/features/adversarial_behaviors.rs | 13 ++-- .../src/tests/client/process_blocks.rs | 21 ++++-- .../src/tests/client/resharding_v2.rs | 6 +- nearcore/src/entity_debug.rs | 21 ++++-- tools/state-viewer/src/commands.rs | 9 ++- 16 files changed, 220 insertions(+), 102 deletions(-) diff --git a/chain/chain/src/blocks_delay_tracker.rs b/chain/chain/src/blocks_delay_tracker.rs index 5cea0ed01e6..8f6f67781f8 100644 --- a/chain/chain/src/blocks_delay_tracker.rs +++ b/chain/chain/src/blocks_delay_tracker.rs @@ -4,6 +4,7 @@ use near_primitives::block::{Block, Tip}; use near_primitives::hash::CryptoHash; use near_primitives::shard_layout::ShardLayout; use near_primitives::sharding::{ChunkHash, ShardChunkHeader}; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::types::{BlockHeight, ShardId}; use near_primitives::views::{ BlockProcessingInfo, BlockProcessingStatus, ChainProcessingInfo, ChunkProcessingInfo, @@ -104,7 +105,13 @@ impl ChunkTrackingStats { let created_by = epoch_manager .get_epoch_id_from_prev_block(&self.prev_block_hash) .and_then(|epoch_id| { - epoch_manager.get_chunk_producer(&epoch_id, self.height_created, self.shard_id) + epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: self.height_created, + shard_id: self.shard_id, + }) + .map(|info| info.take_account_id()) }) .ok(); let request_duration = if let Some(requested_timestamp) = self.requested_timestamp { diff --git a/chain/chain/src/test_utils.rs b/chain/chain/src/test_utils.rs index 7c3caeef7c6..bd18bdc8213 100644 --- a/chain/chain/src/test_utils.rs +++ b/chain/chain/src/test_utils.rs @@ -19,6 +19,7 @@ use near_epoch_manager::shard_tracker::ShardTracker; use near_epoch_manager::{EpochManager, EpochManagerHandle}; use near_primitives::block::Block; use near_primitives::hash::CryptoHash; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::test_utils::create_test_signer; use near_primitives::types::{AccountId, NumBlocks, NumShards}; use near_primitives::utils::MaybeValidated; @@ -231,12 +232,13 @@ pub fn display_chain(me: &Option, chain: &mut Chain, tail: bool) { if let Some(block) = maybe_block { for chunk_header in block.chunks().iter_deprecated() { let chunk_producer = epoch_manager - .get_chunk_producer( - &epoch_id, - chunk_header.height_created(), - chunk_header.shard_id(), - ) - .unwrap(); + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: chunk_header.height_created(), + shard_id: chunk_header.shard_id(), + }) + .unwrap() + .take_account_id(); if let Ok(chunk) = chain_store.get_chunk(&chunk_header.chunk_hash()) { debug!( " {: >3} {} | {} | {: >10} | tx = {: >2}, receipts = {: >2}", diff --git a/chain/chain/src/validate.rs b/chain/chain/src/validate.rs index 103820fc67d..b18299c9ae6 100644 --- a/chain/chain/src/validate.rs +++ b/chain/chain/src/validate.rs @@ -13,6 +13,7 @@ use near_primitives::congestion_info::CongestionInfo; use near_primitives::hash::CryptoHash; use near_primitives::merkle::merklize; use near_primitives::sharding::{ShardChunk, ShardChunkHeader}; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::transaction::SignedTransaction; use near_primitives::types::chunk_extra::ChunkExtra; use near_primitives::types::{AccountId, BlockHeight, EpochId, Nonce}; @@ -299,11 +300,13 @@ fn validate_chunk_authorship( &epoch_id, &chunk_header.prev_block_hash(), )? { - let chunk_producer = epoch_manager.get_chunk_producer( - &epoch_id, - chunk_header.height_created(), - chunk_header.shard_id(), - )?; + let chunk_producer = epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: chunk_header.height_created(), + shard_id: chunk_header.shard_id(), + })? + .take_account_id(); Ok(chunk_producer) } else { Err(Error::InvalidChallenge) diff --git a/chain/chunks/src/shards_manager_actor.rs b/chain/chunks/src/shards_manager_actor.rs index e01e1c1fab0..a2c499dd4e7 100644 --- a/chain/chunks/src/shards_manager_actor.rs +++ b/chain/chunks/src/shards_manager_actor.rs @@ -120,6 +120,7 @@ use near_primitives::sharding::{ PartialEncodedChunkPart, PartialEncodedChunkV2, ShardChunk, ShardChunkHeader, TransactionReceipt, }; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::transaction::SignedTransaction; use near_primitives::types::validator_stake::ValidatorStake; use near_primitives::types::{ @@ -440,11 +441,14 @@ impl ShardsManagerActor { &self.shard_tracker, ); - let chunk_producer_account_id = self.epoch_manager.as_ref().get_chunk_producer( - &self.epoch_manager.get_epoch_id_from_prev_block(ancestor_hash)?, - height, - shard_id, - )?; + let chunk_producer_account_id = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: self.epoch_manager.get_epoch_id_from_prev_block(ancestor_hash)?, + height_created: height, + shard_id, + })? + .take_account_id(); // In the following we compute which target accounts we should request parts and receipts from // First we choose a shard representative target which is either the original chunk producer @@ -645,8 +649,14 @@ impl ShardsManagerActor { return Ok(true); } } - let chunk_producer = - self.epoch_manager.get_chunk_producer(&epoch_id, next_chunk_height, shard_id)?; + let chunk_producer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: next_chunk_height, + shard_id, + })? + .take_account_id(); if &chunk_producer == me { return Ok(true); } @@ -1699,11 +1709,14 @@ impl ShardsManagerActor { let have_all_receipts = self.has_all_receipts(&prev_block_hash, entry, me)?; let can_reconstruct = entry.parts.len() >= self.epoch_manager.num_data_parts(); - let chunk_producer = self.epoch_manager.get_chunk_producer( - &epoch_id, - header.height_created(), - header.shard_id(), - )?; + let chunk_producer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: header.height_created(), + shard_id: header.shard_id(), + })? + .take_account_id(); if have_all_parts { if self.encoded_chunks.mark_chunk_for_inclusion(&chunk_hash) { @@ -1863,11 +1876,14 @@ impl ShardsManagerActor { let shard_id = partial_encoded_chunk.header.shard_id(); let mut accounts_forwarded_to = HashSet::new(); accounts_forwarded_to.insert(me.clone()); - let next_chunk_producer = self.epoch_manager.get_chunk_producer( - &epoch_id, - current_chunk_height + 1, - shard_id, - )?; + let next_chunk_producer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *epoch_id, + height_created: current_chunk_height + 1, + shard_id, + })? + .take_account_id(); for (bp, _) in block_producers { let bp_account_id = bp.take_account_id(); @@ -1907,11 +1923,13 @@ impl ShardsManagerActor { .shard_ids(&epoch_id)? .into_iter() .map(|shard_id| { - self.epoch_manager.get_chunk_producer( - &epoch_id, - current_chunk_height + 1, - shard_id, - ) + self.epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *epoch_id, + height_created: current_chunk_height + 1, + shard_id, + }) + .map(|info| info.take_account_id()) }) .collect::, _>>()?; next_chunk_producers.remove(me); diff --git a/chain/chunks/src/test_utils.rs b/chain/chunks/src/test_utils.rs index cead2000ab8..bb2e70ab44f 100644 --- a/chain/chunks/src/test_utils.rs +++ b/chain/chunks/src/test_utils.rs @@ -15,6 +15,7 @@ use near_primitives::sharding::{ EncodedShardChunk, PartialEncodedChunk, PartialEncodedChunkPart, PartialEncodedChunkV2, ShardChunkHeader, }; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::test_utils::create_test_signer; use near_primitives::types::MerkleHash; use near_primitives::types::{AccountId, EpochId, ShardId}; @@ -96,8 +97,14 @@ impl ChunkTestFixture { let mock_shard_id: ShardId = ShardId::new(0); let mock_epoch_id = epoch_manager.get_epoch_id_from_prev_block(&mock_ancestor_hash).unwrap(); - let mock_chunk_producer = - epoch_manager.get_chunk_producer(&mock_epoch_id, mock_height, mock_shard_id).unwrap(); + let mock_chunk_producer = epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: mock_epoch_id, + height_created: mock_height, + shard_id: mock_shard_id, + }) + .unwrap() + .take_account_id(); let signer = create_test_signer(mock_chunk_producer.as_str()); let validators: Vec<_> = epoch_manager .get_epoch_block_producers_ordered(&EpochId::default(), &CryptoHash::default()) diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs index b6192dd91c6..4ba21252bca 100644 --- a/chain/client/src/client.rs +++ b/chain/client/src/client.rs @@ -65,6 +65,7 @@ use near_primitives::sharding::{ EncodedShardChunk, PartialEncodedChunk, ShardChunk, ShardChunkHeader, StateSyncInfo, StateSyncInfoV1, }; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::transaction::SignedTransaction; use near_primitives::types::chunk_extra::ChunkExtra; use near_primitives::types::{AccountId, ApprovalStake, BlockHeight, EpochId, NumBlocks, ShardId}; @@ -833,8 +834,15 @@ impl Client { Error::ChunkProducer("Called without block producer info.".to_string()) })?; - let chunk_proposer = - self.epoch_manager.get_chunk_producer(epoch_id, next_height, shard_id).unwrap(); + let chunk_proposer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *epoch_id, + height_created: next_height, + shard_id, + }) + .unwrap() + .take_account_id(); if signer.validator_id() != &chunk_proposer { debug!(target: "client", me = ?signer.as_ref().validator_id(), @@ -1429,11 +1437,14 @@ impl Client { ) -> Result<(), Error> { let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(chunk_header.prev_block_hash())?; - let chunk_producer = self.epoch_manager.get_chunk_producer( - &epoch_id, - chunk_header.height_created(), - chunk_header.shard_id(), - )?; + let chunk_producer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: chunk_header.height_created(), + shard_id: chunk_header.shard_id(), + })? + .take_account_id(); error!( target: "client", ?chunk_producer, @@ -1816,8 +1827,14 @@ impl Client { for shard_id in self.epoch_manager.shard_ids(&epoch_id).unwrap() { let next_height = block.header().height() + 1; let epoch_manager = self.epoch_manager.as_ref(); - let chunk_proposer = - epoch_manager.get_chunk_producer(&epoch_id, next_height, shard_id).unwrap(); + let chunk_proposer = epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: next_height, + shard_id, + }) + .unwrap() + .take_account_id(); if &chunk_proposer != &validator_id { continue; } @@ -2201,18 +2218,27 @@ impl Client { .chain(vec![self.config.tx_routing_height_horizon * 2].into_iter()) { let target_height = head.height + horizon - 1; - let validator = - self.epoch_manager.get_chunk_producer(epoch_id, target_height, shard_id)?; + let validator = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *epoch_id, + height_created: target_height, + shard_id, + })? + .take_account_id(); validators.insert(validator); if let Some(next_epoch_id) = &maybe_next_epoch_id { let next_shard_id = self .epoch_manager .account_id_to_shard_id(tx.transaction.signer_id(), next_epoch_id)?; - let validator = self.epoch_manager.get_chunk_producer( - next_epoch_id, - target_height, - next_shard_id, - )?; + let validator = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *next_epoch_id, + height_created: target_height, + shard_id: next_shard_id, + })? + .take_account_id(); validators.insert(validator); } } @@ -2450,8 +2476,14 @@ impl Client { }; for i in 1..=self.config.tx_routing_height_horizon { - let chunk_producer = - self.epoch_manager.get_chunk_producer(&epoch_id, head.height + i, shard_id)?; + let chunk_producer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: head.height + i, + shard_id, + })? + .take_account_id(); if &chunk_producer == account_id { return Ok(true); } diff --git a/chain/client/src/debug.rs b/chain/client/src/debug.rs index e0cda827edd..7b5be135a5d 100644 --- a/chain/client/src/debug.rs +++ b/chain/client/src/debug.rs @@ -22,6 +22,7 @@ use near_primitives::congestion_info::CongestionControl; use near_primitives::errors::EpochError; use near_primitives::state_sync::get_num_state_parts; use near_primitives::stateless_validation::chunk_endorsement::ChunkEndorsement; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::types::{ AccountId, BlockHeight, NumShards, ShardId, ShardIndex, ValidatorInfoIdentifier, }; @@ -144,8 +145,13 @@ impl BlockProductionTracker { chunk_included: true, }); } else { - let chunk_producer = - epoch_manager.get_chunk_producer(epoch_id, block_height, shard_id)?; + let chunk_producer = epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *epoch_id, + height_created: block_height, + shard_id, + })? + .take_account_id(); chunk_collection_info.push(ChunkCollection { chunk_producer, received_time: None, @@ -511,11 +517,12 @@ impl ClientActorInner { chunk_producer: self .client .epoch_manager - .get_chunk_producer( - block_header.epoch_id(), - block_header.height(), - chunk.shard_id(), - ) + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *block_header.epoch_id(), + height_created: block_header.height(), + shard_id: chunk.shard_id(), + }) + .map(|info| info.take_account_id()) .ok(), gas_used: chunk.prev_gas_used(), processing_time_ms: CryptoHashTimer::get_timer_value( @@ -629,8 +636,12 @@ impl ClientActorInner { let chunk_producer = self .client .epoch_manager - .get_chunk_producer(&epoch_id, height, shard_id) - .map(|f| f.to_string()) + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: height, + shard_id, + }) + .map(|info| info.take_account_id().to_string()) .unwrap_or_default(); if chunk_producer == validator_id { production.chunk_production.insert( diff --git a/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs b/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs index aa5b42d22de..34f9d0278f6 100644 --- a/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs +++ b/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs @@ -374,8 +374,10 @@ impl PartialWitnessActor { ) -> Result<(), Error> { let ChunkProductionKey { shard_id, epoch_id, height_created } = partial_witness.chunk_production_key(); - let chunk_producer = - self.epoch_manager.get_chunk_producer(&epoch_id, height_created, shard_id)?; + let chunk_producer = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { epoch_id, height_created, shard_id })? + .take_account_id(); // Forward witness part to chunk validators except the validator that produced the chunk and witness. let target_chunk_validators = self diff --git a/chain/client/src/test_utils/test_env.rs b/chain/client/src/test_utils/test_env.rs index c7a52b751a8..e5aedf30683 100644 --- a/chain/client/src/test_utils/test_env.rs +++ b/chain/client/src/test_utils/test_env.rs @@ -28,6 +28,7 @@ use near_primitives::errors::InvalidTxError; use near_primitives::hash::CryptoHash; use near_primitives::sharding::{ChunkHash, PartialEncodedChunk}; use near_primitives::stateless_validation::state_witness::ChunkStateWitness; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::test_utils::create_test_signer; use near_primitives::transaction::{Action, FunctionCallAction, SignedTransaction}; use near_primitives::types::{AccountId, Balance, BlockHeight, EpochId, NumSeats, ShardId}; @@ -685,7 +686,14 @@ impl TestEnv { let epoch_id = epoch_manager.get_epoch_id_from_prev_block(parent_hash).unwrap(); let height = head.height + height_offset; - epoch_manager.get_chunk_producer(&epoch_id, height, shard_id).unwrap() + epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: height, + shard_id, + }) + .unwrap() + .take_account_id() } pub fn get_runtime_config(&self, idx: usize, epoch_id: EpochId) -> RuntimeConfig { diff --git a/chain/client/src/view_client_actor.rs b/chain/client/src/view_client_actor.rs index f1eabde9371..0b2a1eff15e 100644 --- a/chain/client/src/view_client_actor.rs +++ b/chain/client/src/view_client_actor.rs @@ -48,6 +48,7 @@ use near_primitives::sharding::ShardChunk; use near_primitives::state_sync::{ ShardStateSyncResponse, ShardStateSyncResponseHeader, ShardStateSyncResponseV3, }; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{ AccountId, BlockHeight, BlockId, BlockReference, EpochReference, Finality, MaybeBlockId, @@ -626,11 +627,12 @@ impl ViewClientActorInner { .map_err(|err| TxStatusError::InternalError(err.to_string()))?; let validator = self .epoch_manager - .get_chunk_producer( - &head.epoch_id, - head.height + self.config.tx_routing_height_horizon - 1, - target_shard_id, - ) + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: head.epoch_id, + height_created: head.height + self.config.tx_routing_height_horizon - 1, + shard_id: target_shard_id, + }) + .map(|info| info.take_account_id()) .map_err(|err| TxStatusError::ChainError(err.into()))?; self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests( @@ -830,7 +832,12 @@ impl Handler for ViewClientActorInner { .into_chain_error()?; let author = self .epoch_manager - .get_chunk_producer(&epoch_id, chunk_inner.height_created(), chunk_inner.shard_id()) + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: chunk_inner.height_created(), + shard_id: chunk_inner.shard_id(), + }) + .map(|info| info.take_account_id()) .into_chain_error()?; Ok(ChunkView::from_author_chunk(author, chunk)) diff --git a/chain/epoch-manager/src/adapter.rs b/chain/epoch-manager/src/adapter.rs index e6f2a09df3c..faa6b962d90 100644 --- a/chain/epoch-manager/src/adapter.rs +++ b/chain/epoch-manager/src/adapter.rs @@ -241,17 +241,6 @@ pub trait EpochManagerAdapter: Send + Sync { key: &ChunkProductionKey, ) -> Result; - /// TODO(pugachag): deprecate this by inlining usage - fn get_chunk_producer( - &self, - epoch_id: &EpochId, - height: BlockHeight, - shard_id: ShardId, - ) -> Result { - let key = ChunkProductionKey { epoch_id: *epoch_id, height_created: height, shard_id }; - self.get_chunk_producer_info(&key).map(|info| info.take_account_id()) - } - /// Gets the chunk validators for a given height and shard. fn get_chunk_validator_assignments( &self, diff --git a/integration-tests/src/tests/client/features/adversarial_behaviors.rs b/integration-tests/src/tests/client/features/adversarial_behaviors.rs index 781e243a7ed..9e40d5c8f77 100644 --- a/integration-tests/src/tests/client/features/adversarial_behaviors.rs +++ b/integration-tests/src/tests/client/features/adversarial_behaviors.rs @@ -16,11 +16,11 @@ use near_network::{ types::{NetworkRequests, PeerManagerMessageRequest}, }; use near_o11y::testonly::init_test_logger; -use near_primitives::utils::from_timestamp; use near_primitives::{ shard_layout::ShardLayout, types::{AccountId, EpochId, ShardId}, }; +use near_primitives::{stateless_validation::ChunkProductionKey, utils::from_timestamp}; use near_primitives_core::{checked_feature, version::PROTOCOL_VERSION}; use nearcore::test_utils::TestEnvNightshadeSetupExt; use tracing::log::debug; @@ -251,12 +251,13 @@ fn test_banning_chunk_producer_when_seeing_invalid_chunk_base( } for shard_id in shard_layout.shard_ids() { let chunk_producer = epoch_manager - .get_chunk_producer( - &epoch_id, - block.header().prev_height().unwrap() + 1, + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: block.header().prev_height().unwrap() + 1, shard_id, - ) - .unwrap(); + }) + .unwrap() + .take_account_id(); if &chunk_producer == &bad_chunk_producer { invalid_chunks_in_this_block.insert(shard_id); if !epochs_seen_invalid_chunk.contains(&epoch_id) { diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 253ad205bd5..23bbf94852a 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -48,6 +48,7 @@ use near_primitives::state_part::PartId; use near_primitives::state_sync::StatePartKey; use near_primitives::stateless_validation::chunk_endorsement::ChunkEndorsement; use near_primitives::stateless_validation::chunk_endorsements_bitmap::ChunkEndorsementsBitmap; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::test_utils::create_test_signer; use near_primitives::test_utils::TestBlockBuilder; use near_primitives::transaction::{ @@ -1242,8 +1243,13 @@ fn test_bad_chunk_mask() { for height in 1..5 { let chunk_producer = env.clients[0] .epoch_manager - .get_chunk_producer(&first_epoch_id, height, shard_id) - .unwrap(); + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *first_epoch_id, + height_created: height, + shard_id, + }) + .unwrap() + .take_account_id(); let block_producer = env.clients[0].epoch_manager.get_block_producer(&first_epoch_id, height).unwrap(); @@ -3050,8 +3056,15 @@ fn produce_chunks(env: &mut TestEnv, epoch_id: &EpochId, height: u64) { let shard_layout = env.clients[0].epoch_manager.get_shard_layout(epoch_id).unwrap(); for shard_id in shard_layout.shard_ids() { - let chunk_producer = - env.clients[0].epoch_manager.get_chunk_producer(epoch_id, height, shard_id).unwrap(); + let chunk_producer = env.clients[0] + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id: *epoch_id, + height_created: height, + shard_id, + }) + .unwrap() + .take_account_id(); let produce_chunk_result = create_chunk_on_height(env.client(&chunk_producer), height); let ProduceChunkResult { chunk, encoded_chunk_parts_paths, receipts, .. } = diff --git a/integration-tests/src/tests/client/resharding_v2.rs b/integration-tests/src/tests/client/resharding_v2.rs index 4966c877d53..81773f6a7bf 100644 --- a/integration-tests/src/tests/client/resharding_v2.rs +++ b/integration-tests/src/tests/client/resharding_v2.rs @@ -13,6 +13,7 @@ use near_primitives::epoch_manager::{AllEpochConfig, AllEpochConfigTestOverrides use near_primitives::hash::CryptoHash; use near_primitives::serialize::to_base64; use near_primitives::shard_layout::account_id_to_shard_uid; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::transaction::{ Action, DeployContractAction, FunctionCallAction, SignedTransaction, }; @@ -506,7 +507,10 @@ fn get_chunk_producer(env: &TestEnv, block: &Block, shard_id: ShardId) -> Accoun let parent_hash = block.header().prev_hash(); let epoch_id = epoch_manager.get_epoch_id_from_prev_block(parent_hash).unwrap(); let height = block.header().height() + 1; - let chunk_producer = epoch_manager.get_chunk_producer(&epoch_id, height, shard_id).unwrap(); + let chunk_producer = epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { epoch_id, height_created: height, shard_id }) + .unwrap() + .take_account_id(); chunk_producer } diff --git a/nearcore/src/entity_debug.rs b/nearcore/src/entity_debug.rs index 3d87d02f388..d46f2152fbd 100644 --- a/nearcore/src/entity_debug.rs +++ b/nearcore/src/entity_debug.rs @@ -26,6 +26,7 @@ use near_primitives::state_sync::StateSyncDumpProgress; use near_primitives::stateless_validation::stored_chunk_state_transition_data::{ StoredChunkStateTransitionData, StoredChunkStateTransitionDataV1, }; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::transaction::{ExecutionOutcomeWithProof, SignedTransaction}; use near_primitives::types::chunk_extra::ChunkExtra; use near_primitives::types::{AccountId, Balance, BlockHeight, StateRoot}; @@ -119,11 +120,14 @@ impl EntityDebugHandlerImpl { .ok_or_else(|| anyhow!("Chunk not found"))?; let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(chunk.prev_block())?; - let author = self.epoch_manager.get_chunk_producer( - &epoch_id, - chunk.height_created(), - chunk.shard_id(), - )?; + let author = self + .epoch_manager + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: chunk.height_created(), + shard_id: chunk.shard_id(), + })? + .take_account_id(); Ok(serialize_entity(&ChunkView::from_author_chunk(author, chunk))) } EntityQuery::ChunkExtraByBlockHashShardUId { block_hash, shard_uid } => { @@ -419,7 +423,12 @@ impl EntityDebugHandlerImpl { .shard_ids() .map(|shard_id| { self.epoch_manager - .get_chunk_producer(&epoch_id, block_height, shard_id) + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: block_height, + shard_id, + }) + .map(|info| info.take_account_id()) .context("Getting chunk producer") }) .collect::, _>>()?; diff --git a/tools/state-viewer/src/commands.rs b/tools/state-viewer/src/commands.rs index 0f729a35726..04c5e66157d 100644 --- a/tools/state-viewer/src/commands.rs +++ b/tools/state-viewer/src/commands.rs @@ -35,6 +35,7 @@ use near_primitives::sharding::{ChunkHash, ShardChunk}; use near_primitives::state::FlatStateValue; use near_primitives::state_record::state_record_to_account_id; use near_primitives::state_record::StateRecord; +use near_primitives::stateless_validation::ChunkProductionKey; use near_primitives::trie_key::col::COLUMNS_WITH_ACCOUNT_ID_IN_KEY; use near_primitives::trie_key::TrieKey; use near_primitives::types::{BlockHeight, EpochId, ShardId}; @@ -630,8 +631,12 @@ pub(crate) fn print_chain( let shard_layout = epoch_manager.get_shard_layout(&epoch_id).unwrap(); for (shard_index, shard_id) in shard_layout.shard_ids().enumerate() { let chunk_producer = epoch_manager - .get_chunk_producer(&epoch_id, header.height(), shard_id) - .map(|account_id| account_id.to_string()) + .get_chunk_producer_info(&ChunkProductionKey { + epoch_id, + height_created: header.height(), + shard_id, + }) + .map(|info| info.account_id().to_string()) .unwrap_or_else(|_| "CP Unknown".to_owned()); if header.chunk_mask()[shard_index] { let chunk_hash = &block.chunks()[shard_index].chunk_hash();