Skip to content

Commit

Permalink
feat: update revm 19 alloy 09 (#9605)
Browse files Browse the repository at this point in the history
* feat: update revm 19 alloy 09

* clippy

* updata test

* add back max data gas check
  • Loading branch information
mattsse authored Dec 30, 2024
1 parent e618b2c commit 68aff72
Show file tree
Hide file tree
Showing 25 changed files with 181 additions and 177 deletions.
164 changes: 83 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,43 +172,43 @@ foundry-linking = { path = "crates/linking" }
# solc & compilation utilities
foundry-block-explorers = { version = "0.9.0", default-features = false }
foundry-compilers = { version = "0.12.8", default-features = false }
foundry-fork-db = "0.9.0"
foundry-fork-db = "0.10.0"
solang-parser = "=0.3.3"
solar-ast = { version = "=0.1.0", default-features = false }
solar-parse = { version = "=0.1.0", default-features = false }

## revm
revm = { version = "18.0.0", default-features = false }
revm-primitives = { version = "14.0.0", default-features = false }
revm-inspectors = { version = "0.13.0", features = ["serde"] }
revm = { version = "19.0.0", default-features = false }
revm-primitives = { version = "15.1.0", default-features = false }
revm-inspectors = { version = "0.14.1", features = ["serde"] }

## ethers
ethers-contract-abigen = { version = "2.0.14", default-features = false }

## alloy
alloy-consensus = { version = "0.8.0", default-features = false }
alloy-contract = { version = "0.8.0", default-features = false }
alloy-eips = { version = "0.8.0", default-features = false }
alloy-genesis = { version = "0.8.0", default-features = false }
alloy-json-rpc = { version = "0.8.0", default-features = false }
alloy-network = { version = "0.8.0", default-features = false }
alloy-provider = { version = "0.8.0", default-features = false }
alloy-pubsub = { version = "0.8.0", default-features = false }
alloy-rpc-client = { version = "0.8.0", default-features = false }
alloy-rpc-types = { version = "0.8.0", default-features = true }
alloy-serde = { version = "0.8.0", default-features = false }
alloy-signer = { version = "0.8.0", default-features = false }
alloy-signer-aws = { version = "0.8.0", default-features = false }
alloy-signer-gcp = { version = "0.8.0", default-features = false }
alloy-signer-ledger = { version = "0.8.0", default-features = false }
alloy-signer-local = { version = "0.8.0", default-features = false }
alloy-signer-trezor = { version = "0.8.0", default-features = false }
alloy-transport = { version = "0.8.0", default-features = false }
alloy-transport-http = { version = "0.8.0", default-features = false }
alloy-transport-ipc = { version = "0.8.0", default-features = false }
alloy-transport-ws = { version = "0.8.0", default-features = false }
alloy-node-bindings = { version = "0.8.0", default-features = false }
alloy-network-primitives = { version = "0.8.0", default-features = false }
alloy-consensus = { version = "0.9.0", default-features = false }
alloy-contract = { version = "0.9.0", default-features = false }
alloy-eips = { version = "0.9.0", default-features = false }
alloy-genesis = { version = "0.9.0", default-features = false }
alloy-json-rpc = { version = "0.9.0", default-features = false }
alloy-network = { version = "0.9.0", default-features = false }
alloy-provider = { version = "0.9.0", default-features = false }
alloy-pubsub = { version = "0.9.0", default-features = false }
alloy-rpc-client = { version = "0.9.0", default-features = false }
alloy-rpc-types = { version = "0.9.0", default-features = true }
alloy-serde = { version = "0.9.0", default-features = false }
alloy-signer = { version = "0.9.0", default-features = false }
alloy-signer-aws = { version = "0.9.0", default-features = false }
alloy-signer-gcp = { version = "0.9.0", default-features = false }
alloy-signer-ledger = { version = "0.9.0", default-features = false }
alloy-signer-local = { version = "0.9.0", default-features = false }
alloy-signer-trezor = { version = "0.9.0", default-features = false }
alloy-transport = { version = "0.9.0", default-features = false }
alloy-transport-http = { version = "0.9.0", default-features = false }
alloy-transport-ipc = { version = "0.9.0", default-features = false }
alloy-transport-ws = { version = "0.9.0", default-features = false }
alloy-node-bindings = { version = "0.9.0", default-features = false }
alloy-network-primitives = { version = "0.9.0", default-features = false }

## alloy-core
alloy-dyn-abi = "0.8.14"
Expand All @@ -228,8 +228,8 @@ alloy-rlp = "0.3"
alloy-trie = "0.7.0"

## op-alloy
op-alloy-rpc-types = "0.8.0"
op-alloy-consensus = "0.8.0"
op-alloy-rpc-types = "0.9.0"
op-alloy-consensus = "0.9.0"

## cli
anstream = "0.6"
Expand Down
5 changes: 0 additions & 5 deletions crates/anvil/core/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl Block {
nonce: partial_header.nonce,
base_fee_per_gas: partial_header.base_fee,
requests_hash: partial_header.requests_hash,
target_blobs_per_block: None,
},
transactions,
ommers: vec![],
Expand Down Expand Up @@ -158,7 +157,6 @@ mod tests {
parent_beacon_block_root: Default::default(),
base_fee_per_gas: None,
requests_hash: None,
target_blobs_per_block: None,
};

let encoded = alloy_rlp::encode(&header);
Expand Down Expand Up @@ -200,7 +198,6 @@ mod tests {
nonce: B64::ZERO,
base_fee_per_gas: None,
requests_hash: None,
target_blobs_per_block: None,
};

header.encode(&mut data);
Expand Down Expand Up @@ -234,7 +231,6 @@ mod tests {
parent_beacon_block_root: None,
base_fee_per_gas: None,
requests_hash: None,
target_blobs_per_block: None,
};
let header = Header::decode(&mut data.as_slice()).unwrap();
assert_eq!(header, expected);
Expand Down Expand Up @@ -267,7 +263,6 @@ mod tests {
excess_blob_gas: None,
parent_beacon_block_root: None,
requests_hash: None,
target_blobs_per_block: None,
};
assert_eq!(header.hash_slow(), expected_hash);
}
Expand Down
9 changes: 4 additions & 5 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ impl TryFrom<AnyRpcTransaction> for TypedTransaction {
TxEnvelope::Eip1559(tx) => Ok(Self::EIP1559(tx)),
TxEnvelope::Eip4844(tx) => Ok(Self::EIP4844(tx)),
TxEnvelope::Eip7702(tx) => Ok(Self::EIP7702(tx)),
_ => Err(ConversionError::Custom("UnsupportedTxType".to_string())),
},
AnyTxEnvelope::Unknown(mut tx) => {
// Try to convert to deposit transaction
Expand Down Expand Up @@ -1260,7 +1259,7 @@ impl From<TypedReceipt<Receipt<alloy_rpc_types::Log>>> for OtsReceipt {
} as u8;
let receipt = ReceiptWithBloom::<Receipt<alloy_rpc_types::Log>>::from(value);
let status = receipt.status();
let cumulative_gas_used = receipt.cumulative_gas_used() as u64;
let cumulative_gas_used = receipt.cumulative_gas_used();
let logs = receipt.logs().to_vec();
let logs_bloom = receipt.logs_bloom;

Expand All @@ -1269,7 +1268,7 @@ impl From<TypedReceipt<Receipt<alloy_rpc_types::Log>>> for OtsReceipt {
}

impl TypedReceipt {
pub fn cumulative_gas_used(&self) -> u128 {
pub fn cumulative_gas_used(&self) -> u64 {
self.as_receipt_with_bloom().cumulative_gas_used()
}

Expand Down Expand Up @@ -1653,7 +1652,7 @@ mod tests {
let receipt = TypedReceipt::Legacy(ReceiptWithBloom {
receipt: Receipt {
status: false.into(),
cumulative_gas_used: 0x1u128,
cumulative_gas_used: 0x1,
logs: vec![Log {
address: Address::from_str("0000000000000000000000000000000000000011").unwrap(),
data: LogData::new_unchecked(
Expand Down Expand Up @@ -1688,7 +1687,7 @@ mod tests {
let expected = TypedReceipt::Legacy(ReceiptWithBloom {
receipt: Receipt {
status: false.into(),
cumulative_gas_used: 0x1u128,
cumulative_gas_used: 0x1,
logs: vec![Log {
address: Address::from_str("0000000000000000000000000000000000000011").unwrap(),
data: LogData::new_unchecked(
Expand Down
7 changes: 4 additions & 3 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@ impl NodeConfig {
blob_excess_gas_and_price.clone()
} else if let Some(excess_blob_gas) = self.genesis.as_ref().and_then(|g| g.excess_blob_gas)
{
BlobExcessGasAndPrice::new(excess_blob_gas as u64)
BlobExcessGasAndPrice::new(excess_blob_gas, false)
} else {
// If no excess blob gas is configured, default to 0
BlobExcessGasAndPrice::new(0)
BlobExcessGasAndPrice::new(0, false)
}
}

Expand Down Expand Up @@ -1213,11 +1213,12 @@ latest block number: {latest_block}"
(block.header.excess_blob_gas, block.header.blob_gas_used)
{
env.block.blob_excess_gas_and_price =
Some(BlobExcessGasAndPrice::new(blob_excess_gas));
Some(BlobExcessGasAndPrice::new(blob_excess_gas, false));
let next_block_blob_excess_gas = fees
.get_next_block_blob_excess_gas(blob_excess_gas as u128, blob_gas_used as u128);
fees.set_blob_excess_gas_and_price(BlobExcessGasAndPrice::new(
next_block_blob_excess_gas,
false,
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ impl EthApi {
let to = tx.to();
let gas_price = tx.gas_price();
let value = tx.value();
let gas = tx.gas_limit() as u128;
let gas = tx.gas_limit();
TxpoolInspectSummary { to, value, gas, gas_price }
}

Expand Down
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use foundry_evm::{
traces::CallTraceNode,
utils::odyssey_handler_register,
};
use revm::{db::WrapDatabaseRef, primitives::MAX_BLOB_GAS_PER_BLOCK};
use revm::db::WrapDatabaseRef;
use std::sync::Arc;

/// Represents an executed transaction (transacted on the DB)
Expand All @@ -57,7 +57,7 @@ impl ExecutedTransaction {
let status_code = u8::from(self.exit_reason as u8 <= InstructionResult::SelfDestruct as u8);
let receipt_with_bloom: ReceiptWithBloom = Receipt {
status: (status_code == 1).into(),
cumulative_gas_used: *cumulative_gas_used as u128,
cumulative_gas_used: *cumulative_gas_used,
logs,
}
.into();
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> Iterator for &mut TransactionExec
let max_blob_gas = self.blob_gas_used.saturating_add(
transaction.pending_transaction.transaction.transaction.blob_gas().unwrap_or(0),
);
if max_blob_gas > MAX_BLOB_GAS_PER_BLOCK {
if max_blob_gas > alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK {
return Some(TransactionExecutionOutcome::BlobGasExhausted(transaction))
}

Expand Down
20 changes: 10 additions & 10 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ use op_alloy_consensus::{TxDeposit, DEPOSIT_TX_TYPE_ID};
use parking_lot::{Mutex, RwLock};
use revm::{
db::WrapDatabaseRef,
primitives::{
calc_blob_gasprice, BlobExcessGasAndPrice, HashMap, OptimismFields, ResultAndState,
},
primitives::{BlobExcessGasAndPrice, HashMap, OptimismFields, ResultAndState},
};
use std::{
collections::BTreeMap,
Expand Down Expand Up @@ -1289,8 +1287,10 @@ impl Backend {

// update next base fee
self.fees.set_base_fee(next_block_base_fee);
self.fees
.set_blob_excess_gas_and_price(BlobExcessGasAndPrice::new(next_block_excess_blob_gas));
self.fees.set_blob_excess_gas_and_price(BlobExcessGasAndPrice::new(
next_block_excess_blob_gas,
false,
));

// notify all listeners
self.notify_on_new_block(header, block_hash);
Expand Down Expand Up @@ -2341,7 +2341,8 @@ impl Backend {

// Cancun specific
let excess_blob_gas = block.header.excess_blob_gas;
let blob_gas_price = calc_blob_gasprice(excess_blob_gas.unwrap_or_default());
let blob_gas_price =
alloy_eips::eip4844::calc_blob_gasprice(excess_blob_gas.unwrap_or_default());
let blob_gas_used = transaction.blob_gas();

let effective_gas_price = match transaction.transaction {
Expand Down Expand Up @@ -2409,14 +2410,14 @@ impl Backend {
transaction_hash: info.transaction_hash,
transaction_index: Some(info.transaction_index),
block_number: Some(block.header.number),
gas_used: info.gas_used as u128,
gas_used: info.gas_used,
contract_address: info.contract_address,
effective_gas_price,
block_hash: Some(block_hash),
from: info.from,
to: info.to,
blob_gas_price: Some(blob_gas_price),
blob_gas_used: blob_gas_used.map(|g| g as u128),
blob_gas_used,
authorization_list: None,
};

Expand Down Expand Up @@ -2809,7 +2810,7 @@ impl TransactionValidator for Backend {

// Ensure the tx does not exceed the max blobs per block.
if blob_count > MAX_BLOBS_PER_BLOCK {
return Err(InvalidTransactionError::TooManyBlobs(MAX_BLOBS_PER_BLOCK, blob_count))
return Err(InvalidTransactionError::TooManyBlobs(blob_count))
}

// Check for any blob validation errors
Expand Down Expand Up @@ -2984,7 +2985,6 @@ pub fn transaction_build(
let new_signed = Signed::new_unchecked(t, sig, hash);
AnyTxEnvelope::Ethereum(TxEnvelope::Eip7702(new_signed))
}
_ => unreachable!("unknown tx type"),
};

let tx = Transaction {
Expand Down
7 changes: 2 additions & 5 deletions crates/anvil/src/eth/backend/mem/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,7 @@ impl MinedTransaction {
GethDebugBuiltInTracerType::CallTracer => {
return match tracer_config.into_call_config() {
Ok(call_config) => Ok(GethTraceBuilder::new(self.info.traces.clone())
.geth_call_traces(
call_config,
self.receipt.cumulative_gas_used() as u64,
)
.geth_call_traces(call_config, self.receipt.cumulative_gas_used())
.into()),
Err(e) => Err(RpcError::invalid_params(e.to_string()).into()),
};
Expand All @@ -578,7 +575,7 @@ impl MinedTransaction {
// default structlog tracer
Ok(GethTraceBuilder::new(self.info.traces.clone())
.geth_traces(
self.receipt.cumulative_gas_used() as u64,
self.receipt.cumulative_gas_used(),
self.info.out.clone().unwrap_or_default(),
config,
)
Expand Down
7 changes: 4 additions & 3 deletions crates/anvil/src/eth/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ pub enum InvalidTransactionError {
/// Thrown when there are no `blob_hashes` in the transaction, and it is an EIP-4844 tx.
#[error("`blob_hashes` are required for EIP-4844 transactions")]
NoBlobHashes,
#[error("too many blobs in one transaction, max: {0}, have: {1}")]
TooManyBlobs(usize, usize),
#[error("too many blobs in one transaction, have: {0}")]
TooManyBlobs(usize),
/// Thrown when there's a blob validation error
#[error(transparent)]
BlobTransactionValidationError(#[from] alloy_consensus::BlobTransactionValidationError),
Expand Down Expand Up @@ -297,14 +297,15 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
InvalidTransaction::BlobCreateTransaction => Self::BlobCreateTransaction,
InvalidTransaction::BlobVersionNotSupported => Self::BlobVersionNotSupported,
InvalidTransaction::EmptyBlobs => Self::EmptyBlobs,
InvalidTransaction::TooManyBlobs { max, have } => Self::TooManyBlobs(max, have),
InvalidTransaction::TooManyBlobs { have } => Self::TooManyBlobs(have),
InvalidTransaction::AuthorizationListNotSupported => {
Self::AuthorizationListNotSupported
}
InvalidTransaction::AuthorizationListInvalidFields |
InvalidTransaction::OptimismError(_) |
InvalidTransaction::EofCrateShouldHaveToAddress |
InvalidTransaction::EmptyAuthorizationList => Self::Revm(err),
InvalidTransaction::GasFloorMoreThanGasLimit => Self::Revm(err),
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::eth::{
use alloy_consensus::Header;
use alloy_eips::{
calc_next_block_base_fee, eip1559::BaseFeeParams, eip4844::MAX_DATA_GAS_PER_BLOCK,
eip7840::BlobParams,
};
use alloy_primitives::B256;
use anvil_core::eth::transaction::TypedTransaction;
Expand Down Expand Up @@ -172,7 +173,7 @@ impl FeeManager {

/// Calculates the next block blob base fee, using the provided excess blob gas
pub fn get_next_block_blob_base_fee_per_gas(&self, excess_blob_gas: u128) -> u128 {
crate::revm::primitives::calc_blob_gasprice(excess_blob_gas as u64)
alloy_eips::eip4844::calc_blob_gasprice(excess_blob_gas as u64)
}

/// Calculates the next block blob excess gas, using the provided parent blob gas used and
Expand All @@ -182,7 +183,7 @@ impl FeeManager {
blob_gas_used: u128,
blob_excess_gas: u128,
) -> u64 {
crate::revm::primitives::calc_excess_blob_gas(blob_gas_used as u64, blob_excess_gas as u64)
alloy_eips::eip4844::calc_excess_blob_gas(blob_gas_used as u64, blob_excess_gas as u64)
}
}

Expand Down Expand Up @@ -246,7 +247,7 @@ impl FeeHistoryService {
let base_fee = header.base_fee_per_gas.map(|g| g as u128).unwrap_or_default();
let excess_blob_gas = header.excess_blob_gas.map(|g| g as u128);
let blob_gas_used = header.blob_gas_used.map(|g| g as u128);
let base_fee_per_blob_gas = header.blob_fee();
let base_fee_per_blob_gas = header.blob_fee(BlobParams::cancun());
let mut item = FeeHistoryCacheItem {
base_fee,
gas_used_ratio: 0f64,
Expand All @@ -270,7 +271,7 @@ impl FeeHistoryService {
blob_gas_used.map(|g| g / MAX_DATA_GAS_PER_BLOCK as f64).unwrap_or(0 as f64);

// extract useful tx info (gas_used, effective_reward)
let mut transactions: Vec<(u128, u128)> = receipts
let mut transactions: Vec<(_, _)> = receipts
.iter()
.enumerate()
.map(|(i, receipt)| {
Expand Down Expand Up @@ -312,7 +313,7 @@ impl FeeHistoryService {
item.rewards = reward_percentiles
.into_iter()
.filter_map(|p| {
let target_gas = (p * gas_used / 100f64) as u128;
let target_gas = (p * gas_used / 100f64) as u64;
let mut sum_gas = 0;
for (gas_used, effective_reward) in transactions.iter().cloned() {
sum_gas += gas_used;
Expand Down
Loading

0 comments on commit 68aff72

Please sign in to comment.