From 287409f9f5a982d0afe67537c33d5e131595205e Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Mon, 28 Jun 2021 19:15:37 +0200 Subject: [PATCH] gasPrice substituted with effective_gas_price (#458) --- crates/concensus/miner/src/pool/queue.rs | 4 ++- crates/ethcore/src/client/traits.rs | 15 +++++++---- .../types/src/views/typed_transaction.rs | 25 ++++++++++++++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/concensus/miner/src/pool/queue.rs b/crates/concensus/miner/src/pool/queue.rs index 986fa6b9e..82d41b84c 100644 --- a/crates/concensus/miner/src/pool/queue.rs +++ b/crates/concensus/miner/src/pool/queue.rs @@ -656,7 +656,9 @@ impl TransactionQueue { /// Returns gas price of currently the worst transaction in the pool. pub fn current_worst_gas_price(&self) -> U256 { match self.pool.read().worst_transaction() { - Some(tx) => tx.signed().tx().gas_price, + Some(tx) => tx + .signed() + .effective_gas_price(self.options.read().block_base_fee), None => self.options.read().minimal_gas_price, } } diff --git a/crates/ethcore/src/client/traits.rs b/crates/ethcore/src/client/traits.rs index 80eea0503..b9e7573a1 100644 --- a/crates/ethcore/src/client/traits.rs +++ b/crates/ethcore/src/client/traits.rs @@ -40,7 +40,7 @@ use types::{ pruning_info::PruningInfo, receipt::LocalizedReceipt, trace_filter::Filter as TraceFilter, - transaction::{self, Action, LocalizedTransaction, SignedTransaction}, + transaction::{self, Action, LocalizedTransaction, SignedTransaction, TypedTxId}, BlockNumber, }; use vm::LastHashes; @@ -395,10 +395,15 @@ pub trait BlockChainClient: if block.number() == 0 { return corpus.into(); } - block - .transaction_views() - .iter() - .foreach(|t| corpus.push(t.gas_price())); + block.transaction_views().iter().foreach(|t| { + corpus.push(t.effective_gas_price({ + match t.transaction_type() { + TypedTxId::Legacy => None, + TypedTxId::AccessList => None, + TypedTxId::EIP1559Transaction => Some(block.header().base_fee()), + } + })) + }); h = block.parent_hash().clone(); } } diff --git a/crates/ethcore/types/src/views/typed_transaction.rs b/crates/ethcore/types/src/views/typed_transaction.rs index e91f7122e..62c370239 100644 --- a/crates/ethcore/types/src/views/typed_transaction.rs +++ b/crates/ethcore/types/src/views/typed_transaction.rs @@ -16,6 +16,8 @@ //! View onto transaction rlp +use std::cmp::min; + use crate::{ bytes::Bytes, hash::keccak, @@ -116,6 +118,25 @@ impl<'a> TypedTransactionView<'a> { } } + /// Get the effective_gas_price field of the transaction. + pub fn effective_gas_price(&self, block_base_fee: Option) -> U256 { + match self.transaction_type { + TypedTxId::Legacy => self.gas_price(), + TypedTxId::AccessList => self.gas_price(), + TypedTxId::EIP1559Transaction => { + let max_priority_fee_per_gas: U256 = + view!(Self, &self.rlp.rlp.data().unwrap()[1..]) + .rlp + .val_at(2); + + min( + self.gas_price(), + max_priority_fee_per_gas + block_base_fee.unwrap_or_default(), + ) + } + } + } + /// Get the gas field of the transaction. pub fn gas(&self) -> U256 { match self.transaction_type { @@ -238,6 +259,7 @@ mod tests { let view = view!(TypedTransactionView, &rlp); assert_eq!(view.nonce(), 0.into()); assert_eq!(view.gas_price(), 1.into()); + assert_eq!(view.effective_gas_price(None), 1.into()); assert_eq!(view.gas(), 0x61a8.into()); assert_eq!(view.value(), 0xa.into()); assert_eq!( @@ -279,10 +301,11 @@ mod tests { #[test] fn test_eip1559_transaction_view() { - let rlp = "b8c202f8bf01010a0a8301e24194000000000000000000000000000000000000aaaa8080f85bf859940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000080a082dc119130f280bd72e3fd4e10220e35b767031b84b8dd1f64085e0158f234dba072228551e678a8a6c6e9bae0ae786b8839c7fda0a994caddd23910f45f385cc0".from_hex().unwrap(); + let rlp = "b8c202f8bf0101010a8301e24194000000000000000000000000000000000000aaaa8080f85bf859940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000080a082dc119130f280bd72e3fd4e10220e35b767031b84b8dd1f64085e0158f234dba072228551e678a8a6c6e9bae0ae786b8839c7fda0a994caddd23910f45f385cc0".from_hex().unwrap(); let view = view!(TypedTransactionView, &rlp); assert_eq!(view.nonce(), 0x1.into()); assert_eq!(view.gas_price(), 0xa.into()); + assert_eq!(view.effective_gas_price(Some(0x07.into())), 0x08.into()); assert_eq!(view.gas(), 0x1e241.into()); assert_eq!(view.value(), 0x0.into()); assert_eq!(view.data(), "".from_hex().unwrap());