Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fmt and clippy
  • Loading branch information
anikaraghu committed Nov 21, 2023
commit cf142d6a8f0e8547a60c6164548f44a30d77cdd9
14 changes: 8 additions & 6 deletions crates/anvil/core/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,20 @@ impl TypedReceipt {
/// Returns the gas used by the transactions
pub fn gas_used(&self) -> U256 {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) | TypedReceipt::Deposit(r) => {
r.gas_used
}
TypedReceipt::Legacy(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::Deposit(r) => r.gas_used,
}
}

/// Returns the gas used by the transactions
pub fn logs_bloom(&self) -> &Bloom {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) | TypedReceipt::Deposit(r) => {
&r.logs_bloom
}
TypedReceipt::Legacy(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::Deposit(r) => &r.logs_bloom,
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions crates/anvil/core/src/eth/transaction/ethers_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

use super::EthTransactionRequest;
use crate::eth::transaction::{
EIP1559TransactionRequest, EIP2930TransactionRequest, LegacyTransactionRequest,
MaybeImpersonatedTransaction, TypedTransaction, TypedTransactionRequest,
DepositTransactionRequest,
DepositTransactionRequest, EIP1559TransactionRequest, EIP2930TransactionRequest,
LegacyTransactionRequest, MaybeImpersonatedTransaction, TypedTransaction,
TypedTransactionRequest,
};
use ethers_core::types::{
transaction::eip2718::TypedTransaction as EthersTypedTransactionRequest, Address,
Eip1559TransactionRequest as EthersEip1559TransactionRequest,
transaction::{
eip2718::TypedTransaction as EthersTypedTransactionRequest, optimism::DepositTransaction,
},
Address, Eip1559TransactionRequest as EthersEip1559TransactionRequest,
Eip2930TransactionRequest as EthersEip2930TransactionRequest, NameOrAddress,
Transaction as EthersTransaction, TransactionRequest as EthersLegacyTransactionRequest,
TransactionRequest, H256, U256, U64, transaction::optimism::DepositTransaction,
TransactionRequest, H256, U256, U64,
};

impl From<TypedTransactionRequest> for EthersTypedTransactionRequest {
Expand Down Expand Up @@ -110,9 +112,9 @@ impl From<TypedTransactionRequest> for EthersTypedTransactionRequest {
nonce: Some(0.into()),
chain_id: None,
},
source_hash: source_hash,
source_hash,
mint: Some(mint),
is_system_tx: is_system_tx,
is_system_tx,
})
}
}
Expand Down
31 changes: 22 additions & 9 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use foundry_evm::traces::CallTraceArena;
use foundry_utils::types::ToAlloy;
use revm::{
interpreter::InstructionResult,
primitives::{CreateScheme, TransactTo, TxEnv, OptimismFields},
primitives::{CreateScheme, OptimismFields, TransactTo, TxEnv},
};
use std::ops::Deref;

Expand Down Expand Up @@ -48,7 +48,8 @@ pub enum TypedTransactionRequest {
/// Represents _all_ transaction requests received from RPC
#[derive(Clone, Debug, PartialEq, Eq, Default, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
// #[cfg_attr(feature = "serde", serde(deny_unknown_fields))] // TODO: had to disable this to get tests passing
// #[cfg_attr(feature = "serde", serde(deny_unknown_fields))] // TODO: had to disable this to get
// tests passing
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct EthTransactionRequest {
/// from address
Expand Down Expand Up @@ -154,7 +155,8 @@ impl EthTransactionRequest {
}))
}
// op-stack deposit
(Some(126), _, None, None, None) => { // TODO: gas price should be zero, enforce this here?
(Some(126), _, None, None, None) => {
// TODO: gas price should be zero, enforce this here?
Some(TypedTransactionRequest::Deposit(DepositTransactionRequest {
source_hash: source_hash.unwrap_or_default(),
from: from.unwrap_or_default(),
Expand Down Expand Up @@ -831,9 +833,7 @@ impl TypedTransaction {
let s = U256::from_big_endian(&tx.s[..]);
Signature { r, s, v: v.into() }
}
TypedTransaction::Deposit(_) => {
Signature { r: U256::zero(), s: U256::zero(), v: 0 }
},
TypedTransaction::Deposit(_) => Signature { r: U256::zero(), s: U256::zero(), v: 0 },
}
}
}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ impl PendingTransaction {
}

pub fn nonce(&self) -> &U256 {
&self.transaction.nonce()
self.transaction.nonce()
}

pub fn hash(&self) -> &TxHash {
Expand Down Expand Up @@ -1456,7 +1456,17 @@ impl PendingTransaction {
}
TypedTransaction::Deposit(tx) => {
let chain_id = tx.chain_id();
let DepositTransaction { nonce, source_hash, gas_limit, value, kind, mint, input, is_system_tx, .. } = tx;
let DepositTransaction {
nonce,
source_hash,
gas_limit,
value,
kind,
mint,
input,
is_system_tx,
..
} = tx;
TxEnv {
caller: caller.to_alloy(),
transact_to: transact_to(kind),
Expand Down Expand Up @@ -1803,7 +1813,10 @@ mod tests {
let bytes_sixth = &mut &hex::decode("b8587ef85507a0000000000000000000000000000000000000000000000000000000000000000094cf7f9e66af820a19257a2108375b180b0ec491679461815774383099e24810ab832a5b2a5425c154d5808230398287fb0180").unwrap()[..];
let expected: TypedTransaction = TypedTransaction::Deposit(DepositTransaction {
nonce: 7u64.into(),
source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
source_hash: H256::from_str(
"0000000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
from: H160::from_str("cf7f9e66af820a19257a2108375b180b0ec49167").unwrap(),
kind: TransactionKind::Call(Address::from_slice(
&hex::decode("61815774383099e24810ab832a5b2a5425c154d5").unwrap()[..],
Expand Down
13 changes: 8 additions & 5 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ use ethers::{
eip712::TypedData,
},
Address, Block, BlockId, BlockNumber, Bytes, FeeHistory, Filter, FilteredParams,
GethDebugTracingOptions, GethTrace, Log, Trace, Transaction, TransactionReceipt, TxHash,
TxpoolContent, TxpoolInspectSummary, TxpoolStatus, H256, U256, U64, Signature
GethDebugTracingOptions, GethTrace, Log, Signature, Trace, Transaction, TransactionReceipt,
TxHash, TxpoolContent, TxpoolInspectSummary, TxpoolStatus, H256, U256, U64,
},
utils::rlp,
};
Expand Down Expand Up @@ -411,16 +411,19 @@ impl EthApi {
) -> Result<TypedTransaction> {
match request {
TypedTransactionRequest::Deposit(_) => {
return build_typed_transaction(request, Signature { r: U256([0, 0, 0, 0]), s: U256([0, 0, 0, 0]), v: 0 })
},
return build_typed_transaction(
request,
Signature { r: U256::zero(), s: U256::zero(), v: 0 },
)
}
_ => {
for signer in self.signers.iter() {
if signer.accounts().contains(from) {
let signature = signer.sign_transaction(request.clone(), from)?;
return build_typed_transaction(request, signature)
}
}
},
}
}
Err(BlockchainError::NoSignerAvailable)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use anvil_core::eth::{
block::{Block, BlockInfo, Header, PartialHeader},
receipt::{EIP1559Receipt, EIP2930Receipt, EIP658Receipt, DepositReceipt, Log, TypedReceipt},
receipt::{DepositReceipt, EIP1559Receipt, EIP2930Receipt, EIP658Receipt, Log, TypedReceipt},
transaction::{PendingTransaction, TransactionInfo, TypedTransaction},
trie,
};
Expand Down
3 changes: 2 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,8 @@ impl TransactionValidator for Backend {
}

// check nonce
let is_deposit_tx = matches!(&pending.transaction.transaction, TypedTransaction::Deposit(_));
let is_deposit_tx =
matches!(&pending.transaction.transaction, TypedTransaction::Deposit(_));
let nonce: u64 =
(*tx.nonce()).try_into().map_err(|_| InvalidTransactionError::NonceMaxValue)?;
if nonce < account.nonce && !is_deposit_tx {
Expand Down
4 changes: 1 addition & 3 deletions crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ impl FeeHistoryService {
.max_priority_fee_per_gas
.min(t.max_fee_per_gas.saturating_sub(base_fee))
.as_u64(),
Some(TypedTransaction::Deposit(_)) => {
0
}
Some(TypedTransaction::Deposit(_)) => 0,
None => 0,
};

Expand Down
16 changes: 12 additions & 4 deletions crates/anvil/src/eth/sign.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::eth::error::BlockchainError;
use anvil_core::eth::transaction::{
EIP1559Transaction, EIP1559TransactionRequest, EIP2930Transaction, EIP2930TransactionRequest,
LegacyTransaction, LegacyTransactionRequest, TypedTransaction, TypedTransactionRequest,
DepositTransaction, DepositTransactionRequest,
DepositTransaction, DepositTransactionRequest, EIP1559Transaction, EIP1559TransactionRequest,
EIP2930Transaction, EIP2930TransactionRequest, LegacyTransaction, LegacyTransactionRequest,
TypedTransaction, TypedTransactionRequest,
};
use ethers::{
core::k256::ecdsa::SigningKey,
Expand Down Expand Up @@ -197,7 +197,15 @@ pub fn build_typed_transaction(
}
TypedTransactionRequest::Deposit(tx) => {
let DepositTransactionRequest {
from, gas_limit, kind, value, input, source_hash, mint, is_system_tx, ..
from,
gas_limit,
kind,
value,
input,
source_hash,
mint,
is_system_tx,
..
} = tx;
TypedTransaction::Deposit(DepositTransaction {
from,
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod genesis;
mod geth;
mod ipc;
mod logs;
mod optimism;
mod proof;
mod pubsub;
mod optimism;
// mod revert; // TODO uncomment <https://github.com/gakonst/ethers-rs/issues/2186>
mod otterscan;
mod sign;
Expand Down
29 changes: 21 additions & 8 deletions crates/anvil/tests/it/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! tests for OP chain support
use anvil::{spawn, NodeConfig};
use ethers_core::types::{H256, Bytes};
use ethers::{
types::{transaction::eip2718::TypedTransaction, transaction::optimism::DepositTransaction, TransactionRequest, U256},
providers::Middleware, abi::Address
abi::Address,
providers::Middleware,
types::{
transaction::{eip2718::TypedTransaction, optimism::DepositTransaction},
TransactionRequest, U256,
},
};
use ethers_core::types::{Bytes, H256};
use std::str::FromStr;

#[tokio::test(flavor = "multi_thread")]
Expand All @@ -26,15 +30,21 @@ async fn test_deposits_not_supported_if_optimism_disabled() {
data: Some(Bytes::default()),
nonce: None,
},
source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
source_hash: H256::from_str(
"0000000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
mint: Some(U256::zero()),
is_system_tx: true,
});

// sending the deposit transaction should fail with error saying not supported
let res = provider.send_transaction(deposit_tx.clone(), None).await;
assert!(res.is_err());
assert!(res.unwrap_err().to_string().contains("op-stack deposit tx received but is not supported"));
assert!(res
.unwrap_err()
.to_string()
.contains("op-stack deposit tx received but is not supported"));
}

#[tokio::test(flavor = "multi_thread")]
Expand All @@ -61,7 +71,10 @@ async fn test_send_value_deposit_transaction() {
data: Some(Bytes::default()),
nonce: None,
},
source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
source_hash: H256::from_str(
"0000000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
mint: Some(U256::zero()),
is_system_tx: true,
});
Expand All @@ -75,7 +88,6 @@ async fn test_send_value_deposit_transaction() {
assert_eq!(balance, send_value);
}


// // TODO: get this working - it tests eth_sendRawTransaction
// #[tokio::test(flavor = "multi_thread")]
// async fn test_send_value_raw_deposit_transaction() {
Expand All @@ -101,7 +113,8 @@ async fn test_send_value_deposit_transaction() {
// data: Some(Bytes::default()),
// nonce: None,
// },
// source_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
// source_hash:
// H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
// mint: Some(U256::zero()),
// is_system_tx: true,
// });
Expand Down
8 changes: 6 additions & 2 deletions crates/forge/bin/cmd/script/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl ScriptArgs {
// Make a one-time gas price estimation
let (gas_price, eip1559_fees) = {
match deployment_sequence.transactions.front().unwrap().typed_tx() {
TypedTransaction::Legacy(_) | TypedTransaction::Eip2930(_) | TypedTransaction::DepositTransaction(_) => {
TypedTransaction::Legacy(_) |
TypedTransaction::Eip2930(_) |
TypedTransaction::DepositTransaction(_) => {
(provider.get_gas_price().await.ok(), None)
}
TypedTransaction::Eip1559(_) => {
Expand Down Expand Up @@ -102,7 +104,9 @@ impl ScriptArgs {
} else {
// fill gas price
match tx {
TypedTransaction::Eip2930(_) | TypedTransaction::Legacy(_) | TypedTransaction::DepositTransaction(_) => {
TypedTransaction::Eip2930(_) |
TypedTransaction::Legacy(_) |
TypedTransaction::DepositTransaction(_) => {
tx.set_gas_price(gas_price.expect("Could not get gas_price."));
}
TypedTransaction::Eip1559(ref mut inner) => {
Expand Down