Skip to content

Commit 2fd58cf

Browse files
committed
fix: db
1 parent 6ac6bb9 commit 2fd58cf

File tree

10 files changed

+175
-151
lines changed

10 files changed

+175
-151
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ reth-db = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3
156156
reth-e2e-test-utils = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3" }
157157
reth-eth-wire = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3", default-features = false }
158158
reth-eth-wire-types = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3", default-features = false }
159+
reth-fs-util = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3", default-features = false }
159160
reth-network = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3", default-features = false }
160161
reth-network-api = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3", default-features = false }
161162
reth-network-p2p = { git = "https://github.com/scroll-tech/reth.git", tag = "scroll-v91.3", default-features = false }

crates/node/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ alloy-rpc-types-anvil = { workspace = true, optional = true }
8484
reth-db = { workspace = true, optional = true, features = ["test-utils"] }
8585
reth-e2e-test-utils = { workspace = true, optional = true }
8686
reth-engine-local = { workspace = true, optional = true }
87+
reth-fs-util = { workspace = true, optional = true }
8788
reth-provider = { workspace = true, optional = true }
8889
reth-rpc-layer = { workspace = true, optional = true }
8990
reth-rpc-server-types = { workspace = true, optional = true }
@@ -136,6 +137,7 @@ js-tracer = ["reth-scroll-node/js-tracer", "reth-scroll-rpc/js-tracer"]
136137
test-utils = [
137138
"reth-db",
138139
"reth-engine-local",
140+
"reth-fs-util",
139141
"reth-trie-db/test-utils",
140142
"reth-chainspec/test-utils",
141143
"reth-evm/test-utils",

crates/node/src/test_utils/fixture.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use alloy_transport::layers::RetryBackoffLayer;
2121
use reth_chainspec::EthChainSpec;
2222
use reth_e2e_test_utils::{wallet::Wallet, NodeHelperType, TmpDB};
2323
use reth_eth_wire_types::BasicNetworkPrimitives;
24+
use reth_fs_util::remove_dir_all;
2425
use reth_network::NetworkHandle;
2526
use reth_node_builder::NodeTypes;
2627
use reth_node_types::NodeTypesWithDBAdapter;
@@ -76,6 +77,21 @@ impl Debug for TestFixture {
7677
}
7778
}
7879

80+
impl Drop for TestFixture {
81+
fn drop(&mut self) {
82+
// Manually cleanup test directories.
83+
// TempDatabase's automatic drop only removes the database file itself,
84+
// but the parent directory also contains other files (static files, blob store, etc.)
85+
// that need to be cleaned up to avoid accumulating test artifacts.
86+
let parent_paths: Vec<_> =
87+
self.dbs.iter().filter_map(|db| db.path().parent().map(|p| p.to_path_buf())).collect();
88+
// Delete parent directories containing all database files
89+
for path in parent_paths {
90+
let _ = remove_dir_all(&path);
91+
}
92+
}
93+
}
94+
7995
/// The network handle to the Scroll network.
8096
pub type ScrollNetworkHandle =
8197
NetworkHandle<BasicNetworkPrimitives<ScrollPrimitives, ScrollPooledTransaction>>;
@@ -616,7 +632,7 @@ impl TestFixtureBuilder {
616632
&tasks,
617633
self.config.clone(),
618634
self.num_nodes,
619-
Vec::new(), // Empty dbs for initial setup
635+
None,
620636
chain_spec.clone(),
621637
self.is_dev,
622638
self.no_local_transactions_propagation,

crates/node/src/test_utils/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub async fn setup_engine(
113113
tasks: &TaskManager,
114114
mut scroll_node_config: ScrollRollupNodeConfig,
115115
num_nodes: usize,
116-
mut dbs: Vec<Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>>>,
116+
db_provided: Option<Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>>>,
117117
chain_spec: Arc<<ScrollRollupNode as NodeTypes>::ChainSpec>,
118118
is_dev: bool,
119119
no_local_transactions_propagation: bool,
@@ -144,6 +144,7 @@ where
144144

145145
// Create nodes and peer them
146146
let mut nodes: Vec<NodeTestContext<_, _>> = Vec::with_capacity(num_nodes);
147+
let mut dbs: Vec<Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>>> = Vec::new();
147148

148149
for idx in 0..num_nodes {
149150
// disable sequencer nodes after the first one
@@ -164,22 +165,18 @@ where
164165
.set_dev(is_dev)
165166
.with_txpool(TxPoolArgs { no_local_transactions_propagation, ..Default::default() });
166167

167-
// Check if we already have a database for this index (reboot scenario)
168-
let db: Arc<reth_db::test_utils::TempDatabase<reth_db::DatabaseEnv>> = if idx < dbs.len() {
168+
// Check if we already have provided a database for a node (reboot scenario)
169+
let db = if let Some(ref provided_db) = db_provided {
169170
// Reuse existing database for reboot
170-
let existing_db = dbs[idx].clone();
171-
172-
// Get the existing datadir from the database path
173-
let existing_db_path = existing_db.path();
174-
let test_data_dir =
175-
existing_db_path.parent().expect("db path should have a parent directory");
171+
let db_path = provided_db.path();
172+
let test_data_dir = db_path.parent().expect("db path should have a parent directory");
176173

177174
// Set the datadir in node_config to reuse the same directory
178175
node_config.datadir.datadir =
179176
reth_node_core::dirs::MaybePlatformPath::from(test_data_dir.to_path_buf());
180177

181178
tracing::warn!("Reusing existing database for node {} at {:?}", idx, test_data_dir);
182-
existing_db
179+
provided_db.clone()
183180
} else {
184181
// Create a unique persistent test directory for both Reth and Scroll databases
185182
// Using process ID and node index to ensure uniqueness
@@ -241,7 +238,8 @@ where
241238
NodeTestContext::new(node, |_| panic!("should not build payloads using this method"))
242239
.await?;
243240

244-
if idx >= dbs.len() {
241+
// skip the forkchoice update when a database is provided (reboot scenario)
242+
if !db_provided.is_some() {
245243
let genesis = node.block_hash(0);
246244
node.update_forkchoice(genesis, genesis).await?;
247245
}

crates/node/src/test_utils/reboot.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ impl TestFixture {
105105
/// ```
106106
pub async fn shutdown_node(&mut self, node_index: usize) -> eyre::Result<()> {
107107
if node_index >= self.nodes.len() {
108-
return Err(eyre::eyre!("Node index {} out of bounds (total nodes: {})", node_index, self.nodes.len()));
108+
return Err(eyre::eyre!(
109+
"Node index {} out of bounds (total nodes: {})",
110+
node_index,
111+
self.nodes.len()
112+
));
109113
}
110114

111115
if self.nodes[node_index].is_none() {
@@ -115,7 +119,8 @@ impl TestFixture {
115119
tracing::info!("Shutting down node at index {}", node_index);
116120

117121
// Step 1: Explicitly shutdown the ChainOrchestrator
118-
// This sends a Shutdown command that will make the ChainOrchestrator exit its event loop immediately
122+
// This sends a Shutdown command that will make the ChainOrchestrator exit its event loop
123+
// immediately
119124
if let Some(node) = &self.nodes[node_index] {
120125
tracing::info!("Sending shutdown command to ChainOrchestrator...");
121126
if let Err(e) = node.rollup_manager_handle.shutdown().await {
@@ -175,12 +180,13 @@ impl TestFixture {
175180
/// fixture.l1().sync().await?;
176181
/// fixture.expect_event().l1_synced().await?;
177182
/// ```
178-
pub async fn start_node(
179-
&mut self,
180-
node_index: usize,
181-
) -> eyre::Result<()> {
183+
pub async fn start_node(&mut self, node_index: usize) -> eyre::Result<()> {
182184
if node_index >= self.nodes.len() {
183-
return Err(eyre::eyre!("Node index {} out of bounds (total nodes: {})", node_index, self.nodes.len()));
185+
return Err(eyre::eyre!(
186+
"Node index {} out of bounds (total nodes: {})",
187+
node_index,
188+
self.nodes.len()
189+
));
184190
}
185191

186192
if self.nodes[node_index].is_some() {
@@ -189,24 +195,17 @@ impl TestFixture {
189195

190196
tracing::info!("Starting node at index {} (reusing database)", node_index);
191197

192-
// Step 1: Prepare database for reuse
193-
// Pass only the database for this specific node (preserves all state)
194-
let node_dbs = if node_index < self.dbs.len() {
195-
vec![self.dbs[node_index].clone()]
196-
} else {
197-
Vec::new() // Should not happen, but handle gracefully
198-
};
199-
200198
// Step 2: Create a new node instance with the existing database
201199
let (mut new_nodes, _, _) = setup_engine(
202200
&self.tasks,
203201
self.config.clone(),
204-
1, // Create just one node
205-
node_dbs, // Reuse the database (state is preserved)
202+
1,
203+
Some(self.dbs[node_index].clone()), // reuse provided database
206204
self.chain_spec.clone(),
207-
true, // is_dev
208-
false, // no_local_transactions_propagation
209-
).await?;
205+
true,
206+
false,
207+
)
208+
.await?;
210209

211210
if new_nodes.is_empty() {
212211
return Err(eyre::eyre!("Failed to create new node"));
@@ -240,9 +239,8 @@ impl TestFixture {
240239

241240
// Step 6: Initialize Engine with the restored ForkchoiceState
242241
let engine = Engine::new(Arc::new(engine_client), fcs);
243-
let chain_orchestrator_rx = new_node.inner.add_ons_handle.rollup_manager_handle
244-
.get_event_listener()
245-
.await?;
242+
let chain_orchestrator_rx =
243+
new_node.inner.add_ons_handle.rollup_manager_handle.get_event_listener().await?;
246244

247245
// Step 7: Determine node type (sequencer vs follower)
248246
let was_sequencer = self.config.sequencer_args.sequencer_enabled && node_index == 0;
@@ -267,4 +265,4 @@ impl TestFixture {
267265

268266
Ok(())
269267
}
270-
}
268+
}

crates/node/tests/e2e.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,14 @@ async fn can_forward_tx_to_sequencer() -> eyre::Result<()> {
298298
let chain_spec = (*SCROLL_DEV).clone();
299299
let tasks = TaskManager::current();
300300
let (mut sequencer_node, _, _) =
301-
setup_engine(&tasks, sequencer_node_config, 1, Vec::new(), chain_spec.clone(), false, true)
301+
setup_engine(&tasks, sequencer_node_config, 1, None, chain_spec.clone(), false, true)
302302
.await
303303
.unwrap();
304304

305305
let sequencer_url = format!("http://localhost:{}", sequencer_node[0].rpc_url().port().unwrap());
306306
follower_node_config.network_args.sequencer_url = Some(sequencer_url);
307307
let (mut follower_node, _, wallet) =
308-
setup_engine(&tasks, follower_node_config, 1, Vec::new(), chain_spec, false, true)
309-
.await
310-
.unwrap();
308+
setup_engine(&tasks, follower_node_config, 1, None, chain_spec, false, true).await.unwrap();
311309

312310
let wallet = Arc::new(Mutex::new(wallet));
313311

@@ -469,7 +467,7 @@ async fn can_bridge_blocks() -> eyre::Result<()> {
469467
&tasks,
470468
default_test_scroll_rollup_node_config(),
471469
1,
472-
Vec::new(),
470+
None,
473471
chain_spec.clone(),
474472
false,
475473
false,
@@ -577,7 +575,7 @@ async fn shutdown_consolidates_most_recent_batch_on_startup() -> eyre::Result<()
577575
&tasks,
578576
default_test_scroll_rollup_node_config(),
579577
1,
580-
Vec::new(),
578+
None,
581579
chain_spec.clone(),
582580
false,
583581
false,
@@ -852,8 +850,7 @@ async fn graceful_shutdown_sets_fcs_to_latest_signed_block_in_db_on_start_up() -
852850
// Launch a node
853851
let tasks = TaskManager::current();
854852
let (mut nodes, _, _) =
855-
setup_engine(&tasks, config.clone(), 1, Vec::new(), chain_spec.clone(), false, false)
856-
.await?;
853+
setup_engine(&tasks, config.clone(), 1, None, chain_spec.clone(), false, false).await?;
857854
let node = nodes.pop().unwrap();
858855

859856
// Instantiate the rollup node manager.

0 commit comments

Comments
 (0)