Skip to content

Commit 5dde565

Browse files
committed
Merge branch 'main' into ceyhun/bridge_backend_support
2 parents 31dc639 + 44a8ecf commit 5dde565

File tree

6 files changed

+69
-44
lines changed

6 files changed

+69
-44
lines changed

src/bitcoin.rs

Lines changed: 4 additions & 18 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();
@@ -300,9 +286,9 @@ impl BitcoinNodeCluster {
300286
let mut cluster = Self {
301287
inner: Vec::with_capacity(n_nodes),
302288
};
303-
for config in ctx.config.bitcoin.iter() {
289+
for config in &ctx.config.bitcoin {
304290
let node = BitcoinNode::new(config, Arc::clone(&ctx.docker)).await?;
305-
cluster.inner.push(node)
291+
cluster.inner.push(node);
306292
}
307293

308294
Ok(cluster)
@@ -341,7 +327,7 @@ impl BitcoinNodeCluster {
341327
if i != j {
342328
let ip = match &to_node.spawn_output {
343329
SpawnOutput::Container(container) => container.ip.clone(),
344-
_ => "127.0.0.1".to_string(),
330+
SpawnOutput::Child(_) => "127.0.0.1".to_string(),
345331
};
346332

347333
let add_node_arg = format!("{}:{}", ip, to_node.config.p2p_port);

src/client.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Client {
1919

2020
impl Client {
2121
pub fn new(host: &str, port: u16) -> Result<Self> {
22-
let host = format!("http://{}:{}", host, port);
22+
let host = format!("http://{host}:{port}");
2323
let client = HttpClientBuilder::default()
2424
.request_timeout(Duration::from_secs(120))
2525
.build(host)?;
@@ -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/docker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl DockerEnv {
7474
}
7575

7676
async fn create_network(docker: &Docker, test_case_id: &str) -> Result<(String, String)> {
77-
let network_name = format!("test_network_{}", test_case_id);
77+
let network_name = format!("test_network_{test_case_id}");
7878
let options = CreateNetworkOptions {
7979
name: network_name.clone(),
8080
check_duplicate: true,
@@ -95,15 +95,15 @@ impl DockerEnv {
9595
let exposed_ports: HashMap<String, HashMap<(), ()>> = config
9696
.ports
9797
.iter()
98-
.map(|port| (format!("{}/tcp", port), HashMap::new()))
98+
.map(|port| (format!("{port}/tcp"), HashMap::new()))
9999
.collect();
100100

101101
let port_bindings: HashMap<String, Option<Vec<PortBinding>>> = config
102102
.ports
103103
.iter()
104104
.map(|port| {
105105
(
106-
format!("{}/tcp", port),
106+
format!("{port}/tcp"),
107107
Some(vec![PortBinding {
108108
host_ip: Some("0.0.0.0".to_string()),
109109
host_port: Some(port.to_string()),
@@ -196,7 +196,7 @@ impl DockerEnv {
196196
return Ok(());
197197
}
198198

199-
println!("Pulling image: {}", image);
199+
println!("Pulling image: {image}");
200200
let options = Some(CreateImageOptions {
201201
from_image: image,
202202
..Default::default()
@@ -207,7 +207,7 @@ impl DockerEnv {
207207
match result {
208208
Ok(info) => {
209209
if let (Some(status), Some(progress)) = (info.status, info.progress) {
210-
print!("\r{}: {} ", status, progress);
210+
print!("\r{status}: {progress} ");
211211
stdout().flush().unwrap();
212212
}
213213
}

src/node.rs

Lines changed: 39 additions & 8 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,
@@ -72,12 +79,12 @@ impl<C: Config> Node<C> {
7279
let kind = C::node_kind();
7380

7481
config.node_config().map_or(Ok(Vec::new()), |node_config| {
75-
let config_path = dir.join(format!("{}_config.toml", kind));
82+
let config_path = dir.join(format!("{kind}_config.toml"));
7683
config_to_file(node_config, &config_path)
77-
.with_context(|| format!("Error writing {} config to file", kind))?;
84+
.with_context(|| format!("Error writing {kind} config to file"))?;
7885

7986
Ok(vec![
80-
format!("--{}-config-path", kind),
87+
format!("--{kind}-config-path"),
8188
config_path.display().to_string(),
8289
])
8390
})
@@ -97,7 +104,7 @@ impl<C: Config> Node<C> {
97104
// Handle full node not having any node config
98105
let node_config_args = Self::get_node_config_args(config)?;
99106

100-
let rollup_config_path = dir.join(format!("{}_rollup_config.toml", kind));
107+
let rollup_config_path = dir.join(format!("{kind}_rollup_config.toml"));
101108
config_to_file(&config.rollup_config(), &rollup_config_path)?;
102109

103110
Command::new(citrea)
@@ -115,9 +122,33 @@ impl<C: Config> Node<C> {
115122
.stderr(Stdio::from(stderr_file))
116123
.kill_on_drop(true)
117124
.spawn()
118-
.context(format!("Failed to spawn {} process", kind))
125+
.context(format!("Failed to spawn {kind} process"))
119126
.map(SpawnOutput::Child)
120127
}
128+
129+
pub async fn wait_for_l2_height(&self, num: u64, timeout: Option<Duration>) -> Result<()> {
130+
let start = SystemTime::now();
131+
let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout
132+
loop {
133+
debug!("Waiting for soft confirmation {}", num);
134+
let latest_block = self
135+
.client
136+
.ledger_get_head_soft_confirmation_height()
137+
.await?;
138+
139+
if latest_block >= num {
140+
break;
141+
}
142+
143+
let now = SystemTime::now();
144+
if start + timeout <= now {
145+
bail!("Timeout. Latest L2 block is {:?}", latest_block);
146+
}
147+
148+
sleep(Duration::from_secs(1)).await;
149+
}
150+
Ok(())
151+
}
121152
}
122153

123154
#[async_trait]
@@ -200,7 +231,7 @@ where
200231
async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()> {
201232
let config = self.config_mut();
202233
if let Some(new_config) = new_config {
203-
*config = new_config
234+
*config = new_config;
204235
}
205236
*self.spawn_output() = Self::spawn(config)?;
206237
self.wait_for_ready(None).await

src/test_case.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This module provides the TestCaseRunner and TestCase trait for running and defining test cases.
1+
//! This module provides the `TestCaseRunner` and `TestCase` trait for running and defining test cases.
22
//! It handles setup, execution, and cleanup of test environments.
33
44
use std::{
@@ -37,7 +37,7 @@ use crate::{
3737
pub struct TestCaseRunner<T: TestCase>(T);
3838

3939
impl<T: TestCase> TestCaseRunner<T> {
40-
/// Creates a new TestCaseRunner with the given test case.
40+
/// Creates a new `TestCaseRunner`` with the given test case.
4141
pub fn new(test_case: T) -> Self {
4242
Self(test_case)
4343
}
@@ -86,7 +86,7 @@ impl<T: TestCase> TestCaseRunner<T> {
8686

8787
if let Err(_) | Ok(Err(_)) = result {
8888
if let Err(e) = f.dump_log() {
89-
eprintln!("Error dumping log: {}", e);
89+
eprintln!("Error dumping log: {e}");
9090
}
9191
}
9292

@@ -101,8 +101,7 @@ impl<T: TestCase> TestCaseRunner<T> {
101101
Err(panic_error) => {
102102
let panic_msg = panic_error
103103
.downcast_ref::<String>()
104-
.map(|s| s.to_string())
105-
.unwrap_or_else(|| "Unknown panic".to_string());
104+
.map_or_else(|| "Unknown panic".to_string(), ToString::to_string);
106105
bail!(panic_msg)
107106
}
108107
}
@@ -139,7 +138,7 @@ impl<T: TestCase> TestCaseRunner<T> {
139138
env: env.bitcoin().clone(),
140139
idx: i,
141140
..bitcoin.clone()
142-
})
141+
});
143142
}
144143

145144
let mut bridge_backend_confs = vec![];
@@ -168,7 +167,7 @@ impl<T: TestCase> TestCaseRunner<T> {
168167
..da_config.clone()
169168
},
170169
storage: StorageConfig {
171-
path: dbs_dir.join(format!("{}-db", node_kind)),
170+
path: dbs_dir.join(format!("{node_kind}-db")),
172171
db_max_open_files: None,
173172
},
174173
rpc: RpcConfig {
@@ -203,7 +202,7 @@ impl<T: TestCase> TestCaseRunner<T> {
203202
..da_config.clone()
204203
},
205204
storage: StorageConfig {
206-
path: dbs_dir.join(format!("{}-db", node_kind)),
205+
path: dbs_dir.join(format!("{node_kind}-db")),
207206
db_max_open_files: None,
208207
},
209208
rpc: RpcConfig {
@@ -229,7 +228,7 @@ impl<T: TestCase> TestCaseRunner<T> {
229228
..da_config.clone()
230229
},
231230
storage: StorageConfig {
232-
path: dbs_dir.join(format!("{}-db", node_kind)),
231+
path: dbs_dir.join(format!("{node_kind}-db")),
233232
db_max_open_files: None,
234233
},
235234
rpc: RpcConfig {

src/utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ pub fn get_stderr_path(dir: &Path) -> PathBuf {
4242
/// Get genesis path from resources
4343
/// TODO: assess need for customable genesis path in e2e tests
4444
pub fn get_default_genesis_path() -> PathBuf {
45-
let workspace_root = get_workspace_root();
46-
let mut path = workspace_root.to_path_buf();
45+
let mut path = get_workspace_root();
4746
path.push("resources");
4847
path.push("genesis");
4948
path.push("bitcoin-regtest");
@@ -101,7 +100,7 @@ pub fn tail_file(path: &Path, lines: usize) -> Result<()> {
101100
}
102101

103102
for line in last_lines {
104-
println!("{}", line);
103+
println!("{line}");
105104
}
106105

107106
Ok(())

0 commit comments

Comments
 (0)