Skip to content

Commit fb16804

Browse files
authored
Merge branch 'master' into feature/anvil-block-overrides
2 parents 5590414 + 5775ce1 commit fb16804

File tree

20 files changed

+325
-129
lines changed

20 files changed

+325
-129
lines changed

.devcontainer/Dockerfile.dev

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
FROM ubuntu:22.04
2+
3+
ARG USERNAME=foundry
4+
ARG USER_UID=1000
5+
ARG USER_GID=$USER_UID
6+
ARG PYTHON_VERSION=3.11
7+
ARG NODE_MAJOR=20
8+
ARG VYPER_VERSION=0.4.0
9+
10+
ENV DEBIAN_FRONTEND=noninteractive
11+
ENV CARGO_TERM_COLOR=always \
12+
RUST_BACKTRACE=full
13+
14+
WORKDIR /workspace
15+
16+
RUN apt-get update && apt-get install -y --no-install-recommends \
17+
# Build tools
18+
build-essential \
19+
clang \
20+
lld \
21+
pkg-config \
22+
# Network/SSL
23+
curl \
24+
ca-certificates \
25+
gnupg \
26+
libssl-dev \
27+
# Version control & utils
28+
git \
29+
sudo \
30+
unzip \
31+
# Python
32+
python${PYTHON_VERSION} \
33+
python3-pip \
34+
python${PYTHON_VERSION}-venv \
35+
# Add Node.js repo
36+
&& mkdir -p /etc/apt/keyrings \
37+
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
38+
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
39+
# Update again after adding repo and install Node.js
40+
&& apt-get update && apt-get install -y --no-install-recommends \
41+
nodejs \
42+
# Clean up apt cache
43+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
44+
45+
# Ensure python points to the installed python version
46+
RUN ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
47+
ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python3
48+
49+
# Create non-root user with sudo privileges
50+
RUN groupadd --gid $USER_GID $USERNAME \
51+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
52+
# Setup sudo without password prompt
53+
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
54+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
55+
# Add user to the sudo group (standard practice)
56+
&& usermod -aG sudo $USERNAME
57+
58+
# Switch to the non-root user
59+
USER $USERNAME
60+
WORKDIR /home/$USERNAME
61+
62+
# --- User-specific installations ---
63+
64+
# Install Bun
65+
ENV BUN_INSTALL="/home/$USERNAME/.bun"
66+
ENV PATH="$BUN_INSTALL/bin:$PATH"
67+
RUN curl -fsSL https://bun.sh/install | bash
68+
69+
# Install Rust & cargo-nextest
70+
ENV CARGO_HOME="/home/$USERNAME/.cargo"
71+
ENV RUSTUP_HOME="/home/$USERNAME/.rustup"
72+
ENV PATH="$CARGO_HOME/bin:$PATH"
73+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
74+
&& cargo install cargo-nextest --locked
75+
76+
# Install Vyper using pip
77+
# Ensure pip user install directory is in PATH
78+
ENV PYTHONUSERBASE="/home/$USERNAME/.local"
79+
ENV PATH="$PYTHONUSERBASE/bin:$PATH"
80+
RUN pip3 install --user vyper==${VYPER_VERSION}
81+
82+
# Switch back to the main workspace directory
83+
WORKDIR /workspace
84+

.devcontainer/devcontainer.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// For format details, see https://aka.ms/devcontainer.json.
2+
{
3+
"name": "Foundry Development",
4+
"build": {
5+
"context": "..",
6+
"dockerfile": "Dockerfile.dev"
7+
},
8+
9+
"features": {
10+
"ghcr.io/devcontainers/features/common-utils:2": {
11+
"installZsh": true,
12+
"configureZshAsDefaultShell": true,
13+
"installOhMyZsh": true,
14+
"upgradePackages": true
15+
}
16+
},
17+
18+
"forwardPorts": [],
19+
20+
"postCreateCommand": "rustup default stable && rustup update",
21+
22+
"customizations": {
23+
"vscode": {
24+
"extensions": [
25+
"rust-lang.rust-analyzer",
26+
"serayuzgur.crates",
27+
"tamasfe.even-better-toml",
28+
"ms-python.python",
29+
"dbaeumer.vscode-eslint",
30+
"oven.bun-vscode"
31+
],
32+
"settings": {
33+
"rust-analyzer.checkOnSave": true,
34+
"rust-analyzer.cargo.features": "all"
35+
}
36+
}
37+
},
38+
39+
"remoteUser": "foundry",
40+
41+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
42+
43+
"workspaceFolder": "/workspace",
44+
45+
"mounts": [
46+
"source=${localEnv:HOME}/.cargo/registry,target=/home/foundry/.cargo/registry,type=bind,consistency=cached",
47+
"source=${localEnv:HOME}/.cargo/git,target=/home/foundry/.cargo/git,type=bind,consistency=cached"
48+
]
49+
}

.github/workflows/nextest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
with:
7373
python-version: 3.11
7474
- name: Install Vyper
75+
# Also update vyper version in .devcontainer/Dockerfile.dev
7576
run: pip --version && pip install vyper==0.4.0
7677

7778
- name: Forge RPC cache

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/anvil/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ alloy-rlp.workspace = true
2929
alloy-eips.workspace = true
3030
alloy-consensus = { workspace = true, features = ["k256", "kzg"] }
3131
alloy-dyn-abi = { workspace = true, features = ["std", "eip712"] }
32-
alloy-trie.workspace = true
3332
op-alloy-consensus = { workspace = true, features = ["serde"] }
3433
alloy-network.workspace = true
3534
serde.workspace = true

crates/anvil/core/src/eth/block.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
use super::{
2-
transaction::{TransactionInfo, TypedReceipt},
3-
trie,
4-
};
5-
use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH};
6-
use alloy_eips::eip2718::Encodable2718;
1+
use super::transaction::{TransactionInfo, TypedReceipt};
2+
use alloy_consensus::{proofs::calculate_transaction_root, Header, EMPTY_OMMER_ROOT_HASH};
73
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
84
use alloy_rlp::{RlpDecodable, RlpEncodable};
95

@@ -36,8 +32,9 @@ impl Block {
3632
T: Into<Transaction>,
3733
{
3834
let transactions: Vec<_> = transactions.into_iter().map(Into::into).collect();
39-
let transactions_root =
40-
trie::ordered_trie_root(transactions.iter().map(|r| r.encoded_2718()));
35+
let transactions1: Vec<super::transaction::TypedTransaction> =
36+
transactions.clone().into_iter().map(Into::into).collect();
37+
let transactions_root = calculate_transaction_root(&transactions1);
4138

4239
Self {
4340
header: Header {

crates/anvil/core/src/eth/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ use foundry_common::serde_helpers::{
1818
};
1919

2020
pub mod block;
21-
pub mod proof;
2221
pub mod subscription;
2322
pub mod transaction;
24-
pub mod trie;
2523
pub mod wallet;
2624

2725
pub mod serde_helpers;

crates/anvil/core/src/eth/proof.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +0,0 @@
1-
//! Return types for `eth_getProof`
2-
3-
use crate::eth::trie::KECCAK_NULL_RLP;
4-
use alloy_primitives::{B256, U256};
5-
use revm::primitives::KECCAK_EMPTY;
6-
7-
#[derive(Clone, Debug, PartialEq, Eq, alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable)]
8-
pub struct BasicAccount {
9-
pub nonce: U256,
10-
pub balance: U256,
11-
pub storage_root: B256,
12-
pub code_hash: B256,
13-
}
14-
15-
impl Default for BasicAccount {
16-
fn default() -> Self {
17-
Self {
18-
balance: U256::ZERO,
19-
nonce: U256::ZERO,
20-
code_hash: KECCAK_EMPTY,
21-
storage_root: KECCAK_NULL_RLP,
22-
}
23-
}
24-
}

crates/anvil/core/src/eth/trie.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

crates/anvil/core/src/types.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
1-
use alloy_primitives::{Bytes, B256, U256};
1+
use alloy_primitives::Bytes;
22
use alloy_rpc_types::TransactionRequest;
3-
use serde::{Deserialize, Serialize, Serializer};
4-
5-
/// Represents the result of `eth_getWork`.
6-
///
7-
/// This may or may not include the block number.
8-
#[derive(Debug, Default, PartialEq, Eq)]
9-
pub struct Work {
10-
pub pow_hash: B256,
11-
pub seed_hash: B256,
12-
pub target: B256,
13-
pub number: Option<u64>,
14-
}
15-
16-
impl Serialize for Work {
17-
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
18-
where
19-
S: Serializer,
20-
{
21-
if let Some(num) = self.number {
22-
(&self.pow_hash, &self.seed_hash, &self.target, U256::from(num)).serialize(s)
23-
} else {
24-
(&self.pow_hash, &self.seed_hash, &self.target).serialize(s)
25-
}
26-
}
27-
}
3+
use serde::Deserialize;
284

295
/// Represents the options used in `anvil_reorg`
306
#[derive(Debug, Clone, Deserialize)]

crates/anvil/src/eth/api.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use alloy_rpc_types::{
6565
},
6666
txpool::{TxpoolContent, TxpoolInspect, TxpoolInspectSummary, TxpoolStatus},
6767
AccessList, AccessListResult, BlockId, BlockNumberOrTag as BlockNumber, BlockTransactions,
68-
EIP1186AccountProofResponse, FeeHistory, Filter, FilteredParams, Index, Log,
68+
EIP1186AccountProofResponse, FeeHistory, Filter, FilteredParams, Index, Log, Work,
6969
};
7070
use alloy_serde::WithOtherFields;
7171
use alloy_transport::TransportErrorKind;
@@ -79,7 +79,7 @@ use anvil_core::{
7979
wallet::{WalletCapabilities, WalletError},
8080
EthRequest,
8181
},
82-
types::{ReorgOptions, TransactionData, Work},
82+
types::{ReorgOptions, TransactionData},
8383
};
8484
use anvil_rpc::{error::RpcError, response::ResponseResult};
8585
use foundry_common::provider::ProviderBuilder;
@@ -92,10 +92,14 @@ use foundry_evm::{
9292
primitives::BlockEnv,
9393
},
9494
};
95-
use futures::channel::{mpsc::Receiver, oneshot};
95+
use futures::{
96+
channel::{mpsc::Receiver, oneshot},
97+
StreamExt,
98+
};
9699
use parking_lot::RwLock;
97100
use revm::primitives::Bytecode;
98101
use std::{future::Future, sync::Arc, time::Duration};
102+
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
99103

100104
/// The client version: `anvil/v{major}.{minor}.{patch}`
101105
pub const CLIENT_VERSION: &str = concat!("anvil/v", env!("CARGO_PKG_VERSION"));
@@ -2877,6 +2881,26 @@ impl EthApi {
28772881
self.pool.add_ready_listener()
28782882
}
28792883

2884+
/// Returns a listener for pending transactions, yielding full transactions
2885+
pub fn full_pending_transactions(&self) -> UnboundedReceiver<AnyRpcTransaction> {
2886+
let (tx, rx) = unbounded_channel();
2887+
let mut hashes = self.new_ready_transactions();
2888+
2889+
let this = self.clone();
2890+
2891+
tokio::spawn(async move {
2892+
while let Some(hash) = hashes.next().await {
2893+
if let Ok(Some(txn)) = this.transaction_by_hash(hash).await {
2894+
if tx.send(txn).is_err() {
2895+
break;
2896+
}
2897+
}
2898+
}
2899+
});
2900+
2901+
rx
2902+
}
2903+
28802904
/// Returns a new accessor for certain storage elements
28812905
pub fn storage_info(&self) -> StorageInfo {
28822906
StorageInfo::new(Arc::clone(&self.backend))

crates/anvil/src/eth/backend/executor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ use crate::{
88
mem::inspector::Inspector,
99
PrecompileFactory,
1010
};
11-
use alloy_consensus::{constants::EMPTY_WITHDRAWALS, Receipt, ReceiptWithBloom};
12-
use alloy_eips::{eip2718::Encodable2718, eip7685::EMPTY_REQUESTS_HASH};
11+
use alloy_consensus::{
12+
constants::EMPTY_WITHDRAWALS, proofs::calculate_receipt_root, Receipt, ReceiptWithBloom,
13+
};
14+
use alloy_eips::eip7685::EMPTY_REQUESTS_HASH;
1315
use alloy_primitives::{Bloom, BloomInput, Log, B256};
1416
use anvil_core::eth::{
1517
block::{Block, BlockInfo, PartialHeader},
1618
transaction::{
1719
DepositReceipt, PendingTransaction, TransactionInfo, TypedReceipt, TypedTransaction,
1820
},
19-
trie,
2021
};
2122
use foundry_evm::{
2223
backend::DatabaseError,
@@ -211,8 +212,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> TransactionExecutor<'_, DB, V> {
211212
transactions.push(transaction.pending_transaction.transaction.clone());
212213
}
213214

214-
let receipts_root =
215-
trie::ordered_trie_root(receipts.iter().map(Encodable2718::encoded_2718));
215+
let receipts_root = calculate_receipt_root(&receipts);
216216

217217
let partial_header = PartialHeader {
218218
parent_hash,

0 commit comments

Comments
 (0)