Skip to content

Commit

Permalink
Refactor synchronization with L1 slot time
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailUshakoff committed Aug 29, 2024
1 parent 83e5416 commit c567dc7
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down

0 comments on commit c567dc7

Please sign in to comment.