From c567dc72a876235d28e672647cd1bfec624db9b5 Mon Sep 17 00:00:00 2001 From: mikhailUshakoff Date: Thu, 29 Aug 2024 14:50:22 +0200 Subject: [PATCH] Refactor synchronization with L1 slot time --- Node/src/node/mod.rs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Node/src/node/mod.rs b/Node/src/node/mod.rs index 60ece01..77af61d 100644 --- a/Node/src/node/mod.rs +++ b/Node/src/node/mod.rs @@ -241,13 +241,11 @@ impl Node { } async fn preconfirmation_loop(&mut self) { - let l2_slot_duration = Duration::from_secs(self.l2_slot_duration_sec); // Synchronize with L1 Slot Start Time - self.synchronize_with_l1_slot_start_time(l2_slot_duration) - .await - .unwrap(); + let duration_to_next_slot = self.ethereum_l1.slot_clock.duration_to_next_slot().unwrap(); + sleep_until(Instant::now() + duration_to_next_slot).await; // start preconfirmation loop - let mut interval = tokio::time::interval(l2_slot_duration); + let mut interval = tokio::time::interval(Duration::from_secs(self.l2_slot_duration_sec)); loop { interval.tick().await; @@ -257,19 +255,6 @@ impl Node { } } - async fn synchronize_with_l1_slot_start_time( - &mut self, - l2_slot_duration: Duration, - ) -> Result<(), Error> { - let mut duration_to_next_slot = self.ethereum_l1.slot_clock.duration_to_next_slot()?; - if duration_to_next_slot < l2_slot_duration { - sleep_until(Instant::now() + duration_to_next_slot).await; - duration_to_next_slot = self.ethereum_l1.slot_clock.duration_to_next_slot()?; - } - sleep_until(Instant::now() + duration_to_next_slot).await; - Ok(()) - } - async fn main_block_preconfirmation_step(&mut self) -> Result<(), Error> { let current_epoch = self.ethereum_l1.slot_clock.get_current_epoch()?; if current_epoch != self.epoch {