Skip to content

Commit ab3acb7

Browse files
committed
fix features
1 parent 662ed17 commit ab3acb7

File tree

11 files changed

+121
-96
lines changed

11 files changed

+121
-96
lines changed

crates/chain-orchestrator/src/handle/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,32 @@ use metrics::ChainOrchestratorHandleMetrics;
2222
pub struct ChainOrchestratorHandle<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> {
2323
/// The channel used to send commands to the rollup manager.
2424
to_manager_tx: mpsc::UnboundedSender<ChainOrchestratorCommand<N>>,
25+
/// The metrics for the handle.
2526
handle_metrics: ChainOrchestratorHandleMetrics,
27+
/// Mock for the L1 Watcher used in tests.
28+
#[cfg(feature = "test-utils")]
29+
pub l1_watcher_mock: Option<rollup_node_watcher::test_utils::L1WatcherMock>,
2630
}
2731

2832
impl<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> ChainOrchestratorHandle<N> {
2933
/// Create a new rollup manager handle.
3034
pub fn new(to_manager_tx: mpsc::UnboundedSender<ChainOrchestratorCommand<N>>) -> Self {
31-
Self { to_manager_tx, handle_metrics: ChainOrchestratorHandleMetrics::default() }
35+
Self {
36+
to_manager_tx,
37+
handle_metrics: ChainOrchestratorHandleMetrics::default(),
38+
#[cfg(feature = "test-utils")]
39+
l1_watcher_mock: None,
40+
}
41+
}
42+
43+
/// Sets the L1 watcher mock for the handle.
44+
#[cfg(feature = "test-utils")]
45+
pub fn with_l1_watcher_mock(
46+
mut self,
47+
l1_watcher_mock: Option<rollup_node_watcher::test_utils::L1WatcherMock>,
48+
) -> Self {
49+
self.l1_watcher_mock = l1_watcher_mock;
50+
self
3251
}
3352

3453
/// Sends a command to the rollup manager.

crates/node/src/add_ons/handle.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#[cfg(feature = "test-utils")]
2-
use crate::test_utils::l1_helpers::L1WatcherMock;
31
use reth_network_api::FullNetwork;
42
use reth_node_api::FullNodeComponents;
53
use reth_node_builder::rpc::{RpcHandle, RpcHandleProvider};
@@ -17,9 +15,6 @@ pub struct ScrollAddOnsHandle<
1715
pub rollup_manager_handle: ChainOrchestratorHandle<Node::Network>,
1816
/// The handle used to send commands to the RPC server.
1917
pub rpc_handle: RpcHandle<Node, EthApi>,
20-
/// An optional channel used to send `L1Watcher` notifications to the `RollupNodeManager`.
21-
#[cfg(feature = "test-utils")]
22-
pub l1_watcher_tx: Option<L1WatcherMock>,
2318
}
2419

2520
impl<

crates/node/src/add_ons/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152
});
153153

154154
let rpc_handle = rpc_add_ons.launch_add_ons_with(ctx.clone(), |_| Ok(())).await?;
155-
let (rollup_manager_handle, l1_watcher_tx) =
155+
let rollup_manager_handle =
156156
rollup_node_manager_addon.launch(ctx.clone(), rpc_handle.clone()).await?;
157157

158158
// Only send handle if RPC is enabled
@@ -161,12 +161,7 @@ where
161161
.map_err(|_| eyre::eyre!("failed to send rollup manager handle"))?;
162162
}
163163

164-
Ok(ScrollAddOnsHandle {
165-
rollup_manager_handle,
166-
rpc_handle,
167-
#[cfg(feature = "test-utils")]
168-
l1_watcher_tx,
169-
})
164+
Ok(ScrollAddOnsHandle { rollup_manager_handle, rpc_handle })
170165
}
171166
}
172167

crates/node/src/add_ons/rollup.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{args::ScrollRollupNodeConfig, test_utils::l1_helpers::L1WatcherMock};
1+
use crate::args::ScrollRollupNodeConfig;
22

33
use reth_chainspec::NamedChain;
44
use reth_network::NetworkProtocols;
@@ -53,13 +53,13 @@ impl RollupManagerAddOn {
5353
self,
5454
ctx: AddOnsContext<'_, N>,
5555
rpc: RpcHandle<N, EthApi>,
56-
) -> eyre::Result<(ChainOrchestratorHandle<N::Network>, Option<L1WatcherMock>)>
56+
) -> eyre::Result<ChainOrchestratorHandle<N::Network>>
5757
where
5858
<<N as FullNodeTypes>::Types as NodeTypes>::ChainSpec:
5959
ChainConfig<Config = ScrollChainConfig> + ScrollHardforks + IsDevChain,
6060
N::Network: NetworkProtocols + FullNetwork<Primitives = ScrollNetworkPrimitives>,
6161
{
62-
let (chain_orchestrator, handle, l1_watcher_mock) = self
62+
let (chain_orchestrator, handle) = self
6363
.config
6464
.build((&ctx).into(), self.scroll_wire_event, rpc.rpc_server_handles)
6565
.await?;
@@ -68,6 +68,6 @@ impl RollupManagerAddOn {
6868
.spawn_critical_with_shutdown_signal("rollup_node_manager", |shutdown| {
6969
chain_orchestrator.run_until_shutdown(shutdown)
7070
});
71-
Ok((handle, l1_watcher_mock))
71+
Ok(handle)
7272
}
7373
}

crates/node/src/args.rs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
use scroll_migration::MigratorTrait;
77
use std::{fs, path::PathBuf, sync::Arc};
88

9-
use super::test_utils::l1_helpers::L1WatcherMock;
109
use alloy_chains::NamedChain;
1110
use alloy_primitives::{hex, Address, U128};
1211
use alloy_provider::{layers::CacheLayer, Provider, ProviderBuilder};
@@ -167,7 +166,6 @@ impl ScrollRollupNodeConfig {
167166
impl ScrollEngineApi,
168167
>,
169168
ChainOrchestratorHandle<N>,
170-
Option<L1WatcherMock>,
171169
)>
172170
where
173171
N: FullNetwork<Primitives = ScrollNetworkPrimitives> + NetworkProtocols,
@@ -351,42 +349,49 @@ impl ScrollRollupNodeConfig {
351349
};
352350
let consensus = self.consensus_args.consensus(authorized_signer)?;
353351

354-
let (l1_watcher_mock, l1_watcher_handle) = if let Some(provider) =
355-
l1_provider.filter(|_| !self.test)
356-
{
357-
tracing::info!(target: "scroll::node::args", ?l1_block_startup_info, "Starting L1 watcher");
358-
(
359-
None,
360-
Some(
361-
L1Watcher::spawn(
362-
provider,
363-
l1_block_startup_info,
364-
node_config,
365-
self.l1_provider_args.logs_query_block_range,
366-
)
367-
.await,
368-
),
369-
)
370-
} else {
371-
// Create a channel for L1 notifications that we can use to inject L1 messages for
372-
// testing
373-
#[cfg(feature = "test-utils")]
374-
{
375-
let (notification_tx, notification_rx) = tokio::sync::mpsc::channel(1000);
376-
let (command_tx, command_rx) = tokio::sync::mpsc::unbounded_channel();
377-
let handle = L1WatcherHandle::new(command_tx, notification_rx);
378-
let watcher_mock = L1WatcherMock {
379-
command_rx: Arc::new(tokio::sync::Mutex::new(command_rx)),
380-
notification_tx,
381-
};
382-
(Some(watcher_mock), Some(handle))
383-
}
384-
385-
#[cfg(not(feature = "test-utils"))]
386-
{
387-
(None, None)
388-
}
389-
};
352+
// Define some types to support definitions of return type of following function in no_std.
353+
#[cfg(feature = "test-utils")]
354+
type L1WatcherMockOpt = Option<rollup_node_watcher::test_utils::L1WatcherMock>;
355+
356+
#[cfg(not(feature = "test-utils"))]
357+
type L1WatcherMockOpt = Option<std::convert::Infallible>;
358+
359+
let (_l1_watcher_mock, l1_watcher_handle): (L1WatcherMockOpt, Option<L1WatcherHandle>) =
360+
if let Some(provider) = l1_provider.filter(|_| !self.test) {
361+
tracing::info!(target: "scroll::node::args", ?l1_block_startup_info, "Starting L1 watcher");
362+
(
363+
None,
364+
Some(
365+
L1Watcher::spawn(
366+
provider,
367+
l1_block_startup_info,
368+
node_config,
369+
self.l1_provider_args.logs_query_block_range,
370+
)
371+
.await,
372+
),
373+
)
374+
} else {
375+
// Create a channel for L1 notifications that we can use to inject L1 messages for
376+
// testing
377+
#[cfg(feature = "test-utils")]
378+
{
379+
let (notification_tx, notification_rx) = tokio::sync::mpsc::channel(1000);
380+
let (command_tx, command_rx) = tokio::sync::mpsc::unbounded_channel();
381+
let handle =
382+
rollup_node_watcher::L1WatcherHandle::new(command_tx, notification_rx);
383+
let watcher_mock = rollup_node_watcher::test_utils::L1WatcherMock {
384+
command_rx: Arc::new(tokio::sync::Mutex::new(command_rx)),
385+
notification_tx,
386+
};
387+
(Some(watcher_mock), Some(handle))
388+
}
389+
390+
#[cfg(not(feature = "test-utils"))]
391+
{
392+
(None, None)
393+
}
394+
};
390395

391396
// Construct the l1 provider.
392397
let l1_messages_provider = db.clone();
@@ -475,7 +480,10 @@ impl ScrollRollupNodeConfig {
475480
)
476481
.await?;
477482

478-
Ok((chain_orchestrator, handle, l1_watcher_mock))
483+
#[cfg(feature = "test-utils")]
484+
let handle = handle.with_l1_watcher_mock(_l1_watcher_mock);
485+
486+
Ok((chain_orchestrator, handle))
479487
}
480488
}
481489

crates/node/src/test_utils/fixture.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use super::{
44
block_builder::BlockBuilder, l1_helpers::L1Helper, setup_engine, tx_helpers::TxHelper,
55
};
66
use crate::{
7-
test_utils::l1_helpers::L1WatcherMock, BlobProviderArgs, ChainOrchestratorArgs,
8-
ConsensusAlgorithm, ConsensusArgs, EngineDriverArgs, L1ProviderArgs, RollupNodeDatabaseArgs,
9-
RollupNodeGasPriceOracleArgs, RollupNodeNetworkArgs, RpcArgs, ScrollRollupNode,
10-
ScrollRollupNodeConfig, SequencerArgs, SignerArgs,
7+
BlobProviderArgs, ChainOrchestratorArgs, ConsensusAlgorithm, ConsensusArgs, EngineDriverArgs,
8+
L1ProviderArgs, RollupNodeDatabaseArgs, RollupNodeGasPriceOracleArgs, RollupNodeNetworkArgs,
9+
RpcArgs, ScrollRollupNode, ScrollRollupNodeConfig, SequencerArgs, SignerArgs,
1110
};
1211

1312
use alloy_eips::BlockNumberOrTag;
@@ -75,8 +74,6 @@ pub struct NodeHandle {
7574
pub node: NodeHelperType<ScrollRollupNode, TestBlockChainProvider>,
7675
/// Engine instance for this node.
7776
pub engine: Engine<Arc<dyn ScrollEngineApi + Send + Sync + 'static>>,
78-
/// L1 watcher notification channel.
79-
pub l1_watcher_tx: Option<L1WatcherMock>,
8077
/// Chain orchestrator listener.
8178
pub chain_orchestrator_rx: EventStream<ChainOrchestratorEvent>,
8279
/// Chain orchestrator handle.
@@ -102,7 +99,6 @@ impl Debug for NodeHandle {
10299
f.debug_struct("NodeHandle")
103100
.field("node", &"NodeHelper")
104101
.field("engine", &"Box<dyn ScrollEngineApi>")
105-
.field("l1_watcher_tx", &self.l1_watcher_tx)
106102
.field("rollup_manager_handle", &self.rollup_manager_handle)
107103
.finish()
108104
}
@@ -436,7 +432,7 @@ impl TestFixtureBuilder {
436432
.await?;
437433

438434
let mut node_handles = Vec::with_capacity(nodes.len());
439-
for (index, mut node) in nodes.into_iter().enumerate() {
435+
for (index, node) in nodes.into_iter().enumerate() {
440436
let genesis_hash = node.inner.chain_spec().genesis_hash();
441437

442438
// Create engine for the node
@@ -451,7 +447,6 @@ impl TestFixtureBuilder {
451447
let engine = Engine::new(Arc::new(engine_client), fcs);
452448

453449
// Get handles if available
454-
let l1_watcher_tx = node.inner.add_ons_handle.l1_watcher_tx.take();
455450
let rollup_manager_handle = node.inner.add_ons_handle.rollup_manager_handle.clone();
456451
let chain_orchestrator_rx =
457452
node.inner.add_ons_handle.rollup_manager_handle.get_event_listener().await?;
@@ -460,7 +455,6 @@ impl TestFixtureBuilder {
460455
node,
461456
engine,
462457
chain_orchestrator_rx,
463-
l1_watcher_tx,
464458
rollup_manager_handle,
465459
typ: if config.sequencer_args.sequencer_enabled && index == 0 {
466460
NodeType::Sequencer

crates/node/src/test_utils/l1_helpers.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@ use std::{fmt::Debug, str::FromStr, sync::Arc};
55

66
use alloy_primitives::{Address, Bytes, B256, U256};
77
use rollup_node_primitives::{BatchCommitData, BlockInfo, ConsensusUpdate};
8-
use rollup_node_watcher::{L1Notification, L1WatcherCommand};
8+
use rollup_node_watcher::L1Notification;
99
use scroll_alloy_consensus::TxL1Message;
10-
use tokio::sync::{mpsc, Mutex};
11-
12-
/// Mock for the L1 Watcher.
13-
#[derive(Clone, Debug)]
14-
pub struct L1WatcherMock {
15-
/// Receiver for L1 watcher commands.
16-
pub command_rx: Arc<Mutex<mpsc::UnboundedReceiver<L1WatcherCommand>>>,
17-
/// Sender for L1 notifications.
18-
pub notification_tx: mpsc::Sender<Arc<L1Notification>>,
19-
}
2010

2111
/// Helper for managing L1 interactions in tests.
2212
#[derive(Debug)]
@@ -126,7 +116,7 @@ impl<'a> L1Helper<'a> {
126116
};
127117

128118
for node in nodes {
129-
if let Some(tx) = &node.l1_watcher_tx {
119+
if let Some(tx) = &node.rollup_manager_handle.l1_watcher_mock {
130120
tx.notification_tx.send(notification.clone()).await?;
131121
}
132122
}
@@ -232,7 +222,7 @@ impl<'a> L1MessageBuilder<'a> {
232222
};
233223

234224
for node in nodes {
235-
if let Some(tx) = &node.l1_watcher_tx {
225+
if let Some(tx) = &node.rollup_manager_handle.l1_watcher_mock {
236226
tx.notification_tx.send(notification.clone()).await?;
237227
}
238228
}

0 commit comments

Comments
 (0)