diff --git a/chain/chain/src/chain.rs b/chain/chain/src/chain.rs index 01b9e29fc9d..8e78f914c57 100644 --- a/chain/chain/src/chain.rs +++ b/chain/chain/src/chain.rs @@ -3703,25 +3703,6 @@ impl Chain { Ok(FinalExecutionOutcomeWithReceiptView { final_outcome, receipts }) } - /// Find a validator to forward transactions to - pub fn find_chunk_producer_for_forwarding( - &self, - epoch_id: &EpochId, - shard_id: ShardId, - horizon: BlockHeight, - ) -> Result { - let head = self.head()?; - let target_height = head.height + horizon - 1; - Ok(self.epoch_manager.get_chunk_producer(epoch_id, target_height, shard_id)?) - } - - /// Find a validator that is responsible for a given shard to forward requests to - pub fn find_validator_for_forwarding(&self, shard_id: ShardId) -> Result { - let head = self.head()?; - let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(&head.last_block_hash)?; - self.find_chunk_producer_for_forwarding(&epoch_id, shard_id, TX_ROUTING_HEIGHT_HORIZON) - } - pub fn check_blocks_final_and_canonical( &self, block_headers: &[&BlockHeader], diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs index af8f852b03f..ee519a9f479 100644 --- a/chain/client/src/client.rs +++ b/chain/client/src/client.rs @@ -1884,24 +1884,27 @@ impl Client { fn forward_tx(&self, epoch_id: &EpochId, tx: &SignedTransaction) -> Result<(), Error> { let shard_id = self.epoch_manager.account_id_to_shard_id(&tx.transaction.signer_id, epoch_id)?; - let head = self.chain.head()?; + // Use the header head to make sure the list of validators is as + // up-to-date as possible. + let head = self.chain.header_head()?; let maybe_next_epoch_id = self.get_next_epoch_id_if_at_boundary(&head)?; let mut validators = HashSet::new(); for horizon in (2..=TX_ROUTING_HEIGHT_HORIZON).chain(vec![TX_ROUTING_HEIGHT_HORIZON * 2].into_iter()) { + let target_height = head.height + horizon - 1; let validator = - self.chain.find_chunk_producer_for_forwarding(epoch_id, shard_id, horizon)?; + self.epoch_manager.get_chunk_producer(epoch_id, target_height, shard_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.chain.find_chunk_producer_for_forwarding( + let validator = self.epoch_manager.get_chunk_producer( next_epoch_id, + target_height, next_shard_id, - horizon, )?; validators.insert(validator); } diff --git a/chain/client/src/view_client.rs b/chain/client/src/view_client.rs index f549edab51f..c482c53e34e 100644 --- a/chain/client/src/view_client.rs +++ b/chain/client/src/view_client.rs @@ -11,6 +11,7 @@ use crate::{ }; use actix::{Actor, Addr, Handler, SyncArbiter, SyncContext}; use near_async::messaging::CanSend; +use near_chain::chain::TX_ROUTING_HEIGHT_HORIZON; use near_chain::types::{RuntimeAdapter, Tip}; use near_chain::{ get_epoch_block_producers_view, Chain, ChainGenesis, ChainStoreAccess, DoomslugThresholdMode, @@ -475,7 +476,14 @@ impl ViewClientActor { .epoch_manager .account_id_to_shard_id(&signer_account_id, &head.epoch_id) .map_err(|err| TxStatusError::InternalError(err.to_string()))?; - let validator = self.chain.find_validator_for_forwarding(target_shard_id)?; + let validator = self + .epoch_manager + .get_chunk_producer( + &head.epoch_id, + head.height + TX_ROUTING_HEIGHT_HORIZON - 1, + target_shard_id, + ) + .map_err(|err| TxStatusError::ChainError(err.into()))?; self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests( NetworkRequests::TxStatus(validator, signer_account_id, tx_hash),