From e0fc3342d460db68ea4caf221dbd2c910ca3a9a0 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Thu, 29 Feb 2024 11:59:33 +0000 Subject: [PATCH] feat(primitives): remove `TxValue` wrapper (#6874) --- bin/reth/src/commands/db/static_files/mod.rs | 2 +- crates/consensus/common/src/validation.rs | 4 +- .../interfaces/src/test_utils/generators.rs | 6 +- crates/net/eth-wire/src/types/blocks.rs | 8 +- crates/net/eth-wire/src/types/transactions.rs | 28 ++-- crates/net/network/tests/it/requests.rs | 2 +- crates/primitives/src/lib.rs | 2 +- crates/primitives/src/proofs.rs | 3 +- crates/primitives/src/revm/env.rs | 10 +- .../primitives/src/transaction/access_list.rs | 3 +- crates/primitives/src/transaction/eip1559.rs | 8 +- crates/primitives/src/transaction/eip2930.rs | 10 +- crates/primitives/src/transaction/eip4844.rs | 6 +- crates/primitives/src/transaction/legacy.rs | 8 +- crates/primitives/src/transaction/mod.rs | 18 ++- crates/primitives/src/transaction/optimism.rs | 12 +- crates/primitives/src/transaction/tx_value.rs | 128 ------------------ .../rpc-types-compat/src/transaction/mod.rs | 4 +- .../rpc-types-compat/src/transaction/typed.rs | 8 +- crates/rpc/rpc/src/debug.rs | 3 +- crates/rpc/rpc/src/eth/api/transactions.rs | 2 +- crates/rpc/rpc/src/txpool.rs | 2 +- .../storage/codecs/derive/src/compact/mod.rs | 5 - crates/transaction-pool/src/test_utils/gen.rs | 8 +- .../transaction-pool/src/test_utils/mock.rs | 22 +-- crates/transaction-pool/src/traits.rs | 2 +- crates/transaction-pool/src/validate/eth.rs | 2 +- 27 files changed, 89 insertions(+), 227 deletions(-) delete mode 100644 crates/primitives/src/transaction/tx_value.rs diff --git a/bin/reth/src/commands/db/static_files/mod.rs b/bin/reth/src/commands/db/static_files/mod.rs index eb433ac6143c..7b12437ff2ef 100644 --- a/bin/reth/src/commands/db/static_files/mod.rs +++ b/bin/reth/src/commands/db/static_files/mod.rs @@ -183,7 +183,7 @@ impl Command { fn generate_static_file( &self, factory: Arc>, - segment: impl Segment + Send + Sync, + segment: impl Segment, config: SegmentConfig, ) -> eyre::Result<()> { let dir = PathBuf::default(); diff --git a/crates/consensus/common/src/validation.rs b/crates/consensus/common/src/validation.rs index 6857c4a23084..9c1f523aa31f 100644 --- a/crates/consensus/common/src/validation.rs +++ b/crates/consensus/common/src/validation.rs @@ -439,7 +439,7 @@ mod tests { gas_price: 0x28f000fff, gas_limit: 10, to: TransactionKind::Call(Address::default()), - value: 3_u64.into(), + value: U256::from(3_u64), input: Bytes::from(vec![1, 2]), access_list: Default::default(), }); @@ -461,7 +461,7 @@ mod tests { max_fee_per_blob_gas: 0x7, gas_limit: 10, to: TransactionKind::Call(Address::default()), - value: 3_u64.into(), + value: U256::from(3_u64), input: Bytes::from(vec![1, 2]), access_list: Default::default(), blob_versioned_hashes: std::iter::repeat_with(|| rng.gen()).take(num_blobs).collect(), diff --git a/crates/interfaces/src/test_utils/generators.rs b/crates/interfaces/src/test_utils/generators.rs index d8ebc129ba12..826a737d6684 100644 --- a/crates/interfaces/src/test_utils/generators.rs +++ b/crates/interfaces/src/test_utils/generators.rs @@ -80,7 +80,7 @@ pub fn random_tx(rng: &mut R) -> Transaction { gas_price: rng.gen::().into(), gas_limit: rng.gen::().into(), to: TransactionKind::Call(rng.gen()), - value: U256::from(rng.gen::()).into(), + value: U256::from(rng.gen::()), input: Bytes::default(), }) } @@ -396,7 +396,7 @@ mod tests { nonce: 0x42, gas_limit: 44386, to: TransactionKind::Call(hex!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into()), - value: 0_u64.into(), + value: U256::from(0_u64), input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(), max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, @@ -428,7 +428,7 @@ mod tests { gas_price: 20 * 10_u128.pow(9), gas_limit: 21000, to: TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()), - value: 10_u128.pow(18).into(), + value: U256::from(10_u128.pow(18)), input: Bytes::default(), }); diff --git a/crates/net/eth-wire/src/types/blocks.rs b/crates/net/eth-wire/src/types/blocks.rs index b27c028cf581..9491e34f0948 100644 --- a/crates/net/eth-wire/src/types/blocks.rs +++ b/crates/net/eth-wire/src/types/blocks.rs @@ -386,7 +386,7 @@ mod tests { gas_price: 0x4a817c808, gas_limit: 0x2e248u64, to: TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()), - value: 0x200u64.into(), + value: U256::from(0x200u64), input: Default::default(), }), Signature { @@ -401,7 +401,7 @@ mod tests { gas_price: 0x4a817c809, gas_limit: 0x33450u64, to: TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()), - value: 0x2d9u64.into(), + value: U256::from(0x2d9u64), input: Default::default(), }), Signature { odd_y_parity: false, @@ -458,7 +458,7 @@ mod tests { gas_price: 0x4a817c808, gas_limit: 0x2e248u64, to: TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()), - value: 0x200u64.into(), + value: U256::from(0x200u64), input: Default::default(), }), Signature { @@ -474,7 +474,7 @@ mod tests { gas_price: 0x4a817c809, gas_limit: 0x33450u64, to: TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()), - value: 0x2d9u64.into(), + value: U256::from(0x2d9u64), input: Default::default(), }), Signature { diff --git a/crates/net/eth-wire/src/types/transactions.rs b/crates/net/eth-wire/src/types/transactions.rs index 6288be35cda4..dd593c5c7bb6 100644 --- a/crates/net/eth-wire/src/types/transactions.rs +++ b/crates/net/eth-wire/src/types/transactions.rs @@ -130,7 +130,7 @@ mod tests { to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), - value: 0x200u64.into(), + value: U256::from(0x200u64), input: Default::default(), }), Signature { @@ -154,7 +154,7 @@ mod tests { to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), - value: 0x2d9u64.into(), + value: U256::from(0x2d9u64), input: Default::default(), }), Signature { @@ -192,7 +192,7 @@ mod tests { to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), - value: 0x200u64.into(), + value: U256::from(0x200u64), input: Default::default(), }), Signature { @@ -216,7 +216,7 @@ mod tests { to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), - value: 0x2d9u64.into(), + value: U256::from(0x2d9u64), input: Default::default(), }), Signature { @@ -257,7 +257,7 @@ mod tests { to: TransactionKind::Call( hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(), ), - value: 1234u64.into(), + value: U256::from(1234u64), input: Default::default(), }), Signature { @@ -282,7 +282,7 @@ mod tests { to: TransactionKind::Call( hex!("61815774383099e24810ab832a5b2a5425c154d5").into(), ), - value: 3000000000000000000u64.into(), + value: U256::from(3000000000000000000u64), input: Default::default(), access_list: Default::default(), }), @@ -307,7 +307,7 @@ mod tests { to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), - value: 1000000000000000u64.into(), + value: U256::from(1000000000000000u64), input: Default::default(), }), Signature { @@ -331,7 +331,7 @@ mod tests { to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), - value: 693361000000000u64.into(), + value: U256::from(693361000000000u64), input: Default::default(), }), Signature { @@ -355,7 +355,7 @@ mod tests { to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), - value: 1000000000000000u64.into(), + value: U256::from(1000000000000000u64), input: Default::default(), }), Signature { @@ -400,7 +400,7 @@ mod tests { to: TransactionKind::Call( hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(), ), - value: 1234u64.into(), + value: U256::from(1234u64), input: Default::default(), }), Signature { @@ -425,7 +425,7 @@ mod tests { to: TransactionKind::Call( hex!("61815774383099e24810ab832a5b2a5425c154d5").into(), ), - value: 3000000000000000000u64.into(), + value: U256::from(3000000000000000000u64), input: Default::default(), access_list: Default::default(), }), @@ -450,7 +450,7 @@ mod tests { to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), - value: 1000000000000000u64.into(), + value: U256::from(1000000000000000u64), input: Default::default(), }), Signature { @@ -474,7 +474,7 @@ mod tests { to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), - value: 693361000000000u64.into(), + value: U256::from(693361000000000u64), input: Default::default(), }), Signature { @@ -498,7 +498,7 @@ mod tests { to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), - value: 1000000000000000u64.into(), + value: U256::from(1000000000000000u64), input: Default::default(), }), Signature { diff --git a/crates/net/network/tests/it/requests.rs b/crates/net/network/tests/it/requests.rs index 535cf4167530..decc9ee2507e 100644 --- a/crates/net/network/tests/it/requests.rs +++ b/crates/net/network/tests/it/requests.rs @@ -26,7 +26,7 @@ pub fn rng_transaction(rng: &mut impl rand::RngCore) -> TransactionSigned { gas_price: rng.gen(), gas_limit: rng.gen(), to: TransactionKind::Create, - value: rng.gen::().into(), + value: U256::from(rng.gen::()), input: Bytes::from(vec![1, 2]), access_list: Default::default(), }); diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 1e94e0e41e66..72ebcdfc9b0e 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -92,7 +92,7 @@ pub use transaction::{ AccessList, AccessListItem, FromRecoveredTransaction, IntoRecoveredTransaction, InvalidTransactionError, Signature, Transaction, TransactionKind, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TxEip1559, TxEip2930, - TxEip4844, TxHashOrNumber, TxLegacy, TxType, TxValue, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, + TxEip4844, TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, }; pub use withdrawal::{Withdrawal, Withdrawals}; diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index 1f7fd26635ff..b42a2654822b 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -5,9 +5,8 @@ use crate::{ keccak256, trie::{HashBuilder, Nibbles, TrieAccount}, Address, Header, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, TransactionSigned, Withdrawal, - B256, + B256, U256, }; -use alloy_primitives::U256; use alloy_rlp::Encodable; use bytes::{BufMut, BytesMut}; use itertools::Itertools; diff --git a/crates/primitives/src/revm/env.rs b/crates/primitives/src/revm/env.rs index f8e02a85ecdb..a46eaf5b32a2 100644 --- a/crates/primitives/src/revm/env.rs +++ b/crates/primitives/src/revm/env.rs @@ -200,7 +200,7 @@ where TransactionKind::Call(to) => TransactTo::Call(to), TransactionKind::Create => TransactTo::create(), }; - tx_env.value = tx.value.into(); + tx_env.value = tx.value; tx_env.data = tx.input.clone(); tx_env.chain_id = tx.chain_id; tx_env.nonce = Some(tx.nonce); @@ -216,7 +216,7 @@ where TransactionKind::Call(to) => TransactTo::Call(to), TransactionKind::Create => TransactTo::create(), }; - tx_env.value = tx.value.into(); + tx_env.value = tx.value; tx_env.data = tx.input.clone(); tx_env.chain_id = Some(tx.chain_id); tx_env.nonce = Some(tx.nonce); @@ -239,7 +239,7 @@ where TransactionKind::Call(to) => TransactTo::Call(to), TransactionKind::Create => TransactTo::create(), }; - tx_env.value = tx.value.into(); + tx_env.value = tx.value; tx_env.data = tx.input.clone(); tx_env.chain_id = Some(tx.chain_id); tx_env.nonce = Some(tx.nonce); @@ -262,7 +262,7 @@ where TransactionKind::Call(to) => TransactTo::Call(to), TransactionKind::Create => TransactTo::create(), }; - tx_env.value = tx.value.into(); + tx_env.value = tx.value; tx_env.data = tx.input.clone(); tx_env.chain_id = Some(tx.chain_id); tx_env.nonce = Some(tx.nonce); @@ -287,7 +287,7 @@ where TransactionKind::Call(to) => tx_env.transact_to = TransactTo::Call(to), TransactionKind::Create => tx_env.transact_to = TransactTo::create(), } - tx_env.value = tx.value.into(); + tx_env.value = tx.value; tx_env.data = tx.input.clone(); tx_env.chain_id = None; tx_env.nonce = None; diff --git a/crates/primitives/src/transaction/access_list.rs b/crates/primitives/src/transaction/access_list.rs index ba74aaf1435d..a20ac67cf420 100644 --- a/crates/primitives/src/transaction/access_list.rs +++ b/crates/primitives/src/transaction/access_list.rs @@ -1,5 +1,4 @@ -use crate::{Address, B256}; -use alloy_primitives::U256; +use crate::{Address, B256, U256}; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; use reth_codecs::{main_codec, Compact}; use std::{ diff --git a/crates/primitives/src/transaction/eip1559.rs b/crates/primitives/src/transaction/eip1559.rs index 5c299806b834..f78de0372fa2 100644 --- a/crates/primitives/src/transaction/eip1559.rs +++ b/crates/primitives/src/transaction/eip1559.rs @@ -1,5 +1,5 @@ use super::access_list::AccessList; -use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, TxValue, B256}; +use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use bytes::BytesMut; use reth_codecs::{main_codec, Compact}; @@ -46,7 +46,7 @@ pub struct TxEip1559 { /// be transferred to the message call’s recipient or, /// in the case of contract creation, as an endowment /// to the newly created account; formally Tv. - pub value: TxValue, + pub value: U256, /// The accessList specifies a list of addresses and storage keys; /// these addresses and storage keys are added into the `accessed_addresses` /// and `accessed_storage_keys` global sets (introduced in EIP-2929). @@ -188,7 +188,7 @@ impl TxEip1559 { mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas self.to.size() + // to - mem::size_of::() + // value + mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() // input } @@ -244,7 +244,7 @@ mod tests { nonce: 0x42, gas_limit: 44386, to: TransactionKind::Call( hex!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into()), - value: 0_u64.into(), + value: U256::ZERO, input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(), max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, diff --git a/crates/primitives/src/transaction/eip2930.rs b/crates/primitives/src/transaction/eip2930.rs index 036af743f212..b9c8328bb13b 100644 --- a/crates/primitives/src/transaction/eip2930.rs +++ b/crates/primitives/src/transaction/eip2930.rs @@ -1,5 +1,5 @@ use super::access_list::AccessList; -use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, TxValue, B256}; +use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use bytes::BytesMut; use reth_codecs::{main_codec, Compact}; @@ -34,7 +34,7 @@ pub struct TxEip2930 { /// be transferred to the message call’s recipient or, /// in the case of contract creation, as an endowment /// to the newly created account; formally Tv. - pub value: TxValue, + pub value: U256, /// The accessList specifies a list of addresses and storage keys; /// these addresses and storage keys are added into the `accessed_addresses` /// and `accessed_storage_keys` global sets (introduced in EIP-2929). @@ -58,7 +58,7 @@ impl TxEip2930 { mem::size_of::() + // gas_price mem::size_of::() + // gas_limit self.to.size() + // to - mem::size_of::() + // value + mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() // input } @@ -204,7 +204,7 @@ mod tests { gas_price: 1, gas_limit: 2, to: TransactionKind::Create, - value: 3_u64.into(), + value: U256::from(3), input: Bytes::from(vec![1, 2]), access_list: Default::default(), }); @@ -227,7 +227,7 @@ mod tests { gas_price: 1, gas_limit: 2, to: TransactionKind::Call(Address::default()), - value: 3_u64.into(), + value: U256::from(3), input: Bytes::from(vec![1, 2]), access_list: Default::default(), }); diff --git a/crates/primitives/src/transaction/eip4844.rs b/crates/primitives/src/transaction/eip4844.rs index 11eb6e85684b..3cc6297da5ad 100644 --- a/crates/primitives/src/transaction/eip4844.rs +++ b/crates/primitives/src/transaction/eip4844.rs @@ -1,7 +1,7 @@ use super::access_list::AccessList; use crate::{ constants::eip4844::DATA_GAS_PER_BLOB, keccak256, Bytes, ChainId, Signature, TransactionKind, - TxType, TxValue, B256, + TxType, B256, U256, }; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use bytes::BytesMut; @@ -60,7 +60,7 @@ pub struct TxEip4844 { /// be transferred to the message call’s recipient or, /// in the case of contract creation, as an endowment /// to the newly created account; formally Tv. - pub value: TxValue, + pub value: U256, /// The accessList specifies a list of addresses and storage keys; /// these addresses and storage keys are added into the `accessed_addresses` /// and `accessed_storage_keys` global sets (introduced in EIP-2929). @@ -244,7 +244,7 @@ impl TxEip4844 { mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas self.to.size() + // to - mem::size_of::() + // value + mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() + // input self.blob_versioned_hashes.capacity() * mem::size_of::() + // blob hashes size diff --git a/crates/primitives/src/transaction/legacy.rs b/crates/primitives/src/transaction/legacy.rs index f717764dc2c8..eba89f93dcbe 100644 --- a/crates/primitives/src/transaction/legacy.rs +++ b/crates/primitives/src/transaction/legacy.rs @@ -1,4 +1,4 @@ -use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, TxValue, B256}; +use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Encodable, Header}; use bytes::BytesMut; use reth_codecs::{main_codec, Compact}; @@ -33,7 +33,7 @@ pub struct TxLegacy { /// be transferred to the message call’s recipient or, /// in the case of contract creation, as an endowment /// to the newly created account; formally Tv. - pub value: TxValue, + pub value: U256, /// Input has two uses depending if transaction is Create or Call (if `to` field is None or /// Some). pub init: An unlimited size byte array specifying the /// EVM-code for the account initialisation procedure CREATE, @@ -51,7 +51,7 @@ impl TxLegacy { mem::size_of::() + // gas_price mem::size_of::() + // gas_limit self.to.size() + // to - mem::size_of::() + // value + mem::size_of::() + // value self.input.len() // input } @@ -191,7 +191,7 @@ mod tests { gas_price: 0xfa56ea00, gas_limit: 119902, to: TransactionKind::Call( hex!("06012c8cf97bead5deae237070f9587f8e7a266d").into()), - value: 0x1c6bf526340000u64.into(), + value: U256::from(0x1c6bf526340000u64), input: hex!("f7d8c88300000000000000000000000000000000000000000000000000000000000cee6100000000000000000000000000000000000000000000000000000000000ac3e1").into(), }); diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 7bd67a570c7f..565b88c55398 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1,6 +1,6 @@ use crate::{ compression::{TRANSACTION_COMPRESSOR, TRANSACTION_DECOMPRESSOR}, - keccak256, Address, BlockHashOrNumber, Bytes, TxHash, B256, + keccak256, Address, BlockHashOrNumber, Bytes, TxHash, B256, U256, }; use alloy_rlp::{ Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE, EMPTY_STRING_CODE, @@ -32,7 +32,6 @@ pub use signature::Signature; pub use tx_type::{ TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, }; -pub use tx_value::TxValue; pub use variant::TransactionSignedVariant; mod access_list; @@ -48,7 +47,6 @@ mod pooled; mod sidecar; mod signature; mod tx_type; -mod tx_value; pub(crate) mod util; mod variant; @@ -192,7 +190,7 @@ impl Transaction { } /// Gets the transaction's value field. - pub fn value(&self) -> TxValue { + pub fn value(&self) -> U256 { *match self { Transaction::Legacy(TxLegacy { value, .. }) | Transaction::Eip2930(TxEip2930 { value, .. }) | @@ -481,7 +479,7 @@ impl Transaction { } /// This sets the transaction's value. - pub fn set_value(&mut self, value: TxValue) { + pub fn set_value(&mut self, value: U256) { match self { Transaction::Legacy(tx) => tx.value = value, Transaction::Eip2930(tx) => tx.value = value, @@ -1691,7 +1689,7 @@ mod tests { to: TransactionKind::Call( Address::from_str("d3e8763675e4c425df46cc3b5c0f6cbdac396046").unwrap(), ), - value: 1000000000000000_u64.into(), + value: U256::from(1000000000000000u64), input: Bytes::default(), }); let signature = Signature { @@ -1713,7 +1711,7 @@ mod tests { to: TransactionKind::Call(Address::from_slice( &hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046")[..], )), - value: 693361000000000_u64.into(), + value: U256::from(693361000000000u64), input: Default::default(), }); let signature = Signature { @@ -1734,7 +1732,7 @@ mod tests { to: TransactionKind::Call(Address::from_slice( &hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046")[..], )), - value: 1000000000000000_u64.into(), + value: U256::from(1000000000000000u64), input: Bytes::default(), }); let signature = Signature { @@ -1756,7 +1754,7 @@ mod tests { to: TransactionKind::Call(Address::from_slice( &hex!("61815774383099e24810ab832a5b2a5425c154d5")[..], )), - value: 3000000000000000000_u64.into(), + value: U256::from(3000000000000000000u64), input: Default::default(), access_list: Default::default(), }); @@ -1778,7 +1776,7 @@ mod tests { to: TransactionKind::Call(Address::from_slice( &hex!("cf7f9e66af820a19257a2108375b180b0ec49167")[..], )), - value: 1234_u64.into(), + value: U256::from(1234), input: Bytes::default(), }); let signature = Signature { diff --git a/crates/primitives/src/transaction/optimism.rs b/crates/primitives/src/transaction/optimism.rs index 400074bd0ad7..97d9edc5873a 100644 --- a/crates/primitives/src/transaction/optimism.rs +++ b/crates/primitives/src/transaction/optimism.rs @@ -1,4 +1,4 @@ -use crate::{Address, Bytes, TransactionKind, TxType, TxValue, B256}; +use crate::{Address, Bytes, TransactionKind, TxType, B256, U256}; use alloy_rlp::{ length_of_length, Decodable, Encodable, Error as DecodeError, Header, EMPTY_STRING_CODE, }; @@ -20,7 +20,7 @@ pub struct TxDeposit { /// The ETH value to mint on L2. pub mint: Option, /// The ETH value to send to the recipient account. - pub value: TxValue, + pub value: U256, /// The gas limit for the L2 transaction. pub gas_limit: u64, /// Field indicating if this transaction is exempt from the L2 gas limit. @@ -38,7 +38,7 @@ impl TxDeposit { mem::size_of::
() + // from self.to.size() + // to mem::size_of::>() + // mint - mem::size_of::() + // value + mem::size_of::() + // value mem::size_of::() + // gas_limit mem::size_of::() + // is_system_transaction self.input.len() // input @@ -171,7 +171,7 @@ mod tests { from: Address::default(), to: TransactionKind::default(), mint: Some(100), - value: TxValue::default(), + value: U256::default(), gas_limit: 50000, is_system_transaction: true, input: Bytes::default(), @@ -191,7 +191,7 @@ mod tests { from: Address::default(), to: TransactionKind::default(), mint: Some(100), - value: TxValue::default(), + value: U256::default(), gas_limit: 50000, is_system_transaction: true, input: Bytes::default(), @@ -213,7 +213,7 @@ mod tests { from: Address::default(), to: TransactionKind::default(), mint: Some(100), - value: TxValue::default(), + value: U256::default(), gas_limit: 50000, is_system_transaction: true, input: Bytes::default(), diff --git a/crates/primitives/src/transaction/tx_value.rs b/crates/primitives/src/transaction/tx_value.rs deleted file mode 100644 index da1c133d0c0e..000000000000 --- a/crates/primitives/src/transaction/tx_value.rs +++ /dev/null @@ -1,128 +0,0 @@ -use crate::{ruint::UintTryFrom, U256}; -use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; -use reth_codecs::{add_arbitrary_tests, Compact}; -use serde::{Deserialize, Serialize}; - -/// TxValue is the type of the `value` field in the various Ethereum transactions structs. -/// -/// While the field is 256 bits, for many chains it's not possible for the field to use -/// this full precision, hence we use a wrapper type to allow for overriding of encoding. -#[add_arbitrary_tests(compact, rlp)] -#[derive( - Default, - Debug, - Copy, - Clone, - Hash, - PartialEq, - Eq, - Serialize, - Deserialize, - RlpEncodableWrapper, - RlpDecodableWrapper, -)] -pub struct TxValue(U256); - -impl From for U256 { - #[inline] - fn from(value: TxValue) -> U256 { - value.0 - } -} - -impl From for TxValue -where - U256: UintTryFrom, -{ - #[inline] - #[track_caller] - fn from(value: T) -> Self { - Self(U256::uint_try_from(value).unwrap()) - } -} - -/// As ethereum circulation on mainnet is around 120mil eth as of 2022 that is around -/// 120000000000000000000000000 wei we are safe to use u128 for TxValue's encoding -/// as its max number is 340282366920938463463374607431768211455. -/// This optimization should be disabled for chains such as Optimism, where -/// some tx values may require more than 128-bit precision. -impl Compact for TxValue { - #[inline] - fn to_compact(self, buf: &mut B) -> usize - where - B: bytes::BufMut + AsMut<[u8]>, - { - #[cfg(feature = "optimism")] - { - self.0.to_compact(buf) - } - #[cfg(not(feature = "optimism"))] - { - self.0.to::().to_compact(buf) - } - } - - #[inline] - fn from_compact(buf: &[u8], identifier: usize) -> (Self, &[u8]) { - #[cfg(feature = "optimism")] - { - let (i, buf) = U256::from_compact(buf, identifier); - (TxValue(i), buf) - } - #[cfg(not(feature = "optimism"))] - { - let (i, buf) = u128::from_compact(buf, identifier); - (TxValue::from(i), buf) - } - } -} - -impl std::fmt::Display for TxValue { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) - } -} - -impl PartialEq for TxValue { - fn eq(&self, other: &U256) -> bool { - self.0.eq(other) - } -} - -#[cfg(any(test, feature = "arbitrary"))] -impl<'a> arbitrary::Arbitrary<'a> for TxValue { - #[inline] - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - #[cfg(feature = "optimism")] - { - U256::arbitrary(u).map(Self) - } - #[cfg(not(feature = "optimism"))] - { - u128::arbitrary(u).map(Self::from) - } - } -} - -#[cfg(any(test, feature = "arbitrary"))] -impl proptest::arbitrary::Arbitrary for TxValue { - type Parameters = ::Parameters; - #[inline] - fn arbitrary_with((): Self::Parameters) -> Self::Strategy { - use proptest::strategy::Strategy; - - #[cfg(feature = "optimism")] - { - proptest::prelude::any::().prop_map(Self) - } - #[cfg(not(feature = "optimism"))] - { - proptest::prelude::any::().prop_map(Self::from) - } - } - #[cfg(feature = "optimism")] - type Strategy = proptest::arbitrary::Mapped; - - #[cfg(not(feature = "optimism"))] - type Strategy = proptest::arbitrary::Mapped; -} diff --git a/crates/rpc/rpc-types-compat/src/transaction/mod.rs b/crates/rpc/rpc-types-compat/src/transaction/mod.rs index 5ecad24dca8c..c29359ec7e28 100644 --- a/crates/rpc/rpc-types-compat/src/transaction/mod.rs +++ b/crates/rpc/rpc-types-compat/src/transaction/mod.rs @@ -124,7 +124,7 @@ fn fill( nonce: U64::from(signed_tx.nonce()), from: signer, to, - value: signed_tx.value().into(), + value: signed_tx.value(), gas_price, max_fee_per_gas, max_priority_fee_per_gas: signed_tx.max_priority_fee_per_gas().map(U128::from), @@ -200,7 +200,7 @@ pub fn transaction_to_call_request(tx: TransactionSignedEcRecovered) -> Transact max_fee_per_gas: max_fee_per_gas.map(U256::from), max_priority_fee_per_gas: max_priority_fee_per_gas.map(U256::from), gas: Some(U256::from(gas)), - value: Some(value.into()), + value: Some(value), input: TransactionInput::new(input), nonce: Some(U64::from(nonce)), chain_id: chain_id.map(U64::from), diff --git a/crates/rpc/rpc-types-compat/src/transaction/typed.rs b/crates/rpc/rpc-types-compat/src/transaction/typed.rs index 55d316040d4e..2b9b32471465 100644 --- a/crates/rpc/rpc-types-compat/src/transaction/typed.rs +++ b/crates/rpc/rpc-types-compat/src/transaction/typed.rs @@ -17,7 +17,7 @@ pub fn to_primitive_transaction( gas_price: tx.gas_price.to(), gas_limit: tx.gas_limit.try_into().ok()?, to: to_primitive_transaction_kind(tx.kind), - value: tx.value.into(), + value: tx.value, input: tx.input, }), TypedTransactionRequest::EIP2930(tx) => Transaction::Eip2930(TxEip2930 { @@ -26,7 +26,7 @@ pub fn to_primitive_transaction( gas_price: tx.gas_price.to(), gas_limit: tx.gas_limit.try_into().ok()?, to: to_primitive_transaction_kind(tx.kind), - value: tx.value.into(), + value: tx.value, input: tx.input, access_list: tx.access_list.into(), }), @@ -36,7 +36,7 @@ pub fn to_primitive_transaction( max_fee_per_gas: tx.max_fee_per_gas.to(), gas_limit: tx.gas_limit.try_into().ok()?, to: to_primitive_transaction_kind(tx.kind), - value: tx.value.into(), + value: tx.value, input: tx.input, access_list: tx.access_list.into(), max_priority_fee_per_gas: tx.max_priority_fee_per_gas.to(), @@ -48,7 +48,7 @@ pub fn to_primitive_transaction( max_fee_per_gas: tx.max_fee_per_gas.to(), max_priority_fee_per_gas: tx.max_priority_fee_per_gas.to(), to: to_primitive_transaction_kind(tx.kind), - value: tx.value.into(), + value: tx.value, access_list: tx.access_list.into(), blob_versioned_hashes: tx.blob_versioned_hashes, max_fee_per_blob_gas: tx.max_fee_per_blob_gas.to(), diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index ada59386d6ac..b5105dcd3fc7 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -10,13 +10,12 @@ use crate::{ result::{internal_rpc_err, ToRpcResult}, BlockingTaskGuard, EthApiSpec, }; -use alloy_primitives::U256; use alloy_rlp::{Decodable, Encodable}; use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_primitives::{ revm::env::tx_env_with_recovered, Address, Block, BlockId, BlockNumberOrTag, Bytes, - TransactionSignedEcRecovered, Withdrawals, B256, + TransactionSignedEcRecovered, Withdrawals, B256, U256, }; use reth_provider::{ BlockReaderIdExt, ChainSpecProvider, HeaderProvider, StateProviderBox, TransactionVariant, diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index c96d2ee5d4b6..397407b924ac 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -442,7 +442,7 @@ where if let Some(tx) = self.pool().get_pooled_transaction_element(hash).map(|tx| tx.envelope_encoded()) { - return Ok(Some(tx)); + return Ok(Some(tx)) } self.on_blocking_task(|this| async move { diff --git a/crates/rpc/rpc/src/txpool.rs b/crates/rpc/rpc/src/txpool.rs index c61793f2fdf4..f9def07b1b97 100644 --- a/crates/rpc/rpc/src/txpool.rs +++ b/crates/rpc/rpc/src/txpool.rs @@ -96,7 +96,7 @@ where key, TxpoolInspectSummary { to: tx.to(), - value: tx.value().into(), + value: tx.value(), gas: U256::from(tx.gas_limit()), gas_price: U256::from(tx.transaction.max_fee_per_gas()), }, diff --git a/crates/storage/codecs/derive/src/compact/mod.rs b/crates/storage/codecs/derive/src/compact/mod.rs index 39aaa242f2a9..f7e2082c7631 100644 --- a/crates/storage/codecs/derive/src/compact/mod.rs +++ b/crates/storage/codecs/derive/src/compact/mod.rs @@ -164,11 +164,6 @@ pub fn get_bit_size(ftype: &str) -> u8 { "u64" | "BlockNumber" | "TxNumber" | "ChainId" | "NumTransactions" => 4, "u128" => 5, "U256" => 6, - #[cfg(not(feature = "optimism"))] - "TxValue" => 5, // u128 for ethereum chains assuming high order bits are not used - #[cfg(feature = "optimism")] - // for fuzz/prop testing and chains that may require full 256 bits - "TxValue" => 6, _ => 0, } } diff --git a/crates/transaction-pool/src/test_utils/gen.rs b/crates/transaction-pool/src/test_utils/gen.rs index 020cfd06f96d..614b4b00dfa1 100644 --- a/crates/transaction-pool/src/test_utils/gen.rs +++ b/crates/transaction-pool/src/test_utils/gen.rs @@ -3,7 +3,7 @@ use rand::Rng; use reth_primitives::{ constants::MIN_PROTOCOL_BASE_FEE, sign_message, AccessList, Address, Bytes, FromRecoveredTransaction, Transaction, TransactionKind, TransactionSigned, TxEip1559, - TxEip4844, TxLegacy, TxValue, B256, MAINNET, + TxEip4844, TxLegacy, B256, MAINNET, U256, }; /// A generator for transactions for testing purposes. @@ -129,7 +129,7 @@ pub struct TransactionBuilder { /// The recipient or contract address of the transaction. pub to: TransactionKind, /// The value to be transferred in the transaction. - pub value: TxValue, + pub value: U256, /// The list of addresses and storage keys that the transaction can access. pub access_list: AccessList, /// The input data for the transaction, typically containing function parameters for contract @@ -250,7 +250,7 @@ impl TransactionBuilder { /// Sets the value to be transferred in the transaction. pub fn value(mut self, value: u128) -> Self { - self.value = value.into(); + self.value = U256::from(value); self } @@ -310,7 +310,7 @@ impl TransactionBuilder { /// Sets the value to be transferred in the transaction, mutable reference version. pub fn set_value(&mut self, value: u128) -> &mut Self { - self.value = value.into(); + self.value = U256::from(value); self } diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index 904b932f4c09..8fa0673b5308 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -851,7 +851,7 @@ impl FromRecoveredTransaction for MockTransaction { gas_price, gas_limit, to, - value: value.into(), + value, input, size, }, @@ -873,7 +873,7 @@ impl FromRecoveredTransaction for MockTransaction { max_priority_fee_per_gas, gas_limit, to, - value: value.into(), + value, input, accesslist: access_list, size, @@ -899,7 +899,7 @@ impl FromRecoveredTransaction for MockTransaction { max_fee_per_blob_gas, gas_limit, to, - value: value.into(), + value, input, accesslist: access_list, sidecar: BlobTransactionSidecar::default(), @@ -921,7 +921,7 @@ impl FromRecoveredTransaction for MockTransaction { gas_price, gas_limit, to, - value: value.into(), + value, input, accesslist: access_list, size, @@ -989,7 +989,7 @@ impl From for Transaction { gas_price, gas_limit, to, - value: value.into(), + value, input: input.clone(), }), MockTransaction::Eip1559 { @@ -1011,7 +1011,7 @@ impl From for Transaction { max_fee_per_gas, max_priority_fee_per_gas, to, - value: value.into(), + value, access_list: accesslist.clone(), input: input.clone(), }), @@ -1036,7 +1036,7 @@ impl From for Transaction { max_fee_per_gas, max_priority_fee_per_gas, to, - value: value.into(), + value, access_list: accesslist, blob_versioned_hashes: vec![hash], max_fee_per_blob_gas, @@ -1059,7 +1059,7 @@ impl From for Transaction { gas_price, gas_limit, to, - value: value.into(), + value, access_list: accesslist, input, }), @@ -1101,7 +1101,7 @@ impl proptest::arbitrary::Arbitrary for MockTransaction { gas_price: *gas_price, gas_limit: *gas_limit, to: *to, - value: (*value).into(), + value: (*value), input: (*input).clone(), size: tx.size(), }, @@ -1123,7 +1123,7 @@ impl proptest::arbitrary::Arbitrary for MockTransaction { max_priority_fee_per_gas: *max_priority_fee_per_gas, gas_limit: *gas_limit, to: *to, - value: (*value).into(), + value: (*value), input: (*input).clone(), accesslist: (*access_list).clone(), size: tx.size(), @@ -1148,7 +1148,7 @@ impl proptest::arbitrary::Arbitrary for MockTransaction { max_fee_per_blob_gas: *max_fee_per_blob_gas, gas_limit: *gas_limit, to: *to, - value: (*value).into(), + value: (*value), input: (*input).clone(), accesslist: (*access_list).clone(), // only generate a sidecar if it is a 4844 tx - also for the sake of diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index f4c26f6fa990..97397c9efbdc 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -928,7 +928,7 @@ impl EthPooledTransaction { #[cfg(feature = "optimism")] Transaction::Deposit(_) => U256::ZERO, }; - let mut cost: U256 = transaction.value().into(); + let mut cost: U256 = transaction.value(); cost += gas_cost; if let Some(blob_tx) = transaction.as_eip4844() { diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index b8cfa49ca1b9..426b4ca837d3 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -823,7 +823,7 @@ mod tests { from: signer, to: TransactionKind::Create, mint: None, - value: reth_primitives::TxValue::from(U256::ZERO), + value: reth_primitives::U256::ZERO, gas_limit: 0u64, is_system_transaction: false, input: Default::default(),