@@ -5,9 +5,10 @@ use crate::{
5
5
taiko:: { check_anchor_tx, check_anchor_tx_ontake, check_anchor_tx_pacaya, TaikoData } ,
6
6
EthEvmConfig ,
7
7
} ;
8
+ use anyhow:: Result ;
8
9
use reth_chainspec:: { ChainSpec , MAINNET } ;
9
10
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 } ;
11
12
use reth_evm:: {
12
13
execute:: {
13
14
BatchExecutor , BlockExecutionError , BlockExecutionInput , BlockExecutionOutput ,
@@ -28,15 +29,14 @@ use reth_revm::{
28
29
apply_beacon_root_contract_call, apply_blockhashes_update,
29
30
apply_withdrawal_requests_contract_call, post_block_balance_increments,
30
31
} ,
31
- Evm , State ,
32
- JournaledState ,
32
+ Evm , JournaledState , State ,
33
33
} ;
34
34
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 ,
37
38
} ;
38
39
use std:: sync:: Arc ;
39
- use anyhow:: Result ;
40
40
use tracing:: { debug, warn} ;
41
41
42
42
/// Provides executors to execute regular ethereum blocks
@@ -221,7 +221,9 @@ where
221
221
continue ;
222
222
}
223
223
// 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
+ } ) ;
225
227
}
226
228
227
229
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
@@ -244,7 +246,8 @@ where
244
246
evm. tx_mut ( ) . taiko . is_anchor = is_anchor;
245
247
// set the treasury address
246
248
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 ;
248
251
249
252
// Execute transaction.
250
253
let res = evm. transact ( ) . map_err ( move |err| {
@@ -256,7 +259,8 @@ where
256
259
} ) ;
257
260
if res. is_err ( ) {
258
261
// 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 ( ) ) ;
260
264
261
265
if optimistic {
262
266
match res {
@@ -284,11 +288,13 @@ where
284
288
println ! ( "Invalid tx at {}: {:?}" , idx, invalid_transaction) ;
285
289
// skip the tx
286
290
continue ;
287
- } ,
291
+ }
288
292
_ => {
289
293
// 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
+ }
292
298
} ,
293
299
_ => {
294
300
// Any other type of error is not allowed
@@ -297,6 +303,9 @@ where
297
303
}
298
304
}
299
305
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
+ }
300
309
// append gas used
301
310
cumulative_gas_used += result. gas_used ( ) ;
302
311
if is_taiko {
@@ -344,7 +353,12 @@ where
344
353
vec ! [ ]
345
354
} ;
346
355
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
+ } )
348
362
}
349
363
}
350
364
@@ -368,7 +382,12 @@ pub struct EthBlockExecutor<EvmConfig, DB> {
368
382
impl < EvmConfig , DB > EthBlockExecutor < EvmConfig , DB > {
369
383
/// Creates a new Ethereum block executor.
370
384
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
+ }
372
391
}
373
392
374
393
/// Optimistic execution
@@ -437,7 +456,12 @@ where
437
456
let env = self . evm_env_for_block ( & block. header , total_difficulty) ;
438
457
let output = {
439
458
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
+ )
441
465
} ?;
442
466
443
467
// 3. apply post execution changes
@@ -517,7 +541,14 @@ where
517
541
// NOTE: we need to merge keep the reverts for the bundle retention
518
542
self . state . merge_transitions ( BundleRetention :: Reverts ) ;
519
543
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
+ } )
521
552
}
522
553
}
523
554
0 commit comments