Skip to content

Commit

Permalink
Move edr_provider's cache_dir to ForkConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
iosh committed Dec 16, 2024
1 parent f48a18e commit 738b120
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/edr_generic/tests/issue_570.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn get_provider() -> anyhow::Result<Provider<GenericChainSpec>> {
url: get_alchemy_url().replace("eth-mainnet", "base-sepolia"),
block_number: Some(BLOCK_NUMBER),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));

config.chains.insert(
Expand Down
1 change: 1 addition & 0 deletions crates/edr_napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tracing-flame = { version = "0.2.0", default-features = false, features = ["smal
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["ansi", "env-filter", "fmt", "parking_lot", "smallvec", "std"] }
parking_lot = { version = "0.12.1", default-features = false }
lazy_static = { version = "1.4.0", features = [] }
edr_defaults = { version = "0.3.5", path = "../edr_defaults" }

[target.x86_64-unknown-linux-gnu.dependencies]
openssl-sys = { version = "0.9.93", features = ["vendored"] }
Expand Down
5 changes: 5 additions & 0 deletions crates/edr_napi/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::{
num::NonZeroU64,
path::PathBuf,
time::{Duration, SystemTime},
};

use edr_defaults;
use edr_eth::HashMap;
use edr_provider::AccountConfig;
use napi::{
Expand Down Expand Up @@ -142,6 +144,9 @@ impl TryFrom<ForkConfig> for edr_provider::hardhat_rpc_types::ForkConfig {
url: value.url,
block_number,
http_headers,
cache_dir: value
.cache_dir
.map_or(edr_defaults::CACHE_DIR.into(), PathBuf::from),
})
}
}
Expand Down
9 changes: 1 addition & 8 deletions crates/edr_napi_core/src/provider/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::num::NonZeroU64;
use std::{path::PathBuf, time::SystemTime};
use std::time::SystemTime;

use edr_eth::{account::AccountInfo, block::BlobGas, Address, ChainId, HashMap, B256, U256};
use edr_provider::{
Expand Down Expand Up @@ -52,12 +52,6 @@ where
ChainSpecT: RuntimeSpec<Hardfork: for<'s> From<&'s str>>,
{
fn from(value: Config) -> Self {
let cache_dir = PathBuf::from(
value
.cache_dir
.unwrap_or(String::from(edr_defaults::CACHE_DIR)),
);

let chains = value
.chains
.into_iter()
Expand Down Expand Up @@ -90,7 +84,6 @@ where
bail_on_call_failure: value.bail_on_call_failure,
bail_on_transaction_failure: value.bail_on_transaction_failure,
block_gas_limit: value.block_gas_limit,
cache_dir,
chain_id: value.chain_id,
chains,
coinbase: value.coinbase,
Expand Down
1 change: 1 addition & 0 deletions crates/edr_optimism/tests/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async fn sepolia_call_with_remote_chain_id() -> anyhow::Result<()> {
url: sepolia_url(),
block_number: None,
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));

// Set a different chain ID than the forked chain ID
Expand Down
3 changes: 1 addition & 2 deletions crates/edr_provider/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{num::NonZeroU64, path::PathBuf, time::SystemTime};
use std::{num::NonZeroU64, time::SystemTime};

use derive_where::derive_where;
use edr_eth::{account::AccountInfo, block::BlobGas, Address, ChainId, HashMap, B256, U256};
Expand Down Expand Up @@ -85,7 +85,6 @@ pub struct ProviderConfig<ChainSpecT: RuntimeSpec> {
/// Whether to return an `Err` when a `eth_sendTransaction` fails
pub bail_on_transaction_failure: bool,
pub block_gas_limit: NonZeroU64,
pub cache_dir: PathBuf,
pub chain_id: ChainId,
pub chains: HashMap<ChainId, hardfork::Activations<ChainSpecT>>,
pub coinbase: Address,
Expand Down
8 changes: 5 additions & 3 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ fn create_blockchain_and_state<ChainSpecT: SyncRuntimeSpec<Hardfork: Debug>>(

let rpc_client = Arc::new(EthRpcClient::<ChainSpecT>::new(
&fork_config.url,
config.cache_dir.clone(),
fork_config.cache_dir.clone(),
http_headers.clone(),
)?);

Expand Down Expand Up @@ -3818,10 +3818,11 @@ mod tests {
let mut fixture = ProviderTestFixture::<L1ChainSpec>::new_local()?;

let fork_config = Some(ForkConfig {
json_rpc_url: get_alchemy_url(),
url: get_alchemy_url(),
// Random recent block for better cache consistency
block_number: Some(FORK_BLOCK_NUMBER),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
});

let block_spec = BlockSpec::Number(FORK_BLOCK_NUMBER);
Expand Down Expand Up @@ -3910,9 +3911,10 @@ mod tests {
.build()?;

let default_config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_alchemy_url(),
url: get_alchemy_url(),
block_number: Some(EIP_1559_ACTIVATION_BLOCK),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));

let config = ProviderConfig {
Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/src/requests/hardhat/rpc_types/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};

#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct ResetProviderConfig {
Expand All @@ -12,4 +12,5 @@ pub struct ForkConfig {
pub url: String,
pub block_number: Option<u64>,
pub http_headers: Option<HashMap<String, String>>,
pub cache_dir: PathBuf,
}
2 changes: 1 addition & 1 deletion crates/edr_provider/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn create_test_config_with_fork<ChainSpecT: RuntimeSpec>(
min_gas_price: U256::ZERO,
mining: MiningConfig::default(),
network_id: 123,
cache_dir: edr_defaults::CACHE_DIR.into(),
}
}

Expand Down Expand Up @@ -170,6 +169,7 @@ impl<ChainSpecT: Debug + SyncProviderSpec<CurrentTime>> ProviderTestFixture<Chai
// Random recent block for better cache consistency
block_number: Some(FORK_BLOCK_NUMBER),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}
});

Expand Down
1 change: 1 addition & 0 deletions crates/edr_provider/tests/hardhat_request_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn serde_hardhat_reset() {
url: String::from("http://whatever.com/whatever"),
block_number: Some(123456),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}),
},
)));
Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/tests/issues/issue_324.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ async fn issue_324() -> anyhow::Result<()> {
let subscriber = Box::new(|_event| {});

let mut config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_alchemy_url().replace("mainnet", "sepolia"),
url: get_alchemy_url().replace("mainnet", "sepolia"),
block_number: Some(DEPLOYMENT_BLOCK_NUMBER),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));
config.hardfork = l1::SpecId::CANCUN;

Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/tests/issues/issue_356.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ async fn issue_356() -> anyhow::Result<()> {
let subscriber = Box::new(|_event| {});

let mut config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_alchemy_url().replace("mainnet", "sepolia"),
url: get_alchemy_url().replace("mainnet", "sepolia"),
// Pre-cancun Sepolia block
block_number: Some(4243456),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));
config.hardfork = l1::SpecId::CANCUN;

Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/tests/issues/issue_384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ async fn avalanche_chain_mine_local_block() -> anyhow::Result<()> {
let subscriber = Box::new(|_event| {});

let config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_infura_url().replace("mainnet", "avalanche-mainnet"),
url: get_infura_url().replace("mainnet", "avalanche-mainnet"),
block_number: Some(BLOCK_NUMBER),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));

let provider = Provider::new(
Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/tests/issues/issue_503.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ async fn issue_503() -> anyhow::Result<()> {
let subscriber = Box::new(|_event| {});

let mut config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_alchemy_url(),
url: get_alchemy_url(),
block_number: Some(19_909_475),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));
config.hardfork = l1::SpecId::CANCUN;

Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/tests/issues/issue_533.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ async fn issue_533() -> anyhow::Result<()> {
let subscriber = Box::new(|_event| {});

let mut config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_alchemy_url(),
url: get_alchemy_url(),
block_number: Some(20_384_300),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));

// The default chain id set by Hardhat
Expand Down
3 changes: 2 additions & 1 deletion crates/edr_provider/tests/issues/issue_588.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ async fn issue_588() -> anyhow::Result<()> {
let subscriber = Box::new(|_event| {});

let early_mainnet_fork = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: get_alchemy_url(),
url: get_alchemy_url(),
block_number: Some(2_675_000),
http_headers: None,
cache_dir: edr_defaults::CACHE_DIR.into(),
}));

let current_time_is_1970 = Arc::new(MockTime::with_seconds(0));
Expand Down

0 comments on commit 738b120

Please sign in to comment.