diff --git a/Cargo.toml b/Cargo.toml index 80f2b3f..31deef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" resolver = "2" [dependencies] +alloy-primitives = { version = "0.8.12", default-features = false, features = ["serde"] } anyhow = { version = "1.0.68", default-features = false, features = ["std"] } async-trait = "0.1.71" bitcoin = { version = "0.32.2", features = ["serde", "rand"] } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 8288054..b80b8f5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.79" +channel = "1.81" components = ["rustfmt", "rust-src", "clippy"] profile = "minimal" diff --git a/src/client.rs b/src/client.rs index 92216bd..0fde01e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,6 @@ use std::time::{Duration, SystemTime}; +use alloy_primitives::U64; use anyhow::{bail, Result}; use jsonrpsee::{ core::client::ClientT, @@ -44,14 +45,16 @@ impl Client { Ok(self .client .request("ledger_getLastScannedL1Height", rpc_params![]) - .await?) + .await + .map(|v: U64| v.try_into().expect("U64 to u64 must succeed"))?) } pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result { Ok(self .client .request("ledger_getHeadSoftConfirmationHeight", rpc_params![]) - .await?) + .await + .map(|v: U64| v.try_into().expect("U64 to u64 must succeed"))?) } pub async fn wait_for_l2_block(&self, num: u64, timeout: Option) -> Result<()> { diff --git a/src/node.rs b/src/node.rs index 1ac1acd..fb2d944 100644 --- a/src/node.rs +++ b/src/node.rs @@ -10,7 +10,7 @@ use std::{ time::{Duration, SystemTime}, }; -use anyhow::{bail, Context}; +use anyhow::{anyhow, bail, Context}; use async_trait::async_trait; use bitcoincore_rpc::{Auth, Client as BitcoinClient}; use serde::Serialize; @@ -203,21 +203,20 @@ where async fn wait_for_ready(&self, timeout: Option) -> Result<()> { let start = Instant::now(); let timeout = timeout.unwrap_or(Duration::from_secs(30)); - while start.elapsed() < timeout { - if self - .client - .ledger_get_head_soft_confirmation_height() - .await - .is_ok() - { - return Ok(()); - } + let mut response = Err(anyhow!("initial response value")); + + while response.is_err() && (start.elapsed() < timeout) { + response = self.client.ledger_get_head_soft_confirmation_height().await; sleep(Duration::from_millis(500)).await; } - anyhow::bail!( - "{} failed to become ready within the specified timeout", - C::node_kind() - ) + match response { + Ok(_) => return Ok(()), + Err(e) => anyhow::bail!( + "{} failed to become ready within the specified timeout, latest ledger_get_head_soft_confirmation_height error: {}", + C::node_kind(), + e + ) + } } fn client(&self) -> &Self::Client {