From a4c4f24b93e2b41ee32e800490a14a5794498955 Mon Sep 17 00:00:00 2001 From: Jan Ciolek Date: Tue, 13 Feb 2024 13:54:45 +0000 Subject: [PATCH] Remove witness retrying logic on missing block Sometimes when we would like to process a ChunkStateWitness the block required to process it isn't available yet, we have to wait for it. https://github.com/near/nearcore/pull/10535 implemented a hacky way to do it by retrying the processing every 500ms until the required block arrives. This PR will implement a proper solution, so let's remove the hacky workaround. --- chain/client/src/adapter.rs | 6 +---- chain/client/src/client_actor.rs | 27 +++---------------- .../stateless_validation/chunk_validator.rs | 13 +++------ 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/chain/client/src/adapter.rs b/chain/client/src/adapter.rs index ad1254c1290..40f1d6eb102 100644 --- a/chain/client/src/adapter.rs +++ b/chain/client/src/adapter.rs @@ -141,7 +141,6 @@ pub enum ProcessTxResponse { pub struct ChunkStateWitnessMessage { pub witness: ChunkStateWitness, pub peer_id: PeerId, - pub attempts_remaining: usize, } #[derive(actix::Message, Debug)] @@ -350,10 +349,7 @@ impl near_network::client::Client for Adapter { async fn chunk_state_witness(&self, witness: ChunkStateWitness, peer_id: PeerId) { match self .client_addr - .send( - ChunkStateWitnessMessage { witness, peer_id, attempts_remaining: 5 } - .with_span_context(), - ) + .send(ChunkStateWitnessMessage { witness, peer_id }.with_span_context()) .await { Ok(()) => {} diff --git a/chain/client/src/client_actor.rs b/chain/client/src/client_actor.rs index 684e60a076e..40503b2dead 100644 --- a/chain/client/src/client_actor.rs +++ b/chain/client/src/client_actor.rs @@ -2006,32 +2006,11 @@ impl Handler> for ClientActor { fn handle( &mut self, msg: WithSpanContext, - ctx: &mut Context, + _ctx: &mut Context, ) -> Self::Result { let (_span, msg) = handler_debug_span!(target: "client", msg); - let peer_id = msg.peer_id.clone(); - let attempts_remaining = msg.attempts_remaining; - match self.client.process_chunk_state_witness(msg.witness, msg.peer_id, None) { - Err(err) => { - tracing::error!(target: "client", ?err, "Error processing chunk state witness"); - } - Ok(Some(witness)) => { - if attempts_remaining > 0 { - ctx.run_later(Duration::from_millis(100), move |_, ctx| { - ctx.address().do_send( - ChunkStateWitnessMessage { - witness, - peer_id, - attempts_remaining: attempts_remaining - 1, - } - .with_span_context(), - ); - }); - } else { - tracing::error!(target: "client", "Failed to process chunk state witness even after 5 tries due to missing parent block"); - } - } - Ok(None) => {} + if let Err(err) = self.client.process_chunk_state_witness(msg.witness, msg.peer_id, None) { + tracing::error!(target: "client", ?err, "Error processing chunk state witness"); } } } diff --git a/chain/client/src/stateless_validation/chunk_validator.rs b/chain/client/src/stateless_validation/chunk_validator.rs index 46b184558f0..21e6ffb2351 100644 --- a/chain/client/src/stateless_validation/chunk_validator.rs +++ b/chain/client/src/stateless_validation/chunk_validator.rs @@ -588,18 +588,13 @@ impl Client { witness: ChunkStateWitness, peer_id: PeerId, processing_done_tracker: Option, - ) -> Result, Error> { + ) -> Result<(), Error> { // TODO(#10502): Handle production of state witness for first chunk after genesis. // Properly handle case for chunk right after genesis. // Context: We are currently unable to handle production of the state witness for the // first chunk after genesis as it's not possible to run the genesis chunk in runtime. let prev_block_hash = witness.inner.chunk_header.prev_block_hash(); - let prev_block = match self.chain.get_block(prev_block_hash) { - Ok(block) => block, - Err(_) => { - return Ok(Some(witness)); - } - }; + let prev_block = self.chain.get_block(prev_block_hash)?; let prev_chunk_header = Chain::get_prev_chunk_header( self.epoch_manager.as_ref(), &prev_block, @@ -616,7 +611,7 @@ impl Client { &self.chunk_validator.network_sender, self.chunk_endorsement_tracker.as_ref(), ); - return Ok(None); + return Ok(()); } // TODO(#10265): If the previous block does not exist, we should @@ -635,6 +630,6 @@ impl Client { }, )); } - result.map(|_| None) + result } }