Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
alloy-primitives = { version = "1.0", features = ["map"] }
alloy-provider = { version = "1.0.3", default-features = false }
alloy-rpc-types = { version = "1.0.3", features = ["eth"] }
alloy-consensus = { version = "1.0.3", default-features = false }
alloy-chains = { version = "0.2", default-features = false }
alloy-consensus = { version = "1.0.20", default-features = false }
alloy-hardforks = { version = "0.2.12", default-features = false }
alloy-primitives = { version = "1.2", features = ["map"] }
alloy-provider = { version = "1.0.20", default-features = false }
alloy-rpc-types = { version = "1.0.20", features = ["eth"] }

eyre = "0.6"
futures = "0.3"

parking_lot = "0.12"

revm = { version = "24.0.0", features = ["std", "serde"] }
revm = { version = "27.0.2", features = ["std", "serde"] }

serde = "1.0"
serde_json = "1.0"
Expand All @@ -47,7 +49,7 @@ tracing = "0.1"
url = "2"

[dev-dependencies]
alloy-rpc-client = "1.0.3"
alloy-rpc-client = "1.0.20"
tiny_http = "0.12"

# [patch.crates-io]
Expand Down
3 changes: 2 additions & 1 deletion src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ impl DatabaseRef for SharedBackend {
mod tests {
use super::*;
use crate::cache::{BlockchainDbMeta, JsonBlockCacheDB};
use alloy_chains::Chain;
use alloy_provider::ProviderBuilder;
use alloy_rpc_client::ClientBuilder;
use serde::Deserialize;
Expand All @@ -1017,7 +1018,7 @@ mod tests {
let provider = get_http_provider(endpoint);

let any_rpc_block = provider.get_block(BlockId::latest()).hashes().await.unwrap().unwrap();
let _meta = BlockchainDbMeta::default().with_block(&any_rpc_block.inner);
let _meta = BlockchainDbMeta::default().with_block(Chain::mainnet(), &any_rpc_block.inner);
}

#[tokio::test(flavor = "multi_thread")]
Expand Down
17 changes: 14 additions & 3 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//! Cache related abstraction

use alloy_chains::Chain;
use alloy_consensus::BlockHeader;
use alloy_hardforks::EthereumHardfork;
use alloy_primitives::{Address, B256, U256};
use alloy_provider::network::TransactionResponse;
use parking_lot::RwLock;
use revm::{
context::BlockEnv,
context_interface::block::BlobExcessGasAndPrice,
primitives::{
eip4844::{BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN, BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE},
map::{AddressHashMap, HashMap},
KECCAK_EMPTY,
},
Expand Down Expand Up @@ -145,19 +149,26 @@ impl BlockchainDbMeta {
/// Sets the [BlockEnv] of this instance using the provided [alloy_rpc_types::Block]
pub fn with_block<T: TransactionResponse, H: BlockHeader>(
mut self,
chain: Chain,
block: &alloy_rpc_types::Block<T, H>,
) -> Self {
let blob_base_fee_update_fraction =
match EthereumHardfork::from_chain_and_timestamp(chain, block.header.timestamp()) {
Some(EthereumHardfork::Cancun) => BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN,
_ => BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
};

self.block_env = BlockEnv {
number: block.header.number(),
number: U256::from(block.header.number()),
beneficiary: block.header.beneficiary(),
timestamp: block.header.timestamp(),
timestamp: U256::from(block.header.timestamp()),
difficulty: U256::from(block.header.difficulty()),
basefee: block.header.base_fee_per_gas().unwrap_or_default(),
gas_limit: block.header.gas_limit(),
prevrandao: block.header.mix_hash(),
blob_excess_gas_and_price: Some(BlobExcessGasAndPrice::new(
block.header.excess_blob_gas().unwrap_or_default(),
false,
blob_base_fee_update_fraction,
Copy link
Member

Choose a reason for hiding this comment

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

do we really need this, this previously also just defaulted to pre-prague and I believe we only use this to tag the metadata?
should we just use BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE and remove the chainid arg?

Copy link
Member Author

@zerosnacks zerosnacks Jul 10, 2025

Choose a reason for hiding this comment

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

Updated, now we have a builder method set_chain that allows for optional setting of the chain, defaulting to use BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE if none is set. This should be both correct and a good user experience.

)),
};

Expand Down
Loading