Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anvil): Add memery limit to anvil node #7482

Merged
merged 11 commits into from
Mar 25, 2024
4 changes: 4 additions & 0 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ pub struct NodeArgs {

#[command(flatten)]
pub server_config: ServerConfig,
/// customize the memory limit layer of the anvil node
#[arg(long, visible_alias = "memory-limit")]
pub memory_limit: Option<u64>,
}

#[cfg(windows)]
Expand Down Expand Up @@ -235,6 +238,7 @@ impl NodeArgs {
.with_optimism(self.evm_opts.optimism)
.with_disable_default_create2_deployer(self.evm_opts.disable_default_create2_deployer)
.with_slots_in_an_epoch(self.slots_in_an_epoch)
.with_memory_limit(self.memory_limit)
}

fn account_generator(&self) -> AccountGenerator {
Expand Down
10 changes: 10 additions & 0 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ pub struct NodeConfig {
pub enable_optimism: bool,
/// Slots in an epoch
pub slots_in_an_epoch: u64,
/// Memory configuration layer
pub memory_limit: Option<u64>,
}

impl NodeConfig {
Expand Down Expand Up @@ -407,11 +409,18 @@ impl Default for NodeConfig {
disable_default_create2_deployer: false,
enable_optimism: false,
slots_in_an_epoch: 32,
memory_limit: Some(10000),
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

impl NodeConfig {
/// Returns the memory limit of the node
#[must_use]
pub fn with_memory_limit(mut self, mems_value: Option<u64>) -> Self {
self.memory_limit = mems_value;
self
}
/// Returns the base fee to use
pub fn get_base_fee(&self) -> U256 {
self.base_fee
Expand Down Expand Up @@ -830,6 +839,7 @@ impl NodeConfig {
cfg.disable_eip3607 = true;
cfg.disable_block_gas_limit = self.disable_block_gas_limit;
cfg.handler_cfg.is_optimism = self.enable_optimism;
cfg.memory_limit = self.memory_limit.unwrap_or_default();
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved

let env = revm::primitives::Env {
cfg: cfg.cfg_env,
Expand Down
Loading