Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Nov 28, 2024
1 parent fd95c98 commit 4eeaccd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
15 changes: 10 additions & 5 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_chains::{Chain, NamedChain};
use alloy_consensus::constants::EMPTY_WITHDRAWALS;
use alloy_eips::{
eip1559::INITIAL_BASE_FEE, eip6110::MAINNET_DEPOSIT_CONTRACT_ADDRESS,
eip1559::INITIAL_BASE_FEE, eip4844, eip6110::MAINNET_DEPOSIT_CONTRACT_ADDRESS,
eip7685::EMPTY_REQUESTS_HASH,
};
use alloy_genesis::Genesis;
Expand Down Expand Up @@ -286,10 +286,14 @@ impl ChainSpec {
(None, None, None)
};

// If Prague is activated at genesis we set requests root to an empty trie root.
let requests_hash = self
.is_prague_active_at_timestamp(self.genesis.timestamp)
.then_some(EMPTY_REQUESTS_HASH);
// If Prague is activated at genesis we set requests root to an empty trie root and
// `target_blobs_per_block` to EIP-4844 constant.
let (requests_hash, target_blobs_per_block) =
if self.is_prague_active_at_timestamp(self.genesis.timestamp) {
(Some(EMPTY_REQUESTS_HASH), Some(eip4844::TARGET_BLOBS_PER_BLOCK))
} else {
(None, None)
};

Header {
gas_limit: self.genesis.gas_limit,
Expand All @@ -306,6 +310,7 @@ impl ChainSpec {
blob_gas_used: blob_gas_used.map(Into::into),
excess_blob_gas: excess_blob_gas.map(Into::into),
requests_hash,
target_blobs_per_block,
..Default::default()
}
}
Expand Down
8 changes: 6 additions & 2 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ pub async fn setup<N>(
num_nodes: usize,
chain_spec: Arc<N::ChainSpec>,
is_dev: bool,
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Copy + 'static,
attributes_generator: impl Fn(&N::ChainSpec, u64) -> <N::Engine as PayloadTypes>::PayloadBuilderAttributes
+ Copy
+ 'static,
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
where
N: Default + Node<TmpNodeAdapter<N>> + NodeTypesForTree + NodeTypesWithEngine,
Expand Down Expand Up @@ -114,7 +116,9 @@ pub async fn setup_engine<N>(
num_nodes: usize,
chain_spec: Arc<N::ChainSpec>,
is_dev: bool,
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Copy + 'static,
attributes_generator: impl Fn(&N::ChainSpec, u64) -> <N::Engine as PayloadTypes>::PayloadBuilderAttributes
+ Copy
+ 'static,
) -> eyre::Result<(
Vec<NodeHelperType<N, N::AddOns, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>,
TaskManager,
Expand Down
7 changes: 6 additions & 1 deletion crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ where
/// Creates a new test node
pub async fn new(
node: FullNode<Node, AddOns>,
attributes_generator: impl Fn(u64) -> Engine::PayloadBuilderAttributes + 'static,
attributes_generator: impl Fn(&<Node::Types as NodeTypes>::ChainSpec, u64) -> Engine::PayloadBuilderAttributes
+ 'static,
) -> eyre::Result<Self> {
let builder = node.payload_builder.clone();

let chain_spec = node.chain_spec();

let attributes_generator = move |timestamp| attributes_generator(&chain_spec, timestamp);

Ok(Self {
inner: node.clone(),
payload: PayloadTestContext::new(builder, attributes_generator).await?,
Expand Down
6 changes: 3 additions & 3 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,9 @@ mod tests {
let receipt = receipts.first().unwrap();
assert!(receipt.success);

assert!(requests[0].is_empty(), "there should be no deposits");
assert!(!requests[1].is_empty(), "there should be a withdrawal");
assert!(requests[2].is_empty(), "there should be no consolidations");
// There should be exactly one entry with withdrawal requests
assert_eq!(requests.len(), 1);
assert_eq!(requests[0][0], 1);
}

#[test]
Expand Down
10 changes: 7 additions & 3 deletions crates/ethereum/node/tests/e2e/utils.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
use alloy_primitives::{Address, B256};
use reth::rpc::types::engine::PayloadAttributes;
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_payload_builder::EthPayloadBuilderAttributes;

/// Helper function to create a new eth payload attributes
pub(crate) fn eth_payload_attributes(timestamp: u64) -> EthPayloadBuilderAttributes {
pub(crate) fn eth_payload_attributes(
chain_spec: &ChainSpec,
timestamp: u64,
) -> EthPayloadBuilderAttributes {
let attributes = PayloadAttributes {
timestamp,
prev_randao: B256::ZERO,
suggested_fee_recipient: Address::ZERO,
withdrawals: Some(vec![]),
parent_beacon_block_root: Some(B256::ZERO),
target_blobs_per_block: Some(3),
max_blobs_per_block: Some(6),
target_blobs_per_block: chain_spec.is_prague_active_at_timestamp(timestamp).then_some(3),
max_blobs_per_block: chain_spec.is_prague_active_at_timestamp(timestamp).then_some(6),
};
EthPayloadBuilderAttributes::new(B256::ZERO, attributes)
}
7 changes: 5 additions & 2 deletions crates/optimism/node/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reth::{rpc::types::engine::PayloadAttributes, tasks::TaskManager};
use reth_e2e_test_utils::{
transaction::TransactionTestContext, wallet::Wallet, Adapter, NodeHelperType,
};
use reth_optimism_chainspec::OpChainSpecBuilder;
use reth_optimism_chainspec::{OpChainSpec, OpChainSpecBuilder};
use reth_payload_builder::EthPayloadBuilderAttributes;
use std::sync::Arc;
use tokio::sync::Mutex;
Expand Down Expand Up @@ -49,7 +49,10 @@ pub async fn advance_chain(
}

/// Helper function to create a new eth payload attributes
pub fn optimism_payload_attributes(timestamp: u64) -> OpPayloadBuilderAttributes {
pub fn optimism_payload_attributes(
_chain_spec: &OpChainSpec,
timestamp: u64,
) -> OpPayloadBuilderAttributes {
let attributes = PayloadAttributes {
timestamp,
prev_randao: B256::ZERO,
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloy_consensus::{constants::MAXIMUM_EXTRA_DATA_SIZE, Header, EMPTY_OMMER_RO
use alloy_eips::{
eip2718::{Decodable2718, Encodable2718},
eip4895::Withdrawals,
eip7685::Requests,
};
use alloy_primitives::{B256, U256};
use alloy_rpc_types_engine::{
Expand Down Expand Up @@ -271,7 +270,8 @@ pub fn try_into_block(
};

base_payload.header.parent_beacon_block_root = sidecar.parent_beacon_block_root();
base_payload.header.requests_hash = sidecar.requests().map(Requests::requests_hash);
base_payload.header.requests_hash = sidecar.requests_hash();
base_payload.header.target_blobs_per_block = sidecar.target_blobs_per_block();

Ok(base_payload)
}
Expand Down

0 comments on commit 4eeaccd

Please sign in to comment.