From b3b2a1a8600cb1dc8b5a16d1bdaac5c6efb41cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erce=20Can=20Bekt=C3=BCre?= <47954181+ercecan@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:25:49 +0300 Subject: [PATCH] Full node should also wait for l1 height functionality (#52) --- src/full_node.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/full_node.rs b/src/full_node.rs index abe9f3f..3820a8a 100644 --- a/src/full_node.rs +++ b/src/full_node.rs @@ -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; + +impl FullNode { + pub async fn wait_for_l1_height(&self, height: u64, timeout: Option) -> 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(()) + } +}