Skip to content

Commit

Permalink
refactor into ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Sep 18, 2023
1 parent 108166c commit a65d7cf
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions bin/reth/src/node/cl_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit a65d7cf

Please sign in to comment.