Skip to content

Commit bdfee09

Browse files
authored
feat: execution payload provider (#90)
* chore: refactor providers test utils * feat: wip execution payload provider * feat: alloy execution payload provider * chore: renaming * feat: improve args layout * test: build_node helper * test: execution payload provider * fix: lints * fix: address comments
1 parent c14a138 commit bdfee09

File tree

17 files changed

+273
-174
lines changed

17 files changed

+273
-174
lines changed

Cargo.lock

Lines changed: 9 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,13 @@ reth-eth-wire-types = { git = "https://github.com/scroll-tech/reth.git", default
145145
reth-network = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
146146
reth-network-api = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
147147
reth-network-peers = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
148+
reth-node-builder = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
149+
reth-node-core = { git = "https://github.com/scroll-tech/reth.git" }
150+
reth-payload-primitives = { git = "https://github.com/scroll-tech/reth.git" }
148151
reth-primitives = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
149152
reth-primitives-traits = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
150153
reth-provider = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
154+
reth-rpc-server-types = { git = "https://github.com/scroll-tech/reth.git" }
151155
reth-tasks = { git = "https://github.com/scroll-tech/reth.git" }
152156
reth-tokio-util = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
153157

@@ -191,4 +195,3 @@ thiserror = "2.0"
191195
tokio = { version = "1.39", default-features = false }
192196
tokio-stream = { version = "0.1", default-features = false }
193197
tracing = "0.1.0"
194-
jsonrpsee = "0.24.9"

bin/rollup/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ reth-eth-wire-types.workspace = true
2828
reth-network.workspace = true
2929
reth-network-peers.workspace = true
3030
reth-node-api = { git = "https://github.com/scroll-tech/reth.git" }
31-
reth-node-builder = { git = "https://github.com/scroll-tech/reth.git", features = ["skip-state-root-validation"] }
32-
reth-node-core = { git = "https://github.com/scroll-tech/reth.git" }
31+
reth-node-builder = { workspace = true, features = ["skip-state-root-validation"] }
32+
reth-node-core.workspace = true
3333
reth-node-types = { git = "https://github.com/scroll-tech/reth.git" }
3434
reth-primitives.workspace = true
3535
reth-provider = { workspace = true, features = ["skip-state-root-validation"] }
@@ -43,14 +43,14 @@ reth-scroll-engine-primitives = { git = "https://github.com/scroll-tech/reth.git
4343
reth-scroll-node = { workspace = true, features = ["skip-state-root-validation"] }
4444
reth-scroll-primitives = { workspace = true }
4545
scroll-db = { workspace = true }
46-
scroll-engine = { workspace = true, features = ["test-utils"] }
46+
scroll-engine.workspace = true
4747
scroll-migration.workspace = true
4848
scroll-network.workspace = true
4949
scroll-wire.workspace = true
5050

5151
# rollup-node
5252
rollup-node-manager.workspace = true
53-
rollup-node-providers.workspace = true
53+
rollup-node-providers = { workspace = true, features = ["test-utils"] }
5454
rollup-node-sequencer.workspace = true
5555
rollup-node-watcher.workspace = true
5656

@@ -60,6 +60,7 @@ eyre.workspace = true
6060
reqwest = { version = "0.12", default-features = false }
6161
tokio = { workspace = true, features = ["full"] }
6262
tracing.workspace = true
63+
url = "2.5.4"
6364

6465
[dev-dependencies]
6566
# alloy
@@ -69,7 +70,7 @@ alloy-rpc-types-engine.workspace = true
6970
# reth
7071
reth-e2e-test-utils.workspace = true
7172
reth-payload-builder = { git = "https://github.com/scroll-tech/reth.git" }
72-
reth-rpc-server-types = { git = "https://github.com/scroll-tech/reth.git" }
73+
reth-rpc-server-types.workspace = true
7374
reth-tasks.workspace = true
7475
reth-tracing = { git = "https://github.com/scroll-tech/reth.git" }
7576

@@ -87,7 +88,6 @@ test-utils = [
8788
"reth-primitives/test-utils",
8889
"reth-provider/test-utils",
8990
"reth-transaction-pool/test-utils",
90-
"scroll-engine/test-utils",
9191
"reth-payload-builder/test-utils",
9292
"reth-payload-builder/test-utils",
9393
"reth-scroll-node/test-utils",
@@ -97,6 +97,7 @@ test-utils = [
9797
"reth-scroll-node/test-utils",
9898
"reth-scroll-node/test-utils",
9999
"rollup-node-providers/test-utils",
100+
"scroll-engine/test-utils",
100101
]
101102
serde = [
102103
"alloy-primitives/serde",
@@ -112,6 +113,7 @@ serde = [
112113
"rollup-node-manager/serde",
113114
"alloy-chains/serde",
114115
"reth-transaction-pool/serde",
116+
"url/serde",
115117
]
116118

117119
[[bin]]

bin/rollup/src/args.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,62 @@ pub struct ScrollRollupNodeArgs {
2222
/// The EngineAPI URL.
2323
#[arg(long)]
2424
pub engine_api_url: Option<reqwest::Url>,
25-
/// The provider arguments
25+
/// The beacon provider arguments.
26+
#[command(flatten)]
27+
pub beacon_provider_args: BeaconProviderArgs,
28+
/// The L1 provider arguments
2629
#[command(flatten)]
2730
pub l1_provider_args: L1ProviderArgs,
31+
/// The L2 provider arguments
32+
#[command(flatten)]
33+
pub l2_provider_args: L2ProviderArgs,
2834
/// The sequencer arguments
2935
#[command(flatten)]
3036
pub sequencer_args: SequencerArgs,
3137
}
3238

33-
#[derive(Debug, clap::Args)]
39+
#[derive(Debug, Default, clap::Args)]
3440
pub struct L1ProviderArgs {
35-
/// The URL for the L1 RPC URL.
36-
#[arg(long)]
37-
pub l1_rpc_url: Option<reqwest::Url>,
38-
/// The URL for the Beacon RPC URL.
39-
#[arg(long)]
40-
pub beacon_rpc_url: Option<reqwest::Url>,
41+
/// The URL for the L1 RPC.
42+
#[arg(long = "l1.url", id = "l1_url", value_name = "L1_URL")]
43+
pub url: Option<reqwest::Url>,
44+
/// The compute units per second for the provider.
45+
#[arg(long = "l1.cups", id = "l1_compute_units_per_second", value_name = "L1_COMPUTE_UNITS_PER_SECOND", default_value_t = constants::PROVIDER_COMPUTE_UNITS_PER_SECOND)]
46+
pub compute_units_per_second: u64,
47+
/// The max amount of retries for the provider.
48+
#[arg(long = "l1.max-retries", id = "l1_max_retries", value_name = "L1_MAX_RETRIES", default_value_t = constants::PROVIDER_MAX_RETRIES)]
49+
pub max_retries: u32,
50+
/// The initial backoff for the provider.
51+
#[arg(long = "l1.initial-backoff", id = "l1_initial_backoff", value_name = "L1_INITIAL_BACKOFF", default_value_t = constants::PROVIDER_INITIAL_BACKOFF)]
52+
pub initial_backoff: u64,
53+
}
54+
55+
#[derive(Debug, Default, clap::Args)]
56+
pub struct BeaconProviderArgs {
57+
/// The URL for the Beacon chain.
58+
#[arg(long = "beacon.url", id = "beacon_url", value_name = "BEACON_URL")]
59+
pub url: Option<reqwest::Url>,
60+
/// The compute units per second for the provider.
61+
#[arg(long = "beacon.cups", id = "beacon_compute_units_per_second", value_name = "BEACON_COMPUTE_UNITS_PER_SECOND", default_value_t = constants::PROVIDER_COMPUTE_UNITS_PER_SECOND)]
62+
pub compute_units_per_second: u64,
63+
/// The max amount of retries for the provider.
64+
#[arg(long = "beacon.max-retries", id = "beacon_max_retries", value_name = "BEACON_MAX_RETRIES", default_value_t = constants::PROVIDER_MAX_RETRIES)]
65+
pub max_retries: u32,
66+
/// The initial backoff for the provider.
67+
#[arg(long = "beacon.initial-backoff", id = "beacon_initial_backoff", value_name = "BEACON_INITIAL_BACKOFF", default_value_t = constants::PROVIDER_INITIAL_BACKOFF)]
68+
pub initial_backoff: u64,
69+
}
70+
71+
#[derive(Debug, Default, clap::Args)]
72+
pub struct L2ProviderArgs {
4173
/// The compute units per second for the provider.
42-
#[arg(long, default_value_t = constants::PROVIDER_COMPUTE_UNITS_PER_SECOND)]
74+
#[arg(long = "l2.cups", id = "l2_compute_units_per_second", value_name = "L2_COMPUTE_UNITS_PER_SECOND", default_value_t = constants::PROVIDER_COMPUTE_UNITS_PER_SECOND)]
4375
pub compute_units_per_second: u64,
4476
/// The max amount of retries for the provider.
45-
#[arg(long, default_value_t = constants::PROVIDER_MAX_RETRIES)]
77+
#[arg(long = "l2.max-retries", id = "l2_max_retries", value_name = "L2_MAX_RETRIES", default_value_t = constants::PROVIDER_MAX_RETRIES)]
4678
pub max_retries: u32,
4779
/// The initial backoff for the provider.
48-
#[arg(long, default_value_t = constants::PROVIDER_INITIAL_BACKOFF)]
80+
#[arg(long = "l2.initial-backoff", id = "l2_initial_back_off", value_name = "L2_INITIAL_BACKOFF", default_value_t = constants::PROVIDER_INITIAL_BACKOFF)]
4981
pub initial_backoff: u64,
5082
}
5183

bin/rollup/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Scroll Network Bridge Components.
22
33
mod args;
4-
pub use args::{L1ProviderArgs, ScrollRollupNodeArgs, SequencerArgs};
4+
pub use args::{
5+
BeaconProviderArgs, L1ProviderArgs, L2ProviderArgs, ScrollRollupNodeArgs, SequencerArgs,
6+
};
57

68
mod constants;
79
pub use constants::{PROVIDER_INITIAL_BACKOFF, PROVIDER_MAX_RETRIES, WATCHER_START_BLOCK_NUMBER};

bin/rollup/src/network.rs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
use crate::{
2+
constants::PROVIDER_BLOB_CACHE_SIZE, L1ProviderArgs, ScrollRollupNodeArgs,
3+
WATCHER_START_BLOCK_NUMBER,
4+
};
5+
use std::{sync::Arc, time::Duration};
6+
17
use alloy_provider::ProviderBuilder;
28
use alloy_rpc_client::RpcClient;
39
use alloy_transport::layers::RetryBackoffLayer;
@@ -11,21 +17,18 @@ use reth_scroll_chainspec::ScrollChainSpec;
1117
use reth_scroll_primitives::ScrollPrimitives;
1218
use reth_transaction_pool::{PoolTransaction, TransactionPool};
1319
use rollup_node_manager::{Consensus, NoopConsensus, PoAConsensus, RollupNodeManager};
14-
use rollup_node_providers::{beacon_provider, DatabaseL1MessageProvider, OnlineL1Provider};
20+
use rollup_node_providers::{
21+
beacon_provider, AlloyExecutionPayloadProvider, DatabaseL1MessageProvider, OnlineL1Provider,
22+
};
1523
use rollup_node_sequencer::Sequencer;
1624
use rollup_node_watcher::L1Watcher;
1725
use scroll_alloy_provider::ScrollAuthEngineApiProvider;
1826
use scroll_db::{Database, DatabaseConnectionProvider};
19-
use scroll_engine::{test_utils::NoopExecutionPayloadProvider, EngineDriver, ForkchoiceState};
27+
use scroll_engine::{EngineDriver, ForkchoiceState};
2028
use scroll_network::NetworkManager as ScrollNetworkManager;
2129
use scroll_wire::{ProtocolHandler, ScrollWireConfig};
22-
use std::{sync::Arc, time::Duration};
2330
use tracing::info;
24-
25-
use crate::{
26-
constants::PROVIDER_BLOB_CACHE_SIZE, L1ProviderArgs, ScrollRollupNodeArgs,
27-
WATCHER_START_BLOCK_NUMBER,
28-
};
31+
use url::Url;
2932

3033
/// The network builder for the scroll rollup.
3134
#[derive(Debug)]
@@ -98,7 +101,39 @@ where
98101
auth_secret,
99102
self.config.engine_api_url.unwrap_or(format!("http://localhost:{auth_port}").parse()?),
100103
);
101-
let payload_provider = NoopExecutionPayloadProvider;
104+
105+
// Get a provider
106+
let provider = if let Some(url) = self.config.l1_provider_args.url {
107+
let L1ProviderArgs { max_retries, initial_backoff, compute_units_per_second, .. } =
108+
self.config.l1_provider_args;
109+
let client = RpcClient::builder()
110+
.layer(RetryBackoffLayer::new(
111+
max_retries,
112+
initial_backoff,
113+
compute_units_per_second,
114+
))
115+
.http(url);
116+
Some(ProviderBuilder::new().on_client(client))
117+
} else {
118+
None
119+
};
120+
121+
// Get a payload provider
122+
let payload_provider = if self.config.test || !ctx.config().rpc.http {
123+
None
124+
} else {
125+
let l2_provider_url =
126+
format!("http://{}:{}", ctx.config().rpc.http_addr, ctx.config().rpc.http_port);
127+
let client = RpcClient::builder()
128+
.layer(RetryBackoffLayer::new(
129+
self.config.l2_provider_args.max_retries,
130+
self.config.l2_provider_args.initial_backoff,
131+
self.config.l2_provider_args.compute_units_per_second,
132+
))
133+
.http(Url::parse(&l2_provider_url)?);
134+
let provider = ProviderBuilder::new().on_client(client);
135+
Some(AlloyExecutionPayloadProvider::new(provider))
136+
};
102137

103138
let fcs = if let Some(named) = ctx.config().chain.chain.named() {
104139
ForkchoiceState::head_from_named_chain(named)
@@ -107,7 +142,7 @@ where
107142
};
108143
let engine = EngineDriver::new(
109144
Arc::new(engine_api),
110-
Arc::new(payload_provider),
145+
payload_provider,
111146
fcs,
112147
Duration::from_millis(self.config.sequencer_args.payload_building_duration),
113148
);
@@ -132,22 +167,6 @@ where
132167
// Get the chain specification
133168
let chain_spec = ctx.chain_spec();
134169

135-
// Spawn the L1Watcher
136-
let provider = if let Some(url) = self.config.l1_provider_args.l1_rpc_url {
137-
let L1ProviderArgs { max_retries, initial_backoff, compute_units_per_second, .. } =
138-
self.config.l1_provider_args;
139-
let client = RpcClient::builder()
140-
.layer(RetryBackoffLayer::new(
141-
max_retries,
142-
initial_backoff,
143-
compute_units_per_second,
144-
))
145-
.http(url);
146-
Some(ProviderBuilder::new().on_client(client))
147-
} else {
148-
None
149-
};
150-
151170
// Create the consensus.
152171
let consensus: Box<dyn Consensus> = if self.config.test {
153172
Box::new(NoopConsensus::default())
@@ -173,7 +192,7 @@ where
173192

174193
// Construct the l1 provider.
175194
let l1_messages_provider = DatabaseL1MessageProvider::new(db.clone(), 0);
176-
let l1_provider = if let Some(url) = self.config.l1_provider_args.beacon_rpc_url {
195+
let l1_provider = if let Some(url) = self.config.beacon_provider_args.url {
177196
let beacon_provider = beacon_provider(url.to_string());
178197
let l1_provider = OnlineL1Provider::new(
179198
beacon_provider,

0 commit comments

Comments
 (0)