-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: add precompile cache for execution #15928
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
Conversation
CodSpeed Performance ReportMerging #15928 will not alter performanceComparing Summary
|
ref: #13984 |
82a7a16
to
d0b358a
Compare
4946af7
to
324a283
Compare
90b76d8
to
dda55da
Compare
|data: &Bytes, gas_limit: u64| -> PrecompileResult { | ||
Self::new(precompile, cache).call(data, gas_limit) | ||
} | ||
.into() |
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.
can we add a helper constructor to DynPrecompile that accepts a closure, this is easier than doing from conversions which suck a bit for closures
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.
rn there's no way to construct DynPrecompile from just a impl Precompile
, so we'd need a helper for it in alloy-evm first
|data: &Bytes, gas_limit: u64| -> PrecompileResult { | ||
Self::new(precompile, cache).call(data, gas_limit) | ||
} |
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.
this isn't quite right, because this is the precompile fn, which internally now creates a new CachedPrecompile
and invokes it
the conversion we need here Self::new(precompile, cache).into()
authorization_list: authorization_list | ||
.unwrap_or_default() | ||
.into_iter() | ||
.map(Either::Left) | ||
.collect(), |
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.
hmm, this is a bit horrible,
I don't think it's useful to do this for auths individually, but this is a revm api discussion
crates/engine/tree/src/tree/mod.rs
Outdated
if self.config.precompile_cache_enabled() { | ||
let mut evm = self | ||
.evm_config | ||
.evm_for_block(StateProviderDatabase::new(&state_provider), block.header()); | ||
let precompiles = evm.precompiles_mut(); | ||
precompiles.map_precompiles(|_, precompile| { | ||
CachedPrecompile::wrap(precompile, self.precompile_cache.clone()) | ||
}) | ||
} |
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.
this does not yet have effect right? because this evm does not belong to the executor we're instantiating below
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.
yes exactly, we should obtain the evm from the executor, with the current local block executor provider trait we could extend it to get an evm config
d5fe418
to
4b85afa
Compare
fc8b054
to
dbee913
Compare
ad37727
to
2beaf94
Compare
|
||
impl Precompile for CachedPrecompile { | ||
fn call(&self, data: &[u8], gas_limit: u64) -> PrecompileResult { | ||
let key = CacheKey(Bytes::copy_from_slice(data)); |
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.
we can solve this more efficiently because we only need Borrow
here, but we can take care of this seperately.
} | ||
|
||
impl Precompile for CachedPrecompile { | ||
fn call(&self, data: &[u8], gas_limit: u64) -> PrecompileResult { |
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.
this is a lot simpler now compared to what we previously had :D
@@ -581,6 +581,7 @@ impl From<InvalidTransaction> for RpcInvalidTransactionError { | |||
InvalidTransaction::Eip1559NotSupported | | |||
InvalidTransaction::Eip4844NotSupported | | |||
InvalidTransaction::Eip7702NotSupported => Self::TxTypeNotSupported, | |||
_ => todo!(), |
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.
we cant have a todo here
this must be exhaustive and must not panic
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.
sure, done
if spec == SpecId::PRAGUE { | ||
evm = evm.with_precompiles(PrecompilesMap::from_static(prague_custom())); |
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.
this check I dont understand
why do we need this?
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.
it comes from the current example, the custom precompiles come from Prague's https://github.com/paradigmxyz/reth/blob/main/examples/custom-evm/src/main.rs#L110-L124
Closes #13984