Skip to content

Commit 0f01fdb

Browse files
committed
Add client missing RPC methods
1 parent d09ca9e commit 0f01fdb

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

src/bitcoin.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ use std::{
88
use anyhow::{bail, Context};
99
use async_trait::async_trait;
1010
use bitcoin::Address;
11-
use bitcoin_da::{
12-
service::{get_relevant_blobs_from_txs, FINALITY_DEPTH},
13-
spec::blob::BlobWithSender,
14-
};
11+
use bitcoin_da::service::FINALITY_DEPTH;
1512
use bitcoincore_rpc::{json::AddressType::Bech32m, Auth, Client, RpcApi};
16-
use citrea_primitives::REVEAL_BATCH_PROOF_PREFIX;
1713
use futures::TryStreamExt;
1814
use tokio::{process::Command, sync::OnceCell, time::sleep};
1915

@@ -102,16 +98,6 @@ impl BitcoinNode {
10298
Ok(self.get_block_count().await? - FINALITY_DEPTH + 1)
10399
}
104100

105-
pub async fn get_relevant_blobs_from_block(&self, height: u64) -> Result<Vec<BlobWithSender>> {
106-
let hash = self.get_block_hash(height).await?;
107-
let block = self.get_block(&hash).await?;
108-
109-
Ok(get_relevant_blobs_from_txs(
110-
block.txdata,
111-
REVEAL_BATCH_PROOF_PREFIX,
112-
))
113-
}
114-
115101
async fn wait_for_shutdown(&self) -> Result<()> {
116102
let timeout_duration = Duration::from_secs(30);
117103
let start = std::time::Instant::now();

src/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ impl Client {
7979
Ok(self.client.get_soft_confirmation_by_number(num).await?)
8080
}
8181

82+
pub async fn ledger_get_sequencer_commitments_on_slot_by_hash(
83+
&self,
84+
hash: [u8; 32],
85+
) -> Result<Option<Vec<SequencerCommitmentResponse>>> {
86+
self.client
87+
.get_sequencer_commitments_on_slot_by_hash(hash)
88+
.await
89+
.map_err(|e| e.into())
90+
}
91+
8292
pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result<u64> {
8393
Ok(self.client.get_head_soft_confirmation_height().await?)
8494
}

src/node.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
use std::{fmt, fs::File, path::PathBuf, process::Stdio, time::Duration};
1+
use std::{
2+
fmt,
3+
fs::File,
4+
path::PathBuf,
5+
process::Stdio,
6+
time::{Duration, SystemTime},
7+
};
28

3-
use anyhow::Context;
9+
use anyhow::{bail, Context};
410
use async_trait::async_trait;
11+
use log::debug;
512
use serde::Serialize;
613
use tokio::{
714
process::Command,
@@ -116,6 +123,30 @@ impl<C: Config> Node<C> {
116123
.context(format!("Failed to spawn {} process", kind))
117124
.map(SpawnOutput::Child)
118125
}
126+
127+
pub async fn wait_for_l2_height(&self, num: u64, timeout: Option<Duration>) -> Result<()> {
128+
let start = SystemTime::now();
129+
let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout
130+
loop {
131+
debug!("Waiting for soft confirmation {}", num);
132+
let latest_block = self
133+
.client
134+
.ledger_get_head_soft_confirmation_height()
135+
.await?;
136+
137+
if latest_block >= num {
138+
break;
139+
}
140+
141+
let now = SystemTime::now();
142+
if start + timeout <= now {
143+
bail!("Timeout. Latest L2 block is {:?}", latest_block);
144+
}
145+
146+
sleep(Duration::from_secs(1)).await;
147+
}
148+
Ok(())
149+
}
119150
}
120151

121152
#[async_trait]

0 commit comments

Comments
 (0)