diff --git a/finality-aleph/src/metrics.rs b/finality-aleph/src/metrics.rs index a5563f91f8..a8af808e44 100644 --- a/finality-aleph/src/metrics.rs +++ b/finality-aleph/src/metrics.rs @@ -32,100 +32,32 @@ struct Inner { prev: HashMap, gauges: HashMap>, starts: HashMap>, - sync_broadcast_counter: Counter, - sync_send_request_counter: Counter, - sync_send_to_counter: Counter, - sync_handle_state_counter: Counter, - sync_handle_request_response_counter: Counter, - sync_handle_request_counter: Counter, - sync_handle_task_counter: Counter, - sync_handle_block_imported_counter: Counter, - sync_handle_block_finalized_counter: Counter, - sync_handle_state_response_counter: Counter, - sync_handle_justification_from_user_counter: Counter, - sync_handle_internal_request_counter: Counter, + sync_broadcast_calls_counter: Counter, + sync_broadcast_errors_counter: Counter, + sync_send_request_calls_counter: Counter, + sync_send_request_errors_counter: Counter, + sync_send_to_calls_counter: Counter, + sync_send_to_errors_counter: Counter, + sync_handle_state_calls_counter: Counter, + sync_handle_state_errors_counter: Counter, + sync_handle_request_response_calls_counter: Counter, + sync_handle_request_calls_counter: Counter, + sync_handle_request_errors_counter: Counter, + sync_handle_task_calls_counter: Counter, + sync_handle_task_errors_counter: Counter, + sync_handle_block_imported_calls_counter: Counter, + sync_handle_block_imported_errors_counter: Counter, + sync_handle_block_finalized_calls_counter: Counter, + sync_handle_state_response_calls_counter: Counter, + sync_handle_justification_from_user_calls_counter: Counter, + sync_handle_justification_from_user_errors_counter: Counter, + sync_handle_internal_request_calls_counter: Counter, + sync_handle_internal_request_errors_counter: Counter, network_send_times: HashMap, } impl Inner { - fn report_block(&mut self, hash: H, checkpoint_time: Instant, checkpoint_type: Checkpoint) { - trace!( - target: LOG_TARGET, - "Reporting block stage: {:?} (hash: {:?}, at: {:?}", - checkpoint_type, - hash, - checkpoint_time - ); - - self.starts.entry(checkpoint_type).and_modify(|starts| { - starts.put(hash, checkpoint_time); - }); - - if let Some(prev_checkpoint_type) = self.prev.get(&checkpoint_type) { - if let Some(start) = self - .starts - .get_mut(prev_checkpoint_type) - .expect("All checkpoint types were initialized") - .get(&hash) - { - let duration = match checkpoint_time.checked_duration_since(*start) { - Some(duration) => duration, - None => { - warn!( - target: LOG_TARGET, - "Earlier metrics time {:?} is later that current one \ - {:?}. Checkpoint type {:?}, block: {:?}", - *start, - checkpoint_time, - checkpoint_type, - hash - ); - Duration::new(0, 0) - } - }; - self.gauges - .get(&checkpoint_type) - .expect("All checkpoint types were initialized") - .set(duration.as_millis() as u64); - } - } - } - - fn start_sending_in(&self, protocol: Protocol) -> HistogramTimer { - self.network_send_times[&protocol].start_timer() - } -} - -fn protocol_name(protocol: Protocol) -> String { - use Protocol::*; - match protocol { - Authentication => "authentication", - BlockSync => "block_sync", - } - .to_string() -} - -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] -pub enum Checkpoint { - Importing, - Imported, - Ordering, - Ordered, - Aggregating, - Finalized, -} - -#[derive(Clone)] -pub struct Metrics { - inner: Option>>>, -} - -impl Metrics { - pub fn noop() -> Metrics { - Metrics { inner: None } - } - - pub fn new(registry: &Registry) -> Result, PrometheusError> { + fn new(registry: &Registry) -> Result { use Checkpoint::*; let keys = [ Importing, @@ -172,7 +104,7 @@ impl Metrics { ); } - let inner = Some(Arc::new(Mutex::new(Inner { + Ok(Self { prev, gauges, starts: keys @@ -184,140 +116,251 @@ impl Metrics { ) }) .collect(), - sync_broadcast_counter: register( - Counter::new("aleph_sync_broadcast", "no help")?, + sync_broadcast_calls_counter: register( + Counter::new("aleph_sync_broadcast_calls", "no help")?, registry, )?, - sync_send_request_counter: register( - Counter::new("aleph_sync_send_request", "no help")?, + sync_broadcast_errors_counter: register( + Counter::new("aleph_sync_broadcast_error", "no help")?, registry, )?, - sync_send_to_counter: register( - Counter::new("aleph_sync_send_to", "no help")?, + sync_send_request_calls_counter: register( + Counter::new("aleph_sync_send_request_calls", "no help")?, registry, )?, - sync_handle_state_counter: register( - Counter::new("aleph_sync_handle_state", "no help")?, + sync_send_request_errors_counter: register( + Counter::new("aleph_sync_send_request_error", "no help")?, registry, )?, - sync_handle_request_response_counter: register( - Counter::new("aleph_sync_handle_request_response", "no help")?, + sync_send_to_calls_counter: register( + Counter::new("aleph_sync_send_to_calls", "no help")?, registry, )?, - sync_handle_request_counter: register( - Counter::new("aleph_sync_handle_request", "no help")?, + sync_send_to_errors_counter: register( + Counter::new("aleph_sync_send_to_errors", "no help")?, registry, )?, - sync_handle_task_counter: register( - Counter::new("aleph_sync_handle_task", "no help")?, + sync_handle_state_calls_counter: register( + Counter::new("aleph_sync_handle_state_calls", "no help")?, registry, )?, - sync_handle_block_imported_counter: register( - Counter::new("aleph_sync_handle_block_imported", "no help")?, + sync_handle_state_errors_counter: register( + Counter::new("aleph_sync_handle_state_error", "no help")?, registry, )?, - sync_handle_block_finalized_counter: register( - Counter::new("aleph_sync_handle_block_finalized", "no help")?, + sync_handle_request_response_calls_counter: register( + Counter::new("aleph_sync_handle_request_response_calls", "no help")?, registry, )?, - sync_handle_justification_from_user_counter: register( - Counter::new("aleph_sync_handle_justification_from_user", "no help")?, + sync_handle_request_calls_counter: register( + Counter::new("aleph_sync_handle_request_calls", "no help")?, registry, )?, - sync_handle_state_response_counter: register( - Counter::new("aleph_sync_handle_state_response", "no help")?, + sync_handle_request_errors_counter: register( + Counter::new("aleph_sync_handle_request_error", "no help")?, registry, )?, - sync_handle_internal_request_counter: register( - Counter::new("aleph_sync_handle_internal_request", "no help")?, + sync_handle_task_calls_counter: register( + Counter::new("aleph_sync_handle_task_calls", "no help")?, + registry, + )?, + sync_handle_task_errors_counter: register( + Counter::new("aleph_sync_handle_task_error", "no help")?, + registry, + )?, + sync_handle_block_imported_calls_counter: register( + Counter::new("aleph_sync_handle_block_imported_calls", "no help")?, + registry, + )?, + sync_handle_block_imported_errors_counter: register( + Counter::new("aleph_sync_handle_block_imported_error", "no help")?, + registry, + )?, + sync_handle_block_finalized_calls_counter: register( + Counter::new("aleph_sync_handle_block_finalized_calls", "no help")?, + registry, + )?, + sync_handle_justification_from_user_calls_counter: register( + Counter::new("aleph_sync_handle_justification_from_user_calls", "no help")?, + registry, + )?, + sync_handle_justification_from_user_errors_counter: register( + Counter::new("aleph_sync_handle_justification_from_user_error", "no help")?, + registry, + )?, + sync_handle_state_response_calls_counter: register( + Counter::new("aleph_sync_handle_state_response_calls", "no help")?, + registry, + )?, + sync_handle_internal_request_calls_counter: register( + Counter::new("aleph_sync_handle_internal_request_calls", "no help")?, + registry, + )?, + sync_handle_internal_request_errors_counter: register( + Counter::new("aleph_sync_handle_internal_request_error", "no help")?, registry, )?, network_send_times, - }))); - - Ok(Metrics { inner }) + }) } - pub fn report_block(&self, hash: H, checkpoint_time: Instant, checkpoint_type: Checkpoint) { - if let Some(inner) = &self.inner { - inner - .lock() - .report_block(hash, checkpoint_time, checkpoint_type); - } - } + fn report_block(&mut self, hash: H, checkpoint_time: Instant, checkpoint_type: Checkpoint) { + trace!( + target: LOG_TARGET, + "Reporting block stage: {:?} (hash: {:?}, at: {:?}", + checkpoint_type, + hash, + checkpoint_time + ); - pub fn report_sync_broadcast(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_broadcast_counter.inc(); - } - } + self.starts.entry(checkpoint_type).and_modify(|starts| { + starts.put(hash, checkpoint_time); + }); - pub fn report_sync_send_request(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_send_request_counter.inc(); + if let Some(prev_checkpoint_type) = self.prev.get(&checkpoint_type) { + if let Some(start) = self + .starts + .get_mut(prev_checkpoint_type) + .expect("All checkpoint types were initialized") + .get(&hash) + { + let duration = match checkpoint_time.checked_duration_since(*start) { + Some(duration) => duration, + None => { + warn!( + target: LOG_TARGET, + "Earlier metrics time {:?} is later that current one \ + {:?}. Checkpoint type {:?}, block: {:?}", + *start, + checkpoint_time, + checkpoint_type, + hash + ); + Duration::new(0, 0) + } + }; + self.gauges + .get(&checkpoint_type) + .expect("All checkpoint types were initialized") + .set(duration.as_millis() as u64); + } } } - pub fn report_sync_send_to(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_send_to_counter.inc(); - } + fn start_sending_in(&self, protocol: Protocol) -> HistogramTimer { + self.network_send_times[&protocol].start_timer() } +} - pub fn report_sync_handle_state(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_state_counter.inc(); - } +fn protocol_name(protocol: Protocol) -> String { + use Protocol::*; + match protocol { + Authentication => "authentication", + BlockSync => "block_sync", } + .to_string() +} - pub fn report_sync_handle_request_response(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_request_response_counter.inc(); - } - } +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] +pub enum Checkpoint { + Importing, + Imported, + Ordering, + Ordered, + Aggregating, + Finalized, +} - pub fn report_sync_handle_request(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_request_counter.inc(); - } - } +pub enum SyncEvent { + Broadcast, + SendRequest, + SendTo, + HandleState, + HandleRequestResponse, + HandleRequest, + HandleTask, + HandleBlockImported, + HandleBlockFinalized, + HandleStateResponse, + HandleJustificationFromUserCalls, + HandleInternalRequest, +} - pub fn report_sync_handle_task(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_task_counter.inc(); - } - } +#[derive(Clone)] +pub struct Metrics { + inner: Option>>>, +} - pub fn report_sync_handle_block_imported(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_block_imported_counter.inc(); - } +impl Metrics { + pub fn noop() -> Self { + Self { inner: None } } - pub fn report_sync_handle_block_finalized(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_block_finalized_counter.inc(); - } + pub fn new(registry: &Registry) -> Result { + let inner = Some(Arc::new(Mutex::new(Inner::new(registry)?))); + + Ok(Self { inner }) } - pub fn report_sync_handle_justification_from_user(&self) { - if let Some(inner) = &self.inner { - inner - .lock() - .sync_handle_justification_from_user_counter - .inc(); + pub fn report_event(&self, event: SyncEvent) { + let inner = match &self.inner { + Some(inner) => inner.lock(), + None => return, + }; + + match event { + SyncEvent::Broadcast => inner.sync_broadcast_calls_counter.inc(), + SyncEvent::SendRequest => inner.sync_send_request_calls_counter.inc(), + SyncEvent::SendTo => inner.sync_send_to_calls_counter.inc(), + SyncEvent::HandleState => inner.sync_handle_state_calls_counter.inc(), + SyncEvent::HandleRequestResponse => { + inner.sync_handle_request_response_calls_counter.inc() + } + SyncEvent::HandleRequest => inner.sync_handle_request_calls_counter.inc(), + SyncEvent::HandleTask => inner.sync_handle_task_calls_counter.inc(), + SyncEvent::HandleBlockImported => inner.sync_handle_block_imported_calls_counter.inc(), + SyncEvent::HandleBlockFinalized => { + inner.sync_handle_block_finalized_calls_counter.inc() + } + SyncEvent::HandleStateResponse => inner.sync_handle_state_response_calls_counter.inc(), + SyncEvent::HandleJustificationFromUserCalls => inner + .sync_handle_justification_from_user_calls_counter + .inc(), + SyncEvent::HandleInternalRequest => { + inner.sync_handle_internal_request_calls_counter.inc() + } } } - pub fn report_sync_handle_state_response(&self) { - if let Some(inner) = &self.inner { - inner.lock().sync_handle_state_response_counter.inc(); + pub fn report_event_error(&self, event: SyncEvent) { + let inner = match &self.inner { + Some(inner) => inner.lock(), + None => return, + }; + + match event { + SyncEvent::Broadcast => inner.sync_broadcast_errors_counter.inc(), + SyncEvent::SendRequest => inner.sync_send_request_errors_counter.inc(), + SyncEvent::SendTo => inner.sync_send_to_errors_counter.inc(), + SyncEvent::HandleState => inner.sync_handle_state_errors_counter.inc(), + SyncEvent::HandleRequest => inner.sync_handle_request_errors_counter.inc(), + SyncEvent::HandleTask => inner.sync_handle_task_errors_counter.inc(), + SyncEvent::HandleBlockImported => inner.sync_handle_block_imported_errors_counter.inc(), + SyncEvent::HandleJustificationFromUserCalls => inner + .sync_handle_justification_from_user_errors_counter + .inc(), + SyncEvent::HandleInternalRequest => { + inner.sync_handle_internal_request_errors_counter.inc() + } + _ => {} // events that have not defined error events } } - pub fn report_sync_handle_internal_request(&self) { + pub fn report_block(&self, hash: H, checkpoint_time: Instant, checkpoint_type: Checkpoint) { if let Some(inner) = &self.inner { - inner.lock().sync_handle_internal_request_counter.inc(); + inner + .lock() + .report_block(hash, checkpoint_time, checkpoint_type); } } diff --git a/finality-aleph/src/sync/service.rs b/finality-aleph/src/sync/service.rs index 9e2d4bd289..1e0f549428 100644 --- a/finality-aleph/src/sync/service.rs +++ b/finality-aleph/src/sync/service.rs @@ -6,7 +6,7 @@ use log::{debug, error, trace, warn}; pub use crate::sync::handler::DatabaseIO; use crate::{ - metrics::Key, + metrics::{Key, SyncEvent}, network::GossipNetwork, session::SessionBoundaryInfo, sync::{ @@ -141,9 +141,11 @@ where } fn broadcast(&mut self) { + self.metrics.report_event(SyncEvent::Broadcast); let state = match self.handler.state() { Ok(state) => state, Err(e) => { + self.metrics.report_event_error(SyncEvent::Broadcast); warn!( target: LOG_TARGET, "Failed to construct own knowledge state: {}.", e @@ -154,16 +156,18 @@ where trace!(target: LOG_TARGET, "Broadcasting state: {:?}", state); let data = NetworkData::StateBroadcast(state); - match self.network.broadcast(data) { - Ok(()) => self.metrics.report_sync_broadcast(), - Err(e) => warn!(target: LOG_TARGET, "Error sending broadcast: {}.", e), + if let Err(e) = self.network.broadcast(data) { + self.metrics.report_event_error(SyncEvent::Broadcast); + warn!(target: LOG_TARGET, "Error sending broadcast: {}.", e) } } fn send_request(&mut self, pre_request: PreRequest) { + self.metrics.report_event(SyncEvent::SendRequest); let state = match self.handler.state() { Ok(state) => state, Err(e) => { + self.metrics.report_event_error(SyncEvent::SendRequest); warn!( target: LOG_TARGET, "Failed to construct own knowledge state: {}.", e @@ -175,26 +179,28 @@ where trace!(target: LOG_TARGET, "Sending a request: {:?}", request); let data = NetworkData::Request(request); - match self.network.send_to_random(data, peers) { - Ok(()) => self.metrics.report_sync_send_request(), - Err(e) => warn!(target: LOG_TARGET, "Error sending request: {}.", e), + if let Err(e) = self.network.send_to_random(data, peers) { + self.metrics.report_event_error(SyncEvent::SendRequest); + warn!(target: LOG_TARGET, "Error sending request: {}.", e); } } fn send_to(&mut self, data: NetworkData, peer: N::PeerId) { + self.metrics.report_event(SyncEvent::SendTo); trace!( target: LOG_TARGET, "Sending data {:?} to peer {:?}", data, peer ); - match self.network.send_to(data, peer) { - Ok(()) => self.metrics.report_sync_send_to(), - Err(e) => warn!(target: LOG_TARGET, "Error sending response: {}.", e), + if let Err(e) = self.network.send_to(data, peer) { + self.metrics.report_event_error(SyncEvent::SendTo); + warn!(target: LOG_TARGET, "Error sending response: {}.", e); } } fn handle_state(&mut self, state: State, peer: N::PeerId) { + self.metrics.report_event(SyncEvent::HandleState); use HandleStateAction::*; trace!( target: LOG_TARGET, @@ -203,24 +209,24 @@ where peer ); match self.handler.handle_state(state, peer.clone()) { - Ok(action) => { - self.metrics.report_sync_handle_state(); - match action { - Response(data) => self.send_to(data, peer), - HighestJustified(block_id) => self.request_highest_justified(block_id), - Noop => (), + Ok(action) => match action { + Response(data) => self.send_to(data, peer), + HighestJustified(block_id) => self.request_highest_justified(block_id), + Noop => (), + }, + Err(e) => { + self.metrics.report_event_error(SyncEvent::HandleState); + match e { + HandlerError::Verifier(e) => debug!( + target: LOG_TARGET, + "Could not verify justification in sync state from {:?}: {}.", peer, e + ), + e => warn!( + target: LOG_TARGET, + "Failed to handle sync state from {:?}: {}.", peer, e + ), } } - Err(e) => match e { - HandlerError::Verifier(e) => debug!( - target: LOG_TARGET, - "Could not verify justification in sync state from {:?}: {}.", peer, e - ), - e => warn!( - target: LOG_TARGET, - "Failed to handle sync state from {:?}: {}.", peer, e - ), - }, } } @@ -237,21 +243,20 @@ where maybe_justification, peer ); - self.metrics.report_sync_handle_state_response(); + self.metrics.report_event(SyncEvent::HandleStateResponse); let (maybe_id, maybe_error) = self.handler .handle_state_response(justification, maybe_justification, peer.clone()); - if let Some(e) = maybe_error { - match e { - HandlerError::Verifier(e) => debug!( - target: LOG_TARGET, - "Could not verify justification in sync state from {:?}: {}.", peer, e - ), - e => warn!( - target: LOG_TARGET, - "Failed to handle sync state response from {:?}: {}.", peer, e - ), - } + match maybe_error { + Some(HandlerError::Verifier(e)) => debug!( + target: LOG_TARGET, + "Could not verify justification in sync state from {:?}: {}.", peer, e + ), + Some(e) => warn!( + target: LOG_TARGET, + "Failed to handle sync state response from {:?}: {}.", peer, e + ), + _ => {} } if let Some(id) = maybe_id { self.request_highest_justified(id); @@ -264,23 +269,25 @@ where "Handling a justification {:?} from user.", justification, ); + self.metrics + .report_event(SyncEvent::HandleJustificationFromUserCalls); match self.handler.handle_justification_from_user(justification) { - Ok(maybe_id) => { - self.metrics.report_sync_handle_justification_from_user(); - if let Some(id) = maybe_id { - self.request_highest_justified(id) + Ok(Some(id)) => self.request_highest_justified(id), + Ok(_) => {} + Err(e) => { + self.metrics + .report_event_error(SyncEvent::HandleJustificationFromUserCalls); + match e { + HandlerError::Verifier(e) => debug!( + target: LOG_TARGET, + "Could not verify justification from user: {}", e + ), + e => warn!( + target: LOG_TARGET, + "Failed to handle justification from user: {}", e + ), } } - Err(e) => match e { - HandlerError::Verifier(e) => debug!( - target: LOG_TARGET, - "Could not verify justification from user: {}", e - ), - e => warn!( - target: LOG_TARGET, - "Failed to handle justification from user: {}", e - ), - }, } } @@ -291,21 +298,20 @@ where peer, response_items, ); - self.metrics.report_sync_handle_request_response(); + self.metrics.report_event(SyncEvent::HandleRequestResponse); let (maybe_id, maybe_error) = self .handler .handle_request_response(response_items, peer.clone()); - if let Some(e) = maybe_error { - match e { - HandlerError::Verifier(e) => debug!( - target: LOG_TARGET, - "Could not verify justification from user: {}", e - ), - e => warn!( - target: LOG_TARGET, - "Failed to handle sync request response from {:?}: {}.", peer, e - ), - }; + match maybe_error { + Some(HandlerError::Verifier(e)) => debug!( + target: LOG_TARGET, + "Could not verify justification from user: {}", e + ), + Some(e) => warn!( + target: LOG_TARGET, + "Failed to handle sync request response from {:?}: {}.", peer, e + ), + _ => {} } if let Some(id) = maybe_id { self.request_highest_justified(id); @@ -319,7 +325,7 @@ where request, peer ); - self.metrics.report_sync_handle_request(); + self.metrics.report_event(SyncEvent::HandleRequest); match self.handler.handle_request(request) { Ok(Action::Response(response_items)) => { @@ -327,7 +333,7 @@ where loop { match limiter.next_largest_msg() { Ok(None) => { - break self.metrics.report_sync_handle_request(); + break; } Ok(Some(chunk)) => { self.send_to(NetworkData::RequestResponse(chunk.to_vec()), peer.clone()) @@ -337,25 +343,25 @@ where target: LOG_TARGET, "Error while sending request response: {}.", e ); - break; + break self.metrics.report_event_error(SyncEvent::HandleRequest); } } } } - Ok(Action::RequestBlock(id)) => { - self.metrics.report_sync_handle_request(); - self.request_block(id) + Ok(Action::RequestBlock(id)) => self.request_block(id), + Err(e) => { + self.metrics.report_event_error(SyncEvent::HandleRequest); + match e { + HandlerError::Verifier(e) => debug!( + target: LOG_TARGET, + "Could not verify justification from user: {}", e + ), + e => warn!( + target: LOG_TARGET, + "Error handling request from {:?}: {}.", peer, e + ), + } } - Err(e) => match e { - HandlerError::Verifier(e) => debug!( - target: LOG_TARGET, - "Could not verify justification from user: {}", e - ), - e => warn!( - target: LOG_TARGET, - "Error handling request from {:?}: {}.", peer, e - ), - }, _ => {} } } @@ -368,7 +374,7 @@ where self.send_request(pre_request); self.tasks.schedule_in(task, delay); } - self.metrics.report_sync_handle_task(); + self.metrics.report_event(SyncEvent::HandleTask); } fn handle_chain_event(&mut self, event: ChainStatusNotification) { @@ -376,17 +382,19 @@ where match event { BlockImported(header) => { trace!(target: LOG_TARGET, "Handling a new imported block."); - match self.handler.block_imported(header) { - Ok(()) => self.metrics.report_sync_handle_block_imported(), - Err(e) => error!( + self.metrics.report_event(SyncEvent::HandleBlockImported); + if let Err(e) = self.handler.block_imported(header) { + self.metrics + .report_event_error(SyncEvent::HandleBlockImported); + error!( target: LOG_TARGET, "Error marking block as imported: {}.", e - ), + ) } } BlockFinalized(_) => { trace!(target: LOG_TARGET, "Handling a new finalized block."); - self.metrics.report_sync_handle_block_finalized(); + self.metrics.report_event(SyncEvent::HandleBlockFinalized); if self.broadcast_ticker.try_tick() { self.broadcast(); } @@ -400,25 +408,25 @@ where "Handling an internal request for block {:?}.", id, ); + self.metrics.report_event(SyncEvent::HandleInternalRequest); match self.handler.handle_internal_request(&id) { - Ok(true) => { - self.metrics.report_sync_handle_internal_request(); - self.request_block(id); - } - Ok(_) => { - self.metrics.report_sync_handle_internal_request(); - debug!(target: LOG_TARGET, "Already requested block {:?}.", id); + Ok(true) => self.request_block(id), + + Ok(_) => debug!(target: LOG_TARGET, "Already requested block {:?}.", id), + + Err(e) => { + self.metrics.report_event(SyncEvent::HandleInternalRequest); + match e { + HandlerError::Verifier(e) => debug!( + target: LOG_TARGET, + "Could not verify justification from user: {}", e + ), + e => warn!( + target: LOG_TARGET, + "Error handling internal request for block {:?}: {}.", id, e + ), + } } - Err(e) => match e { - HandlerError::Verifier(e) => debug!( - target: LOG_TARGET, - "Could not verify justification from user: {}", e - ), - e => warn!( - target: LOG_TARGET, - "Error handling internal request for block {:?}: {}.", id, e - ), - }, } }