Skip to content

Commit

Permalink
Merge branch 'main' into emhane/exec-verif-storage-root
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Jan 31, 2025
2 parents a2d539f + bf20c78 commit edc5534
Show file tree
Hide file tree
Showing 73 changed files with 864 additions and 620 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bin/reth-bench/src/bench/new_payload_fcu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ use crate::{
};
use alloy_primitives::B256;
use alloy_provider::{network::AnyRpcBlock, Provider};
use alloy_rpc_types_engine::ForkchoiceState;
use alloy_rpc_types_engine::{ExecutionPayload, ForkchoiceState};
use clap::Parser;
use csv::Writer;
use reth_cli_runner::CliContext;
use reth_node_core::args::BenchmarkArgs;
use reth_primitives::SealedBlock;
use reth_primitives_traits::SealedHeader;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::time::Instant;
use tracing::{debug, info};

Expand Down Expand Up @@ -81,7 +80,8 @@ impl Command {
let versioned_hashes: Vec<B256> =
block.body().blob_versioned_hashes_iter().copied().collect();
let parent_beacon_block_root = block.parent_beacon_block_root;
let payload = block_to_payload(block).0;
let (payload, _) =
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block());

debug!(?block_number, "Sending payload",);

Expand Down
5 changes: 3 additions & 2 deletions bin/reth-bench/src/bench/new_payload_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use crate::{
};
use alloy_primitives::B256;
use alloy_provider::Provider;
use alloy_rpc_types_engine::ExecutionPayload;
use clap::Parser;
use csv::Writer;
use reth_cli_runner::CliContext;
use reth_node_core::args::BenchmarkArgs;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::time::Instant;
use tracing::{debug, info};

Expand Down Expand Up @@ -64,7 +64,8 @@ impl Command {
let versioned_hashes: Vec<B256> =
block.body().blob_versioned_hashes_iter().copied().collect();
let parent_beacon_block_root = block.parent_beacon_block_root;
let payload = block_to_payload(block).0;
let (payload, _) =
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block());

let block_number = payload.block_number();

Expand Down
16 changes: 7 additions & 9 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use parking_lot::RwLock;
use reth_chainspec::ChainInfo;
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_metrics::{metrics::Gauge, Metrics};
use reth_primitives::{
EthPrimitives, NodePrimitives, Receipts, RecoveredBlock, SealedBlock, SealedHeader,
};
use reth_primitives::{EthPrimitives, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
use reth_primitives_traits::{BlockBody as _, SignedTransaction};
use reth_storage_api::StateProviderBox;
use reth_trie::{updates::TrieUpdates, HashedPostState};
Expand Down Expand Up @@ -648,7 +646,7 @@ impl<N: NodePrimitives> BlockState<N> {
}

/// Returns the `Receipts` of executed block that determines the state.
pub fn receipts(&self) -> &Receipts<N::Receipt> {
pub fn receipts(&self) -> &Vec<Vec<N::Receipt>> {
&self.block.execution_outcome().receipts
}

Expand All @@ -660,12 +658,12 @@ impl<N: NodePrimitives> BlockState<N> {
let receipts = self.receipts();

debug_assert!(
receipts.receipt_vec.len() <= 1,
receipts.len() <= 1,
"Expected at most one block's worth of receipts, found {}",
receipts.receipt_vec.len()
receipts.len()
);

receipts.receipt_vec.first().cloned().unwrap_or_default()
receipts.first().cloned().unwrap_or_default()
}

/// Returns a vector of __parent__ `BlockStates`.
Expand Down Expand Up @@ -1244,7 +1242,7 @@ mod tests {

#[test]
fn test_state_receipts() {
let receipts = Receipts { receipt_vec: vec![vec![Receipt::default()]] };
let receipts = vec![vec![Receipt::default()]];
let mut test_block_builder: TestBlockBuilder = TestBlockBuilder::default();
let block =
test_block_builder.get_executed_block_with_receipts(receipts.clone(), B256::random());
Expand Down Expand Up @@ -1532,7 +1530,7 @@ mod tests {
test_block_builder.get_executed_block_with_number(2, block1.recovered_block.hash());

let sample_execution_outcome = ExecutionOutcome {
receipts: Receipts::from_iter([vec![], vec![]]),
receipts: vec![vec![], vec![]],
requests: vec![Requests::default(), Requests::default()],
..Default::default()
};
Expand Down
8 changes: 4 additions & 4 deletions crates/chain-state/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
use alloy_consensus::BlockBody;
use alloy_primitives::{b256, B256};
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{Receipt, Receipts, SealedBlock, TransactionSigned, TxType};
use reth_primitives::{Receipt, SealedBlock, TransactionSigned, TxType};

#[test]
fn test_commit_notification() {
Expand Down Expand Up @@ -334,7 +334,7 @@ mod tests {
};

// Wrap the receipt in a `Receipts` structure, as expected in the `ExecutionOutcome`.
let receipts = Receipts { receipt_vec: vec![vec![receipt1.clone()]] };
let receipts = vec![vec![receipt1.clone()]];

// Define an `ExecutionOutcome` with the created receipts.
let execution_outcome = ExecutionOutcome { receipts, ..Default::default() };
Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {
success: false,
..Default::default()
};
let old_receipts = Receipts { receipt_vec: vec![vec![old_receipt.clone()]] };
let old_receipts = vec![vec![old_receipt.clone()]];

let old_execution_outcome =
ExecutionOutcome { receipts: old_receipts, ..Default::default() };
Expand Down Expand Up @@ -424,7 +424,7 @@ mod tests {
success: true,
..Default::default()
};
let new_receipts = Receipts { receipt_vec: vec![vec![new_receipt.clone()]] };
let new_receipts = vec![vec![new_receipt.clone()]];

let new_execution_outcome =
ExecutionOutcome { receipts: new_receipts, ..Default::default() };
Expand Down
17 changes: 8 additions & 9 deletions crates/chain-state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS};
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{
transaction::SignedTransactionIntoRecoveredExt, BlockBody, EthPrimitives, NodePrimitives,
Receipt, Receipts, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction,
TransactionSigned,
Receipt, Recovered, RecoveredBlock, SealedBlock, SealedHeader, Transaction, TransactionSigned,
};
use reth_primitives_traits::{
proofs::{calculate_receipt_root, calculate_transaction_root, calculate_withdrawals_root},
Expand Down Expand Up @@ -204,11 +203,11 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
fork
}

/// Gets an [`ExecutedBlockWithTrieUpdates`] with [`BlockNumber`], [`Receipts`] and parent hash.
/// Gets an [`ExecutedBlockWithTrieUpdates`] with [`BlockNumber`], receipts and parent hash.
fn get_executed_block(
&mut self,
block_number: BlockNumber,
receipts: Receipts,
receipts: Vec<Vec<Receipt>>,
parent_hash: B256,
) -> ExecutedBlockWithTrieUpdates {
let block_with_senders = self.generate_random_block(block_number, parent_hash);
Expand All @@ -227,10 +226,10 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
)
}

/// Generates an [`ExecutedBlockWithTrieUpdates`] that includes the given [`Receipts`].
/// Generates an [`ExecutedBlockWithTrieUpdates`] that includes the given receipts.
pub fn get_executed_block_with_receipts(
&mut self,
receipts: Receipts,
receipts: Vec<Vec<Receipt>>,
parent_hash: B256,
) -> ExecutedBlockWithTrieUpdates {
let number = rand::thread_rng().gen::<u64>();
Expand All @@ -243,7 +242,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
block_number: BlockNumber,
parent_hash: B256,
) -> ExecutedBlockWithTrieUpdates {
self.get_executed_block(block_number, Receipts { receipt_vec: vec![vec![]] }, parent_hash)
self.get_executed_block(block_number, vec![vec![]], parent_hash)
}

/// Generates a range of executed blocks with ascending block numbers.
Expand Down Expand Up @@ -296,12 +295,12 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {

let execution_outcome = ExecutionOutcome::new(
bundle_state_builder.build(),
vec![vec![]].into(),
vec![vec![]],
block.number,
Vec::new(),
);

execution_outcome.with_receipts(Receipts::from(receipts))
execution_outcome.with_receipts(vec![receipts])
}
}

Expand Down
11 changes: 0 additions & 11 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,6 @@ impl ChainSpec {
}
}

/// Get the [`BlobParams`] for the given timestamp.
///
/// Note: This always return [`BlobParams::cancun`] pre prague.
pub fn blob_fee_params_at_timestamp(&self, timestamp: u64) -> BlobParams {
if self.is_prague_active_at_timestamp(timestamp) {
self.blob_params.prague
} else {
self.blob_params.cancun
}
}

/// Get the hash of the genesis block.
pub fn genesis_hash(&self) -> B256 {
*self.genesis_hash.get_or_init(|| self.genesis_header().hash_slow())
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ reth-stages-api.workspace = true

# alloy
alloy-consensus.workspace = true
alloy-primitives.workspace = true
alloy-primitives = { workspace = true, features = ["getrandom"] }
alloy-rpc-types-engine.workspace = true

# async
Expand Down
1 change: 1 addition & 0 deletions crates/engine/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-errors.workspace = true
reth-chainspec.workspace = true
reth-consensus-common.workspace = true
reth-fs-util.workspace = true
reth-rpc-types-compat.workspace = true
Expand Down
22 changes: 8 additions & 14 deletions crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Stream wrapper that simulates reorgs.
use alloy_consensus::{Header, Transaction};
use alloy_eips::eip7840::BlobParams;
use alloy_rpc_types_engine::{
CancunPayloadFields, ExecutionPayload, ExecutionPayloadSidecar, ForkchoiceState, PayloadStatus,
};
use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt};
use itertools::Either;
use reth_chainspec::EthChainSpec;
use reth_engine_primitives::{
BeaconEngineMessage, BeaconOnNewPayloadError, EngineTypes, OnForkChoiceUpdated,
};
Expand All @@ -18,17 +18,14 @@ use reth_evm::{
};
use reth_payload_primitives::EngineApiMessageVersion;
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{
transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt, Receipts,
};
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt};
use reth_primitives_traits::{block::Block as _, proofs, SignedTransaction};
use reth_provider::{BlockReader, ExecutionOutcome, ProviderError, StateProviderFactory};
use reth_revm::{
database::StateProviderDatabase,
db::{states::bundle_state::BundleRetention, State},
DatabaseCommit,
};
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::{
collections::VecDeque,
future::Future,
Expand Down Expand Up @@ -110,7 +107,7 @@ where
Engine: EngineTypes,
Provider: BlockReader<Block = reth_primitives::Block> + StateProviderFactory,
Evm: ConfigureEvm<Header = Header, Transaction = reth_primitives::TransactionSigned>,
Spec: EthereumHardforks,
Spec: EthChainSpec + EthereumHardforks,
{
type Item = S::Item;

Expand Down Expand Up @@ -257,7 +254,7 @@ fn create_reorg_head<Provider, Evm, Spec>(
where
Provider: BlockReader<Block = reth_primitives::Block> + StateProviderFactory,
Evm: ConfigureEvm<Header = Header, Transaction = reth_primitives::TransactionSigned>,
Spec: EthereumHardforks,
Spec: EthChainSpec + EthereumHardforks,
{
let chain_spec = payload_validator.chain_spec();

Expand Down Expand Up @@ -374,18 +371,15 @@ where

let outcome: ExecutionOutcome = ExecutionOutcome::new(
state.take_bundle(),
Receipts::from(vec![receipts]),
vec![receipts],
reorg_target.number,
Default::default(),
);
let hashed_state = state_provider.hashed_post_state(outcome.state());

let (blob_gas_used, excess_blob_gas) =
if chain_spec.is_cancun_active_at_timestamp(reorg_target.timestamp) {
(
Some(sum_blob_gas_used),
reorg_target_parent.next_block_excess_blob_gas(BlobParams::cancun()),
)
if let Some(blob_params) = chain_spec.blob_params_at_timestamp(reorg_target.timestamp) {
(Some(sum_blob_gas_used), reorg_target_parent.next_block_excess_blob_gas(blob_params))
} else {
(None, None)
};
Expand Down Expand Up @@ -426,7 +420,7 @@ where
.seal_slow();

Ok((
block_to_payload(reorg_block).0,
ExecutionPayload::from_block_unchecked(reorg_block.hash(), &reorg_block.into_block()).0,
// todo(onbjerg): how do we support execution requests?
reorg_target
.header
Expand Down
10 changes: 2 additions & 8 deletions crates/ethereum/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use alloy_consensus::EMPTY_OMMER_ROOT_HASH;
use alloy_eips::{eip7840::BlobParams, merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS};
use alloy_eips::merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS;
use alloy_primitives::U256;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_consensus::{
Expand Down Expand Up @@ -192,13 +192,7 @@ where
)?;

// ensure that the blob gas fields for this block
if self.chain_spec.is_cancun_active_at_timestamp(header.timestamp()) {
let blob_params = if self.chain_spec.is_prague_active_at_timestamp(header.timestamp()) {
BlobParams::prague()
} else {
BlobParams::cancun()
};

if let Some(blob_params) = self.chain_spec.blob_params_at_timestamp(header.timestamp()) {
validate_against_parent_4844(header.header(), parent.header(), blob_params)?;
}

Expand Down
Loading

0 comments on commit edc5534

Please sign in to comment.