-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full node should also wait for l1 height functionality
- Loading branch information
Showing
1 changed file
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |