Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use header_head to determine validators for forwarding transactions #10256

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3776,25 +3776,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<AccountId, Error> {
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<AccountId, Error> {
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],
Expand Down
11 changes: 7 additions & 4 deletions chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2003,24 +2003,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);
}
Expand Down
10 changes: 9 additions & 1 deletion chain/client/src/view_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -526,7 +527,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),
Expand Down
Loading