-
Notifications
You must be signed in to change notification settings - Fork 554
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
feat: introducing EvmWiring, a chain-specific configuration #1672
Conversation
fa066f4
to
0f052b5
Compare
@rakita if at any point it is helpful, I'd be happy to upgrade EDR to test the latest changes in our use case 🙂 |
Changes are mostly done and want to merge it as is.
Try to integrate and we can iterate. Reth has a simpler abstraction that creates Evm behind the trait so integration is easier. |
Awesome; I'll integrate today. |
@@ -182,8 +182,7 @@ impl fmt::Display for EofDecodeError { | |||
} | |||
} | |||
|
|||
#[cfg(feature = "std")] | |||
impl std::error::Error for EofDecodeError {} | |||
impl core::error::Error for EofDecodeError {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this increases MSRV to 1.81 https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror
I've been working on integrating the added changes into EDR. The addition of the We are using references to a dynamic trait object (runtime polymorphic) I was able to work around this partially by splitting the For example: let env = Env::boxed(cfg, block, transaction);
let evm_builder = Evm::builder().with_db(WrapDatabaseRef(DatabaseComponents {
state,
block_hash: blockchain,
}));
// NOTE: Precompiles don't have access to the external context but are still typed on the `type ExternalContext` due
// to the `EvmWiring`. This requires duplication of this code into the two branches of the if-else statements below.
// This seems overly restrictive on the typing.
let precompiles: HashMap<Address, ContextPrecompile<Wiring<ChainSpecT, _, ()>>> =
custom_precompiles
.iter()
.map(|(address, precompile)| (*address, ContextPrecompile::from(precompile.clone())))
.collect();
let result = if let Some(debug_context) = debug_context {
let mut evm = evm_builder
.with_external_context(debug_context.data)
.with_env(env)
.append_handler_register(debug_context.register_handles_fn)
.append_handler_register_box(Box::new(move |handler| {
register_precompiles_handles(handler, precompiles.clone());
}))
.build();
evm.transact_commit()
} else {
let mut evm = evm_builder
.with_env(env)
.append_handler_register_box(Box::new(move |handler| {
register_precompiles_handles(handler, precompiles.clone());
}))
.build();
evm.transact_commit()
}?; To keep code as reusable as possible, I think it would be beneficial to restrict trait bounds by the smallest amount as possible. I'm still in the process of adapting these changes, so I'll share more insights as I uncover them. |
@Wodann can you show me an example, and we can start with that? |
For multi-chain support, most of our codebase is generalised on the Introducing the Some other examples are: For an example of how we use the wiring, see this code. We construct a state using runtime parameters here (old code) and here (new code). This is using immutable references, which would be intertwined with the I still haven't gotten the compiler to accept the code, as we need to construct an trait EvmWiring {
type ChainSpec: ChainSpec;
type Database: Database;
type ExternalContext;
} but I am yet to try that. I'll circle when I've given it a try. |
Why would you want to restrict Block to all those generics:
It Looks brittle. I would try with associated types (for Tx) on Block, maybe this is a good path. |
Sure, in this case we that might simplify things. However, there are some places where we need all or large parts of the For the exact reason you mention, we don't want to pollute our codebase with the |
Experiment to see whether it would be possible to separate optimism and mainnet
SpecId
s and other types, such asHaltReason
.I'm curious to hear whether any of this is in line with #918
Supercedes #1378 (to allow editing by maintainers)