Skip to content

Commit deae682

Browse files
authored
feat: limit l1 messages included up to block gas limit (#238)
* feat: add RollupNodeContext * feat: add cumulative gas used l1 messages predicate
1 parent c8599a5 commit deae682

8 files changed

Lines changed: 333 additions & 53 deletions

File tree

crates/node/src/add_ons/rollup.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ impl RollupManagerAddOn {
5757
{
5858
let (rnm, handle, l1_notification_tx) = self
5959
.config
60-
.build(
61-
ctx.node.network().clone(),
62-
self.scroll_wire_event,
63-
rpc.rpc_server_handles,
64-
ctx.config.chain.clone(),
65-
ctx.config.datadir().db(),
66-
)
60+
.build((&ctx).into(), self.scroll_wire_event, rpc.rpc_server_handles)
6761
.await?;
6862
ctx.node
6963
.task_executor()

crates/node/src/args.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
22
add_ons::IsDevChain,
33
constants::{self},
4+
context::RollupNodeContext,
45
};
56
use std::{fs, path::PathBuf, sync::Arc, time::Duration};
67

@@ -109,22 +110,11 @@ impl ScrollRollupNodeConfig {
109110

110111
impl ScrollRollupNodeConfig {
111112
/// Consumes the [`ScrollRollupNodeConfig`] and builds a [`RollupNodeManager`].
112-
pub async fn build<
113-
N: FullNetwork<Primitives = ScrollNetworkPrimitives> + NetworkProtocols,
114-
CS: ScrollHardforks
115-
+ EthChainSpec<Header: BlockHeader>
116-
+ IsDevChain
117-
+ Clone
118-
+ Send
119-
+ Sync
120-
+ 'static,
121-
>(
113+
pub async fn build<N, CS>(
122114
self,
123-
network: N,
115+
ctx: RollupNodeContext<N, CS>,
124116
events: UnboundedReceiver<ScrollWireEvent>,
125117
rpc_server_handles: RethRpcServerHandles,
126-
chain_spec: CS,
127-
db_path: PathBuf,
128118
) -> eyre::Result<(
129119
RollupNodeManager<
130120
N,
@@ -136,14 +126,22 @@ impl ScrollRollupNodeConfig {
136126
>,
137127
RollupManagerHandle,
138128
Option<Sender<Arc<L1Notification>>>,
139-
)> {
129+
)>
130+
where
131+
N: FullNetwork<Primitives = ScrollNetworkPrimitives> + NetworkProtocols,
132+
CS: EthChainSpec<Header: BlockHeader> + ScrollHardforks + IsDevChain + 'static,
133+
{
140134
tracing::info!(target: "rollup_node::args",
141135
"Building rollup node with config:\n{:#?}",
142136
self
143137
);
144138
// Instantiate the network manager
139+
let network = ctx.network;
145140
let scroll_network_manager = ScrollNetworkManager::from_parts(network.clone(), events);
146141

142+
// Get the chain spec.
143+
let chain_spec = ctx.chain_spec;
144+
147145
// Get the rollup node config.
148146
let named_chain = chain_spec.chain().named().expect("expected named chain");
149147
let node_config = Arc::new(NodeConfig::from_named_chain(named_chain));
@@ -173,6 +171,7 @@ impl ScrollRollupNodeConfig {
173171
.expect("failed to create payload provider");
174172

175173
// Instantiate the database
174+
let db_path = ctx.datadir;
176175
let database_path = if let Some(database_path) = self.database_args.path {
177176
database_path.to_string_lossy().to_string()
178177
} else {
@@ -273,6 +272,7 @@ impl ScrollRollupNodeConfig {
273272
let sequencer = Sequencer::new(
274273
Arc::new(l1_messages_provider),
275274
args.fee_recipient,
275+
ctx.block_gas_limit,
276276
args.max_l1_messages_per_block,
277277
0,
278278
self.sequencer_args.l1_message_inclusion_mode,

crates/node/src/constants.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Constants related to the [`crate::ScrollRollupNode`]
2+
13
/// The max retries for the L1 provider.
24
pub(crate) const PROVIDER_MAX_RETRIES: u32 = 10;
35

@@ -24,3 +26,7 @@ pub(crate) const BLOCK_GAP_TRIGGER: u64 = 500_000;
2426

2527
/// The default suggested priority fee for the gas price oracle.
2628
pub(crate) const DEFAULT_SUGGEST_PRIORITY_FEE: u64 = 100;
29+
30+
/// Scroll default gas limit.
31+
/// Should match <https://github.com/scroll-tech/reth/blob/scroll/crates/scroll/node/src/builder/payload.rs#L36>.
32+
pub const SCROLL_GAS_LIMIT: u64 = 20_000_000;

crates/node/src/context.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::constants::SCROLL_GAS_LIMIT;
2+
use reth_node_api::{AddOnsContext, FullNodeComponents, FullNodeTypes};
3+
use reth_node_core::cli::config::PayloadBuilderConfig;
4+
use reth_node_types::NodeTypes;
5+
use std::{path::PathBuf, sync::Arc};
6+
7+
/// The context passed to `ScrollRollupNodeConfig::build` method.
8+
#[derive(Debug)]
9+
pub struct RollupNodeContext<N, CS> {
10+
/// The network component of the rollup node.
11+
pub network: N,
12+
/// The chain specification of the rollup node.
13+
pub chain_spec: Arc<CS>,
14+
/// The datadir of the rollup node.
15+
pub datadir: PathBuf,
16+
/// The block gas limit of the rollup node.
17+
pub block_gas_limit: u64,
18+
}
19+
20+
impl<N, CS> RollupNodeContext<N, CS> {
21+
/// Returns a new instance of the [`RollupNodeContext`].
22+
pub const fn new(
23+
network: N,
24+
chain_spec: Arc<CS>,
25+
datadir: PathBuf,
26+
block_gas_limit: u64,
27+
) -> Self {
28+
Self { network, chain_spec, datadir, block_gas_limit }
29+
}
30+
}
31+
32+
impl<N> From<&AddOnsContext<'_, N>>
33+
for RollupNodeContext<N::Network, <<N as FullNodeTypes>::Types as NodeTypes>::ChainSpec>
34+
where
35+
N: FullNodeComponents,
36+
{
37+
fn from(value: &AddOnsContext<'_, N>) -> Self {
38+
Self {
39+
network: value.node.network().clone(),
40+
chain_spec: value.config.chain.clone(),
41+
datadir: value.config.datadir().db(),
42+
block_gas_limit: value.config.builder.gas_limit().unwrap_or(SCROLL_GAS_LIMIT),
43+
}
44+
}
45+
}

crates/node/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
33
pub mod add_ons;
44
mod args;
5-
mod constants;
5+
pub mod constants;
6+
mod context;
67
mod node;
78
#[cfg(feature = "test-utils")]
89
pub mod test_utils;
910

1011
pub use args::*;
12+
pub use context::RollupNodeContext;
1113
pub use node::ScrollRollupNode;

crates/node/tests/e2e.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ use reth_scroll_chainspec::SCROLL_DEV;
1313
use reth_scroll_node::ScrollNetworkPrimitives;
1414
use reth_tokio_util::EventStream;
1515
use rollup_node::{
16+
constants::SCROLL_GAS_LIMIT,
1617
test_utils::{
1718
default_sequencer_test_scroll_rollup_node_config, default_test_scroll_rollup_node_config,
1819
generate_tx, setup_engine,
1920
},
2021
BeaconProviderArgs, ConsensusAlgorithm, ConsensusArgs, DatabaseArgs, EngineDriverArgs,
21-
GasPriceOracleArgs, L1ProviderArgs, NetworkArgs as ScrollNetworkArgs, ScrollRollupNodeConfig,
22-
SequencerArgs,
22+
GasPriceOracleArgs, L1ProviderArgs, NetworkArgs as ScrollNetworkArgs, RollupNodeContext,
23+
ScrollRollupNodeConfig, SequencerArgs,
2324
};
2425
use rollup_node_manager::{RollupManagerCommand, RollupManagerEvent, RollupManagerHandle};
2526
use rollup_node_primitives::{sig_encode_hash, BatchCommitData, ConsensusUpdate};
@@ -497,11 +498,14 @@ async fn graceful_shutdown_consolidates_most_recent_batch_on_startup() -> eyre::
497498
let (rnm, handle, l1_notification_tx) = config
498499
.clone()
499500
.build(
500-
node.inner.network.clone(),
501+
RollupNodeContext::new(
502+
node.inner.network.clone(),
503+
chain_spec.clone(),
504+
path.clone(),
505+
SCROLL_GAS_LIMIT,
506+
),
501507
events,
502508
node.inner.add_ons_handle.rpc_handle.rpc_server_handles.clone(),
503-
chain_spec.clone(),
504-
path.clone(),
505509
)
506510
.await?;
507511

@@ -604,11 +608,14 @@ async fn graceful_shutdown_consolidates_most_recent_batch_on_startup() -> eyre::
604608
let (rnm, handle, l1_notification_tx) = config
605609
.clone()
606610
.build(
607-
node.inner.network.clone(),
611+
RollupNodeContext::new(
612+
node.inner.network.clone(),
613+
chain_spec,
614+
path.clone(),
615+
SCROLL_GAS_LIMIT,
616+
),
608617
events,
609618
node.inner.add_ons_handle.rpc_handle.rpc_server_handles.clone(),
610-
chain_spec,
611-
path.clone(),
612619
)
613620
.await?;
614621
let l1_notification_tx = l1_notification_tx.unwrap();
@@ -695,11 +702,14 @@ async fn can_handle_batch_revert() -> eyre::Result<()> {
695702
let (rnm, handle, l1_watcher_tx) = config
696703
.clone()
697704
.build(
698-
node.inner.network.clone(),
705+
RollupNodeContext::new(
706+
node.inner.network.clone(),
707+
chain_spec.clone(),
708+
path.clone(),
709+
SCROLL_GAS_LIMIT,
710+
),
699711
events,
700712
node.inner.add_ons_handle.rpc_handle.rpc_server_handles.clone(),
701-
chain_spec.clone(),
702-
path.clone(),
703713
)
704714
.await?;
705715
let l1_watcher_tx = l1_watcher_tx.unwrap();
@@ -827,11 +837,14 @@ async fn can_handle_reorgs_while_sequencing() -> eyre::Result<()> {
827837
let (rnm, handle, l1_watcher_tx) = config
828838
.clone()
829839
.build(
830-
node.inner.network.clone(),
840+
RollupNodeContext::new(
841+
node.inner.network.clone(),
842+
chain_spec.clone(),
843+
path.clone(),
844+
SCROLL_GAS_LIMIT,
845+
),
831846
events,
832847
node.inner.add_ons_handle.rpc_handle.rpc_server_handles.clone(),
833-
chain_spec.clone(),
834-
path.clone(),
835848
)
836849
.await?;
837850
let l1_watcher_tx = l1_watcher_tx.unwrap();

0 commit comments

Comments
 (0)