Skip to content

Commit 5e3e0dc

Browse files
committed
Merge branch 'main' of github.com:chainwayxyz/citrea-e2e into cleanup-config
2 parents b7d1e08 + 928f681 commit 5e3e0dc

File tree

11 files changed

+102
-38
lines changed

11 files changed

+102
-38
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55
resolver = "2"
66

77
[dependencies]
8+
alloy-primitives = { version = "0.8.12", default-features = false, features = ["serde"] }
89
anyhow = { version = "1.0.68", default-features = false, features = ["std"] }
910
async-trait = "0.1.71"
1011
bitcoin = { version = "0.32.2", features = ["serde", "rand"] }

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.79"
2+
channel = "1.81"
33
components = ["rustfmt", "rust-src", "clippy"]
44
profile = "minimal"

src/bitcoin.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
collections::HashSet,
2+
collections::{HashMap, HashSet},
33
fs::File,
44
future::Future,
55
process::Stdio,
@@ -165,6 +165,16 @@ impl BitcoinNode {
165165
) -> bitcoincore_rpc::Result<Vec<bitcoin::BlockHash>> {
166166
RpcApi::generate(self, block_num, None).await
167167
}
168+
169+
pub async fn generate_block(
170+
&self,
171+
// Address to send the block reward to
172+
output: String,
173+
// Either raw txs or txids, should be in mempool and in correct order
174+
transactions: Vec<String>,
175+
) -> bitcoincore_rpc::Result<HashMap<String, String>> {
176+
RpcApi::call(self, "generateblock", &[output.into(), transactions.into()]).await
177+
}
168178
}
169179

170180
#[async_trait]
@@ -273,7 +283,11 @@ impl Restart for BitcoinNode {
273283
}
274284
}
275285

276-
async fn start(&mut self, config: Option<Self::Config>) -> Result<()> {
286+
async fn start(
287+
&mut self,
288+
config: Option<Self::Config>,
289+
_extra_args: Option<Vec<String>>,
290+
) -> Result<()> {
277291
if let Some(config) = config {
278292
self.config = config;
279293
}

src/citrea_config/rollup.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,17 @@ impl Default for RollupConfig {
163163
32, 64, 64, 227, 100, 193, 15, 43, 236, 156, 31, 229, 0, 161, 205, 76, 36, 124,
164164
137, 214, 80, 160, 30, 215, 232, 44, 171, 168, 103, 135, 124, 33,
165165
],
166-
// private key [4, 95, 252, 129, 163, 193, 253, 179, 175, 19, 89, 219, 242, 209, 20, 176, 179, 239, 191, 127, 41, 204, 156, 93, 160, 18, 103, 170, 57, 210, 199, 141]
167-
// Private Key (WIF): KwNDSCvKqZqFWLWN1cUzvMiJQ7ck6ZKqR6XBqVKyftPZtvmbE6YD
166+
// private key E9873D79C6D87DC0FB6A5778633389F4453213303DA61F20BD67FC233AA33262
167+
// Private Key (WIF): 5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF
168168
sequencer_da_pub_key: vec![
169-
3, 136, 195, 18, 11, 187, 25, 37, 38, 109, 184, 237, 247, 208, 131, 219, 162,
170-
70, 35, 174, 234, 47, 239, 247, 60, 51, 174, 242, 247, 112, 186, 222, 30,
169+
2, 88, 141, 32, 42, 252, 193, 238, 74, 181, 37, 76, 120, 71, 236, 37, 185, 161,
170+
53, 187, 218, 15, 43, 198, 158, 225, 167, 20, 116, 159, 215, 125, 201,
171171
],
172-
// private key [117, 186, 249, 100, 208, 116, 89, 70, 0, 54, 110, 91, 17, 26, 29, 168, 248, 107, 46, 254, 45, 34, 218, 81, 200, 216, 33, 38, 160, 252, 172, 114]
173-
// Private Key (WIF): L1AZdJXzDGGENBBPZGSL7dKJnwn5xSKqzszgK6CDwiBGThYQEVTo
172+
// private key 56D08C2DDE7F412F80EC99A0A328F76688C904BD4D1435281EFC9270EC8C8707
173+
// Private Key (WIF): 5JUX9MqyVroDAjP2itrbaenEKNTioGVnnDSYn3PmLgb23TCLWMs
174174
prover_da_pub_key: vec![
175-
2, 138, 232, 157, 214, 46, 7, 210, 235, 33, 105, 239, 71, 169, 105, 233, 239,
176-
84, 172, 112, 13, 54, 9, 206, 106, 138, 251, 218, 15, 28, 137, 112, 127,
175+
3, 238, 218, 184, 136, 228, 95, 59, 220, 62, 201, 145, 140, 73, 28, 17, 229,
176+
207, 122, 240, 169, 31, 56, 185, 127, 188, 30, 19, 90, 228, 5, 102, 1,
177177
],
178178
},
179179
telemetry: Default::default(),

src/client.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::time::{Duration, SystemTime};
22

3+
use alloy_primitives::U64;
34
use anyhow::{bail, Result};
45
use jsonrpsee::{
56
core::client::ClientT,
@@ -44,14 +45,16 @@ impl Client {
4445
Ok(self
4546
.client
4647
.request("ledger_getLastScannedL1Height", rpc_params![])
47-
.await?)
48+
.await
49+
.map(|v: U64| v.try_into().expect("U64 to u64 must succeed"))?)
4850
}
4951

5052
pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result<u64> {
5153
Ok(self
5254
.client
5355
.request("ledger_getHeadSoftConfirmationHeight", rpc_params![])
54-
.await?)
56+
.await
57+
.map(|v: U64| v.try_into().expect("U64 to u64 must succeed"))?)
5558
}
5659

5760
pub async fn wait_for_l2_block(&self, num: u64, timeout: Option<Duration>) -> Result<()> {

src/config/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,30 @@ impl fmt::Display for DaLayer {
4242
}
4343
}
4444

45+
#[derive(Clone, Debug, Default, Copy)]
46+
pub enum CitreaMode {
47+
#[default]
48+
Dev,
49+
DevAllForks,
50+
}
51+
52+
impl fmt::Display for CitreaMode {
53+
// This trait requires `fmt` with this exact signature.
54+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
55+
match self {
56+
CitreaMode::Dev => write!(f, "dev"),
57+
CitreaMode::DevAllForks => write!(f, "dev-all-forks"),
58+
}
59+
}
60+
}
61+
4562
#[derive(Clone, Debug)]
4663
pub struct BaseNodeConfig {
4764
pub dir: PathBuf,
4865
pub env: Vec<(&'static str, &'static str)>,
4966
pub da_layer: DaLayer,
5067
pub docker_image: Option<String>,
68+
pub mode: CitreaMode,
5169
}
5270

5371
#[derive(Clone, Debug)]
@@ -72,12 +90,14 @@ where
7290
docker_image: Option<String>,
7391
dir: PathBuf,
7492
env: Vec<(&'static str, &'static str)>,
93+
mode: CitreaMode,
7594
) -> Result<Self> {
7695
let base = BaseNodeConfig {
7796
dir: dir.clone(),
7897
env,
7998
da_layer: DaLayer::Bitcoin,
8099
docker_image,
100+
mode,
81101
};
82102

83103
let conf = Self {
@@ -179,6 +199,10 @@ where
179199
pub fn da_layer(&self) -> &DaLayer {
180200
&self.base.da_layer
181201
}
202+
203+
pub fn mode(&self) -> &CitreaMode {
204+
&self.base.mode
205+
}
182206
}
183207

184208
impl<T> LogPathProvider for FullL2NodeConfig<T>

src/config/test_case.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{env, path::PathBuf, time::Duration};
22

33
use tempfile::TempDir;
44

5+
use super::CitreaMode;
56
use crate::utils::generate_test_id;
67

78
#[derive(Clone, Default)]
@@ -60,6 +61,7 @@ pub struct TestCaseConfig {
6061
// Defaults to resources/genesis/bitcoin-regtest
6162
pub genesis_dir: Option<String>,
6263
pub test_id: String,
64+
pub mode: CitreaMode,
6365
}
6466

6567
impl Default for TestCaseConfig {
@@ -85,6 +87,7 @@ impl Default for TestCaseConfig {
8587
docker: TestCaseDockerConfig::default(),
8688
genesis_dir: None,
8789
test_id,
90+
mode: CitreaMode::Dev,
8891
}
8992
}
9093
}

src/framework.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn generate_test_config<T: TestCase>(
321321
RollupConfig {
322322
da: BitcoinServiceConfig {
323323
da_private_key: Some(
324-
"045FFC81A3C1FDB3AF1359DBF2D114B0B3EFBF7F29CC9C5DA01267AA39D2C78D".to_string(),
324+
"E9873D79C6D87DC0FB6A5778633389F4453213303DA61F20BD67FC233AA33262".to_string(),
325325
),
326326
node_url: format!("http://{}/wallet/{}", da_config.node_url, node_kind),
327327
tx_backup_dir: tx_backup_dir.display().to_string(),
@@ -356,7 +356,7 @@ fn generate_test_config<T: TestCase>(
356356
RollupConfig {
357357
da: BitcoinServiceConfig {
358358
da_private_key: Some(
359-
"75BAF964D074594600366E5B111A1DA8F86B2EFE2D22DA51C8D82126A0FCAC72".to_string(),
359+
"56D08C2DDE7F412F80EC99A0A328F76688C904BD4D1435281EFC9270EC8C8707".to_string(),
360360
),
361361
node_url: format!("http://{}/wallet/{}", da_config.node_url, node_kind),
362362
tx_backup_dir: tx_backup_dir.display().to_string(),
@@ -437,6 +437,7 @@ fn generate_test_config<T: TestCase>(
437437
citrea_docker_image.clone(),
438438
sequencer_dir,
439439
env.sequencer(),
440+
test_case.mode,
440441
)?,
441442
batch_prover: FullBatchProverConfig::new(
442443
NodeKind::BatchProver,
@@ -445,6 +446,7 @@ fn generate_test_config<T: TestCase>(
445446
citrea_docker_image.clone(),
446447
batch_prover_dir,
447448
env.batch_prover(),
449+
test_case.mode,
448450
)?,
449451
light_client_prover: FullLightClientProverConfig::new(
450452
NodeKind::LightClientProver,
@@ -453,6 +455,7 @@ fn generate_test_config<T: TestCase>(
453455
citrea_docker_image.clone(),
454456
light_client_prover_dir,
455457
env.light_client_prover(),
458+
test_case.mode,
456459
)?,
457460
full_node: FullFullNodeConfig::new(
458461
NodeKind::FullNode,
@@ -461,6 +464,7 @@ fn generate_test_config<T: TestCase>(
461464
citrea_docker_image,
462465
full_node_dir,
463466
env.full_node(),
467+
test_case.mode,
464468
)?,
465469
test_case,
466470
})

src/node.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
time::{Duration, SystemTime},
1010
};
1111

12-
use anyhow::{bail, Context};
12+
use anyhow::{anyhow, bail, Context};
1313
use async_trait::async_trait;
1414
use bitcoincore_rpc::{Auth, Client as BitcoinClient};
1515
use serde::Serialize;
@@ -22,8 +22,8 @@ use tracing::{debug, info, trace};
2222
use crate::{
2323
client::Client,
2424
config::{
25-
BatchProverConfig, BitcoinConfig, DockerConfig, EmptyConfig, FullL2NodeConfig,
26-
LightClientProverConfig, SequencerConfig,
25+
BatchProverConfig, BitcoinConfig, DockerConfig, EmptyConfig,
26+
FullL2NodeConfig, LightClientProverConfig, SequencerConfig,
2727
},
2828
docker::DockerEnv,
2929
log_provider::LogPathProvider,
@@ -114,7 +114,7 @@ where
114114
})
115115
}
116116

117-
fn spawn(config: &FullL2NodeConfig<C>) -> Result<SpawnOutput> {
117+
fn spawn(config: &FullL2NodeConfig<C>, extra_args: Option<Vec<String>>) -> Result<SpawnOutput> {
118118
let citrea = get_citrea_path()?;
119119

120120
let kind = config.kind();
@@ -134,6 +134,7 @@ where
134134

135135
Command::new(citrea)
136136
.args(get_citrea_args(config))
137+
.args(extra_args.unwrap_or_default())
137138
.envs(config.env())
138139
.stdout(Stdio::from(stdout_file))
139140
.stderr(Stdio::from(stderr_file))
@@ -200,8 +201,8 @@ where
200201

201202
async fn spawn(config: &Self::Config, docker: &Arc<Option<DockerEnv>>) -> Result<SpawnOutput> {
202203
match docker.as_ref() {
203-
Some(docker) if docker.citrea() => docker.spawn(config.clone().into()).await,
204-
_ => Self::spawn(config),
204+
Some(docker) if docker.citrea() => docker.spawn(config.to_owned().into()).await,
205+
_ => Self::spawn(config, None),
205206
}
206207
}
207208

@@ -212,18 +213,20 @@ where
212213
async fn wait_for_ready(&self, timeout: Option<Duration>) -> Result<()> {
213214
let start = Instant::now();
214215
let timeout = timeout.unwrap_or(Duration::from_secs(30));
215-
while start.elapsed() < timeout {
216-
if self
217-
.client
218-
.ledger_get_head_soft_confirmation_height()
219-
.await
220-
.is_ok()
221-
{
222-
return Ok(());
223-
}
216+
let mut response = Err(anyhow!("initial response value"));
217+
218+
while response.is_err() && (start.elapsed() < timeout) {
219+
response = self.client.ledger_get_head_soft_confirmation_height().await;
224220
sleep(Duration::from_millis(500)).await;
225221
}
226-
anyhow::bail!("TODO failed to become ready within the specified timeout",)
222+
match response {
223+
Ok(_) => return Ok(()),
224+
Err(e) => anyhow::bail!(
225+
"{} failed to become ready within the specified timeout, latest ledger_get_head_soft_confirmation_height error: {}",
226+
self.config.kind(),
227+
e
228+
)
229+
}
227230
}
228231

229232
fn client(&self) -> &Self::Client {
@@ -258,7 +261,11 @@ where
258261
Ok(())
259262
}
260263

261-
async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()> {
264+
async fn start(
265+
&mut self,
266+
new_config: Option<Self::Config>,
267+
extra_args: Option<Vec<String>>,
268+
) -> Result<()> {
262269
let config = self.config_mut();
263270

264271
if let Some(new_config) = new_config {
@@ -279,7 +286,7 @@ where
279286
copy_directory(old_dir, &new_dir)?;
280287
config.set_dir(new_dir);
281288

282-
*self.spawn_output() = Self::spawn(config)?;
289+
*self.spawn_output() = Self::spawn(config, extra_args)?;
283290
self.wait_for_ready(None).await
284291
}
285292
}
@@ -292,7 +299,7 @@ where
292299
let rollup_config_args = config.get_rollup_config_args();
293300

294301
[
295-
vec!["--dev".to_string()],
302+
vec![format!("--{}", config.mode())],
296303
vec!["--da-layer".to_string(), config.da_layer().to_string()],
297304
node_config_args,
298305
rollup_config_args,

src/traits.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,19 @@ pub trait NodeT: Send {
6868
#[async_trait]
6969
pub trait Restart: NodeT + Send {
7070
async fn wait_until_stopped(&mut self) -> Result<()>;
71-
async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()>;
71+
async fn start(
72+
&mut self,
73+
new_config: Option<Self::Config>,
74+
extra_args: Option<Vec<String>>,
75+
) -> Result<()>;
7276

7377
// Default implementation to support waiting for node to be fully shutdown and brough back up with new config.
74-
async fn restart(&mut self, new_config: Option<Self::Config>) -> Result<()> {
78+
async fn restart(
79+
&mut self,
80+
new_config: Option<Self::Config>,
81+
extra_args: Option<Vec<String>>,
82+
) -> Result<()> {
7583
self.wait_until_stopped().await?;
76-
self.start(new_config).await
84+
self.start(new_config, extra_args).await
7785
}
7886
}

0 commit comments

Comments
 (0)