Skip to content

Commit

Permalink
feat(anvil): Add memery limit to anvil node (#7482)
Browse files Browse the repository at this point in the history
* add memery-limit to anvil node

* Update config.rs

* use unwrap_or_default

* add variable alias

* custom value to 100 for memory-limit

* Update config.rs

* Update config.rs

* remove old comment

* nightly fmt

* fmt

* docs

---------

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
DoTheBestToGetTheBest and mattsse authored Mar 25, 2024
1 parent e5acbcf commit bf5bfe0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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,
/// The memory limit per EVM execution in bytes.
#[arg(long)]
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
13 changes: 13 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: None,
}
}
}

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 @@ -831,6 +840,10 @@ impl NodeConfig {
cfg.disable_block_gas_limit = self.disable_block_gas_limit;
cfg.handler_cfg.is_optimism = self.enable_optimism;

if let Some(value) = self.memory_limit {
cfg.memory_limit = value;
}

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

0 comments on commit bf5bfe0

Please sign in to comment.