Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize with L1 Slot Start Time #96

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Node/src/ethereum_l1/slot_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl SlotClock {
self.slots_per_epoch
}

fn duration_to_next_slot(&self) -> Result<Duration, Error> {
pub fn duration_to_next_slot(&self) -> Result<Duration, Error> {
let now = SystemTime::now().duration_since(UNIX_EPOCH)?;
self.duration_to_next_slot_from(now)
}
Expand Down
14 changes: 12 additions & 2 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ use std::{
collections::HashMap,
sync::{atomic::AtomicBool, Arc},
};
use tokio::time::{sleep_until, Duration, Instant};
use tokio::sync::{
mpsc::{Receiver, Sender},
Mutex,

};
use tracing::info;

Expand Down Expand Up @@ -240,9 +242,17 @@ impl Node {
}

async fn preconfirmation_loop(&mut self) {
// TODO syncronize with slot clock
// Synchronize with L1 Slot Start Time
mikhailUshakoff marked this conversation as resolved.
Show resolved Hide resolved
let sleep_duration = Duration::from_secs(self.l2_slot_duration_sec);
mikhailUshakoff marked this conversation as resolved.
Show resolved Hide resolved
let mut duration = self.ethereum_l1.slot_clock.duration_to_next_slot().unwrap();
if duration < sleep_duration {
sleep_until(Instant::now() + duration).await;
mikhailUshakoff marked this conversation as resolved.
Show resolved Hide resolved
duration = self.ethereum_l1.slot_clock.duration_to_next_slot().unwrap();
}
sleep_until(Instant::now() + duration - sleep_duration).await;
mikhailUshakoff marked this conversation as resolved.
Show resolved Hide resolved
// start preconfirmation loop
let mut interval =
tokio::time::interval(std::time::Duration::from_secs(self.l2_slot_duration_sec));
tokio::time::interval(sleep_duration);
loop {
interval.tick().await;

Expand Down
Loading