Skip to content

Commit

Permalink
Full node should also wait for l1 height functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ercecan committed Nov 19, 2024
1 parent 582d086 commit 62580cd
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/full_node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
use super::config::FullFullNodeConfig;
use std::time::SystemTime;

use anyhow::bail;
use tokio::time::{sleep, Duration};
use tracing::trace;

use super::{config::FullFullNodeConfig, Result};
use crate::node::Node;

pub type FullNode = Node<FullFullNodeConfig>;

impl FullNode {
pub async fn wait_for_l1_height(&self, height: u64, timeout: Option<Duration>) -> Result<()> {
let start = SystemTime::now();
let timeout = timeout.unwrap_or(Duration::from_secs(600));
loop {
trace!("Waiting for batch prover height {}", height);
let latest_block = self.client.ledger_get_last_scanned_l1_height().await?;

if latest_block >= height {
break;
}

let now = SystemTime::now();
if start + timeout <= now {
bail!("Timeout. Latest batch prover L1 height is {}", latest_block);
}

sleep(Duration::from_secs(1)).await;
}
Ok(())
}
}

0 comments on commit 62580cd

Please sign in to comment.