Skip to content

Commit 4471728

Browse files
authored
chore(deps): bump revm 27.0.2 (#53)
* bump for revm 25 compatibility, not clear what BlobExcessGasAndPrice should be - considering it should strictly be derived we could use alloy-hardforks to match the block number. Foundry only instantiates using ::new with the block environment already configured * bump deps * remove with_block, it is no longer possible to reliably set directly from block due to changes in BlobExcessGasAndPrice * bump alloy * re-add with_block * bump to revm 27 * update new `from_chain_and_timestamp` method * bump alloy * remove with_block as it is unused in Foundry * restore test * revert, pass chain as parameter is cleanest in my opinion * add set_chain builder method, default to `mainnet` => Prague * Option<Chain>, default to Prague if not set * fmt * address feedback, meta should also handle chain accordingly * fix, apply default
1 parent c08e79b commit 4471728

File tree

3 files changed

+51
-40
lines changed

3 files changed

+51
-40
lines changed

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ all-features = true
2525
rustdoc-args = ["--cfg", "docsrs"]
2626

2727
[dependencies]
28-
alloy-primitives = { version = "1.0", features = ["map"] }
29-
alloy-provider = { version = "1.0.3", default-features = false }
30-
alloy-rpc-types = { version = "1.0.3", features = ["eth"] }
31-
alloy-consensus = { version = "1.0.3", default-features = false }
28+
alloy-chains = { version = "0.2", default-features = false, features = ["serde"] }
29+
alloy-consensus = { version = "1.0.20", default-features = false }
30+
alloy-hardforks = { version = "0.2.12", default-features = false }
31+
alloy-primitives = { version = "1.2", features = ["map"] }
32+
alloy-provider = { version = "1.0.20", default-features = false }
33+
alloy-rpc-types = { version = "1.0.20", features = ["eth"] }
3234

3335
eyre = "0.6"
3436
futures = "0.3"
3537

3638
parking_lot = "0.12"
3739

38-
revm = { version = "24.0.0", features = ["std", "serde"] }
40+
revm = { version = "27.0.2", features = ["std", "serde"] }
3941

4042
serde = "1.0"
4143
serde_json = "1.0"
@@ -47,7 +49,7 @@ tracing = "0.1"
4749
url = "2"
4850

4951
[dev-dependencies]
50-
alloy-rpc-client = "1.0.3"
52+
alloy-rpc-client = "1.0.20"
5153
tiny_http = "0.12"
5254

5355
# [patch.crates-io]

src/backend.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -997,10 +997,11 @@ impl DatabaseRef for SharedBackend {
997997
mod tests {
998998
use super::*;
999999
use crate::cache::{BlockchainDbMeta, JsonBlockCacheDB};
1000+
use alloy_consensus::BlockHeader;
10001001
use alloy_provider::ProviderBuilder;
10011002
use alloy_rpc_client::ClientBuilder;
10021003
use serde::Deserialize;
1003-
use std::{collections::BTreeSet, fs, path::PathBuf};
1004+
use std::{fs, path::PathBuf};
10041005
use tiny_http::{Response, Server};
10051006

10061007
pub fn get_http_provider(endpoint: &str) -> impl Provider<AnyNetwork> + Clone {
@@ -1017,18 +1018,17 @@ mod tests {
10171018
let provider = get_http_provider(endpoint);
10181019

10191020
let any_rpc_block = provider.get_block(BlockId::latest()).hashes().await.unwrap().unwrap();
1020-
let _meta = BlockchainDbMeta::default().with_block(&any_rpc_block.inner);
1021+
let meta = BlockchainDbMeta::default().with_block(&any_rpc_block.inner);
1022+
1023+
assert_eq!(meta.block_env.number, U256::from(any_rpc_block.header.number()));
10211024
}
10221025

10231026
#[tokio::test(flavor = "multi_thread")]
10241027
async fn shared_backend() {
10251028
let Some(endpoint) = ENDPOINT else { return };
10261029

10271030
let provider = get_http_provider(endpoint);
1028-
let meta = BlockchainDbMeta {
1029-
block_env: Default::default(),
1030-
hosts: BTreeSet::from([endpoint.to_string()]),
1031-
};
1031+
let meta = BlockchainDbMeta::new(Default::default(), endpoint.to_string());
10321032

10331033
let db = BlockchainDb::new(meta, None);
10341034
let backend = SharedBackend::spawn_backend(Arc::new(provider), db.clone(), None).await;
@@ -1076,10 +1076,7 @@ mod tests {
10761076
let Some(endpoint) = ENDPOINT else { return };
10771077

10781078
let provider = get_http_provider(endpoint);
1079-
let meta = BlockchainDbMeta {
1080-
block_env: Default::default(),
1081-
hosts: BTreeSet::from([endpoint.to_string()]),
1082-
};
1079+
let meta = BlockchainDbMeta::new(Default::default(), endpoint.to_string());
10831080

10841081
let db = BlockchainDb::new(meta, None);
10851082
let backend = SharedBackend::spawn_backend(Arc::new(provider), db.clone(), None).await;
@@ -1141,10 +1138,7 @@ mod tests {
11411138
let Some(endpoint) = ENDPOINT else { return };
11421139

11431140
let provider = get_http_provider(endpoint);
1144-
let meta = BlockchainDbMeta {
1145-
block_env: Default::default(),
1146-
hosts: BTreeSet::from([endpoint.to_string()]),
1147-
};
1141+
let meta = BlockchainDbMeta::new(Default::default(), endpoint.to_string());
11481142

11491143
let db = BlockchainDb::new(meta, None);
11501144
let backend = SharedBackend::spawn_backend(Arc::new(provider), db.clone(), None).await;
@@ -1203,10 +1197,7 @@ mod tests {
12031197
let Some(endpoint) = ENDPOINT else { return };
12041198

12051199
let provider = get_http_provider(endpoint);
1206-
let meta = BlockchainDbMeta {
1207-
block_env: Default::default(),
1208-
hosts: BTreeSet::from([endpoint.to_string()]),
1209-
};
1200+
let meta = BlockchainDbMeta::new(Default::default(), endpoint.to_string());
12101201

12111202
let db = BlockchainDb::new(meta, None);
12121203
let backend = SharedBackend::spawn_backend(Arc::new(provider), db.clone(), None).await;
@@ -1255,10 +1246,7 @@ mod tests {
12551246
let Some(endpoint) = ENDPOINT else { return };
12561247

12571248
let provider = get_http_provider(endpoint);
1258-
let meta = BlockchainDbMeta {
1259-
block_env: Default::default(),
1260-
hosts: BTreeSet::from([endpoint.to_string()]),
1261-
};
1249+
let meta = BlockchainDbMeta::new(Default::default(), endpoint.to_string());
12621250

12631251
// create a temporary file
12641252
fs::copy("test-data/storage.json", "test-data/storage-tmp.json").unwrap();
@@ -1413,10 +1401,7 @@ mod tests {
14131401
});
14141402

14151403
let provider = get_http_provider(&endpoint);
1416-
let meta = BlockchainDbMeta {
1417-
block_env: Default::default(),
1418-
hosts: BTreeSet::from([endpoint.to_string()]),
1419-
};
1404+
let meta = BlockchainDbMeta::new(Default::default(), endpoint.to_string());
14201405

14211406
let db = BlockchainDb::new(meta, None);
14221407
let provider_inner = provider.clone();

src/cache.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
//! Cache related abstraction
2+
3+
use alloy_chains::Chain;
24
use alloy_consensus::BlockHeader;
5+
use alloy_hardforks::EthereumHardfork;
36
use alloy_primitives::{Address, B256, U256};
47
use alloy_provider::network::TransactionResponse;
58
use parking_lot::RwLock;
69
use revm::{
710
context::BlockEnv,
811
context_interface::block::BlobExcessGasAndPrice,
912
primitives::{
13+
eip4844::{BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN, BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE},
1014
map::{AddressHashMap, HashMap},
1115
KECCAK_EMPTY,
1216
},
@@ -123,8 +127,11 @@ impl BlockchainDb {
123127
}
124128

125129
/// relevant identifying markers in the context of [BlockchainDb]
126-
#[derive(Clone, Debug, Eq, Serialize, Default)]
130+
#[derive(Clone, Debug, Default, Eq, Serialize)]
127131
pub struct BlockchainDbMeta {
132+
/// The chain of the blockchain of the block environment
133+
#[serde(default, skip_serializing_if = "Option::is_none")]
134+
pub chain: Option<Chain>,
128135
/// The block environment
129136
pub block_env: BlockEnv,
130137
/// All the hosts used to connect to
@@ -139,25 +146,33 @@ impl BlockchainDbMeta {
139146
.and_then(|url| url.host().map(|host| host.to_string()))
140147
.unwrap_or(url);
141148

142-
Self { block_env, hosts: BTreeSet::from([host]) }
149+
Self { chain: None, block_env, hosts: BTreeSet::from([host]) }
143150
}
144151

145-
/// Sets the [BlockEnv] of this instance using the provided [alloy_rpc_types::Block]
152+
/// Sets the [BlockEnv] of this instance using the provided [Chain] and [alloy_rpc_types::Block]
146153
pub fn with_block<T: TransactionResponse, H: BlockHeader>(
147154
mut self,
148155
block: &alloy_rpc_types::Block<T, H>,
149156
) -> Self {
157+
let blob_base_fee_update_fraction =
158+
self.chain.map_or(BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE, |chain| {
159+
match EthereumHardfork::from_chain_and_timestamp(chain, block.header.timestamp()) {
160+
Some(EthereumHardfork::Cancun) => BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN,
161+
_ => BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
162+
}
163+
});
164+
150165
self.block_env = BlockEnv {
151-
number: block.header.number(),
166+
number: U256::from(block.header.number()),
152167
beneficiary: block.header.beneficiary(),
153-
timestamp: block.header.timestamp(),
168+
timestamp: U256::from(block.header.timestamp()),
154169
difficulty: U256::from(block.header.difficulty()),
155170
basefee: block.header.base_fee_per_gas().unwrap_or_default(),
156171
gas_limit: block.header.gas_limit(),
157172
prevrandao: block.header.mix_hash(),
158173
blob_excess_gas_and_price: Some(BlobExcessGasAndPrice::new(
159174
block.header.excess_blob_gas().unwrap_or_default(),
160-
false,
175+
blob_base_fee_update_fraction,
161176
)),
162177
};
163178

@@ -174,9 +189,16 @@ impl BlockchainDbMeta {
174189
self
175190
}
176191

192+
/// Sets the [Chain] of this instance
193+
pub fn set_chain(mut self, chain: Chain) -> Self {
194+
self.chain = Some(chain);
195+
self
196+
}
197+
177198
/// Sets the [BlockEnv] of this instance
178-
pub fn set_block_env(mut self, block_env: revm::context::BlockEnv) {
199+
pub fn set_block_env(mut self, block_env: revm::context::BlockEnv) -> Self {
179200
self.block_env = block_env;
201+
self
180202
}
181203
}
182204

@@ -229,6 +251,7 @@ impl<'de> Deserialize<'de> for BlockchainDbMeta {
229251
// custom deserialize impl to not break existing cache files
230252
#[derive(Deserialize)]
231253
struct Meta {
254+
chain: Option<Chain>,
232255
block_env: BlockEnvBackwardsCompat,
233256
/// all the hosts used to connect to
234257
#[serde(alias = "host")]
@@ -242,8 +265,9 @@ impl<'de> Deserialize<'de> for BlockchainDbMeta {
242265
Single(String),
243266
}
244267

245-
let Meta { block_env, hosts } = Meta::deserialize(deserializer)?;
268+
let Meta { chain, block_env, hosts } = Meta::deserialize(deserializer)?;
246269
Ok(Self {
270+
chain,
247271
block_env: block_env.inner,
248272
hosts: match hosts {
249273
Hosts::Multi(hosts) => hosts,

0 commit comments

Comments
 (0)