Skip to content

Commit

Permalink
chore: bump alloy-core deps + revm (#8988)
Browse files Browse the repository at this point in the history
* chore: bump alloy-core deps + revm

* bump alloy to 0.4.0

* bump revm-inspectors + type casting to u128

* fix

* Revert "fix"

This reverts commit 5e0e0d1.

* Revert "bump revm-inspectors + type casting to u128"

This reverts commit 25aa23c.

* Revert "bump alloy to 0.4.0"

This reverts commit f9721e0.

* replace std HashMap with alloy_primitives maps

* bump compilers

* replace remaining HashMaps

* fmt

* nit

* replace HashSets

* fmt
  • Loading branch information
yash-atreya authored Sep 30, 2024
1 parent 4bcb309 commit 3ff3d05
Show file tree
Hide file tree
Showing 52 changed files with 187 additions and 161 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ foundry-fork-db = "0.3.2"
solang-parser = "=0.3.3"

## revm
revm = { version = "14.0.2", default-features = false }
revm = { version = "14.0.3", default-features = false }
revm-primitives = { version = "10.0.0", default-features = false }
revm-inspectors = { version = "0.7.7", features = ["serde"] }

Expand Down Expand Up @@ -203,17 +203,17 @@ alloy-transport-ipc = { version = "0.3.6", default-features = false }
alloy-transport-ws = { version = "0.3.6", default-features = false }

## alloy-core
alloy-dyn-abi = "0.8.1"
alloy-json-abi = "0.8.1"
alloy-primitives = { version = "0.8.1", features = [
alloy-dyn-abi = "0.8.5"
alloy-json-abi = "0.8.5"
alloy-primitives = { version = "0.8.5", features = [
"getrandom",
"rand",
"map-fxhash",
] }
alloy-sol-macro-expander = "0.8.1"
alloy-sol-macro-input = "0.8.1"
alloy-sol-types = "0.8.1"
syn-solidity = "0.8.1"
alloy-sol-macro-expander = "0.8.5"
alloy-sol-macro-input = "0.8.5"
alloy-sol-types = "0.8.5"
syn-solidity = "0.8.5"

alloy-chains = "0.1"
alloy-rlp = "0.3"
Expand Down
3 changes: 1 addition & 2 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};
use alloy_genesis::Genesis;
use alloy_network::AnyNetwork;
use alloy_primitives::{hex, utils::Unit, BlockNumber, TxHash, U256};
use alloy_primitives::{hex, map::HashMap, utils::Unit, BlockNumber, TxHash, U256};
use alloy_provider::Provider;
use alloy_rpc_types::{Block, BlockNumberOrTag, Transaction};
use alloy_serde::WithOtherFields;
Expand Down Expand Up @@ -46,7 +46,6 @@ use rand::thread_rng;
use revm::primitives::BlobExcessGasAndPrice;
use serde_json::{json, to_writer, Value};
use std::{
collections::HashMap,
fmt::Write as FmtWrite,
fs::File,
net::{IpAddr, Ipv4Addr},
Expand Down
8 changes: 4 additions & 4 deletions crates/anvil/src/eth/backend/cheats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Support for "cheat codes" / bypass functions

use alloy_primitives::Address;
use alloy_primitives::{map::AddressHashSet, Address};
use parking_lot::RwLock;
use std::{collections::HashSet, sync::Arc};
use std::sync::Arc;

/// Manages user modifications that may affect the node's behavior
///
Expand Down Expand Up @@ -55,7 +55,7 @@ impl CheatsManager {
}

/// Returns all accounts that are currently being impersonated.
pub fn impersonated_accounts(&self) -> HashSet<Address> {
pub fn impersonated_accounts(&self) -> AddressHashSet {
self.state.read().impersonated_accounts.clone()
}
}
Expand All @@ -64,7 +64,7 @@ impl CheatsManager {
#[derive(Clone, Debug, Default)]
pub struct CheatsState {
/// All accounts that are currently impersonated
pub impersonated_accounts: HashSet<Address>,
pub impersonated_accounts: AddressHashSet,
/// If set to true will make the `is_impersonated` function always return true
pub auto_impersonate_accounts: bool,
}
19 changes: 11 additions & 8 deletions crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::eth::{backend::db::Db, error::BlockchainError, pool::transactions::Po
use alloy_consensus::Account;
use alloy_eips::eip2930::AccessListResult;
use alloy_network::BlockResponse;
use alloy_primitives::{Address, Bytes, StorageValue, B256, U256};
use alloy_primitives::{
map::{FbHashMap, HashMap},
Address, Bytes, StorageValue, B256, U256,
};
use alloy_provider::{
ext::{DebugApi, TraceApi},
Provider,
Expand All @@ -27,7 +30,7 @@ use parking_lot::{
RawRwLock, RwLock,
};
use revm::primitives::BlobExcessGasAndPrice;
use std::{collections::HashMap, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};
use tokio::sync::RwLock as AsyncRwLock;

/// Represents a fork of a remote client
Expand Down Expand Up @@ -675,14 +678,14 @@ impl ClientForkConfig {
/// This is used as a cache so repeated requests to the same data are not sent to the remote client
#[derive(Clone, Debug, Default)]
pub struct ForkedStorage {
pub uncles: HashMap<B256, Vec<AnyNetworkBlock>>,
pub blocks: HashMap<B256, AnyNetworkBlock>,
pub uncles: FbHashMap<32, Vec<AnyNetworkBlock>>,
pub blocks: FbHashMap<32, AnyNetworkBlock>,
pub hashes: HashMap<u64, B256>,
pub transactions: HashMap<B256, WithOtherFields<Transaction>>,
pub transaction_receipts: HashMap<B256, ReceiptResponse>,
pub transaction_traces: HashMap<B256, Vec<Trace>>,
pub transactions: FbHashMap<32, WithOtherFields<Transaction>>,
pub transaction_receipts: FbHashMap<32, ReceiptResponse>,
pub transaction_traces: FbHashMap<32, Vec<Trace>>,
pub logs: HashMap<Filter, Vec<Log>>,
pub geth_transaction_traces: HashMap<B256, GethTrace>,
pub geth_transaction_traces: FbHashMap<32, GethTrace>,
pub block_traces: HashMap<u64, Vec<Trace>>,
pub block_receipts: HashMap<u64, Vec<ReceiptResponse>>,
pub code_at: HashMap<(Address, u64), Bytes>,
Expand Down
37 changes: 22 additions & 15 deletions crates/anvil/src/eth/backend/mem/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use crate::eth::{
error::BlockchainError,
pool::transactions::PoolTransaction,
};
use alloy_primitives::{Bytes, TxHash, B256, U256, U64};
use alloy_primitives::{
map::{B256HashMap, HashMap},
Bytes, B256, U256, U64,
};
use alloy_rpc_types::{
trace::{
geth::{
Expand All @@ -35,12 +38,8 @@ use foundry_evm::{
},
};
use parking_lot::RwLock;
use std::{
collections::{HashMap, VecDeque},
fmt,
sync::Arc,
time::Duration,
};
use std::{collections::VecDeque, fmt, sync::Arc, time::Duration};
// use yansi::Paint;

// === various limits in number of blocks ===

Expand All @@ -52,9 +51,9 @@ const MAX_ON_DISK_HISTORY_LIMIT: usize = 3_600;
/// Represents the complete state of single block
pub struct InMemoryBlockStates {
/// The states at a certain block
states: HashMap<B256, StateDb>,
states: B256HashMap<StateDb>,
/// states which data is moved to disk
on_disk_states: HashMap<B256, StateDb>,
on_disk_states: B256HashMap<StateDb>,
/// How many states to store at most
in_memory_limit: usize,
/// minimum amount of states we keep in memory
Expand Down Expand Up @@ -245,7 +244,7 @@ impl Default for InMemoryBlockStates {
#[derive(Clone)]
pub struct BlockchainStorage {
/// all stored blocks (block hash -> block)
pub blocks: HashMap<B256, Block>,
pub blocks: B256HashMap<Block>,
/// mapping from block number -> block hash
pub hashes: HashMap<U64, B256>,
/// The current best hash
Expand All @@ -256,7 +255,7 @@ pub struct BlockchainStorage {
pub genesis_hash: B256,
/// Mapping from the transaction hash to a tuple containing the transaction as well as the
/// transaction receipt
pub transactions: HashMap<TxHash, MinedTransaction>,
pub transactions: B256HashMap<MinedTransaction>,
/// The total difficulty of the chain until this block
pub total_difficulty: U256,
}
Expand All @@ -280,9 +279,14 @@ impl BlockchainStorage {
let best_hash = genesis_hash;
let best_number: U64 = U64::from(0u64);

let mut blocks = B256HashMap::default();
blocks.insert(genesis_hash, block);

let mut hashes = HashMap::default();
hashes.insert(best_number, genesis_hash);
Self {
blocks: HashMap::from([(genesis_hash, block)]),
hashes: HashMap::from([(best_number, genesis_hash)]),
blocks,
hashes,
best_hash,
best_number,
genesis_hash,
Expand All @@ -292,9 +296,12 @@ impl BlockchainStorage {
}

pub fn forked(block_number: u64, block_hash: B256, total_difficulty: U256) -> Self {
let mut hashes = HashMap::default();
hashes.insert(U64::from(block_number), block_hash);

Self {
blocks: Default::default(),
hashes: HashMap::from([(U64::from(block_number), block_hash)]),
blocks: B256HashMap::default(),
hashes,
best_hash: block_hash,
best_number: U64::from(block_number),
genesis_hash: Default::default(),
Expand Down
5 changes: 2 additions & 3 deletions crates/anvil/src/eth/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ use crate::eth::error::BlockchainError;
use alloy_consensus::SignableTransaction;
use alloy_dyn_abi::TypedData;
use alloy_network::TxSignerSync;
use alloy_primitives::{Address, Signature, B256};
use alloy_primitives::{map::AddressHashMap, Address, Signature, B256};
use alloy_signer::Signer as AlloySigner;
use alloy_signer_local::PrivateKeySigner;
use anvil_core::eth::transaction::{
optimism::{DepositTransaction, DepositTransactionRequest},
TypedTransaction, TypedTransactionRequest,
};
use std::collections::HashMap;

/// A transaction signer
#[async_trait::async_trait]
Expand Down Expand Up @@ -47,7 +46,7 @@ pub trait Signer: Send + Sync {
/// Maintains developer keys
pub struct DevSigner {
addresses: Vec<Address>,
accounts: HashMap<Address, PrivateKeySigner>,
accounts: AddressHashMap<PrivateKeySigner>,
}

impl DevSigner {
Expand Down
3 changes: 1 addition & 2 deletions crates/anvil/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use crate::{
pubsub::filter_logs,
StorageInfo,
};
use alloy_primitives::TxHash;
use alloy_primitives::{map::HashMap, TxHash};
use alloy_rpc_types::{Filter, FilteredParams, Log};
use anvil_core::eth::subscription::SubscriptionId;
use anvil_rpc::response::ResponseResult;
use futures::{channel::mpsc::Receiver, Stream, StreamExt};
use std::{
collections::HashMap,
pin::Pin,
sync::Arc,
task::{Context, Poll},
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/tests/it/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
utils::{http_provider_with_signer, ws_provider_with_signer},
};
use alloy_network::EthereumWallet;
use alloy_primitives::B256;
use alloy_primitives::{map::B256HashSet, B256};
use alloy_provider::Provider;
use alloy_rpc_types::{BlockNumberOrTag, Filter};
use anvil::{spawn, NodeConfig};
Expand Down Expand Up @@ -120,7 +120,7 @@ async fn get_all_events() {
// test that logs returned from get_logs and get_transaction_receipt have
// the same log_index, block_number, and transaction_hash
let mut tasks = vec![];
let mut seen_tx_hashes = std::collections::HashSet::new();
let mut seen_tx_hashes = B256HashSet::default();
for log in &logs {
if seen_tx_hashes.contains(&log.transaction_hash.unwrap()) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions crates/anvil/tests/it/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
utils::{connect_pubsub, http_provider_with_signer},
};
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::{Address, Bytes, FixedBytes, U256};
use alloy_primitives::{map::B256HashSet, Address, Bytes, FixedBytes, U256};
use alloy_provider::Provider;
use alloy_rpc_types::{
state::{AccountOverride, StateOverride},
Expand All @@ -13,7 +13,7 @@ use alloy_serde::WithOtherFields;
use anvil::{spawn, EthereumHardfork, NodeConfig};
use eyre::Ok;
use futures::{future::join_all, FutureExt, StreamExt};
use std::{collections::HashSet, str::FromStr, time::Duration};
use std::{str::FromStr, time::Duration};
use tokio::time::timeout;

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -950,7 +950,7 @@ async fn can_stream_pending_transactions() {
if watch_received.len() == num_txs && sub_received.len() == num_txs {
if let Some(sent) = &sent {
assert_eq!(sent.len(), watch_received.len());
let sent_txs = sent.iter().map(|tx| tx.transaction_hash).collect::<HashSet<_>>();
let sent_txs = sent.iter().map(|tx| tx.transaction_hash).collect::<B256HashSet>();
assert_eq!(sent_txs, watch_received.iter().copied().collect());
assert_eq!(sent_txs, sub_received.iter().copied().collect());
break
Expand Down
5 changes: 2 additions & 3 deletions crates/cheatcodes/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Result;
use crate::{script::ScriptWallets, Vm::Rpc};
use alloy_primitives::{Address, U256};
use alloy_primitives::{map::AddressHashMap, U256};
use foundry_common::{fs::normalize_path, ContractsByArtifact};
use foundry_compilers::{utils::canonicalize, ProjectPathsConfig};
use foundry_config::{
Expand All @@ -10,7 +10,6 @@ use foundry_config::{
use foundry_evm_core::opts::EvmOpts;
use semver::Version;
use std::{
collections::HashMap,
path::{Path, PathBuf},
time::Duration,
};
Expand Down Expand Up @@ -43,7 +42,7 @@ pub struct CheatsConfig {
/// How the evm was configured by the user
pub evm_opts: EvmOpts,
/// Address labels from config
pub labels: HashMap<Address, String>,
pub labels: AddressHashMap<String>,
/// Script wallets
pub script_wallets: Option<ScriptWallets>,
/// Artifacts which are guaranteed to be fresh (either recompiled or cached).
Expand Down
17 changes: 10 additions & 7 deletions crates/cheatcodes/src/evm/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
use crate::{Cheatcode, Cheatcodes, Result, Vm::*};
use alloy_primitives::{keccak256, Address, B256, U256};
use alloy_primitives::{
keccak256,
map::{AddressHashMap, B256HashMap},
Address, B256, U256,
};
use alloy_sol_types::SolValue;
use revm::interpreter::{opcode, Interpreter};
use std::collections::HashMap;

/// Recorded mapping slots.
#[derive(Clone, Debug, Default)]
pub struct MappingSlots {
/// Holds mapping parent (slots => slots)
pub parent_slots: HashMap<B256, B256>,
pub parent_slots: B256HashMap<B256>,

/// Holds mapping key (slots => key)
pub keys: HashMap<B256, B256>,
pub keys: B256HashMap<B256>,

/// Holds mapping child (slots => slots[])
pub children: HashMap<B256, Vec<B256>>,
pub children: B256HashMap<Vec<B256>>,

/// Holds the last sha3 result `sha3_result => (data_low, data_high)`, this would only record
/// when sha3 is called with `size == 0x40`, and the lower 256 bits would be stored in
/// `data_low`, higher 256 bits in `data_high`.
/// This is needed for mapping_key detect if the slot is for some mapping and record that.
pub seen_sha3: HashMap<B256, (B256, B256)>,
pub seen_sha3: B256HashMap<(B256, B256)>,
}

impl MappingSlots {
Expand Down Expand Up @@ -113,7 +116,7 @@ fn slot_child<'a>(
}

#[cold]
pub(crate) fn step(mapping_slots: &mut HashMap<Address, MappingSlots>, interpreter: &Interpreter) {
pub(crate) fn step(mapping_slots: &mut AddressHashMap<MappingSlots>, interpreter: &Interpreter) {
match interpreter.current_opcode() {
opcode::KECCAK256 => {
if interpreter.stack.peek(1) == Ok(U256::from(0x40)) {
Expand Down
Loading

0 comments on commit 3ff3d05

Please sign in to comment.