Skip to content

Commit

Permalink
Ledger rpc type changes (#72)
Browse files Browse the repository at this point in the history
* ledger rpc U64 change

* return context in wait for ready

* lint

* use rustc 1.81
  • Loading branch information
exeokan authored Jan 29, 2025
1 parent e6140b2 commit 928f681
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.79"
channel = "1.81"
components = ["rustfmt", "rust-src", "clippy"]
profile = "minimal"
7 changes: 5 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::{Duration, SystemTime};

use alloy_primitives::U64;
use anyhow::{bail, Result};
use jsonrpsee::{
core::client::ClientT,
Expand Down Expand Up @@ -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<u64> {
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<Duration>) -> Result<()> {
Expand Down
27 changes: 13 additions & 14 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -203,21 +203,20 @@ where
async fn wait_for_ready(&self, timeout: Option<Duration>) -> 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 {
Expand Down

0 comments on commit 928f681

Please sign in to comment.