Use cmp and match for epoch_tip in action_schedule
+use crate::blockchain::EpochLeadership;
use crate::{
blockcfg::{
Block, BlockDate, BlockVersion, Contents, HeaderBuilderNew, LeaderOutput, Leadership,
@@ -21,6 +22,7 @@ use jormungandr_lib::{
time::SystemTime,
};
use slog::Logger;
+use std::cmp::Ordering;
use std::{sync::Arc, time::Instant};
use thiserror::Error;
use tokio::time::{delay_until, timeout_at, Instant as TokioInstant};
@@ -536,7 +538,6 @@ impl Module {
}
}
- #[allow(clippy::comparison_chain)]
async fn action_schedule(self) -> Result<Self, LeadershipError> {
let current_slot_position = self.current_slot_position().unwrap();
@@ -548,8 +549,9 @@ impl Module {
"current_slot" => current_slot_position.slot.0,
));
- if epoch_tip < current_slot_position.epoch {
- let (_, leadership, _, _, _, _) = new_epoch_leadership_from(
+ match epoch_tip.cmp(&current_slot_position.epoch) {
+ Ordering::Less => {
+ let EpochLeadership { leadership, .. } = new_epoch_leadership_from(
current_slot_position.epoch.0,
Arc::clone(&self.tip_ref),
false,
@@ -566,7 +568,8 @@ impl Module {
self.action_run_schedule(running_ref, slot_start, nb_slots)
.await
- } else if epoch_tip == current_slot_position.epoch {
+ }
+ Ordering::Equal => {
// check for current epoch
let slot_start = current_slot_position.slot.0 + 1;
let nb_slots = self
@@ -584,7 +587,8 @@ impl Module {
self.action_run_schedule(running_ref, slot_start, nb_slots)
.await
- } else {
+ }
+ Ordering::Greater => {
// The only reason this would happen is if we had accepted a block
// that is set in the future or our system local date time is off
@@ -595,6 +599,7 @@ impl Module {
Ok(self)
}
}
+ }
async fn action_run_schedule(
mut self,
