Skip to content

Commit ccff8bd

Browse files
committed
refactor: improve code formatting and structure in execute.rs
1 parent 68e1e0a commit ccff8bd

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

crates/ethereum/evm/src/execute.rs

+47-16
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use crate::{
55
taiko::{check_anchor_tx, check_anchor_tx_ontake, check_anchor_tx_pacaya, TaikoData},
66
EthEvmConfig,
77
};
8+
use anyhow::Result;
89
use reth_chainspec::{ChainSpec, MAINNET};
910
pub use reth_consensus::Consensus;
10-
pub use reth_ethereum_consensus::{EthBeaconConsensus, validate_block_post_execution};
11+
pub use reth_ethereum_consensus::{validate_block_post_execution, EthBeaconConsensus};
1112
use reth_evm::{
1213
execute::{
1314
BatchExecutor, BlockExecutionError, BlockExecutionInput, BlockExecutionOutput,
@@ -28,15 +29,14 @@ use reth_revm::{
2829
apply_beacon_root_contract_call, apply_blockhashes_update,
2930
apply_withdrawal_requests_contract_call, post_block_balance_increments,
3031
},
31-
Evm, State,
32-
JournaledState,
32+
Evm, JournaledState, State,
3333
};
3434
use revm_primitives::{
35-
db::{Database, DatabaseCommit}, Address, BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState,
36-
EVMError, HashSet, SpecId,
35+
db::{Database, DatabaseCommit},
36+
Address, BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, HashSet, ResultAndState,
37+
SpecId,
3738
};
3839
use std::sync::Arc;
39-
use anyhow::Result;
4040
use tracing::{debug, warn};
4141

4242
/// Provides executors to execute regular ethereum blocks
@@ -221,7 +221,9 @@ where
221221
continue;
222222
}
223223
// In all other cases, the tx needs to have a valid signature
224-
return Err(BlockExecutionError::CanonicalRevert { inner: "invalid tx".to_string() });
224+
return Err(BlockExecutionError::CanonicalRevert {
225+
inner: "invalid tx".to_string(),
226+
});
225227
}
226228

227229
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
@@ -244,7 +246,8 @@ where
244246
evm.tx_mut().taiko.is_anchor = is_anchor;
245247
// set the treasury address
246248
evm.tx_mut().taiko.treasury = taiko_data.clone().unwrap().l2_contract;
247-
evm.tx_mut().taiko.basefee_ratio = taiko_data.clone().unwrap().base_fee_config.sharing_pctg;
249+
evm.tx_mut().taiko.basefee_ratio =
250+
taiko_data.clone().unwrap().base_fee_config.sharing_pctg;
248251

249252
// Execute transaction.
250253
let res = evm.transact().map_err(move |err| {
@@ -256,7 +259,8 @@ where
256259
});
257260
if res.is_err() {
258261
// Clear the state for the next tx
259-
evm.context.evm.journaled_state = JournaledState::new(evm.context.evm.journaled_state.spec, HashSet::new());
262+
evm.context.evm.journaled_state =
263+
JournaledState::new(evm.context.evm.journaled_state.spec, HashSet::new());
260264

261265
if optimistic {
262266
match res {
@@ -284,11 +288,13 @@ where
284288
println!("Invalid tx at {}: {:?}", idx, invalid_transaction);
285289
// skip the tx
286290
continue;
287-
},
291+
}
288292
_ => {
289293
// any other error is not allowed
290-
return Err(BlockExecutionError::Validation(BlockValidationError::EVM { hash, error }));
291-
},
294+
return Err(BlockExecutionError::Validation(
295+
BlockValidationError::EVM { hash, error },
296+
));
297+
}
292298
},
293299
_ => {
294300
// Any other type of error is not allowed
@@ -297,6 +303,9 @@ where
297303
}
298304
}
299305
let ResultAndState { result, state } = res?;
306+
if is_taiko && is_anchor && !result.is_success() {
307+
return Err(BlockExecutionError::Other("anchor transaction must be success"));
308+
}
300309
// append gas used
301310
cumulative_gas_used += result.gas_used();
302311
if is_taiko {
@@ -344,7 +353,12 @@ where
344353
vec![]
345354
};
346355

347-
Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used, valid_transaction_indices })
356+
Ok(EthExecuteOutput {
357+
receipts,
358+
requests,
359+
gas_used: cumulative_gas_used,
360+
valid_transaction_indices,
361+
})
348362
}
349363
}
350364

@@ -368,7 +382,12 @@ pub struct EthBlockExecutor<EvmConfig, DB> {
368382
impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB> {
369383
/// Creates a new Ethereum block executor.
370384
pub const fn new(chain_spec: Arc<ChainSpec>, evm_config: EvmConfig, state: State<DB>) -> Self {
371-
Self { executor: EthEvmExecutor { chain_spec, evm_config }, state, optimistic: false, taiko_data: None }
385+
Self {
386+
executor: EthEvmExecutor { chain_spec, evm_config },
387+
state,
388+
optimistic: false,
389+
taiko_data: None,
390+
}
372391
}
373392

374393
/// Optimistic execution
@@ -437,7 +456,12 @@ where
437456
let env = self.evm_env_for_block(&block.header, total_difficulty);
438457
let output = {
439458
let evm = self.executor.evm_config.evm_with_env(&mut self.state, env);
440-
self.executor.execute_state_transitions(block, evm, self.optimistic, self.taiko_data.clone())
459+
self.executor.execute_state_transitions(
460+
block,
461+
evm,
462+
self.optimistic,
463+
self.taiko_data.clone(),
464+
)
441465
}?;
442466

443467
// 3. apply post execution changes
@@ -517,7 +541,14 @@ where
517541
// NOTE: we need to merge keep the reverts for the bundle retention
518542
self.state.merge_transitions(BundleRetention::Reverts);
519543

520-
Ok(BlockExecutionOutput { state: self.state.take_bundle(), receipts, requests, gas_used, db: self.state, valid_transaction_indices })
544+
Ok(BlockExecutionOutput {
545+
state: self.state.take_bundle(),
546+
receipts,
547+
requests,
548+
gas_used,
549+
db: self.state,
550+
valid_transaction_indices,
551+
})
521552
}
522553
}
523554

0 commit comments

Comments
 (0)