Skip to content

Commit e85ecd3

Browse files
authored
Dump log revamp (#21)
* Impl LogProvider on config directly * Don't dump logs if node not present in test_case
1 parent a96abcf commit e85ecd3

File tree

14 files changed

+153
-129
lines changed

14 files changed

+153
-129
lines changed

src/bitcoin.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
collections::HashSet,
3-
path::PathBuf,
3+
fs::File,
4+
process::Stdio,
45
sync::Arc,
56
time::{Duration, Instant},
67
};
@@ -17,10 +18,10 @@ use super::{
1718
config::BitcoinConfig,
1819
docker::DockerEnv,
1920
framework::TestContext,
20-
traits::{LogProvider, NodeT, Restart, SpawnOutput},
21+
traits::{NodeT, Restart, SpawnOutput},
2122
Result,
2223
};
23-
use crate::node::NodeKind;
24+
use crate::{log_provider::LogPathProvider, node::NodeKind};
2425

2526
pub const FINALITY_DEPTH: u64 = 8;
2627

@@ -185,10 +186,19 @@ impl NodeT for BitcoinNode {
185186
let args = config.args();
186187
debug!("Running bitcoind with args : {args:?}");
187188

189+
info!(
190+
"Bitcoin debug.log available at : {}",
191+
config.log_path().display()
192+
);
193+
194+
let stderr_path = config.stderr_path();
195+
let stderr_file = File::create(stderr_path).context("Failed to create stderr file")?;
196+
188197
Command::new("bitcoind")
189198
.args(&args)
190199
.kill_on_drop(true)
191200
.envs(config.env.clone())
201+
.stderr(Stdio::from(stderr_file))
192202
.spawn()
193203
.context("Failed to spawn bitcoind process")
194204
.map(SpawnOutput::Child)
@@ -258,7 +268,7 @@ impl Restart for BitcoinNode {
258268

259269
async fn start(&mut self, config: Option<Self::Config>) -> Result<()> {
260270
if let Some(config) = config {
261-
self.config = config
271+
self.config = config;
262272
}
263273
self.spawn_output = Self::spawn(&self.config, &self.docker_env).await?;
264274

@@ -271,16 +281,6 @@ impl Restart for BitcoinNode {
271281
}
272282
}
273283

274-
impl LogProvider for BitcoinNode {
275-
fn kind(&self) -> NodeKind {
276-
NodeKind::Bitcoin
277-
}
278-
279-
fn log_path(&self) -> PathBuf {
280-
self.config.data_dir.join("regtest").join("debug.log")
281-
}
282-
}
283-
284284
pub struct BitcoinNodeCluster {
285285
inner: Vec<BitcoinNode>,
286286
}
@@ -361,7 +361,7 @@ async fn wait_for_rpc_ready(client: &Client, timeout: Option<Duration>) -> Resul
361361
Ok(_) => return Ok(()),
362362
Err(e) => {
363363
trace!("[wait_for_rpc_ready] error {e}");
364-
sleep(Duration::from_millis(500)).await
364+
sleep(Duration::from_millis(500)).await;
365365
}
366366
}
367367
}

src/citrea_config/rollup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const fn default_max_subscriptions_per_connection() -> u32 {
8686
pub struct StorageConfig {
8787
/// Path that can be utilized by concrete rollup implementation
8888
pub path: PathBuf,
89-
/// File descriptor limit for RocksDB
89+
/// File descriptor limit for `RocksDB`
9090
pub db_max_open_files: Option<i32>,
9191
}
9292

src/citrea_config/sequencer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Default for SequencerConfig {
2929
deposit_mempool_fetch_limit: 10,
3030
block_production_interval_ms: 100,
3131
da_update_interval_ms: 100,
32-
mempool_conf: Default::default(),
32+
mempool_conf: SequencerMempoolConfig::default(),
3333
}
3434
}
3535
}
@@ -57,11 +57,11 @@ pub struct SequencerMempoolConfig {
5757
impl Default for SequencerMempoolConfig {
5858
fn default() -> Self {
5959
Self {
60-
pending_tx_limit: 100000,
60+
pending_tx_limit: 100_000,
6161
pending_tx_size: 200,
62-
queue_tx_limit: 100000,
62+
queue_tx_limit: 100_000,
6363
queue_tx_size: 200,
64-
base_fee_tx_limit: 100000,
64+
base_fee_tx_limit: 100_000,
6565
base_fee_tx_size: 200,
6666
max_account_slots: 16,
6767
}

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Client {
8686
self.client
8787
.get_sequencer_commitments_on_slot_by_hash(hash)
8888
.await
89-
.map_err(|e| e.into())
89+
.map_err(Into::into)
9090
}
9191

9292
pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result<u64> {

src/config/bitcoin.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::path::PathBuf;
33
use bitcoin::Network;
44
use tempfile::TempDir;
55

6+
use crate::{log_provider::LogPathProvider, node::NodeKind};
7+
68
#[derive(Debug, Clone)]
79
pub struct BitcoinConfig {
810
pub p2p_port: u16,
@@ -62,3 +64,17 @@ impl BitcoinConfig {
6264
.concat()
6365
}
6466
}
67+
68+
impl LogPathProvider for BitcoinConfig {
69+
fn kind() -> NodeKind {
70+
NodeKind::Bitcoin
71+
}
72+
73+
fn log_path(&self) -> PathBuf {
74+
self.data_dir.join("regtest").join("debug.log")
75+
}
76+
77+
fn stderr_path(&self) -> PathBuf {
78+
self.data_dir.join("stderr.log")
79+
}
80+
}

src/config/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub use crate::citrea_config::{
2222
rollup::{FullNodeConfig, RollupPublicKeys, RpcConfig, RunnerConfig, StorageConfig},
2323
sequencer::SequencerConfig,
2424
};
25-
use crate::node::{Config, NodeKind};
25+
use crate::{
26+
log_provider::LogPathProvider,
27+
node::{Config, NodeKind},
28+
};
2629

2730
#[derive(Clone, Debug)]
2831
pub struct FullL2NodeConfig<T> {
@@ -96,3 +99,20 @@ where
9699
&self.rollup
97100
}
98101
}
102+
103+
impl<T: Clone + Serialize> LogPathProvider for FullL2NodeConfig<T>
104+
where
105+
FullL2NodeConfig<T>: Config,
106+
{
107+
fn kind() -> NodeKind {
108+
Self::node_kind()
109+
}
110+
111+
fn log_path(&self) -> PathBuf {
112+
self.dir().join("stdout.log")
113+
}
114+
115+
fn stderr_path(&self) -> PathBuf {
116+
self.dir().join("stderr.log")
117+
}
118+
}

src/config/rollup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl From<BitcoinConfig> for BitcoinServiceConfig {
6666
node_password: v.rpc_password,
6767
network: v.network,
6868
da_private_key: None,
69-
tx_backup_dir: "".to_string(),
69+
tx_backup_dir: String::new(),
7070
}
7171
}
7272
}

src/framework.rs

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ use bitcoincore_rpc::RpcApi;
44
use tracing::{debug, info};
55

66
use super::{
7-
bitcoin::BitcoinNodeCluster,
8-
config::TestConfig,
9-
docker::DockerEnv,
10-
full_node::FullNode,
11-
node::NodeKind,
12-
sequencer::Sequencer,
13-
traits::{LogProvider, LogProviderErased, NodeT},
14-
Result,
7+
bitcoin::BitcoinNodeCluster, config::TestConfig, docker::DockerEnv, full_node::FullNode,
8+
node::NodeKind, sequencer::Sequencer, traits::NodeT, Result,
9+
};
10+
use crate::{
11+
batch_prover::BatchProver,
12+
light_client_prover::LightClientProver,
13+
log_provider::{LogPathProvider, LogPathProviderErased},
14+
utils::tail_file,
1515
};
16-
use crate::{batch_prover::BatchProver, light_client_prover::LightClientProver, utils::tail_file};
1716

1817
pub struct TestContext {
1918
pub config: TestConfig,
@@ -41,7 +40,6 @@ pub struct TestFramework {
4140
pub batch_prover: Option<BatchProver>,
4241
pub light_client_prover: Option<LightClientProver>,
4342
pub full_node: Option<FullNode>,
44-
show_logs: bool,
4543
pub initial_da_height: u64,
4644
}
4745

@@ -64,15 +62,13 @@ impl TestFramework {
6462

6563
let bitcoin_nodes = BitcoinNodeCluster::new(&ctx).await?;
6664

67-
// tokio::time::sleep(std::time::Duration::from_secs(30)).await;
6865
Ok(Self {
6966
bitcoin_nodes,
7067
sequencer: None,
7168
batch_prover: None,
7269
light_client_prover: None,
7370
full_node: None,
7471
ctx,
75-
show_logs: true,
7672
initial_da_height: 0,
7773
})
7874
}
@@ -103,36 +99,31 @@ impl TestFramework {
10399
Ok(())
104100
}
105101

106-
fn get_nodes_as_log_provider(&self) -> Vec<&dyn LogProviderErased> {
107-
vec![
108-
self.bitcoin_nodes.get(0).map(LogProvider::as_erased),
109-
self.sequencer.as_ref().map(LogProvider::as_erased),
110-
self.full_node.as_ref().map(LogProvider::as_erased),
111-
self.batch_prover.as_ref().map(LogProvider::as_erased),
112-
self.light_client_prover
113-
.as_ref()
114-
.map(LogProvider::as_erased),
115-
]
116-
.into_iter()
117-
.flatten()
118-
.collect()
119-
}
120-
121-
pub fn show_log_paths(&self) {
122-
if self.show_logs {
123-
info!(
124-
"Logs available at {}",
125-
self.ctx.config.test_case.dir.display()
126-
);
127-
128-
for node in self.get_nodes_as_log_provider() {
129-
info!(
130-
"{} logs available at : {}",
131-
node.kind(),
132-
node.log_path().display()
133-
);
134-
}
135-
}
102+
fn get_nodes_as_log_provider(&self) -> Vec<&dyn LogPathProviderErased> {
103+
let test_case = &self.ctx.config.test_case;
104+
105+
self.ctx
106+
.config
107+
.bitcoin
108+
.iter()
109+
.map(LogPathProvider::as_erased)
110+
.map(Option::Some)
111+
.chain(vec![
112+
test_case
113+
.with_sequencer
114+
.then(|| LogPathProvider::as_erased(&self.ctx.config.sequencer)),
115+
test_case
116+
.with_full_node
117+
.then(|| LogPathProvider::as_erased(&self.ctx.config.full_node)),
118+
test_case
119+
.with_batch_prover
120+
.then(|| LogPathProvider::as_erased(&self.ctx.config.batch_prover)),
121+
test_case
122+
.with_light_client_prover
123+
.then(|| LogPathProvider::as_erased(&self.ctx.config.light_client_prover)),
124+
])
125+
.flatten()
126+
.collect()
136127
}
137128

138129
pub fn dump_log(&self) -> Result<()> {
@@ -142,11 +133,11 @@ impl TestFramework {
142133
.ok()
143134
.and_then(|v| v.parse::<usize>().ok())
144135
.unwrap_or(25);
145-
for node in self.get_nodes_as_log_provider() {
146-
debug!("{} logs (last {n_lines} lines):", node.kind());
147-
if let Err(e) = tail_file(&node.log_path(), n_lines) {
148-
eprint!("{e}");
149-
}
136+
for provider in self.get_nodes_as_log_provider() {
137+
println!("{} logs (last {n_lines} lines):", provider.kind());
138+
let _ = tail_file(&provider.log_path(), n_lines);
139+
println!("{} stderr logs (last {n_lines} lines):", provider.kind());
140+
let _ = tail_file(&provider.stderr_path(), n_lines);
150141
}
151142
Ok(())
152143
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod docker;
77
pub mod framework;
88
pub mod full_node;
99
pub mod light_client_prover;
10+
mod log_provider;
1011
pub mod node;
1112
pub mod sequencer;
1213
pub mod test_case;

src/log_provider.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::path::PathBuf;
2+
3+
use crate::node::NodeKind;
4+
5+
pub trait LogPathProvider {
6+
fn kind() -> NodeKind;
7+
fn log_path(&self) -> PathBuf;
8+
fn stderr_path(&self) -> PathBuf;
9+
fn as_erased(&self) -> &dyn LogPathProviderErased
10+
where
11+
Self: Sized,
12+
{
13+
self
14+
}
15+
}
16+
17+
pub trait LogPathProviderErased {
18+
fn kind(&self) -> NodeKind;
19+
fn log_path(&self) -> PathBuf;
20+
fn stderr_path(&self) -> PathBuf;
21+
}
22+
23+
impl<T: LogPathProvider> LogPathProviderErased for T {
24+
fn kind(&self) -> NodeKind {
25+
T::kind()
26+
}
27+
28+
fn log_path(&self) -> PathBuf {
29+
LogPathProvider::log_path(self)
30+
}
31+
32+
fn stderr_path(&self) -> PathBuf {
33+
LogPathProvider::stderr_path(self)
34+
}
35+
}

0 commit comments

Comments
 (0)