Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
27 changes: 26 additions & 1 deletion crates/anvil-polkadot/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anvil_server::ServerConfig;
use clap::Parser;
use foundry_common::shell;
use foundry_config::Chain;
use polkadot_sdk::sp_core::H256;
use rand_08::{SeedableRng, rngs::StdRng};
use std::{net::IpAddr, path::PathBuf, time::Duration};

Expand Down Expand Up @@ -134,7 +135,11 @@ impl NodeArgs {
.with_code_size_limit(self.evm.code_size_limit)
.disable_code_size_limit(self.evm.disable_code_size_limit)
.with_disable_default_create2_deployer(self.evm.disable_default_create2_deployer)
.with_memory_limit(self.evm.memory_limit);
.with_memory_limit(self.evm.memory_limit)
.with_fork_url(self.fork.fork_url)
.with_fork_block_hash(self.fork.fork_block_hash)
.with_fork_delay(self.fork.fork_delay)
.with_fork_retries(self.fork.fork_retries);

let substrate_node_config = SubstrateNodeConfig::new(&anvil_config);

Expand Down Expand Up @@ -245,6 +250,26 @@ pub struct AnvilEvmArgs {
pub memory_limit: Option<u64>,
}

#[derive(Clone, Debug, Parser)]
#[command(next_help_heading = "Fork options")]
pub struct ForkArgs {
/// Fetch state over a remote endpoint instead of starting from an empty state.
#[arg(long = "fork-url", short = 'f', value_name = "URL")]
pub fork_url: Option<String>,

/// Fetch state from a specific block hash over a remote endpoint.
#[arg(long, value_name = "BLOCK")]
pub fork_block_hash: Option<H256>,

/// Delay between RPC requests in milliseconds to avoid rate limiting.
#[arg(long, default_value = "0", value_name = "MS")]
pub fork_delay: u32,

/// Maximum number of retries per RPC request.
#[arg(long, default_value = "3", value_name = "NUM")]
pub fork_retries: u32,
}

/// Clap's value parser for genesis. Loads a genesis.json file.
fn read_genesis_file(path: &str) -> Result<Genesis, String> {
foundry_common::fs::read_json_file(path.as_ref()).map_err(|err| err.to_string())
Expand Down
41 changes: 41 additions & 0 deletions crates/anvil-polkadot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use polkadot_sdk::{
RPC_DEFAULT_MAX_SUBS_PER_CONN, RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN,
},
sc_service,
sp_core::H256,
};
use rand_08::thread_rng;
use serde_json::{Value, json};
Expand Down Expand Up @@ -328,6 +329,14 @@ pub struct AnvilNodeConfig {
pub memory_limit: Option<u64>,
/// Do not print log messages.
pub silent: bool,
/// Fetch state over a remote endpoint instead of starting from an empty state.
pub fork_url: Option<String>,
/// Fetch state from a specific block hash over a remote endpoint.
pub fork_block_hash: Option<H256>,
/// Delay between RPC requests in milliseconds when forking.
pub fork_delay: u32,
/// Maximum number of retries per RPC request when forking.
pub fork_retries: u32,
}

impl AnvilNodeConfig {
Expand Down Expand Up @@ -547,6 +556,10 @@ impl Default for AnvilNodeConfig {
disable_default_create2_deployer: false,
memory_limit: None,
silent: false,
fork_url: None,
fork_block_hash: None,
fork_delay: 0,
fork_retries: 3,
}
}
}
Expand Down Expand Up @@ -850,6 +863,34 @@ impl AnvilNodeConfig {
self.silent = silent;
self
}

/// Sets the fork url
#[must_use]
pub fn with_fork_url(mut self, fork_url: Option<String>) -> Self {
self.fork_url = fork_url;
self
}

/// Sets the fork block
#[must_use]
pub fn with_fork_block_hash(mut self, fork_block_hash: Option<H256>) -> Self {
self.fork_block_hash = fork_block_hash;
self
}

/// Sets the fork delay between RPC requests
#[must_use]
pub fn with_fork_delay(mut self, fork_delay: u32) -> Self {
self.fork_delay = fork_delay;
self
}

/// Sets the fork max retries per RPC request
#[must_use]
pub fn with_fork_retries(mut self, fork_retries: u32) -> Self {
self.fork_retries = fork_retries;
self
}
}

/// Can create dev accounts
Expand Down
Loading