Skip to content

Commit

Permalink
chore: simplify some generics (#2032)
Browse files Browse the repository at this point in the history
* wip

* chore: simplify generics
  • Loading branch information
klkvr authored Jan 28, 2025
1 parent 4c77354 commit 6e98049
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions crates/context/interface/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<HaltReasonT> HaltReasonTrait for HaltReasonT where

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ResultAndState<HaltReasonT: HaltReasonTrait> {
pub struct ResultAndState<HaltReasonT: HaltReasonTrait = HaltReason> {
/// Status of execution
pub result: ExecutionResult<HaltReasonT>,
/// State that got updated
Expand All @@ -37,7 +37,7 @@ impl<HaltReasonT: HaltReasonTrait> ResultAndState<HaltReasonT> {
/// Result of a transaction execution
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ExecutionResult<HaltReasonT: HaltReasonTrait> {
pub enum ExecutionResult<HaltReasonT: HaltReasonTrait = HaltReason> {
/// Returned successfully
Success {
reason: SuccessReason,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Output {
/// Main EVM error
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EVMError<DBError, TransactionError> {
pub enum EVMError<DBError, TransactionError = InvalidTransaction> {
/// Transaction validation error
Transaction(TransactionError),
/// Header validation error
Expand Down
17 changes: 12 additions & 5 deletions crates/context/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{vec, vec::Vec};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub struct CfgEnv<SPEC: Into<SpecId> = SpecId> {
pub struct CfgEnv<SPEC = SpecId> {
/// Chain ID of the EVM
///
/// `chain_id` will be compared to the transaction's Chain ID.
Expand Down Expand Up @@ -77,7 +77,14 @@ pub struct CfgEnv<SPEC: Into<SpecId> = SpecId> {
pub disable_base_fee: bool,
}

impl<SPEC: Into<SpecId>> CfgEnv<SPEC> {
impl CfgEnv {
/// Creates new `CfgEnv` with default values.
pub fn new() -> Self {
Self::default()
}
}

impl<SPEC> CfgEnv<SPEC> {
pub fn with_chain_id(mut self, chain_id: u64) -> Self {
self.chain_id = chain_id;
self
Expand Down Expand Up @@ -196,12 +203,12 @@ impl<SPEC: Into<SpecId> + Copy> Cfg for CfgEnv<SPEC> {
}
}

impl Default for CfgEnv {
impl<SPEC: Default> Default for CfgEnv<SPEC> {
fn default() -> Self {
Self {
chain_id: 1,
limit_contract_code_size: None,
spec: SpecId::PRAGUE,
spec: Default::default(),
disable_nonce_check: false,
blob_target_and_max_count: vec![(SpecId::CANCUN, 3, 6), (SpecId::PRAGUE, 6, 9)],
#[cfg(feature = "memory_limit")]
Expand All @@ -226,7 +233,7 @@ mod test {

#[test]
fn blob_max_and_target_count() {
let cfg = CfgEnv::default();
let cfg: CfgEnv = Default::default();
assert_eq!(cfg.blob_max_count(SpecId::BERLIN), (6));
assert_eq!(cfg.blob_max_count(SpecId::CANCUN), (6));
assert_eq!(cfg.blob_max_count(SpecId::PRAGUE), (9));
Expand Down
10 changes: 4 additions & 6 deletions crates/inspector/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use revm::{
};
use std::vec::Vec;

pub trait InspectEvm<CTX, INTR: InterpreterTypes>: ExecuteEvm {
pub trait InspectEvm<INTR: InterpreterTypes>: ExecuteEvm {
fn inspect<'a, 'b, INSP>(&'a mut self, tx: Self::Transaction, inspector: INSP) -> Self::Output
where
INSP: Inspector<&'a mut Self, INTR> + 'b,
Expand All @@ -45,7 +45,7 @@ impl<
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
CHAIN,
> InspectEvm<&mut Self, EthInterpreter> for Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>
> InspectEvm<EthInterpreter> for Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>
{
fn inspect_previous<'a, 'b, INSP>(&'a mut self, inspector: INSP) -> Self::Output
where
Expand All @@ -56,9 +56,7 @@ impl<
}
}

pub trait InspectCommitEvm<CTX, INTR: InterpreterTypes>:
InspectEvm<CTX, INTR> + ExecuteCommitEvm
{
pub trait InspectCommitEvm<INTR: InterpreterTypes>: InspectEvm<INTR> + ExecuteCommitEvm {
fn inspect_commit<'a, 'b, INSP>(
&'a mut self,
tx: Self::Transaction,
Expand All @@ -83,7 +81,7 @@ impl<
DB: Database + DatabaseCommit,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
CHAIN,
> InspectCommitEvm<&mut Self, EthInterpreter> for Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>
> InspectCommitEvm<EthInterpreter> for Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>
{
fn inspect_commit_previous<'a, 'b, INSP>(&'a mut self, inspector: INSP) -> Self::CommitOutput
where
Expand Down
8 changes: 3 additions & 5 deletions crates/optimism/src/api/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<
CFG: Cfg<Spec = crate::OpSpec>,
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
> InspectEvm<&mut Self, EthInterpreter> for OpContext<BLOCK, TX, CFG, DB, JOURNAL>
> InspectEvm<EthInterpreter> for OpContext<BLOCK, TX, CFG, DB, JOURNAL>
{
fn inspect_previous<'a, 'b, INSP>(&'a mut self, inspector: INSP) -> Self::Output
where
Expand All @@ -43,9 +43,7 @@ impl<
}
}

pub trait InspectCommitEvm<CTX, INTR: InterpreterTypes>:
InspectEvm<CTX, INTR> + ExecuteCommitEvm
{
pub trait InspectCommitEvm<INTR: InterpreterTypes>: InspectEvm<INTR> + ExecuteCommitEvm {
fn inspect_commit<'a, 'b, INSP>(
&'a mut self,
tx: Self::Transaction,
Expand All @@ -69,7 +67,7 @@ impl<
CFG: Cfg<Spec = OpSpec>,
DB: Database + DatabaseCommit,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
> InspectCommitEvm<&mut Self, EthInterpreter> for OpContext<BLOCK, TX, CFG, DB, JOURNAL>
> InspectCommitEvm<EthInterpreter> for OpContext<BLOCK, TX, CFG, DB, JOURNAL>
{
fn inspect_commit_previous<'a, 'b, INSP>(&'a mut self, inspector: INSP) -> Self::CommitOutput
where
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/src/api/into_optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl DefaultOp
fn default_op() -> Self {
Context::default()
.with_tx(OpTransaction::default())
.with_cfg(CfgEnv::default().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_chain(L1BlockInfo::default())
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Default for OpContext {
Self(
Context::default()
.with_tx(OpTransaction::default())
.with_cfg(CfgEnv::default().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_chain(L1BlockInfo::default()),
)
}
Expand All @@ -55,7 +55,7 @@ impl OpContext {
> {
Context::default()
.with_tx(OpTransaction::default())
.with_cfg(CfgEnv::default().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_chain(L1BlockInfo::default())
}
}
Expand Down

0 comments on commit 6e98049

Please sign in to comment.