mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
Update transactions.rs (#3094)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -197,22 +197,42 @@ where
|
||||
f(state)
|
||||
}
|
||||
|
||||
async fn evm_env_at(&self, mut at: BlockId) -> EthResult<(CfgEnv, BlockEnv, BlockId)> {
|
||||
async fn evm_env_at(&self, at: BlockId) -> EthResult<(CfgEnv, BlockEnv, BlockId)> {
|
||||
if at.is_pending() {
|
||||
if let Some(pending) = self.client().pending_header()? {
|
||||
let mut cfg = CfgEnv::default();
|
||||
let mut block_env = BlockEnv::default();
|
||||
self.client().fill_block_env_with_header(&mut block_env, &pending.header)?;
|
||||
self.client().fill_cfg_env_with_header(&mut cfg, &pending.header)?;
|
||||
return Ok((cfg, block_env, pending.hash.into()))
|
||||
}
|
||||
// No pending block, use latest
|
||||
at = BlockId::Number(BlockNumberOrTag::Latest);
|
||||
let header = if let Some(pending) = self.client().pending_header()? {
|
||||
pending
|
||||
} else {
|
||||
// no pending block from the CL yet, so we use the latest block and modify the env
|
||||
// values that we can
|
||||
let mut latest = self
|
||||
.client()
|
||||
.latest_header()?
|
||||
.ok_or_else(|| EthApiError::UnknownBlockNumber)?;
|
||||
|
||||
// child block
|
||||
latest.number += 1;
|
||||
// assumed child block is in the next slot
|
||||
latest.timestamp += 12;
|
||||
// base fee of the child block
|
||||
latest.base_fee_per_gas = latest.next_block_base_fee();
|
||||
|
||||
latest
|
||||
};
|
||||
|
||||
let mut cfg = CfgEnv::default();
|
||||
let mut block_env = BlockEnv::default();
|
||||
self.client().fill_block_env_with_header(&mut block_env, &header)?;
|
||||
self.client().fill_cfg_env_with_header(&mut cfg, &header)?;
|
||||
return Ok((cfg, block_env, header.hash.into()))
|
||||
} else {
|
||||
// Use cached values if there is no pending block
|
||||
let block_hash = self
|
||||
.client()
|
||||
.block_hash_for_id(at)?
|
||||
.ok_or_else(|| EthApiError::UnknownBlockNumber)?;
|
||||
let (cfg, env) = self.cache().get_evm_env(block_hash).await?;
|
||||
Ok((cfg, env, block_hash.into()))
|
||||
}
|
||||
let block_hash =
|
||||
self.client().block_hash_for_id(at)?.ok_or_else(|| EthApiError::UnknownBlockNumber)?;
|
||||
let (cfg, env) = self.cache().get_evm_env(block_hash).await?;
|
||||
Ok((cfg, env, block_hash.into()))
|
||||
}
|
||||
|
||||
async fn evm_env_for_raw_block(&self, header: &Header) -> EthResult<(CfgEnv, BlockEnv)> {
|
||||
|
||||
Reference in New Issue
Block a user