Skip to content

Commit f28c71c

Browse files
authored
chore: simplify evm setup (#13864)
1 parent 88de40a commit f28c71c

File tree

13 files changed

+39
-130
lines changed

13 files changed

+39
-130
lines changed

crates/ethereum/evm/src/lib.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,12 @@ impl ConfigureEvmEnv for EthEvmConfig {
230230
impl ConfigureEvm for EthEvmConfig {
231231
type Evm<'a, DB: Database + 'a, I: 'a> = EthEvm<'a, I, DB>;
232232

233-
fn evm_with_env<DB: Database>(
234-
&self,
235-
db: DB,
236-
evm_env: EvmEnv,
237-
tx: TxEnv,
238-
) -> Self::Evm<'_, DB, ()> {
233+
fn evm_with_env<DB: Database>(&self, db: DB, evm_env: EvmEnv) -> Self::Evm<'_, DB, ()> {
239234
EthEvm(
240235
EvmBuilder::default()
241236
.with_db(db)
242237
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
243238
.with_block_env(evm_env.block_env)
244-
.with_tx_env(tx)
245239
.build(),
246240
)
247241
}
@@ -250,7 +244,6 @@ impl ConfigureEvm for EthEvmConfig {
250244
&self,
251245
db: DB,
252246
evm_env: EvmEnv,
253-
tx: TxEnv,
254247
inspector: I,
255248
) -> Self::Evm<'_, DB, I>
256249
where
@@ -263,7 +256,6 @@ impl ConfigureEvm for EthEvmConfig {
263256
.with_external_context(inspector)
264257
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
265258
.with_block_env(evm_env.block_env)
266-
.with_tx_env(tx)
267259
.append_handler_register(inspector_handle_register)
268260
.build(),
269261
)
@@ -319,7 +311,7 @@ mod tests {
319311

320312
let evm_env = EvmEnv::default();
321313

322-
let evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
314+
let evm = evm_config.evm_with_env(db, evm_env.clone());
323315

324316
// Check that the EVM environment
325317
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
@@ -350,7 +342,7 @@ mod tests {
350342
..Default::default()
351343
};
352344

353-
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
345+
let evm = evm_config.evm_with_env(db, evm_env);
354346

355347
// Check that the EVM environment is initialized with the custom environment
356348
assert_eq!(evm.context.evm.inner.env.cfg, cfg);
@@ -376,7 +368,6 @@ mod tests {
376368
number: U256::from(42),
377369
..Default::default()
378370
};
379-
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
380371

381372
let evm_env = EvmEnv {
382373
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
@@ -386,11 +377,10 @@ mod tests {
386377
block_env: block,
387378
};
388379

389-
let evm = evm_config.evm_with_env(db, evm_env.clone(), tx.clone());
380+
let evm = evm_config.evm_with_env(db, evm_env.clone());
390381

391382
// Verify that the block and transaction environments are set correctly
392383
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
393-
assert_eq!(evm.context.evm.env.tx, tx);
394384

395385
// Default spec ID
396386
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
@@ -416,7 +406,7 @@ mod tests {
416406
..Default::default()
417407
};
418408

419-
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
409+
let evm = evm_config.evm_with_env(db, evm_env);
420410

421411
// Check that the spec ID is setup properly
422412
assert_eq!(evm.handler.spec_id(), SpecId::PETERSBURG);
@@ -436,12 +426,7 @@ mod tests {
436426

437427
let evm_env = EvmEnv::default();
438428

439-
let evm = evm_config.evm_with_env_and_inspector(
440-
db,
441-
evm_env.clone(),
442-
Default::default(),
443-
NoOpInspector,
444-
);
429+
let evm = evm_config.evm_with_env_and_inspector(db, evm_env.clone(), NoOpInspector);
445430

446431
// Check that the EVM environment is set to default values
447432
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
@@ -461,7 +446,6 @@ mod tests {
461446

462447
let cfg_env = CfgEnv::default().with_chain_id(111);
463448
let block = BlockEnv::default();
464-
let tx = TxEnv::default();
465449
let evm_env = EvmEnv {
466450
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
467451
cfg_env: cfg_env.clone(),
@@ -470,7 +454,7 @@ mod tests {
470454
block_env: block,
471455
};
472456

473-
let evm = evm_config.evm_with_env_and_inspector(db, evm_env, tx, NoOpInspector);
457+
let evm = evm_config.evm_with_env_and_inspector(db, evm_env, NoOpInspector);
474458

475459
// Check that the EVM environment is set with custom configuration
476460
assert_eq!(evm.context.evm.env.cfg, cfg_env);
@@ -494,15 +478,12 @@ mod tests {
494478
number: U256::from(42),
495479
..Default::default()
496480
};
497-
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
498481
let evm_env = EvmEnv { block_env: block, ..Default::default() };
499482

500-
let evm =
501-
evm_config.evm_with_env_and_inspector(db, evm_env.clone(), tx.clone(), NoOpInspector);
483+
let evm = evm_config.evm_with_env_and_inspector(db, evm_env.clone(), NoOpInspector);
502484

503485
// Verify that the block and transaction environments are set correctly
504486
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
505-
assert_eq!(evm.context.evm.env.tx, tx);
506487
assert_eq!(evm.context.external, NoOpInspector);
507488
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
508489

@@ -525,12 +506,7 @@ mod tests {
525506
..Default::default()
526507
};
527508

528-
let evm = evm_config.evm_with_env_and_inspector(
529-
db,
530-
evm_env.clone(),
531-
Default::default(),
532-
NoOpInspector,
533-
);
509+
let evm = evm_config.evm_with_env_and_inspector(db, evm_env.clone(), NoOpInspector);
534510

535511
// Check that the spec ID is set properly
536512
assert_eq!(evm.handler.spec_id(), SpecId::PETERSBURG);

crates/ethereum/payload/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ where
226226
PayloadBuilderError::Internal(err.into())
227227
})?;
228228

229-
let mut evm = evm_config.evm_with_env(&mut db, evm_env, Default::default());
229+
let mut evm = evm_config.evm_with_env(&mut db, evm_env);
230230

231231
let mut receipts = Vec::new();
232232
while let Some(pool_tx) = best_txs.next() {

crates/evm/src/lib.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,7 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
9090
/// including the spec id and transaction environment.
9191
///
9292
/// This will preserve any handler modifications
93-
fn evm_with_env<DB: Database>(
94-
&self,
95-
db: DB,
96-
evm_env: EvmEnv,
97-
tx: TxEnv,
98-
) -> Self::Evm<'_, DB, ()>;
93+
fn evm_with_env<DB: Database>(&self, db: DB, evm_env: EvmEnv) -> Self::Evm<'_, DB, ()>;
9994

10095
/// Returns a new EVM with the given database configured with `cfg` and `block_env`
10196
/// configuration derived from the given header. Relies on
@@ -106,7 +101,7 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
106101
/// This does not initialize the tx environment.
107102
fn evm_for_block<DB: Database>(&self, db: DB, header: &Self::Header) -> Self::Evm<'_, DB, ()> {
108103
let evm_env = self.cfg_and_block_env(header);
109-
self.evm_with_env(db, evm_env, Default::default())
104+
self.evm_with_env(db, evm_env)
110105
}
111106

112107
/// Returns a new EVM with the given database configured with the given environment settings,
@@ -119,7 +114,6 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
119114
&self,
120115
db: DB,
121116
evm_env: EvmEnv,
122-
tx: TxEnv,
123117
inspector: I,
124118
) -> Self::Evm<'_, DB, I>
125119
where
@@ -138,27 +132,21 @@ where
138132
(*self).evm_for_block(db, header)
139133
}
140134

141-
fn evm_with_env<DB: Database>(
142-
&self,
143-
db: DB,
144-
evm_env: EvmEnv,
145-
tx: TxEnv,
146-
) -> Self::Evm<'_, DB, ()> {
147-
(*self).evm_with_env(db, evm_env, tx)
135+
fn evm_with_env<DB: Database>(&self, db: DB, evm_env: EvmEnv) -> Self::Evm<'_, DB, ()> {
136+
(*self).evm_with_env(db, evm_env)
148137
}
149138

150139
fn evm_with_env_and_inspector<DB, I>(
151140
&self,
152141
db: DB,
153142
evm_env: EvmEnv,
154-
tx_env: TxEnv,
155143
inspector: I,
156144
) -> Self::Evm<'_, DB, I>
157145
where
158146
DB: Database,
159147
I: GetInspector<DB>,
160148
{
161-
(*self).evm_with_env_and_inspector(db, evm_env, tx_env, inspector)
149+
(*self).evm_with_env_and_inspector(db, evm_env, inspector)
162150
}
163151
}
164152

crates/evm/src/system_calls/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ where
131131
DB::Error: Display,
132132
{
133133
let evm_config = self.evm_config.clone();
134-
let mut evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
134+
let mut evm = evm_config.evm_with_env(db, evm_env.clone());
135135

136136
self.apply_blockhashes_contract_call(
137137
evm_env.block_env.timestamp.to(),
@@ -181,7 +181,7 @@ where
181181
DB::Error: Display,
182182
{
183183
let evm_config = self.evm_config.clone();
184-
let mut evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
184+
let mut evm = evm_config.evm_with_env(db, evm_env.clone());
185185

186186
self.apply_beacon_root_contract_call(
187187
evm_env.block_env.timestamp.to(),
@@ -230,7 +230,7 @@ where
230230
DB::Error: Display,
231231
{
232232
let evm_config = self.evm_config.clone();
233-
let mut evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
233+
let mut evm = evm_config.evm_with_env(db, evm_env.clone());
234234

235235
let result = self.apply_withdrawal_requests_contract_call(&mut evm)?;
236236

@@ -263,7 +263,7 @@ where
263263
DB::Error: Display,
264264
{
265265
let evm_config = self.evm_config.clone();
266-
let mut evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
266+
let mut evm = evm_config.evm_with_env(db, evm_env.clone());
267267

268268
let res = self.apply_consolidation_requests_contract_call(&mut evm)?;
269269

0 commit comments

Comments
 (0)