Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 5e345b5

Browse files
committed
fix: use prague during payload building
1 parent 1610d9b commit 5e345b5

File tree

8 files changed

+394
-199
lines changed

8 files changed

+394
-199
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,35 @@ alloy-signer-local = { version = "0.3", features = ["mnemonic"] }
7070
tokio = { version = "1.21", default-features = false }
7171

7272
# reth
73-
reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
74-
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
73+
reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
74+
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
7575
"optimism",
7676
] }
77-
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
78-
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
79-
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
80-
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
81-
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
77+
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
78+
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
79+
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
80+
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
81+
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
8282
"optimism",
8383
] }
84-
reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
84+
reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
8585
"optimism",
8686
] }
87-
reth-optimism-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
87+
reth-optimism-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
8888
"optimism",
8989
] }
90-
reth-optimism-rpc = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
90+
reth-optimism-rpc = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
9191
"optimism",
9292
] }
93-
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
93+
reth-payload-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
94+
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
9495
"optimism",
9596
] }
96-
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7", features = [
97+
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e", features = [
9798
"optimism",
9899
] }
99-
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "ef1d9e7" }
100+
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
101+
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", rev = "5659d19e1c1e" }
100102

101103
# misc
102104
clap = "4"

bin/alphanet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ reth-optimism-rpc.workspace = true
2121
clap = { workspace = true, features = ["derive"] }
2222

2323
[target.'cfg(not(windows))'.dependencies]
24-
tikv-jemallocator = { version = "0.5", optional = true }
24+
tikv-jemallocator = { version = "0.6", optional = true }
2525

2626
[features]
2727
default = ["jemalloc"]

bin/alphanet/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use alphanet_node::{chainspec::AlphanetChainSpecParser, node::AlphaNetNode};
2727
use clap::Parser;
2828
use reth_node_optimism::args::RollupArgs;
2929
use reth_optimism_cli::Cli;
30-
use reth_optimism_rpc::eth::rpc::SequencerClient;
30+
use reth_optimism_rpc::sequencer::SequencerClient;
3131

3232
// We use jemalloc for performance reasons.
3333
#[cfg(all(feature = "jemalloc", unix))]
@@ -53,7 +53,7 @@ fn main() {
5353
if let Some(sequencer_http) = rollup_args.sequencer_http.clone() {
5454
ctx.registry
5555
.eth_api()
56-
.set_sequencer_client(SequencerClient::new(sequencer_http));
56+
.set_sequencer_client(SequencerClient::new(sequencer_http))?;
5757
}
5858

5959
Ok(())

crates/node/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ reth-node-builder.workspace = true
1818
reth-node-core.workspace = true
1919
reth-node-optimism.workspace = true
2020
reth-chainspec.workspace = true
21+
reth-payload-builder.workspace = true
2122
reth-primitives.workspace = true
2223
reth-revm.workspace = true
24+
reth-transaction-pool.workspace = true
2325
serde_json.workspace = true
2426

2527
eyre.workspace = true

crates/node/src/chainspec.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use once_cell::sync::Lazy;
44
use reth_chainspec::{
5-
BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec, EthereumHardfork,
6-
ForkCondition, OptimismHardfork,
5+
once_cell_set, BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec,
6+
EthereumHardfork, ForkCondition, OptimismHardfork,
77
};
88
use reth_cli::chainspec::ChainSpecParser;
99
use reth_node_core::args::utils::parse_custom_chain_spec;
@@ -44,7 +44,7 @@ pub static ALPHANET_DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
4444
chain: Chain::dev(),
4545
genesis: serde_json::from_str(include_str!("../../../etc/alphanet-genesis.json"))
4646
.expect("Can't deserialize alphanet genesis json"),
47-
genesis_hash: Some(b256!(
47+
genesis_hash: once_cell_set(b256!(
4848
"2f980576711e3617a5e4d83dd539548ec0f7792007d505a3d2e9674833af2d7c"
4949
)),
5050
paris_block_and_final_difficulty: Some((0, U256::from(0))),
@@ -64,7 +64,7 @@ pub static ALPHANET_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
6464
// manually from trusted source
6565
genesis: serde_json::from_str(include_str!("../../../etc/alphanet-genesis.json"))
6666
.expect("Can't deserialize alphanet genesis json"),
67-
genesis_hash: Some(b256!(
67+
genesis_hash: once_cell_set(b256!(
6868
"2f980576711e3617a5e4d83dd539548ec0f7792007d505a3d2e9674833af2d7c"
6969
)),
7070
paris_block_and_final_difficulty: Some((0, U256::from(0))),
@@ -104,6 +104,15 @@ impl ChainSpecParser for AlphanetChainSpecParser {
104104
// a good way to do it.
105105
chainspec.hardforks.insert(EthereumHardfork::Prague, ForkCondition::Timestamp(0));
106106

107+
// NOTE(onbjerg): op-node will fetch the genesis block and check that the hash
108+
// matches whatever is in the L2 rollup config, which it will not when we activate
109+
// Prague, since the autogenerated genesis header will include a requests root of
110+
// `EMPTY_ROOT`. To circumvent this without modifying the OP stack genesis
111+
// generator, we simply remove the requests root manually here.
112+
let mut header = chainspec.genesis_header().clone();
113+
header.requests_root = None;
114+
chainspec.genesis_header = once_cell_set(header);
115+
107116
Arc::new(chainspec)
108117
}
109118
})

crates/node/src/evm.rs

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use alphanet_precompile::secp256r1;
1414
use reth_chainspec::{ChainSpec, EthereumHardfork, Head, OptimismHardfork};
15-
use reth_node_api::{ConfigureEvm, ConfigureEvmEnv};
15+
use reth_node_api::{ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
1616
use reth_primitives::{
1717
revm_primitives::{CfgEnvWithHandlerCfg, TxEnv},
1818
transaction::FillTxEnv,
@@ -22,7 +22,10 @@ use reth_revm::{
2222
handler::register::EvmHandler,
2323
inspector_handle_register,
2424
precompile::PrecompileSpecId,
25-
primitives::{AnalysisKind, Env, OptimismFields},
25+
primitives::{
26+
AnalysisKind, BlobExcessGasAndPrice, BlockEnv, CfgEnv, Env, HandlerCfg, OptimismFields,
27+
SpecId,
28+
},
2629
ContextPrecompiles, Database, Evm, EvmBuilder, GetInspector,
2730
};
2831
use std::sync::Arc;
@@ -65,6 +68,8 @@ impl AlphaNetEvmConfig {
6568
}
6669

6770
impl ConfigureEvmEnv for AlphaNetEvmConfig {
71+
type Header = Header;
72+
6873
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
6974
transaction.fill_tx_env(tx_env, sender);
7075
}
@@ -135,7 +140,89 @@ impl ConfigureEvmEnv for AlphaNetEvmConfig {
135140
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;
136141

137142
cfg_env.handler_cfg.spec_id = spec_id;
138-
cfg_env.handler_cfg.is_optimism = self.chain_spec.is_optimism();
143+
cfg_env.handler_cfg.is_optimism = true;
144+
}
145+
146+
fn fill_block_env(&self, block_env: &mut BlockEnv, header: &Self::Header, after_merge: bool) {
147+
block_env.number = U256::from(header.number);
148+
block_env.coinbase = header.beneficiary;
149+
block_env.timestamp = U256::from(header.timestamp);
150+
if after_merge {
151+
block_env.prevrandao = Some(header.mix_hash);
152+
block_env.difficulty = U256::ZERO;
153+
} else {
154+
block_env.difficulty = header.difficulty;
155+
block_env.prevrandao = None;
156+
}
157+
block_env.basefee = U256::from(header.base_fee_per_gas.unwrap_or_default());
158+
block_env.gas_limit = U256::from(header.gas_limit);
159+
160+
// EIP-4844 excess blob gas of this block, introduced in Cancun
161+
if let Some(excess_blob_gas) = header.excess_blob_gas {
162+
block_env.set_blob_excess_gas_and_price(excess_blob_gas);
163+
}
164+
}
165+
166+
fn next_cfg_and_block_env(
167+
&self,
168+
parent: &Self::Header,
169+
attributes: NextBlockEnvAttributes,
170+
) -> (CfgEnvWithHandlerCfg, BlockEnv) {
171+
// configure evm env based on parent block
172+
let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id());
173+
174+
// ensure we're not missing any timestamp based hardforks
175+
let spec_id = revm_spec(
176+
&self.chain_spec,
177+
&Head {
178+
number: parent.number + 1,
179+
timestamp: attributes.timestamp,
180+
..Default::default()
181+
},
182+
);
183+
184+
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
185+
// cancun now, we need to set the excess blob gas to the default value
186+
let blob_excess_gas_and_price = parent
187+
.next_block_excess_blob_gas()
188+
.or_else(|| {
189+
if spec_id.is_enabled_in(SpecId::CANCUN) {
190+
// default excess blob gas is zero
191+
Some(0)
192+
} else {
193+
None
194+
}
195+
})
196+
.map(BlobExcessGasAndPrice::new);
197+
198+
let block_env = BlockEnv {
199+
number: U256::from(parent.number + 1),
200+
coinbase: attributes.suggested_fee_recipient,
201+
timestamp: U256::from(attributes.timestamp),
202+
difficulty: U256::ZERO,
203+
prevrandao: Some(attributes.prev_randao),
204+
gas_limit: U256::from(parent.gas_limit),
205+
// calculate basefee based on parent block's gas usage
206+
basefee: U256::from(
207+
parent
208+
.next_block_base_fee(
209+
self.chain_spec.base_fee_params_at_timestamp(attributes.timestamp),
210+
)
211+
.unwrap_or_default(),
212+
),
213+
// calculate excess gas based on parent block's blob gas usage
214+
blob_excess_gas_and_price,
215+
};
216+
217+
let cfg_with_handler_cfg;
218+
{
219+
cfg_with_handler_cfg = CfgEnvWithHandlerCfg {
220+
cfg_env: cfg,
221+
handler_cfg: HandlerCfg { spec_id, is_optimism: true },
222+
};
223+
}
224+
225+
(cfg_with_handler_cfg, block_env)
139226
}
140227
}
141228

crates/node/src/node.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::evm::AlphaNetEvmConfig;
77
use reth_chainspec::ChainSpec;
88
use reth_node_api::{FullNodeTypes, NodeTypesWithEngine};
99
use reth_node_builder::{
10-
components::{ComponentsBuilder, ExecutorBuilder},
10+
components::{ComponentsBuilder, ExecutorBuilder, PayloadServiceBuilder},
1111
BuilderContext, Node, NodeTypes,
1212
};
1313
use reth_node_optimism::{
@@ -18,6 +18,8 @@ use reth_node_optimism::{
1818
},
1919
OpExecutorProvider, OptimismEngineTypes,
2020
};
21+
use reth_payload_builder::PayloadBuilderHandle;
22+
use reth_transaction_pool::TransactionPool;
2123

2224
/// Type configuration for a regular AlphaNet node.
2325
#[derive(Debug, Clone, Default)]
@@ -38,7 +40,7 @@ impl AlphaNetNode {
3840
) -> ComponentsBuilder<
3941
Node,
4042
OptimismPoolBuilder,
41-
OptimismPayloadBuilder,
43+
AlphaNetPayloadBuilder,
4244
OptimismNetworkBuilder,
4345
AlphaNetExecutorBuilder,
4446
OptimismConsensusBuilder,
@@ -52,7 +54,7 @@ impl AlphaNetNode {
5254
ComponentsBuilder::default()
5355
.node_types::<Node>()
5456
.pool(OptimismPoolBuilder::default())
55-
.payload(OptimismPayloadBuilder::new(compute_pending_block))
57+
.payload(AlphaNetPayloadBuilder::new(compute_pending_block))
5658
.network(OptimismNetworkBuilder {
5759
disable_txpool_gossip,
5860
disable_discovery_v4: !discovery_v4,
@@ -81,7 +83,7 @@ where
8183
type ComponentsBuilder = ComponentsBuilder<
8284
N,
8385
OptimismPoolBuilder,
84-
OptimismPayloadBuilder,
86+
AlphaNetPayloadBuilder,
8587
OptimismNetworkBuilder,
8688
AlphaNetExecutorBuilder,
8789
OptimismConsensusBuilder,
@@ -118,3 +120,36 @@ where
118120
Ok((evm_config, executor))
119121
}
120122
}
123+
124+
/// The AlphaNet payload service builder.
125+
///
126+
/// This service wraps the default Optimism payload builder, but replaces the default evm config
127+
/// with AlphaNet's own.
128+
#[derive(Debug, Default, Clone)]
129+
pub struct AlphaNetPayloadBuilder {
130+
/// Inner Optimism payload builder service.
131+
inner: OptimismPayloadBuilder,
132+
}
133+
134+
impl AlphaNetPayloadBuilder {
135+
/// Create a new instance with the given `compute_pending_block` flag.
136+
pub const fn new(compute_pending_block: bool) -> Self {
137+
Self { inner: OptimismPayloadBuilder::new(compute_pending_block) }
138+
}
139+
}
140+
141+
impl<Node, Pool> PayloadServiceBuilder<Node, Pool> for AlphaNetPayloadBuilder
142+
where
143+
Node: FullNodeTypes<
144+
Types: NodeTypesWithEngine<Engine = OptimismEngineTypes, ChainSpec = ChainSpec>,
145+
>,
146+
Pool: TransactionPool + Unpin + 'static,
147+
{
148+
async fn spawn_payload_service(
149+
self,
150+
ctx: &BuilderContext<Node>,
151+
pool: Pool,
152+
) -> eyre::Result<PayloadBuilderHandle<OptimismEngineTypes>> {
153+
self.inner.spawn(AlphaNetEvmConfig::new(ctx.chain_spec().clone()), ctx, pool)
154+
}
155+
}

0 commit comments

Comments
 (0)