Skip to content

Commit

Permalink
Merge branch 'foundry-rs:master' into tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangZhuoSJTU authored Jul 3, 2024
2 parents 962783d + 0dceb53 commit 4c890fc
Show file tree
Hide file tree
Showing 48 changed files with 627 additions and 1,722 deletions.
43 changes: 40 additions & 3 deletions Cargo.lock

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

47 changes: 29 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,33 @@ all = "warn"
# NOTE: Debuggers may provide less useful information with this setting.
# Uncomment this section if you're using a debugger.
[profile.dev]
debug = 1
# https://davidlattimore.github.io/posts/2024/02/04/speeding-up-the-rust-edit-build-run-cycle.html
debug = "line-tables-only"
split-debuginfo = "unpacked"

[profile.release]
opt-level = 3
lto = "thin"
debug = "line-tables-only"
strip = "symbols"
panic = "abort"
codegen-units = 16

# Use the `--profile profiling` flag to show symbols in release mode.
# e.g. `cargo build --profile profiling`
[profile.profiling]
inherits = "release"
debug = 2
split-debuginfo = "unpacked"
strip = false

[profile.bench]
inherits = "profiling"

[profile.maxperf]
inherits = "release"
lto = "fat"
codegen-units = 1

# Speed up tests and dev build.
[profile.dev.package]
Expand Down Expand Up @@ -96,26 +122,10 @@ axum.opt-level = 3
# keystores
scrypt.opt-level = 3

[profile.release]
opt-level = 3
lto = "thin"
debug = "line-tables-only"
strip = true
panic = "abort"
codegen-units = 16

# Use the `--profile profiling` flag to show symbols in release mode.
# e.g. `cargo build --profile profiling`
[profile.profiling]
inherits = "release"
debug = 1
strip = false

# Override packages which aren't perf-sensitive for faster compilation speed.
[profile.release.package]
mdbook.opt-level = 1
protobuf.opt-level = 1
toml_edit.opt-level = 1
trezor-client.opt-level = 1

[workspace.dependencies]
Expand Down Expand Up @@ -151,6 +161,7 @@ foundry-linking = { path = "crates/linking" }
# solc & compilation utilities
foundry-block-explorers = { version = "0.5.0", default-features = false }
foundry-compilers = { version = "0.9.0", default-features = false }
foundry-fork-db = "0.1"
solang-parser = "=0.3.3"

## revm
Expand Down Expand Up @@ -251,4 +262,4 @@ reqwest = { version = "0.12", default-features = false }
tower = "0.4"
tower-http = "0.5"
# soldeer
soldeer = "0.2.15"
soldeer = "0.2.17"
5 changes: 5 additions & 0 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl NodeArgs {
.with_transaction_order(self.order)
.with_genesis(self.init)
.with_steps_tracing(self.evm_opts.steps_tracing)
.with_print_logs(!self.evm_opts.disable_console_log)
.with_auto_impersonate(self.evm_opts.auto_impersonate)
.with_ipc(self.ipc)
.with_code_size_limit(self.evm_opts.code_size_limit)
Expand Down Expand Up @@ -507,6 +508,10 @@ pub struct AnvilEvmArgs {
#[arg(long, visible_alias = "tracing")]
pub steps_tracing: bool,

/// Disable printing of `console.log` invocations to stdout.
#[arg(long, visible_alias = "no-console-log")]
pub disable_console_log: bool,

/// Enable autoImpersonate on startup
#[arg(long, visible_alias = "auto-impersonate")]
pub auto_impersonate: bool,
Expand Down
36 changes: 35 additions & 1 deletion crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use foundry_common::{
};
use foundry_config::Config;
use foundry_evm::{
backend::{BlockchainDb, BlockchainDbMeta, SharedBackend},
constants::DEFAULT_CREATE2_DEPLOYER,
fork::{BlockchainDb, BlockchainDbMeta, SharedBackend},
revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv},
utils::apply_chain_and_block_specific_env_changes,
};
Expand Down Expand Up @@ -155,6 +155,8 @@ pub struct NodeConfig {
pub ipc_path: Option<Option<String>>,
/// Enable transaction/call steps tracing for debug calls returning geth-style traces
pub enable_steps_tracing: bool,
/// Enable printing of `console.log` invocations.
pub print_logs: bool,
/// Enable auto impersonation of accounts on startup
pub enable_auto_impersonate: bool,
/// Configure the code size limit
Expand Down Expand Up @@ -245,6 +247,10 @@ Chain ID: {}
fork.block_hash(),
fork.chain_id()
);

if let Some(tx_hash) = fork.transaction_hash() {
let _ = writeln!(config_string, "Transaction hash: {tx_hash}");
}
} else {
let _ = write!(
config_string,
Expand Down Expand Up @@ -400,6 +406,7 @@ impl Default for NodeConfig {
blob_excess_gas_and_price: None,
enable_tracing: true,
enable_steps_tracing: false,
print_logs: true,
enable_auto_impersonate: false,
no_storage_caching: false,
server_config: Default::default(),
Expand Down Expand Up @@ -785,6 +792,13 @@ impl NodeConfig {
self
}

/// Sets whether to print `console.log` invocations to stdout.
#[must_use]
pub fn with_print_logs(mut self, print_logs: bool) -> Self {
self.print_logs = print_logs;
self
}

/// Sets whether to enable autoImpersonate
#[must_use]
pub fn with_auto_impersonate(mut self, enable_auto_impersonate: bool) -> Self {
Expand Down Expand Up @@ -945,6 +959,7 @@ impl NodeConfig {
fees,
Arc::new(RwLock::new(fork)),
self.enable_steps_tracing,
self.print_logs,
self.prune_history,
self.transaction_block_keeper,
self.block_time,
Expand Down Expand Up @@ -1169,6 +1184,7 @@ latest block number: {latest_block}"
eth_rpc_url,
block_number: fork_block_number,
block_hash,
transaction_hash: self.fork_choice.and_then(|fc| fc.transaction_hash()),
provider,
chain_id,
override_chain_id,
Expand Down Expand Up @@ -1245,6 +1261,24 @@ pub enum ForkChoice {
Transaction(TxHash),
}

impl ForkChoice {
/// Returns the block number to fork from
pub fn block_number(&self) -> Option<BlockNumber> {
match self {
Self::Block(block_number) => Some(*block_number),
Self::Transaction(_) => None,
}
}

/// Returns the transaction hash to fork from
pub fn transaction_hash(&self) -> Option<TxHash> {
match self {
Self::Block(_) => None,
Self::Transaction(transaction_hash) => Some(*transaction_hash),
}
}
}

/// Convert a transaction hash into a ForkChoice
impl From<TxHash> for ForkChoice {
fn from(tx_hash: TxHash) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ impl EthApi {
/// Handler for ETH RPC call: `anvil_impersonateAccount`
pub async fn anvil_impersonate_account(&self, address: Address) -> Result<()> {
node_info!("anvil_impersonateAccount");
self.backend.impersonate(address).await?;
self.backend.impersonate(address);
Ok(())
}

Expand All @@ -1569,7 +1569,7 @@ impl EthApi {
/// Handler for ETH RPC call: `anvil_stopImpersonatingAccount`
pub async fn anvil_stop_impersonating_account(&self, address: Address) -> Result<()> {
node_info!("anvil_stopImpersonatingAccount");
self.backend.stop_impersonating(address).await?;
self.backend.stop_impersonating(address);
Ok(())
}

Expand All @@ -1578,7 +1578,7 @@ impl EthApi {
/// Handler for ETH RPC call: `anvil_autoImpersonateAccount`
pub async fn anvil_auto_impersonate_account(&self, enabled: bool) -> Result<()> {
node_info!("anvil_autoImpersonateAccount");
self.backend.auto_impersonate_account(enabled).await;
self.backend.auto_impersonate_account(enabled);
Ok(())
}

Expand Down
5 changes: 3 additions & 2 deletions crates/anvil/src/eth/backend/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use alloy_rpc_types::BlockId;
use anvil_core::eth::{block::Block, transaction::TypedTransaction};
use foundry_common::errors::FsPathError;
use foundry_evm::{
backend::{DatabaseError, DatabaseResult, MemDb, RevertSnapshotAction, StateSnapshot},
fork::BlockchainDb,
backend::{
BlockchainDb, DatabaseError, DatabaseResult, MemDb, RevertSnapshotAction, StateSnapshot,
},
revm::{
db::{CacheDB, DatabaseRef, DbAccount},
primitives::{BlockEnv, Bytecode, HashMap, KECCAK_EMPTY},
Expand Down
4 changes: 4 additions & 0 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct TransactionExecutor<'a, Db: ?Sized, Validator: TransactionValidator>
/// Cumulative blob gas used by all executed transactions
pub blob_gas_used: u128,
pub enable_steps_tracing: bool,
pub print_logs: bool,
/// Precompiles to inject to the EVM.
pub precompile_factory: Option<Arc<dyn PrecompileFactory>>,
}
Expand Down Expand Up @@ -304,6 +305,9 @@ impl<'a, 'b, DB: Db + ?Sized, Validator: TransactionValidator> Iterator
if self.enable_steps_tracing {
inspector = inspector.with_steps_tracing();
}
if self.print_logs {
inspector = inspector.with_log_collector();
}

let exec_result = {
let mut evm =
Expand Down
7 changes: 7 additions & 0 deletions crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ impl ClientFork {
self.config.read().block_number
}

/// Returns the transaction hash we forked off of, if any.
pub fn transaction_hash(&self) -> Option<B256> {
self.config.read().transaction_hash
}

pub fn total_difficulty(&self) -> U256 {
self.config.read().total_difficulty
}
Expand Down Expand Up @@ -579,6 +584,8 @@ pub struct ClientForkConfig {
pub block_number: u64,
/// The hash of the forked block
pub block_hash: B256,
/// The transaction hash we forked off of, if any.
pub transaction_hash: Option<B256>,
// TODO make provider agnostic
pub provider: Arc<RetryProvider>,
pub chain_id: u64,
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/mem/fork_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
use alloy_primitives::{Address, B256, U256, U64};
use alloy_rpc_types::BlockId;
use foundry_evm::{
backend::{DatabaseResult, RevertSnapshotAction, StateSnapshot},
fork::{database::ForkDbSnapshot, BlockchainDb},
backend::{BlockchainDb, DatabaseResult, RevertSnapshotAction, StateSnapshot},
fork::database::ForkDbSnapshot,
revm::Database,
};

Expand Down
3 changes: 1 addition & 2 deletions crates/anvil/src/eth/backend/mem/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::{
use alloy_primitives::{Address, B256, U256, U64};
use alloy_rpc_types::BlockId;
use foundry_evm::{
backend::{DatabaseResult, StateSnapshot},
fork::BlockchainDb,
backend::{BlockchainDb, DatabaseResult, StateSnapshot},
hashbrown::HashMap,
};

Expand Down
Loading

0 comments on commit 4c890fc

Please sign in to comment.