Skip to content

Commit

Permalink
refactor: remove unused alloy-rpc-types-eth dependency and update Car…
Browse files Browse the repository at this point in the history
…go.toml files
  • Loading branch information
johntaiko committed Dec 23, 2024
1 parent be3a467 commit 47299a6
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 1,382 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

49 changes: 24 additions & 25 deletions crates/evm/execution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ revm.workspace = true
alloy-consensus.workspace = true
alloy-primitives.workspace = true
alloy-eips.workspace = true
alloy-rpc-types-eth.workspace = true

serde = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true }
Expand All @@ -38,34 +37,34 @@ reth-primitives = { workspace = true, features = ["arbitrary", "test-utils"] }
default = ["std"]
optimism = ["reth-primitives/optimism", "revm/optimism"]
serde = [
"dep:serde",
"rand/serde",
"revm/serde",
"alloy-eips/serde",
"alloy-primitives/serde",
"reth-primitives-traits/serde",
"alloy-consensus/serde",
"reth-trie/serde",
"reth-trie-common?/serde"
"dep:serde",
"rand/serde",
"revm/serde",
"alloy-eips/serde",
"alloy-primitives/serde",
"reth-primitives-traits/serde",
"alloy-consensus/serde",
"reth-trie/serde",
"reth-trie-common?/serde",
]
serde-bincode-compat = [
"serde",
"reth-trie-common/serde-bincode-compat",
"reth-primitives/serde-bincode-compat",
"reth-primitives-traits/serde-bincode-compat",
"serde_with",
"alloy-eips/serde-bincode-compat",
"serde",
"reth-trie-common/serde-bincode-compat",
"reth-primitives/serde-bincode-compat",
"reth-primitives-traits/serde-bincode-compat",
"serde_with",
"alloy-eips/serde-bincode-compat",
"alloy-consensus/serde-bincode-compat",
]
std = [
"reth-primitives/std",
"alloy-eips/std",
"alloy-primitives/std",
"revm/std",
"serde?/std",
"reth-primitives-traits/std",
"alloy-consensus/std",
"serde_with?/std"
"reth-primitives/std",
"alloy-eips/std",
"alloy-primitives/std",
"revm/std",
"serde?/std",
"reth-primitives-traits/std",
"alloy-consensus/std",
"serde_with?/std",
]

taiko = ["revm/taiko"]
taiko = ["revm/taiko"]
4 changes: 2 additions & 2 deletions crates/evm/execution-types/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_eips::eip7685::Requests;
use alloy_primitives::U256;
use alloy_rpc_types_eth::transaction::Transaction;
use reth_primitives::TransactionSigned;
use revm::db::BundleState;

/// A helper type for ethereum block inputs that consists of a block and the total difficulty.
Expand Down Expand Up @@ -47,7 +47,7 @@ impl<'a, Block> From<(&'a Block, U256)> for BlockExecutionInput<'a, Block> {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TaskResult {
/// Transactions
pub txs: Vec<Transaction>,
pub txs: Vec<TransactionSigned>,
/// Estimated gas used
pub estimated_gas_used: u64,
/// Bytes length
Expand Down
3 changes: 2 additions & 1 deletion crates/taiko/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ reth-ethereum-consensus.workspace = true
# ethereum
alloy-eips.workspace = true
alloy-primitives.workspace = true
op-alloy-consensus.workspace = true
alloy-consensus.workspace = true
alloy-rlp.workspace = true

# Optimism
reth-taiko-consensus.workspace = true
Expand All @@ -45,6 +45,7 @@ revm-primitives = { workspace = true, features = ["taiko"] }
# misc
derive_more.workspace = true
tracing.workspace = true
flate2.workspace = true

[dev-dependencies]
reth-evm = { workspace = true, features = ["test-utils"] }
Expand Down
76 changes: 40 additions & 36 deletions crates/taiko/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::{Header, Transaction as _};
use alloy_eips::eip7685::Requests;
use core::fmt::Display;
use flate2::write::ZlibEncoder;
use flate2::Compression;
use reth_chainspec::{EthereumHardfork, EthereumHardforks};
use reth_consensus::ConsensusError;
use reth_ethereum_consensus::validate_block_post_execution;
Expand All @@ -19,14 +21,15 @@ use reth_evm::{
ConfigureEvm, TxEnvOverrides,
};
use reth_evm_ethereum::dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS};
use reth_execution_types::BlockExecutionInput;
use reth_execution_types::{BlockExecutionInput, TaskResult};
use reth_primitives::{BlockWithSenders, EthPrimitives, Receipt, TransactionSigned};
use reth_revm::{Database, State};
use reth_taiko_chainspec::TaikoChainSpec;
use reth_taiko_consensus::{check_anchor_tx, decode_ontake_extra_data};
use reth_taiko_forks::TaikoHardforks;
use revm::JournaledState;
use revm::{interpreter::Host, Evm, JournaledState};
use revm_primitives::{db::DatabaseCommit, EnvWithHandlerCfg, HashSet, ResultAndState, U256};
use std::io::{self, Write};
use tracing::debug;

/// Factory for [`OpExecutionStrategy`].
Expand Down Expand Up @@ -102,33 +105,22 @@ where
let system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone());
Self { state, chain_spec, evm_config, system_caller, tx_env_overrides: None }
}
}

impl<DB, EvmConfig> TaikoExecutionStrategy<DB, EvmConfig>
where
DB: Database<Error: Into<ProviderError> + Display>,
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header, Transaction = TransactionSigned>,
{
fn build_transaction_list(
&mut self,
block: &BlockWithSenders,
max_bytes_per_tx_list: u64,
max_transactions_lists: u64,
total_difficulty: U256,
) -> Result<Vec<TaskResult>, BlockExecutionError> {
let env = self.evm_env_for_block(&block.header, U256::ZERO);
let mut evm = self.executor.evm_config.evm_with_env(&mut self.state, env);
// 2. configure the evm and execute
// apply pre execution changes
apply_beacon_root_contract_call(
&self.executor.chain_spec,
block.timestamp,
block.number,
block.parent_beacon_block_root,
&mut evm,
)?;

apply_blockhashes_update(
evm.db_mut(),
&self.executor.chain_spec,
block.timestamp,
block.number,
block.parent_hash,
)?;

let env = self.evm_env_for_block(&block.header, total_difficulty);
let mut evm = self.evm_config.evm_with_env(&mut self.state, env);
let mut target_list: Vec<TaskResult> = vec![];
// get previous env
let previous_env = Box::new(evm.context.env().clone());
Expand All @@ -142,15 +134,15 @@ where
let mut tx_list: Vec<TransactionSigned> = vec![];
let mut buf_len: u64 = 0;

for i in 0..block.body.len() {
let transaction = block.body.get(i).unwrap();
for i in 0..block.body.transactions.len() {
let ref transaction = block.body.transactions[i];
let sender = block.senders.get(i).unwrap();
let block_available_gas = block.header.gas_limit - cumulative_gas_used;
if transaction.gas_limit() > block_available_gas {
break;
}

EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
self.evm_config.fill_tx_env(evm.tx_mut(), &transaction, *sender);

// Execute transaction.
let ResultAndState { result, state } = match evm.transact() {
Expand Down Expand Up @@ -178,11 +170,7 @@ where
break;
}
target_list.push(TaskResult {
txs: tx_list[..]
.iter()
.cloned()
.map(|tx| reth_rpc_types_compat::transaction::from_signed(tx).unwrap())
.collect(),
txs: tx_list,
estimated_gas_used: cumulative_gas_used,
bytes_length: buf_len,
});
Expand Down Expand Up @@ -253,14 +241,22 @@ where
} = input;

if enable_build {
let target_list =
self.build_transaction_list(block, max_bytes_per_tx_list, max_transactions_lists)?;
Ok(ExecuteOutput { receipts: vec![], gas_used: 0, target_list, skipped_list: vec![] })
let target_list = self.build_transaction_list(
block,
max_bytes_per_tx_list,
max_transactions_lists,
total_difficulty,
)?;
return Ok(ExecuteOutput {
receipts: vec![],
gas_used: 0,
target_list,
skipped_list: vec![],
});
}

let env = self.evm_env_for_block(&block.header, total_difficulty);
let mut evm = self.evm_config.evm_with_env(&mut self.state, env);

let mut cumulative_gas_used = 0;
let mut receipts = Vec::with_capacity(block.body.transactions.len());
let mut skipped_transactions = Vec::with_capacity(block.body.transactions.len());
Expand All @@ -286,7 +282,7 @@ where
if transaction.gas_limit() > block_available_gas {
if !is_anchor && enable_skip {
debug!(target: "taiko::executor", hash = ?transaction.hash(), want = ?transaction.gas_limit(), got = block_available_gas, "Invalid gas limit for tx");
skipped_transactions.push(transaction);
skipped_transactions.push(idx);
continue;
}
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
Expand Down Expand Up @@ -330,6 +326,7 @@ where
HashSet::default(),
);
debug!(target: "taiko::executor", hash = ?transaction.hash(), error = ?err, "Invalid execute for tx");
skipped_transactions.push(idx);
continue;
}
return Err(err.into());
Expand Down Expand Up @@ -361,7 +358,7 @@ where
Ok(ExecuteOutput {
receipts,
gas_used: cumulative_gas_used,
skipped_list,
skipped_list: skipped_transactions,
target_list: vec![],
})
}
Expand Down Expand Up @@ -456,3 +453,10 @@ impl TaikoExecutorProvider {
BasicBlockExecutorProvider::new(TaikoExecutionStrategyFactory::taiko(chain_spec))
}
}

fn encode_and_compress_tx_list(txs: &Vec<TransactionSigned>) -> io::Result<Vec<u8>> {
let encoded_buf = alloy_rlp::encode(txs);
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default());
encoder.write_all(&encoded_buf)?;
encoder.finish()
}
46 changes: 0 additions & 46 deletions crates/taiko/evmbakl/Cargo.toml

This file was deleted.

Loading

0 comments on commit 47299a6

Please sign in to comment.