gasPrice substituted with effective_gas_price (#458)
This commit is contained in:
parent
e5ae846de4
commit
287409f9f5
@ -656,7 +656,9 @@ impl TransactionQueue {
|
|||||||
/// Returns gas price of currently the worst transaction in the pool.
|
/// Returns gas price of currently the worst transaction in the pool.
|
||||||
pub fn current_worst_gas_price(&self) -> U256 {
|
pub fn current_worst_gas_price(&self) -> U256 {
|
||||||
match self.pool.read().worst_transaction() {
|
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,
|
None => self.options.read().minimal_gas_price,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ use types::{
|
|||||||
pruning_info::PruningInfo,
|
pruning_info::PruningInfo,
|
||||||
receipt::LocalizedReceipt,
|
receipt::LocalizedReceipt,
|
||||||
trace_filter::Filter as TraceFilter,
|
trace_filter::Filter as TraceFilter,
|
||||||
transaction::{self, Action, LocalizedTransaction, SignedTransaction},
|
transaction::{self, Action, LocalizedTransaction, SignedTransaction, TypedTxId},
|
||||||
BlockNumber,
|
BlockNumber,
|
||||||
};
|
};
|
||||||
use vm::LastHashes;
|
use vm::LastHashes;
|
||||||
@ -395,10 +395,15 @@ pub trait BlockChainClient:
|
|||||||
if block.number() == 0 {
|
if block.number() == 0 {
|
||||||
return corpus.into();
|
return corpus.into();
|
||||||
}
|
}
|
||||||
block
|
block.transaction_views().iter().foreach(|t| {
|
||||||
.transaction_views()
|
corpus.push(t.effective_gas_price({
|
||||||
.iter()
|
match t.transaction_type() {
|
||||||
.foreach(|t| corpus.push(t.gas_price()));
|
TypedTxId::Legacy => None,
|
||||||
|
TypedTxId::AccessList => None,
|
||||||
|
TypedTxId::EIP1559Transaction => Some(block.header().base_fee()),
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
});
|
||||||
h = block.parent_hash().clone();
|
h = block.parent_hash().clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
//! View onto transaction rlp
|
//! View onto transaction rlp
|
||||||
|
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bytes::Bytes,
|
bytes::Bytes,
|
||||||
hash::keccak,
|
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>) -> 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.
|
/// Get the gas field of the transaction.
|
||||||
pub fn gas(&self) -> U256 {
|
pub fn gas(&self) -> U256 {
|
||||||
match self.transaction_type {
|
match self.transaction_type {
|
||||||
@ -238,6 +259,7 @@ mod tests {
|
|||||||
let view = view!(TypedTransactionView, &rlp);
|
let view = view!(TypedTransactionView, &rlp);
|
||||||
assert_eq!(view.nonce(), 0.into());
|
assert_eq!(view.nonce(), 0.into());
|
||||||
assert_eq!(view.gas_price(), 1.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.gas(), 0x61a8.into());
|
||||||
assert_eq!(view.value(), 0xa.into());
|
assert_eq!(view.value(), 0xa.into());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -279,10 +301,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_eip1559_transaction_view() {
|
fn test_eip1559_transaction_view() {
|
||||||
let rlp = "b8c202f8bf01010a0a8301e24194000000000000000000000000000000000000aaaa8080f85bf859940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000080a082dc119130f280bd72e3fd4e10220e35b767031b84b8dd1f64085e0158f234dba072228551e678a8a6c6e9bae0ae786b8839c7fda0a994caddd23910f45f385cc0".from_hex().unwrap();
|
let rlp = "b8c202f8bf0101010a8301e24194000000000000000000000000000000000000aaaa8080f85bf859940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000080a082dc119130f280bd72e3fd4e10220e35b767031b84b8dd1f64085e0158f234dba072228551e678a8a6c6e9bae0ae786b8839c7fda0a994caddd23910f45f385cc0".from_hex().unwrap();
|
||||||
let view = view!(TypedTransactionView, &rlp);
|
let view = view!(TypedTransactionView, &rlp);
|
||||||
assert_eq!(view.nonce(), 0x1.into());
|
assert_eq!(view.nonce(), 0x1.into());
|
||||||
assert_eq!(view.gas_price(), 0xa.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.gas(), 0x1e241.into());
|
||||||
assert_eq!(view.value(), 0x0.into());
|
assert_eq!(view.value(), 0x0.into());
|
||||||
assert_eq!(view.data(), "".from_hex().unwrap());
|
assert_eq!(view.data(), "".from_hex().unwrap());
|
||||||
|
Loading…
Reference in New Issue
Block a user