From a65d7cf31143dfa1252992e1f68d153826652a96 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Mon, 18 Sep 2023 19:12:02 +0100 Subject: [PATCH] refactor into ifs --- bin/reth/src/node/cl_events.rs | 50 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/bin/reth/src/node/cl_events.rs b/bin/reth/src/node/cl_events.rs index 8d0f108fa593..1cf43682aed0 100644 --- a/bin/reth/src/node/cl_events.rs +++ b/bin/reth/src/node/cl_events.rs @@ -42,38 +42,36 @@ impl Stream for ConsensusLayerHealthEvents { loop { ready!(this.interval.poll_tick(cx)); - return match ( - this.canon_chain.last_exchanged_transition_configuration_timestamp(), - this.canon_chain.last_received_update_timestamp(), - ) { - // Short circuit if we recently had an FCU. - (_, Some(fork_choice)) - if fork_choice.elapsed() <= NO_FORKCHOICE_UPDATE_RECEIVED_PERIOD => - { + if let Some(fork_choice) = this.canon_chain.last_received_update_timestamp() { + if fork_choice.elapsed() <= NO_FORKCHOICE_UPDATE_RECEIVED_PERIOD { + // We had an FCU, and it's recent. CL is healthy. continue + } else { + // We had an FCU, but it's too old. + return Poll::Ready(Some( + ConsensusLayerHealthEvent::HaveNotReceivedUpdatesForAWhile( + fork_choice.elapsed(), + ), + )) } - // Otherwise, continue with health checks based on Transition Configuration exchange - // and Fork Choice update. - (None, None) => Poll::Ready(Some(ConsensusLayerHealthEvent::NeverSeen)), - (Some(_), None) => { - Poll::Ready(Some(ConsensusLayerHealthEvent::NeverReceivedUpdates)) - } - (Some(transition_config), _) - if transition_config.elapsed() > NO_TRANSITION_CONFIG_EXCHANGED_PERIOD => - { - Poll::Ready(Some(ConsensusLayerHealthEvent::HasNotBeenSeenForAWhile( + } + + if let Some(transition_config) = + this.canon_chain.last_exchanged_transition_configuration_timestamp() + { + if transition_config.elapsed() <= NO_TRANSITION_CONFIG_EXCHANGED_PERIOD { + // We never had an FCU, but had a transition config exchange, and it's recent. + return Poll::Ready(Some(ConsensusLayerHealthEvent::NeverReceivedUpdates)) + } else { + // We never had an FCU, but had a transition config exchange, but it's too old. + return Poll::Ready(Some(ConsensusLayerHealthEvent::HasNotBeenSeenForAWhile( transition_config.elapsed(), ))) } - (Some(_), Some(fork_choice)) - if fork_choice.elapsed() > NO_FORKCHOICE_UPDATE_RECEIVED_PERIOD => - { - Poll::Ready(Some(ConsensusLayerHealthEvent::HaveNotReceivedUpdatesForAWhile( - fork_choice.elapsed(), - ))) - } - _ => continue, } + + // We never had both FCU and transition config exchange. + return Poll::Ready(Some(ConsensusLayerHealthEvent::NeverSeen)) } } }