Skip to content

Commit

Permalink
Merge branch 'master' into dani/hyper-1
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Mar 28, 2024
2 parents 253959a + 369597f commit 24bf601
Show file tree
Hide file tree
Showing 60 changed files with 600 additions and 237 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ jobs:
target="${{ matrix.target }}"
flags=()
# `keccak-asm` does not support MSVC or aarch64 Linux.
[[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]] && flags+=(--features=asm-keccak)
# `jemalloc` and `keccak-asm` are not supported on MSVC or aarch64 Linux.
if [[ "$target" != *msvc* && "$target" != "aarch64-unknown-linux-gnu" ]]; then
flags+=(--features asm-keccak,jemalloc)
fi
[[ "$target" == *windows* ]] && exe=".exe"
Expand Down
52 changes: 39 additions & 13 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ruint.opt-level = 3
sha2.opt-level = 3
sha3.opt-level = 3
tiny-keccak.opt-level = 3
bitvec.opt-level = 3

# fuzzing
proptest.opt-level = 3
Expand Down Expand Up @@ -208,6 +209,7 @@ tracing = "0.1"
tracing-subscriber = "0.3"
vergen = { version = "8", default-features = false }
indexmap = "2.2"
tikv-jemallocator = "0.5.4"

axum = "0.7"
hyper = "1.0"
Expand Down
18 changes: 8 additions & 10 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ path = "src/anvil.rs"
required-features = ["cli"]

[build-dependencies]
vergen = { workspace = true, default-features = false, features = [
"build",
"git",
"gitcl",
] }
vergen = { workspace = true, default-features = false, features = ["build", "git", "gitcl"] }

[dependencies]
# foundry internal
Expand Down Expand Up @@ -81,11 +77,7 @@ rand = "0.8"
eyre.workspace = true

# cli
clap = { version = "4", features = [
"derive",
"env",
"wrap_help",
], optional = true }
clap = { version = "4", features = ["derive", "env", "wrap_help"], optional = true }
clap_complete = { version = "4", optional = true }
chrono.workspace = true
auto_impl = "1"
Expand All @@ -94,6 +86,9 @@ fdlimit = { version = "0.3", optional = true }
clap_complete_fig = "4"
ethereum-forkid = "0.12"

[target.'cfg(unix)'.dependencies]
tikv-jemallocator = { workspace = true, optional = true }

[dev-dependencies]
alloy-json-abi.workspace = true
ethers = { workspace = true, features = ["abigen"] }
Expand All @@ -109,3 +104,6 @@ default = ["cli"]
cmd = ["clap", "clap_complete", "ctrlc", "anvil-server/clap"]
cli = ["tokio/full", "cmd", "fdlimit"]
asm-keccak = ["alloy-primitives/asm-keccak"]
# TODO: parity dependencies are not compatible with a different global allocator.
# jemalloc = ["dep:tikv-jemallocator"]
jemalloc = []
14 changes: 14 additions & 0 deletions crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,13 @@ pub enum EthRequest {
/// contract.
#[cfg_attr(feature = "serde", serde(rename = "ots_getContractCreator", with = "sequence"))]
OtsGetContractCreator(Address),

/// Removes transactions from the pool by sender origin.
#[cfg_attr(
feature = "serde",
serde(rename = "anvil_removePoolTransactions", with = "sequence")
)]
RemovePoolTransactions(Address),
}

/// Represents ethereum JSON-RPC API
Expand Down Expand Up @@ -1506,4 +1513,11 @@ true}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}

#[test]
fn test_remove_pool_transactions() {
let s = r#"{"method": "anvil_removePoolTransactions", "params":["0x364d6D0333432C3Ac016Ca832fb8594A8cE43Ca6"]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
}
10 changes: 10 additions & 0 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,16 @@ impl TypedReceipt {
TypedReceipt::Deposit(r) => &r.bloom,
}
}

pub fn logs(&self) -> &Vec<Log> {
match self {
TypedReceipt::Legacy(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP4844(r) |
TypedReceipt::Deposit(r) => &r.receipt.logs,
}
}
}

impl From<TypedReceipt> for ReceiptWithBloom {
Expand Down
6 changes: 6 additions & 0 deletions crates/anvil/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use anvil::cmd::NodeArgs;
use clap::{CommandFactory, Parser, Subcommand};
use foundry_cli::utils;

// TODO: parity dependencies are not compatible with a different global allocator.
#[cfg(any())]
#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

/// A fast local Ethereum development node.
#[derive(Parser)]
#[command(name = "anvil", version = anvil::VERSION_MESSAGE, next_display_order = None)]
Expand Down
5 changes: 5 additions & 0 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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.evm_opts.memory_limit)
}

fn account_generator(&self) -> AccountGenerator {
Expand Down Expand Up @@ -503,6 +504,10 @@ pub struct AnvilEvmArgs {
/// Disable the default create2 deployer
#[arg(long, visible_alias = "no-create2")]
pub disable_default_create2_deployer: bool,

/// The memory limit per EVM execution in bytes.
#[arg(long)]
pub memory_limit: Option<u64>,
}

/// Resolves an alias passed as fork-url to the matching url defined in the rpc_endpoints section
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,
/// The memory limit per EVM execution in bytes.
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
9 changes: 9 additions & 0 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ impl EthApi {
EthRequest::OtsGetContractCreator(address) => {
self.ots_get_contract_creator(address).await.to_rpc_result()
}
EthRequest::RemovePoolTransactions(address) => {
self.anvil_remove_pool_transactions(address).await.to_rpc_result()
}
}
}

Expand Down Expand Up @@ -1781,6 +1784,12 @@ impl EthApi {
})
}

pub async fn anvil_remove_pool_transactions(&self, address: Address) -> Result<()> {
node_info!("anvil_removePoolTransactions");
self.pool.remove_transactions_by_address(address);
Ok(())
}

/// Snapshot the state of the blockchain at the current block.
///
/// Handler for RPC call: `evm_snapshot`
Expand Down
14 changes: 8 additions & 6 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ impl<'a, DB: Db + ?Sized, Validator: TransactionValidator> TransactionExecutor<'
let ExecutedTransaction { transaction, logs, out, traces, exit_reason: exit, .. } = tx;
logs_bloom(logs.clone(), &mut bloom);

let contract_address = if let Some(Output::Create(_, contract_address)) = out {
trace!(target: "backend", "New contract deployed: at {:?}", contract_address);
contract_address
} else {
None
};
let contract_address = out.as_ref().and_then(|out| {
if let Output::Create(_, contract_address) = out {
trace!(target: "backend", "New contract deployed: at {:?}", contract_address);
*contract_address
} else {
None
}
});

let transaction_index = transaction_infos.len() as u32;
let info = TransactionInfo {
Expand Down
5 changes: 3 additions & 2 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,8 +2009,9 @@ impl Backend {
let mut pre_receipts_log_index = None;
if !cumulative_receipts.is_empty() {
cumulative_receipts.truncate(cumulative_receipts.len() - 1);
pre_receipts_log_index =
Some(cumulative_receipts.iter().map(|_r| logs.len() as u32).sum::<u32>());
pre_receipts_log_index = Some(
cumulative_receipts.iter().map(|r| r.logs().len() as u32).sum::<u32>(),
);
}
logs.iter()
.enumerate()
Expand Down
Loading

0 comments on commit 24bf601

Please sign in to comment.