Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify some generics #2032

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Didn't even notice

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
Loading