Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement EIP-7685 #8424

Merged
merged 16 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion bin/reth/src/commands/db/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use clap::Parser;
use reth_db::{
cursor::DbCursorRO, database::Database, open_db_read_only, table::Table, transaction::DbTx,
AccountChangeSets, AccountsHistory, AccountsTrie, BlockBodyIndices, BlockOmmers,
AccountChangeSets, AccountsHistory, AccountsTrie, BlockBodyIndices, BlockOmmers, BlockRequests,
BlockWithdrawals, Bytecodes, CanonicalHeaders, DatabaseEnv, HashedAccounts, HashedStorages,
HeaderNumbers, HeaderTerminalDifficulties, Headers, PlainAccountState, PlainStorageState,
PruneCheckpoints, Receipts, StageCheckpointProgresses, StageCheckpoints, StorageChangeSets,
Expand Down Expand Up @@ -98,6 +98,9 @@ impl Command {
Tables::BlockWithdrawals => {
find_diffs::<BlockWithdrawals>(primary_tx, secondary_tx, output_dir)?
}
Tables::BlockRequests => {
find_diffs::<BlockRequests>(primary_tx, secondary_tx, output_dir)?
}
Tables::TransactionBlocks => {
find_diffs::<TransactionBlocks>(primary_tx, secondary_tx, output_dir)?
}
Expand Down
13 changes: 7 additions & 6 deletions bin/reth/src/commands/db/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use human_bytes::human_bytes;
use itertools::Itertools;
use reth_db::{
database::Database, mdbx, static_file::iter_static_files, AccountChangeSets, AccountsHistory,
AccountsTrie, BlockBodyIndices, BlockOmmers, BlockWithdrawals, Bytecodes, CanonicalHeaders,
DatabaseEnv, HashedAccounts, HashedStorages, HeaderNumbers, HeaderTerminalDifficulties,
Headers, PlainAccountState, PlainStorageState, PruneCheckpoints, Receipts,
StageCheckpointProgresses, StageCheckpoints, StorageChangeSets, StoragesHistory, StoragesTrie,
Tables, TransactionBlocks, TransactionHashNumbers, TransactionSenders, Transactions,
VersionHistory,
AccountsTrie, BlockBodyIndices, BlockOmmers, BlockRequests, BlockWithdrawals, Bytecodes,
CanonicalHeaders, DatabaseEnv, HashedAccounts, HashedStorages, HeaderNumbers,
HeaderTerminalDifficulties, Headers, PlainAccountState, PlainStorageState, PruneCheckpoints,
Receipts, StageCheckpointProgresses, StageCheckpoints, StorageChangeSets, StoragesHistory,
StoragesTrie, Tables, TransactionBlocks, TransactionHashNumbers, TransactionSenders,
Transactions, VersionHistory,
};
use reth_fs_util as fs;
use reth_node_core::dirs::{ChainPath, DataDirPath};
Expand Down Expand Up @@ -333,6 +333,7 @@ impl Command {
Tables::BlockBodyIndices => viewer.get_checksum::<BlockBodyIndices>().unwrap(),
Tables::BlockOmmers => viewer.get_checksum::<BlockOmmers>().unwrap(),
Tables::BlockWithdrawals => viewer.get_checksum::<BlockWithdrawals>().unwrap(),
Tables::BlockRequests => viewer.get_checksum::<BlockRequests>().unwrap(),
Tables::Bytecodes => viewer.get_checksum::<Bytecodes>().unwrap(),
Tables::CanonicalHeaders => viewer.get_checksum::<CanonicalHeaders>().unwrap(),
Tables::HashedAccounts => viewer.get_checksum::<HashedAccounts>().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl Command {
match get_single_header(&client, BlockHashOrNumber::Number(block)).await {
Ok(tip_header) => {
info!(target: "reth::cli", ?block, "Successfully fetched block");
return Ok(tip_header.hash());
return Ok(tip_header.hash())
}
Err(error) => {
error!(target: "reth::cli", ?block, %error, "Failed to fetch the block. Retrying...");
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Command {
provider.get_stage_checkpoint(StageId::Finish)?.map(|ch| ch.block_number);
if latest_block_number.unwrap_or_default() >= self.to {
info!(target: "reth::cli", latest = latest_block_number, "Nothing to run");
return Ok(());
return Ok(())
}

let pipeline_events = pipeline.events();
Expand Down
3 changes: 2 additions & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ impl Command {
PruneModes::none(),
);
executor.execute_and_verify_one((&sealed_block.clone().unseal(), td).into())?;
let BatchBlockExecutionOutput { bundle, receipts, first_block } = executor.finalize();
let BatchBlockExecutionOutput { bundle, receipts, requests: _, first_block } =
executor.finalize();
BundleStateWithReceipts::new(bundle, receipts, first_block).write_to_storage(
provider_rw.tx_ref(),
None,
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/commands/stage/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl Command {
tx.clear::<tables::TransactionBlocks>()?;
tx.clear::<tables::BlockOmmers>()?;
tx.clear::<tables::BlockWithdrawals>()?;
tx.clear::<tables::BlockRequests>()?;
tx.put::<tables::StageCheckpoints>(
StageId::Bodies.to_string(),
Default::default(),
Expand Down
1 change: 1 addition & 0 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ mod tests {
body: body.clone().into_iter().map(|tx| tx.into_signed()).collect(),
ommers: Vec::new(),
withdrawals: Some(Withdrawals::default()),
requests: None,
},
body.iter().map(|tx| tx.signer()).collect(),
)
Expand Down
8 changes: 5 additions & 3 deletions crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use reth_blockchain_tree_api::{
error::{BlockchainTreeError, InsertBlockErrorKind},
BlockAttachment, BlockValidationKind,
};
use reth_consensus::{Consensus, ConsensusError};
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
use reth_db::database::Database;
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_execution_errors::BlockExecutionError;
Expand Down Expand Up @@ -210,8 +210,10 @@ impl AppendableChain {
let block = block.unseal();

let state = executor.execute((&block, U256::MAX).into())?;
let BlockExecutionOutput { state, receipts, .. } = state;
externals.consensus.validate_block_post_execution(&block, &receipts)?;
let BlockExecutionOutput { state, receipts, requests, .. } = state;
externals
.consensus
.validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?;

let bundle_state = BundleStateWithReceipts::new(
state,
Expand Down
26 changes: 20 additions & 6 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use reth_beacon_consensus::BeaconEngineMessage;
use reth_consensus::{Consensus, ConsensusError};
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
use reth_engine_primitives::EngineTypes;
use reth_interfaces::executor::{BlockExecutionError, BlockValidationError};
use reth_primitives::{
constants::{EMPTY_TRANSACTIONS, ETHEREUM_BLOCK_GAS_LIMIT},
eip4844::calculate_excess_blob_gas,
proofs, Block, BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithSenders,
ChainSpec, Header, Receipt, Receipts, SealedBlock, SealedHeader, TransactionSigned,
ChainSpec, Header, Receipts, Requests, SealedBlock, SealedHeader, TransactionSigned,
Withdrawals, B256, U256,
};
use reth_provider::{
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Consensus for AutoSealConsensus {
fn validate_block_post_execution(
&self,
_block: &BlockWithSenders,
_receipts: &[Receipt],
_input: PostExecutionInput<'_>,
) -> Result<(), ConsensusError> {
Ok(())
}
Expand Down Expand Up @@ -277,6 +277,7 @@ impl StorageInner {
transactions: &[TransactionSigned],
ommers: &[Header],
withdrawals: Option<&Withdrawals>,
requests: Option<&Requests>,
chain_spec: Arc<ChainSpec>,
) -> Header {
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
Expand Down Expand Up @@ -319,6 +320,7 @@ impl StorageInner {
excess_blob_gas: None,
extra_data: Default::default(),
parent_beacon_block_root: None,
requests_root: requests.map(|r| proofs::calculate_requests_root(&r.0)),
};

if chain_spec.is_cancun_active_at_timestamp(timestamp) {
Expand Down Expand Up @@ -354,11 +356,13 @@ impl StorageInner {
/// Builds and executes a new block with the given transactions, on the provided executor.
///
/// This returns the header of the executed block, as well as the poststate from execution.
#[allow(clippy::too_many_arguments)]
pub(crate) fn build_and_execute<Provider, Executor>(
&mut self,
transactions: Vec<TransactionSigned>,
ommers: Vec<Header>,
withdrawals: Option<Withdrawals>,
requests: Option<Requests>,
provider: &Provider,
chain_spec: Arc<ChainSpec>,
executor: &Executor,
Expand All @@ -367,14 +371,20 @@ impl StorageInner {
Executor: BlockExecutorProvider,
Provider: StateProviderFactory,
{
let header =
self.build_header_template(&transactions, &ommers, withdrawals.as_ref(), chain_spec);
let header = self.build_header_template(
&transactions,
&ommers,
withdrawals.as_ref(),
requests.as_ref(),
chain_spec,
);

let block = Block {
header,
body: transactions,
ommers: ommers.clone(),
withdrawals: withdrawals.clone(),
requests: requests.clone(),
}
.with_recovered_senders()
.ok_or(BlockExecutionError::Validation(BlockValidationError::SenderRecoveryError))?;
Expand All @@ -394,8 +404,12 @@ impl StorageInner {
block.number,
);

// todo(onbjerg): we should not pass requests around as this is building a block, which
// means we need to extract the requests from the execution output and compute the requests
// root here

let Block { mut header, body, .. } = block.block;
let body = BlockBody { transactions: body, ommers, withdrawals };
let body = BlockBody { transactions: body, ommers, withdrawals, requests };

trace!(target: "consensus::auto", ?bundle_state, ?header, ?body, "executed block, calculating state root and completing header");

Expand Down
6 changes: 5 additions & 1 deletion crates/consensus/auto-seal/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use reth_beacon_consensus::{BeaconEngineMessage, ForkchoiceStatus};
use reth_engine_primitives::EngineTypes;
use reth_evm::execute::BlockExecutorProvider;
use reth_primitives::{
Block, ChainSpec, IntoRecoveredTransaction, SealedBlockWithSenders, Withdrawals,
Block, ChainSpec, IntoRecoveredTransaction, Requests, SealedBlockWithSenders, Withdrawals,
};
use reth_provider::{CanonChainTracker, CanonStateNotificationSender, Chain, StateProviderFactory};
use reth_rpc_types::engine::ForkchoiceState;
Expand Down Expand Up @@ -137,12 +137,15 @@ where
})
.unzip();
let ommers = vec![];
// todo(onbjerg): these two dont respect chainspec
let withdrawals = Some(Withdrawals::default());
let requests = Some(Requests::default());

match storage.build_and_execute(
transactions.clone(),
ommers.clone(),
withdrawals.clone(),
requests.clone(),
&client,
chain_spec,
&executor,
Expand Down Expand Up @@ -201,6 +204,7 @@ where
body: transactions,
ommers,
withdrawals,
requests,
};
let sealed_block = block.seal_slow();

Expand Down
Loading
Loading