From 115d5fea1f5a3adfb355ce46d8a07c5613296e89 Mon Sep 17 00:00:00 2001 From: ceciliaz030 Date: Fri, 19 Jan 2024 03:11:48 +0800 Subject: [PATCH] cleanup --- crates/primitives/src/env.rs | 89 ++++++++++++++++++++++++------------ crates/revm/src/handler.rs | 12 ----- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index fc668cf314..6463077620 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -256,6 +256,7 @@ impl Env { } } + /// EVM configuration. #[derive(Clone, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -464,18 +465,6 @@ pub struct BlockEnv { pub blob_excess_gas_and_price: Option, } -/// Structure holding block blob excess gas and it calculates blob fee. -/// -/// Incorporated as part of the Cancun upgrade via [EIP-4844]. -/// -/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct BlobExcessGasAndPrice { - pub excess_blob_gas: u64, - pub blob_gasprice: u128, -} - impl BlobExcessGasAndPrice { /// Takes excess blob gas and calculated blob fee with [`calc_blob_fee`] pub fn new(excess_blob_gas: u64) -> Self { @@ -487,23 +476,6 @@ impl BlobExcessGasAndPrice { } } -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct OptimismFields { - pub source_hash: Option, - pub mint: Option, - pub is_system_transaction: Option, - /// An enveloped EIP-2718 typed transaction. This is used - /// to compute the L1 tx cost using the L1 block info, as - /// opposed to requiring downstream apps to compute the cost - /// externally. - /// This field is optional to allow the [TxEnv] to be constructed - /// for non-optimism chains when the `optimism` feature is enabled, - /// but the [CfgEnv] `optimism` field is set to false. - pub enveloped_tx: Option, -} - #[cfg(all(feature = "taiko", not(feature = "optimism")))] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -644,6 +616,65 @@ impl TxEnv { } } +/// Structure holding block blob excess gas and it calculates blob fee. +/// +/// Incorporated as part of the Cancun upgrade via [EIP-4844]. +/// +/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BlobExcessGasAndPrice { + /// The excess blob gas of the block. + pub excess_blob_gas: u64, + /// The calculated blob gas price based on the `excess_blob_gas`, See [calc_blob_gasprice] + pub blob_gasprice: u128, +} + +impl BlobExcessGasAndPrice { + /// Creates a new instance by calculating the blob gas price with [`calc_blob_gasprice`]. + pub fn new(excess_blob_gas: u64) -> Self { + let blob_gasprice = calc_blob_gasprice(excess_blob_gas); + Self { + excess_blob_gas, + blob_gasprice, + } + } +} + +/// Additional [TxEnv] fields for optimism. +#[cfg(feature = "optimism")] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct OptimismFields { + /// The source hash is used to make sure that deposit transactions do + /// not have identical hashes. + /// + /// L1 originated deposit transaction source hashes are computed using + /// the hash of the l1 block hash and the l1 log index. + /// L1 attributes deposit source hashes are computed with the l1 block + /// hash and the sequence number = l2 block number - l2 epoch start + /// block number. + /// + /// These two deposit transaction sources specify a domain in the outer + /// hash so there are no collisions. + pub source_hash: Option, + /// The amount to increase the balance of the `from` account as part of + /// a deposit transaction. This is unconditional and is applied to the + /// `from` account even if the deposit transaction fails since + /// the deposit is pre-paid on L1. + pub mint: Option, + /// Whether or not the transaction is a system transaction. + pub is_system_transaction: Option, + /// An enveloped EIP-2718 typed transaction. This is used + /// to compute the L1 tx cost using the L1 block info, as + /// opposed to requiring downstream apps to compute the cost + /// externally. + /// This field is optional to allow the [TxEnv] to be constructed + /// for non-optimism chains when the `optimism` feature is enabled, + /// but the [CfgEnv] `optimism` field is set to false. + pub enveloped_tx: Option, +} + impl Default for TxEnv { fn default() -> Self { Self { diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index 29fa20c8c8..c43b3c3b2a 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -51,18 +51,6 @@ impl<'a, H: Host, EXT: 'a, DB: Database + 'a> Handler<'a, H, EXT, DB> { } } - /// Handler for the taiko - // #[cfg(all(feature = "taiko", not(feature = "optimism")))] - // pub fn taiko() -> Self { - // use crate::taiko::handler; - // Self { - // call_return: mainnet::handle_call_return::, - // calculate_gas_refund: mainnet::calculate_gas_refund::, - // reimburse_caller: handler::handle_reimburse_caller::, - // reward_beneficiary: handler::reward_beneficiary::, - // } - // } - /// Creates handler with variable spec id, inside it will call `mainnet::` for /// appropriate spec. pub fn mainnet_with_spec(spec_id: SpecId) -> Self {