From 32e2904b98b264bd125a595ea8e1d3c61ca90690 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:09:10 +0200 Subject: [PATCH 01/22] Add trait methods to alloy_consensus::Transaction needed for reth integration --- crates/consensus/src/transaction/mod.rs | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 0b2307c4122..1e8f28669e3 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -1,6 +1,7 @@ //! Transaction types. use crate::Signed; +use alloy_eips::eip2930::AccessList; use alloy_primitives::{keccak256, ChainId, TxKind, B256, U256}; use core::any; @@ -39,6 +40,9 @@ pub use typed::TypedTransaction; /// Represents a minimal EVM transaction. #[doc(alias = "Tx")] pub trait Transaction: any::Any + Send + Sync + 'static { + /// Hash of the transaction. + fn hash(&self) -> &B256; + /// Get `chain_id`. fn chain_id(&self) -> Option; @@ -51,6 +55,24 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// Get `gas_price`. fn gas_price(&self) -> Option; + /// Returns the EIP-1559 the maximum fee per gas the caller is willing to pay. + /// + /// For legacy transactions this is `gas_price`. + /// + /// This is also commonly referred to as the "Gas Fee Cap" (`GasFeeCap`). + fn max_fee_per_gas(&self) -> u128; + + /// Returns the EIP-1559 Priority fee the caller is paying to the block author. + /// + /// This will return `None` for non-EIP1559 transactions + fn max_priority_fee_per_gas(&self) -> Option; + + /// Returns the effective tip for this transaction. + /// + /// For EIP-1559 transactions: `min(max_fee_per_gas - base_fee, max_priority_fee_per_gas)`. + /// For legacy transactions: `gas_price - base_fee`. + fn effective_tip_per_gas(&self, base_fee: u64) -> Option; + /// Get `to`. fn to(&self) -> TxKind; @@ -59,6 +81,17 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// Get `data`. fn input(&self) -> &[u8]; + + /// Returns the transaction type + fn tx_type(&self) -> u8; + + /// Returns the EIP2930 `access_list` for the particular transaction type. Returns `None` for + /// older transaction types. + fn access_list(&self) -> Option<&AccessList>; + + /// Blob versioned hashes for eip4844 transaction. For previous transaction types this is + /// `None`. + fn blob_versioned_hashes(&self) -> Option>; } /// A signable transaction. From 924227b774a30e86106484510acc557befd981e9 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:16:46 +0200 Subject: [PATCH 02/22] Implement alloy_consensus::Transaction gas trait methods --- crates/consensus/src/transaction/eip1559.rs | 8 +++++++ crates/consensus/src/transaction/eip2930.rs | 8 +++++++ crates/consensus/src/transaction/eip4844.rs | 22 ++++++++++++++++++++ crates/consensus/src/transaction/eip7702.rs | 11 +++++++++- crates/consensus/src/transaction/envelope.rs | 18 ++++++++++++++++ crates/consensus/src/transaction/legacy.rs | 8 +++++++ crates/consensus/src/transaction/mod.rs | 2 +- crates/consensus/src/transaction/typed.rs | 18 ++++++++++++++++ 8 files changed, 93 insertions(+), 2 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 219cf98c6fd..efac16715d0 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -280,6 +280,14 @@ impl Transaction for TxEip1559 { None } + fn max_fee_per_gas(&self) -> u128 { + self.max_fee_per_gas + } + + fn max_priority_fee_per_gas(&self) -> Option { + Some(self.max_priority_fee_per_gas) + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index ee0f0896323..10118a7c6b4 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -244,6 +244,14 @@ impl Transaction for TxEip2930 { Some(self.gas_price) } + fn max_fee_per_gas(&self) -> u128 { + self.gas_price + } + + fn max_priority_fee_per_gas(&self) -> Option { + None + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 0b886fcfe19..119473a1ee7 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -214,6 +214,20 @@ impl Transaction for TxEip4844Variant { } } + fn max_fee_per_gas(&self) -> u128 { + match self { + Self::TxEip4844(tx) => tx.max_fee_per_gas(), + Self::TxEip4844WithSidecar(tx) => tx.tx().max_fee_per_gas(), + } + } + + fn max_priority_fee_per_gas(&self) -> Option { + match self { + Self::TxEip4844(tx) => tx.max_priority_fee_per_gas(), + Self::TxEip4844WithSidecar(tx) => tx.tx().max_priority_fee_per_gas(), + } + } + fn gas_price(&self) -> Option { None } @@ -653,6 +667,14 @@ impl Transaction for TxEip4844 { None } + fn max_fee_per_gas(&self) -> u128 { + self.max_fee_per_gas + } + + fn max_priority_fee_per_gas(&self) -> Option { + Some(self.max_priority_fee_per_gas) + } + fn to(&self) -> TxKind { self.to.into() } diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 6db47db3905..93247fd21f7 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -269,7 +269,8 @@ impl TxEip7702 { mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() + // input - self.authorization_list.capacity() * mem::size_of::() // authorization_list + self.authorization_list.capacity() * mem::size_of::() + // authorization_list } } @@ -290,6 +291,14 @@ impl Transaction for TxEip7702 { None } + fn max_fee_per_gas(&self) -> u128 { + self.max_fee_per_gas + } + + fn max_priority_fee_per_gas(&self) -> Option { + Some(self.max_priority_fee_per_gas) + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index a5e7e90c7f0..9c936bf296c 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -389,6 +389,24 @@ impl Transaction for TxEnvelope { } } + fn max_fee_per_gas(&self) -> u128 { + match self { + Self::Legacy(tx) => tx.tx().max_fee_per_gas(), + Self::Eip2930(tx) => tx.tx().max_fee_per_gas(), + Self::Eip1559(tx) => tx.tx().max_fee_per_gas(), + Self::Eip4844(tx) => tx.tx().max_fee_per_gas(), + } + } + + fn max_priority_fee_per_gas(&self) -> Option { + match self { + Self::Legacy(tx) => tx.tx().max_priority_fee_per_gas(), + Self::Eip2930(tx) => tx.tx().max_priority_fee_per_gas(), + Self::Eip1559(tx) => tx.tx().max_priority_fee_per_gas(), + Self::Eip4844(tx) => tx.tx().max_priority_fee_per_gas(), + } + } + fn input(&self) -> &[u8] { match self { Self::Legacy(tx) => tx.tx().input(), diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 04733e405cc..1a5c3dfc397 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -217,6 +217,14 @@ impl Transaction for TxLegacy { Some(self.gas_price) } + fn max_fee_per_gas(&self) -> u128 { + self.gas_price + } + + fn max_priority_fee_per_gas(&self) -> Option { + None + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 1e8f28669e3..3693a154a1d 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -85,7 +85,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// Returns the transaction type fn tx_type(&self) -> u8; - /// Returns the EIP2930 `access_list` for the particular transaction type. Returns `None` for + /// Returns the EIP2930 `access_list` for the particular transaction type. Returns `None` for /// older transaction types. fn access_list(&self) -> Option<&AccessList>; diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 38641ad4f9a..807f1115a0b 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -151,6 +151,24 @@ impl Transaction for TypedTransaction { } } + fn max_fee_per_gas(&self) -> u128 { + match self { + Self::Legacy(tx) => tx.max_fee_per_gas(), + Self::Eip2930(tx) => tx.max_fee_per_gas(), + Self::Eip1559(tx) => tx.max_fee_per_gas(), + Self::Eip4844(tx) => tx.max_fee_per_gas(), + } + } + + fn max_priority_fee_per_gas(&self) -> Option { + match self { + Self::Legacy(tx) => tx.max_priority_fee_per_gas(), + Self::Eip2930(tx) => tx.max_priority_fee_per_gas(), + Self::Eip1559(tx) => tx.max_priority_fee_per_gas(), + Self::Eip4844(tx) => tx.max_priority_fee_per_gas(), + } + } + fn to(&self) -> TxKind { match self { Self::Legacy(tx) => tx.to(), From 7cd7e2bb5cbcca59ea4d5cda2a61abcc430351c2 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:23:10 +0200 Subject: [PATCH 03/22] Implement alloy_consensus::Transaction tx type trait method --- crates/consensus/src/transaction/eip1559.rs | 4 ++++ crates/consensus/src/transaction/eip2930.rs | 4 ++++ crates/consensus/src/transaction/eip4844.rs | 12 ++++++++++++ crates/consensus/src/transaction/eip7702.rs | 4 ++++ crates/consensus/src/transaction/envelope.rs | 9 +++++++++ crates/consensus/src/transaction/legacy.rs | 10 ++++++++-- crates/consensus/src/transaction/mod.rs | 2 +- crates/consensus/src/transaction/typed.rs | 9 +++++++++ 8 files changed, 51 insertions(+), 3 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index efac16715d0..7b389dc064b 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -299,6 +299,10 @@ impl Transaction for TxEip1559 { fn input(&self) -> &[u8] { &self.input } + + fn ty(&self) -> u8 { + TxType::Eip2930 as u8 + } } impl SignableTransaction for TxEip1559 { diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 10118a7c6b4..6e6775ad7bd 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -263,6 +263,10 @@ impl Transaction for TxEip2930 { fn input(&self) -> &[u8] { &self.input } + + fn ty(&self) -> u8 { + TxType::Eip2930 as u8 + } } impl SignableTransaction for TxEip2930 { diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 119473a1ee7..64b0025bcd7 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -253,6 +253,10 @@ impl Transaction for TxEip4844Variant { Self::TxEip4844WithSidecar(tx) => tx.tx().input.as_ref(), } } + + fn ty(&self) -> u8 { + TxType::Eip4844 as u8 + } } impl SignableTransaction for TxEip4844Variant { @@ -686,6 +690,10 @@ impl Transaction for TxEip4844 { fn input(&self) -> &[u8] { &self.input } + + fn ty(&self) -> u8 { + TxType::Eip4844 as u8 + } } impl Encodable for TxEip4844 { @@ -924,6 +932,10 @@ impl Transaction for TxEip4844WithSidecar { fn input(&self) -> &[u8] { self.tx.input() } + + fn ty(&self) -> u8 { + TxType::Eip4844 as u8 + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 93247fd21f7..aead8a81ee1 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -310,6 +310,10 @@ impl Transaction for TxEip7702 { fn input(&self) -> &[u8] { &self.input } + + fn ty(&self) -> u8 { + TxType::Eip7702 as u8 + } } impl SignableTransaction for TxEip7702 { diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 9c936bf296c..678ca505ccb 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -442,6 +442,15 @@ impl Transaction for TxEnvelope { Self::Eip4844(tx) => tx.tx().value(), } } + + fn ty(&self) -> u8 { + match self { + Self::Legacy(tx) => tx.tx().ty(), + Self::Eip2930(tx) => tx.tx().ty(), + Self::Eip1559(tx) => tx.tx().ty(), + Self::Eip4844(tx) => tx.tx().ty(), + } + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 1a5c3dfc397..79b44733a6c 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,7 +1,9 @@ -use crate::{EncodableSignature, SignableTransaction, Signed, Transaction}; +use core::mem; + use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; -use core::mem; + +use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; #[cfg(not(feature = "std"))] use alloc::vec::Vec; @@ -236,6 +238,10 @@ impl Transaction for TxLegacy { fn input(&self) -> &[u8] { &self.input } + + fn ty(&self) -> u8 { + TxType::Legacy as u8 + } } impl SignableTransaction for TxLegacy { diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 3693a154a1d..8bd4bf62776 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -83,7 +83,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static { fn input(&self) -> &[u8]; /// Returns the transaction type - fn tx_type(&self) -> u8; + fn ty(&self) -> u8; /// Returns the EIP2930 `access_list` for the particular transaction type. Returns `None` for /// older transaction types. diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 807f1115a0b..5d225994c55 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -195,6 +195,15 @@ impl Transaction for TypedTransaction { Self::Eip4844(tx) => tx.input(), } } + + fn ty(&self) -> u8 { + match self { + Self::Legacy(tx) => tx.ty(), + Self::Eip2930(tx) => tx.ty(), + Self::Eip1559(tx) => tx.ty(), + Self::Eip4844(tx) => tx.ty(), + } + } } #[cfg(feature = "serde")] From b6f22105be8ef28e06f0f2130227f3c55e254e43 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:31:44 +0200 Subject: [PATCH 04/22] fixup! Implement alloy_consensus::Transaction gas trait methods --- crates/consensus/src/transaction/eip4844.rs | 12 ++++++------ crates/consensus/src/transaction/envelope.rs | 2 ++ crates/consensus/src/transaction/typed.rs | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index a9b4cac75a1..af06b704708 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -212,24 +212,24 @@ impl Transaction for TxEip4844Variant { } } + fn gas_price(&self) -> Option { + None + } + fn max_fee_per_gas(&self) -> u128 { match self { Self::TxEip4844(tx) => tx.max_fee_per_gas(), - Self::TxEip4844WithSidecar(tx) => tx.tx().max_fee_per_gas(), + Self::TxEip4844WithSidecar(tx) => tx.max_fee_per_gas(), } } fn max_priority_fee_per_gas(&self) -> Option { match self { Self::TxEip4844(tx) => tx.max_priority_fee_per_gas(), - Self::TxEip4844WithSidecar(tx) => tx.tx().max_priority_fee_per_gas(), + Self::TxEip4844WithSidecar(tx) => tx.max_priority_fee_per_gas(), } } - fn gas_price(&self) -> Option { - None - } - fn to(&self) -> TxKind { match self { Self::TxEip4844(tx) => tx.to, diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 20f9b4bbea1..21d63d73add 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -438,6 +438,7 @@ impl Transaction for TxEnvelope { Self::Eip2930(tx) => tx.tx().max_fee_per_gas(), Self::Eip1559(tx) => tx.tx().max_fee_per_gas(), Self::Eip4844(tx) => tx.tx().max_fee_per_gas(), + Self::Eip7702(tx) => tx.tx().max_fee_per_gas(), } } @@ -447,6 +448,7 @@ impl Transaction for TxEnvelope { Self::Eip2930(tx) => tx.tx().max_priority_fee_per_gas(), Self::Eip1559(tx) => tx.tx().max_priority_fee_per_gas(), Self::Eip4844(tx) => tx.tx().max_priority_fee_per_gas(), + Self::Eip7702(tx) => tx.tx().max_priority_fee_per_gas(), } } diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index a925d9d48fe..b1ea3ea4770 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -180,6 +180,7 @@ impl Transaction for TypedTransaction { Self::Eip2930(tx) => tx.max_fee_per_gas(), Self::Eip1559(tx) => tx.max_fee_per_gas(), Self::Eip4844(tx) => tx.max_fee_per_gas(), + Self::Eip7702(tx) => tx.max_fee_per_gas(), } } @@ -189,6 +190,7 @@ impl Transaction for TypedTransaction { Self::Eip2930(tx) => tx.max_priority_fee_per_gas(), Self::Eip1559(tx) => tx.max_priority_fee_per_gas(), Self::Eip4844(tx) => tx.max_priority_fee_per_gas(), + Self::Eip7702(tx) => tx.max_priority_fee_per_gas(), } } From ca5784008d52c93803df5d5923df0406bacf6a99 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:34:21 +0200 Subject: [PATCH 05/22] fixup! Implement alloy_consensus::Transaction tx type trait method --- crates/consensus/src/transaction/envelope.rs | 1 + crates/consensus/src/transaction/typed.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 21d63d73add..595f6829f6a 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -498,6 +498,7 @@ impl Transaction for TxEnvelope { Self::Eip2930(tx) => tx.tx().ty(), Self::Eip1559(tx) => tx.tx().ty(), Self::Eip4844(tx) => tx.tx().ty(), + Self::Eip7702(tx) => tx.tx().ty(), } } } diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index b1ea3ea4770..d54fc3ef680 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -230,6 +230,7 @@ impl Transaction for TypedTransaction { Self::Eip2930(tx) => tx.ty(), Self::Eip1559(tx) => tx.ty(), Self::Eip4844(tx) => tx.ty(), + Self::Eip7702(tx) => tx.ty(), } } } From da14c4286ade22ab3b54995da66741c3e2d1e029 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:41:31 +0200 Subject: [PATCH 06/22] Implement alloy_consensus::Transaction access list trait method --- crates/consensus/src/transaction/eip1559.rs | 4 ++++ crates/consensus/src/transaction/eip2930.rs | 4 ++++ crates/consensus/src/transaction/eip4844.rs | 15 +++++++++++++++ crates/consensus/src/transaction/eip7702.rs | 4 ++++ crates/consensus/src/transaction/envelope.rs | 15 ++++++++++++++- crates/consensus/src/transaction/legacy.rs | 5 +++++ crates/consensus/src/transaction/typed.rs | 11 +++++++++++ 7 files changed, 57 insertions(+), 1 deletion(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index ce2b20b2d71..0796a0e9dc1 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -301,6 +301,10 @@ impl Transaction for TxEip1559 { fn ty(&self) -> u8 { TxType::Eip2930 as u8 } + + fn access_list(&self) -> Option<&AccessList> { + Some(&self.access_list) + } } impl SignableTransaction for TxEip1559 { diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 282c65aafb3..421426b4612 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -265,6 +265,10 @@ impl Transaction for TxEip2930 { fn ty(&self) -> u8 { TxType::Eip2930 as u8 } + + fn access_list(&self) -> Option<&AccessList> { + Some(&self.access_list) + } } impl SignableTransaction for TxEip2930 { diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index af06b704708..5e1221c1875 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -255,6 +255,13 @@ impl Transaction for TxEip4844Variant { fn ty(&self) -> u8 { TxType::Eip4844 as u8 } + + fn access_list(&self) -> Option<&AccessList> { + match self { + Self::TxEip4844(tx) => tx.access_list(), + Self::TxEip4844WithSidecar(tx) => tx.access_list(), + } + } } impl SignableTransaction for TxEip4844Variant { @@ -690,6 +697,10 @@ impl Transaction for TxEip4844 { fn ty(&self) -> u8 { TxType::Eip4844 as u8 } + + fn access_list(&self) -> Option<&AccessList> { + Some(&self.access_list) + } } impl Encodable for TxEip4844 { @@ -935,6 +946,10 @@ impl Transaction for TxEip4844WithSidecar { fn ty(&self) -> u8 { TxType::Eip4844 as u8 } + + fn access_list(&self) -> Option<&AccessList> { + Some(&self.tx.access_list) + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 9c6ad5c86ee..b9fc6f44228 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -325,6 +325,10 @@ impl Transaction for TxEip7702 { fn ty(&self) -> u8 { TxType::Eip7702 as u8 } + + fn access_list(&self) -> Option<&AccessList> { + Some(&self.access_list) + } } impl SignableTransaction for TxEip7702 { diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 595f6829f6a..fdf4c31f619 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -1,7 +1,10 @@ use core::fmt; use crate::{Signed, Transaction, TxEip1559, TxEip2930, TxEip7702, TxLegacy}; -use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718}; +use alloy_eips::{ + eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718}, + eip2930::AccessList, +}; use alloy_primitives::{TxKind, B256}; use alloy_rlp::{Decodable, Encodable, Header}; @@ -501,6 +504,16 @@ impl Transaction for TxEnvelope { Self::Eip7702(tx) => tx.tx().ty(), } } + + fn access_list(&self) -> Option<&AccessList> { + match self { + Self::Legacy(tx) => tx.tx().access_list(), + Self::Eip2930(tx) => tx.tx().access_list(), + Self::Eip1559(tx) => tx.tx().access_list(), + Self::Eip4844(tx) => tx.tx().access_list(), + Self::Eip7702(tx) => tx.tx().access_list(), + } + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 79b44733a6c..b7857fce29d 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,5 +1,6 @@ use core::mem; +use alloy_eips::eip2930::AccessList; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; @@ -242,6 +243,10 @@ impl Transaction for TxLegacy { fn ty(&self) -> u8 { TxType::Legacy as u8 } + + fn access_list(&self) -> Option<&AccessList> { + None + } } impl SignableTransaction for TxLegacy { diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index d54fc3ef680..bb1fb525d74 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -2,6 +2,7 @@ use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, Transaction, TxEip1559, TxEip2930, TxEip7702, TxEnvelope, TxLegacy, TxType, }; +use alloy_eips::eip2930::AccessList; use alloy_primitives::{ChainId, TxKind}; /// The TypedTransaction enum represents all Ethereum transaction request types. @@ -233,6 +234,16 @@ impl Transaction for TypedTransaction { Self::Eip7702(tx) => tx.ty(), } } + + fn access_list(&self) -> Option<&AccessList> { + match self { + Self::Legacy(tx) => tx.access_list(), + Self::Eip2930(tx) => tx.access_list(), + Self::Eip1559(tx) => tx.access_list(), + Self::Eip4844(tx) => tx.access_list(), + Self::Eip7702(tx) => tx.access_list(), + } + } } #[cfg(feature = "serde")] From 40d57965f2ba06c404fdc30e54d7405158d6ea3f Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:49:30 +0200 Subject: [PATCH 07/22] Implement alloy_consensus::Transaction blob versioned hashes trait method --- crates/consensus/src/transaction/eip1559.rs | 4 ++++ crates/consensus/src/transaction/eip2930.rs | 4 ++++ crates/consensus/src/transaction/eip4844.rs | 11 +++++++++++ crates/consensus/src/transaction/eip7702.rs | 6 +++++- crates/consensus/src/transaction/envelope.rs | 10 ++++++++++ crates/consensus/src/transaction/legacy.rs | 6 +++++- crates/consensus/src/transaction/typed.rs | 10 ++++++++++ 7 files changed, 49 insertions(+), 2 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 0796a0e9dc1..1c82ce73735 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -305,6 +305,10 @@ impl Transaction for TxEip1559 { fn access_list(&self) -> Option<&AccessList> { Some(&self.access_list) } + + fn blob_versioned_hashes(&self) -> Option> { + None + } } impl SignableTransaction for TxEip1559 { diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 421426b4612..f63335da957 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -269,6 +269,10 @@ impl Transaction for TxEip2930 { fn access_list(&self) -> Option<&AccessList> { Some(&self.access_list) } + + fn blob_versioned_hashes(&self) -> Option> { + None + } } impl SignableTransaction for TxEip2930 { diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 5e1221c1875..c1da8bc7506 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -262,6 +262,13 @@ impl Transaction for TxEip4844Variant { Self::TxEip4844WithSidecar(tx) => tx.access_list(), } } + + fn blob_versioned_hashes(&self) -> Option> { + match self { + Self::TxEip4844(tx) => tx.blob_versioned_hashes(), + Self::TxEip4844WithSidecar(tx) => tx.blob_versioned_hashes(), + } + } } impl SignableTransaction for TxEip4844Variant { @@ -701,6 +708,10 @@ impl Transaction for TxEip4844 { fn access_list(&self) -> Option<&AccessList> { Some(&self.access_list) } + + fn blob_versioned_hashes(&self) -> Option> { + Some(self.blob_versioned_hashes.iter().collect()) + } } impl Encodable for TxEip4844 { diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index b9fc6f44228..d4fad3757d5 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -1,6 +1,6 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -329,6 +329,10 @@ impl Transaction for TxEip7702 { fn access_list(&self) -> Option<&AccessList> { Some(&self.access_list) } + + fn blob_versioned_hashes(&self) -> Option> { + None + } } impl SignableTransaction for TxEip7702 { diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index fdf4c31f619..1de6d85e542 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -514,6 +514,16 @@ impl Transaction for TxEnvelope { Self::Eip7702(tx) => tx.tx().access_list(), } } + + fn blob_versioned_hashes(&self) -> Option> { + match self { + Self::Legacy(tx) => tx.tx().blob_versioned_hashes(), + Self::Eip2930(tx) => tx.tx().blob_versioned_hashes(), + Self::Eip1559(tx) => tx.tx().blob_versioned_hashes(), + Self::Eip4844(tx) => tx.tx().blob_versioned_hashes(), + Self::Eip7702(tx) => tx.tx().blob_versioned_hashes(), + } + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index b7857fce29d..b52f72eccc4 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,7 +1,7 @@ use core::mem; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; @@ -247,6 +247,10 @@ impl Transaction for TxLegacy { fn access_list(&self) -> Option<&AccessList> { None } + + fn blob_versioned_hashes(&self) -> Option> { + None + } } impl SignableTransaction for TxLegacy { diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index bb1fb525d74..cd7b694aef9 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -244,6 +244,16 @@ impl Transaction for TypedTransaction { Self::Eip7702(tx) => tx.access_list(), } } + + fn blob_versioned_hashes(&self) -> Option> { + match self { + Self::Legacy(tx) => tx.blob_versioned_hashes(), + Self::Eip2930(tx) => tx.blob_versioned_hashes(), + Self::Eip1559(tx) => tx.blob_versioned_hashes(), + Self::Eip4844(tx) => tx.blob_versioned_hashes(), + Self::Eip7702(tx) => tx.blob_versioned_hashes(), + } + } } #[cfg(feature = "serde")] From 76f9d3ede232ba2591d46d84eae19ddafb1cfa24 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 19:55:01 +0200 Subject: [PATCH 08/22] Implement alloy_consensus::Transaction effective tip per gas as default trait method --- crates/consensus/src/transaction/eip1559.rs | 6 +++- crates/consensus/src/transaction/eip2930.rs | 6 +++- crates/consensus/src/transaction/eip4844.rs | 4 +++ crates/consensus/src/transaction/eip7702.rs | 4 +++ crates/consensus/src/transaction/envelope.rs | 10 +++++++ crates/consensus/src/transaction/legacy.rs | 4 +++ crates/consensus/src/transaction/mod.rs | 30 +++++++++++++++++++- crates/consensus/src/transaction/typed.rs | 10 +++++++ 8 files changed, 71 insertions(+), 3 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 1c82ce73735..eda42704718 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -1,6 +1,6 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; @@ -286,6 +286,10 @@ impl Transaction for TxEip1559 { Some(self.max_priority_fee_per_gas) } + fn priority_fee_or_price(&self) -> u128 { + self.max_priority_fee_per_gas + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index f63335da957..76ccd1d6b9e 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -1,6 +1,6 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -250,6 +250,10 @@ impl Transaction for TxEip2930 { None } + fn priority_fee_or_price(&self) -> u128 { + self.gas_price + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index c1da8bc7506..04b3f54f719 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -689,6 +689,10 @@ impl Transaction for TxEip4844 { Some(self.max_priority_fee_per_gas) } + fn priority_fee_or_price(&self) -> u128 { + self.max_priority_fee_per_gas + } + fn to(&self) -> TxKind { self.to.into() } diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index d4fad3757d5..345770b767a 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -310,6 +310,10 @@ impl Transaction for TxEip7702 { Some(self.max_priority_fee_per_gas) } + fn priority_fee_or_price(&self) -> u128 { + self.max_priority_fee_per_gas + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 1de6d85e542..b9ce7fbb3aa 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -455,6 +455,16 @@ impl Transaction for TxEnvelope { } } + fn priority_fee_or_price(&self) -> u128 { + match self { + Self::Legacy(tx) => tx.tx().priority_fee_or_price(), + Self::Eip2930(tx) => tx.tx().priority_fee_or_price(), + Self::Eip1559(tx) => tx.tx().priority_fee_or_price(), + Self::Eip4844(tx) => tx.tx().priority_fee_or_price(), + Self::Eip7702(tx) => tx.tx().priority_fee_or_price(), + } + } + fn input(&self) -> &[u8] { match self { Self::Legacy(tx) => tx.tx().input(), diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index b52f72eccc4..494c9d03398 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -228,6 +228,10 @@ impl Transaction for TxLegacy { None } + fn priority_fee_or_price(&self) -> u128 { + self.gas_price + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 8bd4bf62776..452508b352d 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -67,11 +67,39 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// This will return `None` for non-EIP1559 transactions fn max_priority_fee_per_gas(&self) -> Option; + /// Return the max priority fee per gas if the transaction is an EIP-1559 transaction, and + /// otherwise return the gas price. + /// + /// # Warning + /// + /// This is different than the `max_priority_fee_per_gas` method, which returns `None` for + /// non-EIP-1559 transactions. + fn priority_fee_or_price(&self) -> u128; + /// Returns the effective tip for this transaction. /// /// For EIP-1559 transactions: `min(max_fee_per_gas - base_fee, max_priority_fee_per_gas)`. /// For legacy transactions: `gas_price - base_fee`. - fn effective_tip_per_gas(&self, base_fee: u64) -> Option; + fn effective_tip_per_gas(&self, base_fee: u64) -> Option { + let base_fee = base_fee as u128; + + let max_fee_per_gas = self.max_fee_per_gas(); + + // Check if max_fee_per_gas is less than base_fee + if max_fee_per_gas < base_fee { + return None; + } + + // Calculate the difference between max_fee_per_gas and base_fee + let fee = max_fee_per_gas - base_fee; + + // Compare the fee with max_priority_fee_per_gas (or gas price for non-EIP1559 transactions) + if let Some(priority_fee) = self.max_priority_fee_per_gas() { + Some(fee.min(priority_fee)) + } else { + Some(fee) + } + } /// Get `to`. fn to(&self) -> TxKind; diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index cd7b694aef9..6851041af58 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -195,6 +195,16 @@ impl Transaction for TypedTransaction { } } + fn priority_fee_or_price(&self) -> u128 { + match self { + Self::Legacy(tx) => tx.priority_fee_or_price(), + Self::Eip2930(tx) => tx.priority_fee_or_price(), + Self::Eip1559(tx) => tx.priority_fee_or_price(), + Self::Eip4844(tx) => tx.priority_fee_or_price(), + Self::Eip7702(tx) => tx.priority_fee_or_price(), + } + } + fn to(&self) -> TxKind { match self { Self::Legacy(tx) => tx.to(), From ca6a44c356e37c6e54e46cdadbef1679e328044e Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 20:07:29 +0200 Subject: [PATCH 09/22] Remove alloy_consensus::Transaction::hash in favour of using alloy_consensus::Signed --- crates/consensus/src/transaction/eip4844.rs | 23 +++++++++++++++++++++ crates/consensus/src/transaction/mod.rs | 3 --- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 04b3f54f719..2ca3b4b1653 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -230,6 +230,13 @@ impl Transaction for TxEip4844Variant { } } + fn priority_fee_or_price(&self) -> u128 { + match self { + Self::TxEip4844(tx) => tx.priority_fee_or_price(), + Self::TxEip4844WithSidecar(tx) => tx.priority_fee_or_price(), + } + } + fn to(&self) -> TxKind { match self { Self::TxEip4844(tx) => tx.to, @@ -946,6 +953,18 @@ impl Transaction for TxEip4844WithSidecar { self.tx.gas_price() } + fn max_fee_per_gas(&self) -> u128 { + self.tx.max_fee_per_gas() + } + + fn max_priority_fee_per_gas(&self) -> Option { + self.tx.max_priority_fee_per_gas() + } + + fn priority_fee_or_price(&self) -> u128 { + self.tx.priority_fee_or_price() + } + fn to(&self) -> TxKind { self.tx.to() } @@ -965,6 +984,10 @@ impl Transaction for TxEip4844WithSidecar { fn access_list(&self) -> Option<&AccessList> { Some(&self.tx.access_list) } + + fn blob_versioned_hashes(&self) -> Option> { + self.tx.blob_versioned_hashes() + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 452508b352d..ca20e97fd0a 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -40,9 +40,6 @@ pub use typed::TypedTransaction; /// Represents a minimal EVM transaction. #[doc(alias = "Tx")] pub trait Transaction: any::Any + Send + Sync + 'static { - /// Hash of the transaction. - fn hash(&self) -> &B256; - /// Get `chain_id`. fn chain_id(&self) -> Option; From 9ed90b0f84f0bc1696f9676ad157a83a843a4f11 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 21:56:06 +0200 Subject: [PATCH 10/22] Implement alloy_consensus::Transaction::fill for alloy_rpc_types_eth::Transaction --- crates/consensus/src/transaction/mod.rs | 9 ++- crates/network-primitives/Cargo.toml | 1 + crates/network-primitives/src/traits.rs | 45 +++++++++++++- crates/rpc-types-eth/src/transaction/mod.rs | 69 ++++++++++++++++++++- 4 files changed, 119 insertions(+), 5 deletions(-) diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index ca20e97fd0a..7548a7597ce 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -56,7 +56,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// /// For legacy transactions this is `gas_price`. /// - /// This is also commonly referred to as the "Gas Fee Cap" (`GasFeeCap`). + /// This is also commonly referred to as the "Gas Fee Cap". fn max_fee_per_gas(&self) -> u128; /// Returns the EIP-1559 Priority fee the caller is paying to the block author. @@ -64,6 +64,13 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// This will return `None` for non-EIP1559 transactions fn max_priority_fee_per_gas(&self) -> Option; + /// Max fee per blob gas for EIP-4844 transaction. + /// + /// Returns `None` for non-eip4844 transactions. + /// + /// This is also commonly referred to as the "Blob Gas Fee Cap". + fn max_fee_per_blob_gas(&self) -> Option; + /// Return the max priority fee per gas if the transaction is an EIP-1559 transaction, and /// otherwise return the gas price. /// diff --git a/crates/network-primitives/Cargo.toml b/crates/network-primitives/Cargo.toml index a56fb3e6239..7e7e58dfce8 100644 --- a/crates/network-primitives/Cargo.toml +++ b/crates/network-primitives/Cargo.toml @@ -21,6 +21,7 @@ workspace = true [dependencies] alloy-primitives.workspace = true alloy-serde.workspace = true +alloy-consensus.workspace = true serde.workspace = true diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index 9580f19b584..d14149c8a03 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -1,4 +1,5 @@ -use alloy_primitives::{Address, BlockHash, Bytes, TxHash, U256}; +use alloy_consensus::Signed; +use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256}; use alloy_serde::WithOtherFields; /// Receipt JSON-RPC response. @@ -44,6 +45,22 @@ pub trait TransactionResponse { /// Input data #[doc(alias = "calldata")] fn input(&self) -> &Bytes; + + /// Returns the gas price formatted for the RPC response. + fn gas_price(tx: impl alloy_consensus::Transaction, base_fee: Option) -> u128; + + /// Returns the max fee per gas. + fn max_fee_per_gas(tx: impl alloy_consensus::Transaction) -> Option; + + /// Assemble from signed transaction. + fn fill( + signed_tx: Signed, + signer: Address, + block_hash: Option, + block_number: Option, + base_fee: Option, + transaction_index: Option, + ) -> Self; } impl TransactionResponse for WithOtherFields { @@ -70,6 +87,32 @@ impl TransactionResponse for WithOtherFields { fn input(&self) -> &Bytes { self.inner.input() } + + fn gas_price(tx: impl alloy_consensus::Transaction, base_fee: Option) -> u128 { + T::gas_price(tx, base_fee) + } + + fn max_fee_per_gas(tx: impl alloy_consensus::Transaction) -> Option { + T::max_fee_per_gas(tx) + } + + fn fill( + signed_tx: Signed, + signer: Address, + block_hash: Option, + block_number: Option, + base_fee: Option, + transaction_index: Option, + ) -> Self { + WithOtherFields::new(T::fill( + signed_tx, + signer, + block_hash, + block_number, + base_fee, + transaction_index, + )) + } } impl ReceiptResponse for WithOtherFields { diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index df121b03569..77e092c696a 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -40,7 +40,7 @@ pub use alloy_consensus::{AnyReceiptEnvelope, Receipt, ReceiptEnvelope, ReceiptW #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] #[serde(rename_all = "camelCase")] #[doc(alias = "Tx")] -pub struct Transaction { +pub struct Transaction { /// Hash pub hash: TxHash, /// Nonce @@ -82,7 +82,7 @@ pub struct Transaction { /// /// Note: this is an option so special transaction types without a signature (e.g. ) can be supported. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub signature: Option, + pub signature: Option, /// The chain id of the transaction, if any. #[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")] pub chain_id: Option, @@ -298,7 +298,7 @@ impl TryFrom for TxEnvelope { } } -impl TransactionResponse for Transaction { +impl TransactionResponse for Transaction { fn tx_hash(&self) -> B256 { self.hash } @@ -322,7 +322,70 @@ impl TransactionResponse for Transaction { fn input(&self) -> &Bytes { &self.input } + + fn gas_price(tx: impl alloy_consensus::Transaction, base_fee: Option) -> u128 { + match TxType::try_from(tx.ty()).expect("should decode") { + TxType::Legacy | TxType::Eip2930 => tx.max_fee_per_gas(), + TxType::Eip1559 | TxType::Eip4844 | TxType::Eip7702 => { + // the gas price field for EIP1559 is set to `min(tip, gasFeeCap - baseFee) + + // baseFee` + base_fee + .and_then(|base_fee| { + tx.effective_tip_per_gas(base_fee).map(|tip| tip + base_fee as u128) + }) + .unwrap_or_else(|| tx.max_fee_per_gas()) + } + } + } + + fn max_fee_per_gas(tx: impl alloy_consensus::Transaction) -> Option { + match TxType::try_from(tx.ty()).expect("should decode") { + TxType::Legacy | TxType::Eip2930 => None, + TxType::Eip1559 | TxType::Eip4844 | TxType::Eip7702 => Some(tx.max_fee_per_gas()), + } + } + + fn fill( + signed_tx: Signed, + signer: Address, + block_hash: Option, + block_number: Option, + base_fee: Option, + transaction_index: Option, + ) -> Self { + let (tx, signature, hash) = signed_tx.into_parts(); + + Self { + hash, + nonce: tx.nonce(), + from: signer, + to: tx.to().to().copied(), + value: tx.value(), + gas_price: Some(Self::gas_price(tx, base_fee)), + max_fee_per_gas: Some(tx.max_fee_per_gas()), + max_priority_fee_per_gas: tx.max_priority_fee_per_gas(), + signature: Some(signature), + gas: tx.gas_limit(), + input: tx.input().clone().into(), + chain_id: tx.chain_id(), + access_list: tx.access_list().cloned(), + transaction_type: Some(tx.ty()), + // These fields are set to None because they are not stored as part of the transaction + block_hash, + block_number, + transaction_index: transaction_index.map(|idx| idx as u64), + // EIP-4844 fields + max_fee_per_blob_gas: tx.max_fee_per_blob_gas(), + blob_versioned_hashes: tx + .blob_versioned_hashes() + .into_iter() + .clone() + .collect::>(), + authorization_list: tx.authorization_list().map(|l| l.to_vec()), + } + } } + #[cfg(test)] mod tests { use super::*; From 223460c1d7139889e7861c4973b0908c17abdbc3 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 22:04:34 +0200 Subject: [PATCH 11/22] Add alloy_consensus::Transaction::max_fee_per_blob_gas trait method --- crates/consensus/src/transaction/eip1559.rs | 4 ++++ crates/consensus/src/transaction/eip2930.rs | 4 ++++ crates/consensus/src/transaction/eip4844.rs | 15 +++++++++++++++ crates/consensus/src/transaction/eip7702.rs | 4 ++++ crates/consensus/src/transaction/envelope.rs | 10 ++++++++++ crates/consensus/src/transaction/legacy.rs | 4 ++++ crates/consensus/src/transaction/mod.rs | 2 +- crates/consensus/src/transaction/typed.rs | 10 ++++++++++ crates/rpc-types-eth/src/transaction/mod.rs | 6 +----- 9 files changed, 53 insertions(+), 6 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index eda42704718..579f418049c 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -290,6 +290,10 @@ impl Transaction for TxEip1559 { self.max_priority_fee_per_gas } + fn max_fee_per_blob_gas(&self) -> Option { + None + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 76ccd1d6b9e..518d31bf807 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -254,6 +254,10 @@ impl Transaction for TxEip2930 { self.gas_price } + fn max_fee_per_blob_gas(&self) -> Option { + None + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 2ca3b4b1653..3e2f7779735 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -237,6 +237,13 @@ impl Transaction for TxEip4844Variant { } } + fn max_fee_per_blob_gas(&self) -> Option { + match self { + Self::TxEip4844(tx) => tx.max_fee_per_blob_gas(), + Self::TxEip4844WithSidecar(tx) => tx.max_fee_per_blob_gas(), + } + } + fn to(&self) -> TxKind { match self { Self::TxEip4844(tx) => tx.to, @@ -700,6 +707,10 @@ impl Transaction for TxEip4844 { self.max_priority_fee_per_gas } + fn max_fee_per_blob_gas(&self) -> Option { + Some(self.max_fee_per_blob_gas) + } + fn to(&self) -> TxKind { self.to.into() } @@ -965,6 +976,10 @@ impl Transaction for TxEip4844WithSidecar { self.tx.priority_fee_or_price() } + fn max_fee_per_blob_gas(&self) -> Option { + self.tx.max_fee_per_blob_gas() + } + fn to(&self) -> TxKind { self.tx.to() } diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 345770b767a..98b14584ffd 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -314,6 +314,10 @@ impl Transaction for TxEip7702 { self.max_priority_fee_per_gas } + fn max_fee_per_blob_gas(&self) -> Option { + None + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index b9ce7fbb3aa..1c96bf83767 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -465,6 +465,16 @@ impl Transaction for TxEnvelope { } } + fn max_fee_per_blob_gas(&self) -> Option { + match self { + Self::Legacy(tx) => tx.tx().max_fee_per_blob_gas(), + Self::Eip2930(tx) => tx.tx().max_fee_per_blob_gas(), + Self::Eip1559(tx) => tx.tx().max_fee_per_blob_gas(), + Self::Eip4844(tx) => tx.tx().max_fee_per_blob_gas(), + Self::Eip7702(tx) => tx.tx().max_fee_per_blob_gas(), + } + } + fn input(&self) -> &[u8] { match self { Self::Legacy(tx) => tx.tx().input(), diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 494c9d03398..a61be97d759 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -232,6 +232,10 @@ impl Transaction for TxLegacy { self.gas_price } + fn max_fee_per_blob_gas(&self) -> Option { + None + } + fn to(&self) -> TxKind { self.to } diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 7548a7597ce..f57f2fecf6f 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -117,7 +117,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// Returns the transaction type fn ty(&self) -> u8; - /// Returns the EIP2930 `access_list` for the particular transaction type. Returns `None` for + /// Returns the EIP-2930 `access_list` for the particular transaction type. Returns `None` for /// older transaction types. fn access_list(&self) -> Option<&AccessList>; diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 6851041af58..45332e45fa2 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -205,6 +205,16 @@ impl Transaction for TypedTransaction { } } + fn max_fee_per_blob_gas(&self) -> Option { + match self { + Self::Legacy(tx) => tx.max_fee_per_blob_gas(), + Self::Eip2930(tx) => tx.max_fee_per_blob_gas(), + Self::Eip1559(tx) => tx.max_fee_per_blob_gas(), + Self::Eip4844(tx) => tx.max_fee_per_blob_gas(), + Self::Eip7702(tx) => tx.max_fee_per_blob_gas(), + } + } + fn to(&self) -> TxKind { match self { Self::Legacy(tx) => tx.to(), diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 77e092c696a..23f0bd45047 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -376,11 +376,7 @@ impl TransactionResponse for Transaction { transaction_index: transaction_index.map(|idx| idx as u64), // EIP-4844 fields max_fee_per_blob_gas: tx.max_fee_per_blob_gas(), - blob_versioned_hashes: tx - .blob_versioned_hashes() - .into_iter() - .clone() - .collect::>(), + blob_versioned_hashes: tx.blob_versioned_hashes().into_iter().cloned().collect(), authorization_list: tx.authorization_list().map(|l| l.to_vec()), } } From 28a82663768abfe302bcb3f8125c5d270ae018a4 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 22:31:08 +0200 Subject: [PATCH 12/22] Add alloy_consensus::Transaction::authorization_list & conversion between alloy_primitives::Signature and alloy_rpc_types_eth::Signature --- crates/consensus/src/transaction/eip1559.rs | 6 +++- crates/consensus/src/transaction/eip2930.rs | 6 +++- crates/consensus/src/transaction/eip4844.rs | 14 ++++++++- crates/consensus/src/transaction/eip7702.rs | 4 +++ crates/consensus/src/transaction/envelope.rs | 10 ++++++ crates/consensus/src/transaction/legacy.rs | 6 +++- crates/consensus/src/transaction/mod.rs | 7 ++++- crates/consensus/src/transaction/typed.rs | 12 +++++++- crates/network-primitives/src/traits.rs | 4 +-- crates/rpc-types-eth/src/transaction/mod.rs | 32 +++++++++++++++----- 10 files changed, 85 insertions(+), 16 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 579f418049c..4c1fc1ba549 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -1,5 +1,5 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; -use alloy_eips::eip2930::AccessList; +use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; @@ -317,6 +317,10 @@ impl Transaction for TxEip1559 { fn blob_versioned_hashes(&self) -> Option> { None } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + None + } } impl SignableTransaction for TxEip1559 { diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 518d31bf807..199f1b94585 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -1,5 +1,5 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; -use alloy_eips::eip2930::AccessList; +use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -281,6 +281,10 @@ impl Transaction for TxEip2930 { fn blob_versioned_hashes(&self) -> Option> { None } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + None + } } impl SignableTransaction for TxEip2930 { diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 3e2f7779735..512a0d6631d 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -1,6 +1,6 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; -use alloy_eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB}; +use alloy_eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -283,6 +283,10 @@ impl Transaction for TxEip4844Variant { Self::TxEip4844WithSidecar(tx) => tx.blob_versioned_hashes(), } } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + None + } } impl SignableTransaction for TxEip4844Variant { @@ -734,6 +738,10 @@ impl Transaction for TxEip4844 { fn blob_versioned_hashes(&self) -> Option> { Some(self.blob_versioned_hashes.iter().collect()) } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + None + } } impl Encodable for TxEip4844 { @@ -1003,6 +1011,10 @@ impl Transaction for TxEip4844WithSidecar { fn blob_versioned_hashes(&self) -> Option> { self.tx.blob_versioned_hashes() } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + None + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 98b14584ffd..b7ea162450e 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -341,6 +341,10 @@ impl Transaction for TxEip7702 { fn blob_versioned_hashes(&self) -> Option> { None } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + Some(&self.authorization_list) + } } impl SignableTransaction for TxEip7702 { diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 1c96bf83767..9fb3085e592 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -544,6 +544,16 @@ impl Transaction for TxEnvelope { Self::Eip7702(tx) => tx.tx().blob_versioned_hashes(), } } + + fn authorization_list(&self) -> Option<&[alloy_eips::eip7702::SignedAuthorization]> { + match self { + Self::Legacy(tx) => tx.tx().authorization_list(), + Self::Eip2930(tx) => tx.tx().authorization_list(), + Self::Eip1559(tx) => tx.tx().authorization_list(), + Self::Eip4844(tx) => tx.tx().authorization_list(), + Self::Eip7702(tx) => tx.tx().authorization_list(), + } + } } #[cfg(test)] diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index a61be97d759..a038f55e0be 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,6 +1,6 @@ use core::mem; -use alloy_eips::eip2930::AccessList; +use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; @@ -259,6 +259,10 @@ impl Transaction for TxLegacy { fn blob_versioned_hashes(&self) -> Option> { None } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + None + } } impl SignableTransaction for TxLegacy { diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index f57f2fecf6f..eff6f932244 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -1,7 +1,7 @@ //! Transaction types. use crate::Signed; -use alloy_eips::eip2930::AccessList; +use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, ChainId, TxKind, B256, U256}; use core::any; @@ -124,6 +124,11 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// Blob versioned hashes for eip4844 transaction. For previous transaction types this is /// `None`. fn blob_versioned_hashes(&self) -> Option>; + + /// Returns the [`SignedAuthorization`] list of the transaction. + /// + /// Returns `None` if this transaction is not EIP-7702. + fn authorization_list(&self) -> Option<&[SignedAuthorization]>; } /// A signable transaction. diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 45332e45fa2..c1627bae8a6 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -2,7 +2,7 @@ use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, Transaction, TxEip1559, TxEip2930, TxEip7702, TxEnvelope, TxLegacy, TxType, }; -use alloy_eips::eip2930::AccessList; +use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{ChainId, TxKind}; /// The TypedTransaction enum represents all Ethereum transaction request types. @@ -274,6 +274,16 @@ impl Transaction for TypedTransaction { Self::Eip7702(tx) => tx.blob_versioned_hashes(), } } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + match self { + Self::Legacy(tx) => tx.authorization_list(), + Self::Eip2930(tx) => tx.authorization_list(), + Self::Eip1559(tx) => tx.authorization_list(), + Self::Eip4844(tx) => tx.authorization_list(), + Self::Eip7702(tx) => tx.authorization_list(), + } + } } #[cfg(feature = "serde")] diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index d14149c8a03..7fa671c8f8c 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -47,7 +47,7 @@ pub trait TransactionResponse { fn input(&self) -> &Bytes; /// Returns the gas price formatted for the RPC response. - fn gas_price(tx: impl alloy_consensus::Transaction, base_fee: Option) -> u128; + fn gas_price(tx: &impl alloy_consensus::Transaction, base_fee: Option) -> u128; /// Returns the max fee per gas. fn max_fee_per_gas(tx: impl alloy_consensus::Transaction) -> Option; @@ -88,7 +88,7 @@ impl TransactionResponse for WithOtherFields { self.inner.input() } - fn gas_price(tx: impl alloy_consensus::Transaction, base_fee: Option) -> u128 { + fn gas_price(tx: &impl alloy_consensus::Transaction, base_fee: Option) -> u128 { T::gas_price(tx, base_fee) } diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 23f0bd45047..a09f100d335 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -40,7 +40,7 @@ pub use alloy_consensus::{AnyReceiptEnvelope, Receipt, ReceiptEnvelope, ReceiptW #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] #[serde(rename_all = "camelCase")] #[doc(alias = "Tx")] -pub struct Transaction { +pub struct Transaction { /// Hash pub hash: TxHash, /// Nonce @@ -82,7 +82,7 @@ pub struct Transaction { /// /// Note: this is an option so special transaction types without a signature (e.g. ) can be supported. #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub signature: Option, + pub signature: Option, /// The chain id of the transaction, if any. #[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")] pub chain_id: Option, @@ -157,6 +157,20 @@ impl Transaction { } } +impl From for Signature { + fn from(signature: alloy_primitives::Signature) -> Self { + Self { + v: U256::from(signature.v().to_u64()), + r: signature.r(), + s: signature.s(), + y_parity: Some(Parity::from( + signature.v().y_parity_byte_non_eip155().unwrap_or(signature.v().y_parity_byte()) + != 0, + )), + } + } +} + impl TryFrom for Signed { type Error = ConversionError; @@ -298,7 +312,7 @@ impl TryFrom for TxEnvelope { } } -impl TransactionResponse for Transaction { +impl TransactionResponse for Transaction { fn tx_hash(&self) -> B256 { self.hash } @@ -323,7 +337,7 @@ impl TransactionResponse for Transaction { &self.input } - fn gas_price(tx: impl alloy_consensus::Transaction, base_fee: Option) -> u128 { + fn gas_price(tx: &impl alloy_consensus::Transaction, base_fee: Option) -> u128 { match TxType::try_from(tx.ty()).expect("should decode") { TxType::Legacy | TxType::Eip2930 => tx.max_fee_per_gas(), TxType::Eip1559 | TxType::Eip4844 | TxType::Eip7702 => { @@ -361,12 +375,12 @@ impl TransactionResponse for Transaction { from: signer, to: tx.to().to().copied(), value: tx.value(), - gas_price: Some(Self::gas_price(tx, base_fee)), + gas_price: Some(Self::gas_price(&tx, base_fee)), max_fee_per_gas: Some(tx.max_fee_per_gas()), max_priority_fee_per_gas: tx.max_priority_fee_per_gas(), - signature: Some(signature), + signature: Some(signature.into()), gas: tx.gas_limit(), - input: tx.input().clone().into(), + input: tx.input().to_vec().into(), chain_id: tx.chain_id(), access_list: tx.access_list().cloned(), transaction_type: Some(tx.ty()), @@ -376,7 +390,9 @@ impl TransactionResponse for Transaction { transaction_index: transaction_index.map(|idx| idx as u64), // EIP-4844 fields max_fee_per_blob_gas: tx.max_fee_per_blob_gas(), - blob_versioned_hashes: tx.blob_versioned_hashes().into_iter().cloned().collect(), + blob_versioned_hashes: tx + .blob_versioned_hashes() + .map(|hashes| hashes.into_iter().copied().collect()), authorization_list: tx.authorization_list().map(|l| l.to_vec()), } } From b8f104bc615d8c2997c3f428002414cb0169b4a1 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 22:55:23 +0200 Subject: [PATCH 13/22] Impl no-std support --- crates/consensus/src/transaction/envelope.rs | 2 ++ crates/consensus/src/transaction/typed.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index b9ce7fbb3aa..9b4ebf59802 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -1,3 +1,5 @@ +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use core::fmt; use crate::{Signed, Transaction, TxEip1559, TxEip2930, TxEip7702, TxLegacy}; diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 6851041af58..6dc35a594d4 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -1,9 +1,13 @@ +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + +use alloy_eips::eip2930::AccessList; +use alloy_primitives::{ChainId, TxKind}; + use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, Transaction, TxEip1559, TxEip2930, TxEip7702, TxEnvelope, TxLegacy, TxType, }; -use alloy_eips::eip2930::AccessList; -use alloy_primitives::{ChainId, TxKind}; /// The TypedTransaction enum represents all Ethereum transaction request types. /// From e689b0a5c8b0337d7b193cd639f3f6b93ac4f491 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 21 Aug 2024 22:57:43 +0200 Subject: [PATCH 14/22] Fix lint --- crates/consensus/src/transaction/mod.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index ca20e97fd0a..6224942504d 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -91,11 +91,8 @@ pub trait Transaction: any::Any + Send + Sync + 'static { let fee = max_fee_per_gas - base_fee; // Compare the fee with max_priority_fee_per_gas (or gas price for non-EIP1559 transactions) - if let Some(priority_fee) = self.max_priority_fee_per_gas() { - Some(fee.min(priority_fee)) - } else { - Some(fee) - } + self.max_priority_fee_per_gas() + .map_or(Some(fee), |priority_fee| Some(fee.min(priority_fee))) } /// Get `to`. From f84b9d699f1b385e96e5f8caff800d3be6905dcc Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Thu, 22 Aug 2024 15:08:53 +0200 Subject: [PATCH 15/22] Return slice instead of vec --- crates/consensus/src/transaction/eip1559.rs | 2 +- crates/consensus/src/transaction/eip2930.rs | 2 +- crates/consensus/src/transaction/eip4844.rs | 8 ++++---- crates/consensus/src/transaction/eip7702.rs | 2 +- crates/consensus/src/transaction/envelope.rs | 2 +- crates/consensus/src/transaction/legacy.rs | 2 +- crates/consensus/src/transaction/mod.rs | 2 +- crates/consensus/src/transaction/typed.rs | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index eda42704718..1777e661ab3 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -310,7 +310,7 @@ impl Transaction for TxEip1559 { Some(&self.access_list) } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { None } } diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 76ccd1d6b9e..4cfbeb615dd 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -274,7 +274,7 @@ impl Transaction for TxEip2930 { Some(&self.access_list) } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { None } } diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 2ca3b4b1653..c239a12ea59 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -270,7 +270,7 @@ impl Transaction for TxEip4844Variant { } } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { match self { Self::TxEip4844(tx) => tx.blob_versioned_hashes(), Self::TxEip4844WithSidecar(tx) => tx.blob_versioned_hashes(), @@ -720,8 +720,8 @@ impl Transaction for TxEip4844 { Some(&self.access_list) } - fn blob_versioned_hashes(&self) -> Option> { - Some(self.blob_versioned_hashes.iter().collect()) + fn blob_versioned_hashes(&self) -> Option<&[B256]> { + Some(&self.blob_versioned_hashes) } } @@ -985,7 +985,7 @@ impl Transaction for TxEip4844WithSidecar { Some(&self.tx.access_list) } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { self.tx.blob_versioned_hashes() } } diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 345770b767a..93214fd7600 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -334,7 +334,7 @@ impl Transaction for TxEip7702 { Some(&self.access_list) } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { None } } diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index 9b4ebf59802..7c00564265e 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -527,7 +527,7 @@ impl Transaction for TxEnvelope { } } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { match self { Self::Legacy(tx) => tx.tx().blob_versioned_hashes(), Self::Eip2930(tx) => tx.tx().blob_versioned_hashes(), diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 494c9d03398..e45ac32ebd0 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -252,7 +252,7 @@ impl Transaction for TxLegacy { None } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { None } } diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 6224942504d..c77fa28da0d 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -113,7 +113,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// Blob versioned hashes for eip4844 transaction. For previous transaction types this is /// `None`. - fn blob_versioned_hashes(&self) -> Option>; + fn blob_versioned_hashes(&self) -> Option<&[B256]>; } /// A signable transaction. diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 6dc35a594d4..361b9049d31 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -2,7 +2,7 @@ use alloc::vec::Vec; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{ChainId, TxKind}; +use alloy_primitives::{ChainId, TxKind, B256}; use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, @@ -259,7 +259,7 @@ impl Transaction for TypedTransaction { } } - fn blob_versioned_hashes(&self) -> Option> { + fn blob_versioned_hashes(&self) -> Option<&[B256]> { match self { Self::Legacy(tx) => tx.blob_versioned_hashes(), Self::Eip2930(tx) => tx.blob_versioned_hashes(), From 66328a3e13aad53bcb6cd09ae935fd19d081000c Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Thu, 22 Aug 2024 16:37:30 +0200 Subject: [PATCH 16/22] Fix docs Co-authored-by: Arsenii Kulikov --- crates/consensus/src/transaction/eip7702.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index 93214fd7600..44bd709b373 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -267,8 +267,7 @@ impl TxEip7702 { mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() + // input - self.authorization_list.capacity() * mem::size_of::() - // authorization_list + self.authorization_list.capacity() * mem::size_of::() // authorization_list } /// Output the length of the RLP signed transaction encoding, _without_ a RLP string header. From 6275d284007168bfdab4cde165bbdb20dcc08b3e Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Mon, 26 Aug 2024 20:10:36 +0200 Subject: [PATCH 17/22] Implement conversion from alloy_primitives::Signature to alloy_rpc_types_eth::Signature --- crates/rpc-types-eth/src/transaction/signature.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/rpc-types-eth/src/transaction/signature.rs b/crates/rpc-types-eth/src/transaction/signature.rs index 2a456b11cd3..c4572e55bb4 100644 --- a/crates/rpc-types-eth/src/transaction/signature.rs +++ b/crates/rpc-types-eth/src/transaction/signature.rs @@ -75,6 +75,20 @@ impl TryFrom for alloy_primitives::Signature { } } +impl From for Signature { + fn from(signature: alloy_primitives::Signature) -> Self { + Self { + v: U256::from(signature.v().to_u64()), + r: signature.r(), + s: signature.s(), + y_parity: Some(Parity::from( + signature.v().y_parity_byte_non_eip155().unwrap_or(signature.v().y_parity_byte()) + != 0, + )), + } + } +} + #[cfg(test)] mod tests { use super::*; From 688bcb83917db98a6b209787d3a568599cb8b914 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Mon, 26 Aug 2024 20:23:03 +0200 Subject: [PATCH 18/22] Remove outdated comment --- crates/rpc-types-eth/src/transaction/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 6f46e217660..9f5347ff443 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -370,7 +370,6 @@ impl TransactionResponse for Transaction { chain_id: tx.chain_id(), access_list: tx.access_list().cloned(), transaction_type: Some(tx.ty()), - // These fields are set to None because they are not stored as part of the transaction block_hash, block_number, transaction_index: transaction_index.map(|idx| idx as u64), From 74c9bf7847f2b038914f656209ddf14846ac8a67 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Mon, 26 Aug 2024 20:24:04 +0200 Subject: [PATCH 19/22] Mark out eip4844 fields --- crates/rpc-types-eth/src/transaction/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 9f5347ff443..4ea82dad455 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -373,9 +373,10 @@ impl TransactionResponse for Transaction { block_hash, block_number, transaction_index: transaction_index.map(|idx| idx as u64), - // EIP-4844 fields + // EIP-4844 fields // max_fee_per_blob_gas: tx.max_fee_per_blob_gas(), blob_versioned_hashes: tx.blob_versioned_hashes().map(|hashes| hashes.to_vec()), + ///////////////////// authorization_list: tx.authorization_list().map(|l| l.to_vec()), } } From b18979be47160bef89066e0262ecf6e6150b0476 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 28 Aug 2024 12:31:08 +0200 Subject: [PATCH 20/22] Move alloy_rpc_types_eth::TransactionInfo into crate alloy-network-primitives --- crates/network-primitives/src/lib.rs | 3 +++ .../src/transaction.rs} | 15 --------------- crates/rpc-types-eth/src/transaction/mod.rs | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 18 deletions(-) rename crates/{rpc-types-eth/src/transaction/common.rs => network-primitives/src/transaction.rs} (67%) diff --git a/crates/network-primitives/src/lib.rs b/crates/network-primitives/src/lib.rs index d1534307e4a..e525c7320c0 100644 --- a/crates/network-primitives/src/lib.rs +++ b/crates/network-primitives/src/lib.rs @@ -6,6 +6,9 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +mod transaction; +pub use transaction::TransactionInfo; + mod traits; pub use traits::{BlockResponse, HeaderResponse, ReceiptResponse, TransactionResponse}; diff --git a/crates/rpc-types-eth/src/transaction/common.rs b/crates/network-primitives/src/transaction.rs similarity index 67% rename from crates/rpc-types-eth/src/transaction/common.rs rename to crates/network-primitives/src/transaction.rs index f729c0f74f1..393f6dc7753 100644 --- a/crates/rpc-types-eth/src/transaction/common.rs +++ b/crates/network-primitives/src/transaction.rs @@ -1,7 +1,6 @@ //! Commonly used additional types that are not part of the JSON RPC spec but are often required //! when working with RPC types, such as [Transaction] -use crate::Transaction; use alloy_primitives::{BlockHash, TxHash}; /// Additional fields in the context of a block that contains this transaction. @@ -27,17 +26,3 @@ impl TransactionInfo { self } } - -impl From<&Transaction> for TransactionInfo { - fn from(tx: &Transaction) -> Self { - Self { - hash: Some(tx.hash), - index: tx.transaction_index, - block_hash: tx.block_hash, - block_number: tx.block_number, - // We don't know the base fee of the block when we're constructing this from - // `Transaction` - base_fee: None, - } - } -} diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 6b06613753c..66aafd40fa4 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -14,9 +14,7 @@ pub use alloy_eips::{ eip2930::{AccessList, AccessListItem, AccessListResult}, eip7702::Authorization, }; - -mod common; -pub use common::TransactionInfo; +pub use alloy_network_primitives::TransactionInfo; mod error; pub use error::ConversionError; @@ -154,6 +152,20 @@ impl Transaction { } } +impl From<&Transaction> for TransactionInfo { + fn from(tx: &Transaction) -> Self { + Self { + hash: Some(tx.hash), + index: tx.transaction_index, + block_hash: tx.block_hash, + block_number: tx.block_number, + // We don't know the base fee of the block when we're constructing this from + // `Transaction` + base_fee: None, + } + } +} + impl TryFrom for Signed { type Error = ConversionError; From ec17b2d56143e93bb469d8a2328203aa5c6c7ff3 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 28 Aug 2024 12:40:21 +0200 Subject: [PATCH 21/22] Reduce params of trait method TransactionResponse::fill using alloy_network_primitives::TransactionInfo --- crates/network-primitives/src/traits.rs | 14 ++++---------- crates/rpc-types-eth/src/transaction/mod.rs | 15 ++++++++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index ec48f95e81d..5bd81639210 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -2,7 +2,7 @@ use alloy_consensus::Signed; use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256}; use alloy_serde::WithOtherFields; -use crate::BlockTransactions; +use crate::{BlockTransactions, TransactionInfo}; /// Receipt JSON-RPC response. pub trait ReceiptResponse { @@ -58,10 +58,7 @@ pub trait TransactionResponse { fn fill( signed_tx: Signed, signer: Address, - block_hash: Option, - block_number: Option, - base_fee: Option, - transaction_index: Option, + tx_info: TransactionInfo, ) -> Self; } @@ -139,12 +136,9 @@ impl TransactionResponse for WithOtherFields { fn fill( signed_tx: Signed, signer: Address, - block_hash: Option, - block_number: Option, - base_fee: Option, - transaction_index: Option, + tx_info: TransactionInfo, ) -> Self { - Self::new(T::fill(signed_tx, signer, block_hash, block_number, base_fee, transaction_index)) + Self::new(T::fill(signed_tx, signer, tx_info)) } } diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 66aafd40fa4..86359558ac2 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -1,8 +1,8 @@ //! RPC types for transactions use alloy_consensus::{ - SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEip7702, - TxEnvelope, TxLegacy, TxType, + transaction, SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, + TxEip7702, TxEnvelope, TxLegacy, TxType, }; use alloy_eips::eip7702::SignedAuthorization; use alloy_network_primitives::TransactionResponse; @@ -357,13 +357,14 @@ impl TransactionResponse for Transaction { fn fill( signed_tx: Signed, signer: Address, - block_hash: Option, - block_number: Option, - base_fee: Option, - transaction_index: Option, + tx_info: TransactionInfo, ) -> Self { let (tx, signature, hash) = signed_tx.into_parts(); + let TransactionInfo { + block_hash, block_number, base_fee, index: transaction_index, .. + } = tx_info; + Self { hash, nonce: tx.nonce(), @@ -381,7 +382,7 @@ impl TransactionResponse for Transaction { transaction_type: Some(tx.ty()), block_hash, block_number, - transaction_index: transaction_index.map(|idx| idx as u64), + transaction_index, // EIP-4844 fields // max_fee_per_blob_gas: tx.max_fee_per_blob_gas(), blob_versioned_hashes: tx.blob_versioned_hashes().map(|hashes| hashes.to_vec()), From 8c2cc541885e04e1b482e5d4e3f8fcae64c283dd Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 28 Aug 2024 12:44:34 +0200 Subject: [PATCH 22/22] Fix lint --- crates/network-primitives/src/traits.rs | 2 +- crates/rpc-types-eth/src/transaction/mod.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index 5bd81639210..a7e2f576bd5 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -1,5 +1,5 @@ use alloy_consensus::Signed; -use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256}; +use alloy_primitives::{Address, BlockHash, Bytes, TxHash, U256}; use alloy_serde::WithOtherFields; use crate::{BlockTransactions, TransactionInfo}; diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 86359558ac2..72762447d85 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -1,15 +1,17 @@ //! RPC types for transactions use alloy_consensus::{ - transaction, SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, - TxEip7702, TxEnvelope, TxLegacy, TxType, + SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEip7702, + TxEnvelope, TxLegacy, TxType, }; use alloy_eips::eip7702::SignedAuthorization; use alloy_network_primitives::TransactionResponse; use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxKind, B256, U256}; use serde::{Deserialize, Serialize}; -pub use alloy_consensus::BlobTransactionSidecar; +pub use alloy_consensus::{ + AnyReceiptEnvelope, BlobTransactionSidecar, Receipt, ReceiptEnvelope, ReceiptWithBloom, +}; pub use alloy_eips::{ eip2930::{AccessList, AccessListItem, AccessListResult}, eip7702::Authorization, @@ -28,8 +30,6 @@ pub use request::{TransactionInput, TransactionRequest}; mod signature; pub use signature::{Parity, Signature}; -pub use alloy_consensus::{AnyReceiptEnvelope, Receipt, ReceiptEnvelope, ReceiptWithBloom}; - /// Transaction object used in RPC #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] @@ -371,7 +371,7 @@ impl TransactionResponse for Transaction { from: signer, to: tx.to().to().copied(), value: tx.value(), - gas_price: Some(Self::gas_price(&tx, base_fee)), + gas_price: Some(Self::gas_price(&tx, base_fee.map(|bf| bf as u64))), max_fee_per_gas: Some(tx.max_fee_per_gas()), max_priority_fee_per_gas: tx.max_priority_fee_per_gas(), signature: Some(signature.into()),