mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: support pending blob fee (#4443)
This commit is contained in:
@ -92,6 +92,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
pending_basefee: latest
|
||||
.next_block_base_fee(chain_spec.base_fee_params)
|
||||
.unwrap_or_default(),
|
||||
pending_blob_fee: latest.next_block_blob_fee().map(|fee| fee.saturating_to()),
|
||||
};
|
||||
pool.set_block_info(info);
|
||||
}
|
||||
@ -234,9 +235,11 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
|
||||
let chain_spec = client.chain_spec();
|
||||
|
||||
// base fee for the next block: `new_tip+1`
|
||||
// fees for the next block: `new_tip+1`
|
||||
let pending_block_base_fee =
|
||||
new_tip.next_block_base_fee(chain_spec.base_fee_params).unwrap_or_default();
|
||||
let pending_block_blob_fee =
|
||||
new_tip.next_block_blob_fee().map(|fee| fee.saturating_to());
|
||||
|
||||
// we know all changed account in the new chain
|
||||
let new_changed_accounts: HashSet<_> =
|
||||
@ -292,6 +295,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
let update = CanonicalStateUpdate {
|
||||
new_tip: &new_tip.block,
|
||||
pending_block_base_fee,
|
||||
pending_block_blob_fee,
|
||||
changed_accounts,
|
||||
// all transactions mined in the new chain need to be removed from the pool
|
||||
mined_transactions: new_mined_transactions.into_iter().collect(),
|
||||
@ -314,9 +318,11 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
let tip = blocks.tip();
|
||||
let chain_spec = client.chain_spec();
|
||||
|
||||
// base fee for the next block: `tip+1`
|
||||
// fees for the next block: `tip+1`
|
||||
let pending_block_base_fee =
|
||||
tip.next_block_base_fee(chain_spec.base_fee_params).unwrap_or_default();
|
||||
let pending_block_blob_fee =
|
||||
tip.next_block_blob_fee().map(|fee| fee.saturating_to());
|
||||
|
||||
let first_block = blocks.first();
|
||||
trace!(
|
||||
@ -337,6 +343,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
last_seen_block_hash: tip.hash,
|
||||
last_seen_block_number: tip.number,
|
||||
pending_basefee: pending_block_base_fee,
|
||||
pending_blob_fee: pending_block_blob_fee,
|
||||
};
|
||||
pool.set_block_info(info);
|
||||
|
||||
@ -367,6 +374,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
let update = CanonicalStateUpdate {
|
||||
new_tip: &tip.block,
|
||||
pending_block_base_fee,
|
||||
pending_block_blob_fee,
|
||||
changed_accounts,
|
||||
mined_transactions,
|
||||
};
|
||||
|
||||
@ -38,6 +38,7 @@ impl TransactionPool for NoopTransactionPool {
|
||||
last_seen_block_hash: Default::default(),
|
||||
last_seen_block_number: 0,
|
||||
pending_basefee: 0,
|
||||
pending_blob_fee: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,9 @@ use crate::{
|
||||
};
|
||||
use fnv::FnvHashMap;
|
||||
use reth_primitives::{
|
||||
constants::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE},
|
||||
constants::{
|
||||
eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE,
|
||||
},
|
||||
Address, TxHash, H256,
|
||||
};
|
||||
use std::{
|
||||
@ -135,9 +137,15 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
last_seen_block_hash: self.all_transactions.last_seen_block_hash,
|
||||
last_seen_block_number: self.all_transactions.last_seen_block_number,
|
||||
pending_basefee: self.all_transactions.pending_basefee,
|
||||
pending_blob_fee: Some(self.all_transactions.pending_blob_fee),
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the tracked blob fee
|
||||
fn update_blob_fee(&mut self, _pending_blob_fee: u64) {
|
||||
// TODO(mattsse): update blob txs
|
||||
}
|
||||
|
||||
/// Updates the tracked basefee
|
||||
///
|
||||
/// Depending on the change in direction of the basefee, this will promote or demote
|
||||
@ -182,11 +190,21 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
///
|
||||
/// This will also apply updates to the pool based on the new base fee
|
||||
pub(crate) fn set_block_info(&mut self, info: BlockInfo) {
|
||||
let BlockInfo { last_seen_block_hash, last_seen_block_number, pending_basefee } = info;
|
||||
let BlockInfo {
|
||||
last_seen_block_hash,
|
||||
last_seen_block_number,
|
||||
pending_basefee,
|
||||
pending_blob_fee,
|
||||
} = info;
|
||||
self.all_transactions.last_seen_block_hash = last_seen_block_hash;
|
||||
self.all_transactions.last_seen_block_number = last_seen_block_number;
|
||||
self.all_transactions.pending_basefee = pending_basefee;
|
||||
self.update_basefee(pending_basefee)
|
||||
self.update_basefee(pending_basefee);
|
||||
|
||||
if let Some(blob_fee) = pending_blob_fee {
|
||||
self.all_transactions.pending_blob_fee = blob_fee;
|
||||
self.update_blob_fee(pending_basefee)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator that yields transactions that are ready to be included in the block.
|
||||
@ -683,6 +701,8 @@ pub(crate) struct AllTransactions<T: PoolTransaction> {
|
||||
last_seen_block_hash: H256,
|
||||
/// Expected base fee for the pending block.
|
||||
pending_basefee: u64,
|
||||
/// Expected blob fee for the pending block.
|
||||
pending_blob_fee: u64,
|
||||
/// Configured price bump settings for replacements
|
||||
price_bumps: PriceBumpConfig,
|
||||
}
|
||||
@ -741,11 +761,18 @@ impl<T: PoolTransaction> AllTransactions<T> {
|
||||
|
||||
/// Updates the block specific info
|
||||
fn set_block_info(&mut self, block_info: BlockInfo) {
|
||||
let BlockInfo { last_seen_block_hash, last_seen_block_number, pending_basefee } =
|
||||
block_info;
|
||||
let BlockInfo {
|
||||
last_seen_block_hash,
|
||||
last_seen_block_number,
|
||||
pending_basefee,
|
||||
pending_blob_fee,
|
||||
} = block_info;
|
||||
self.last_seen_block_number = last_seen_block_number;
|
||||
self.last_seen_block_hash = last_seen_block_hash;
|
||||
self.pending_basefee = pending_basefee;
|
||||
if let Some(pending_blob_fee) = pending_blob_fee {
|
||||
self.pending_blob_fee = pending_blob_fee;
|
||||
}
|
||||
}
|
||||
|
||||
/// Rechecks all transactions in the pool against the changes.
|
||||
@ -1296,6 +1323,7 @@ impl<T: PoolTransaction> Default for AllTransactions<T> {
|
||||
last_seen_block_number: 0,
|
||||
last_seen_block_hash: Default::default(),
|
||||
pending_basefee: Default::default(),
|
||||
pending_blob_fee: BLOB_TX_MIN_BLOB_GASPRICE,
|
||||
price_bumps: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,6 +484,10 @@ pub struct CanonicalStateUpdate<'a> {
|
||||
///
|
||||
/// The base fee of a block depends on the utilization of the last block and its base fee.
|
||||
pub pending_block_base_fee: u64,
|
||||
/// EIP-4844 blob fee of the _next_ (pending) block
|
||||
///
|
||||
/// Only after Cancun
|
||||
pub pending_block_blob_fee: Option<u64>,
|
||||
/// A set of changed accounts across a range of blocks.
|
||||
pub changed_accounts: Vec<ChangedAccount>,
|
||||
/// All mined transactions in the block range.
|
||||
@ -512,14 +516,15 @@ impl<'a> CanonicalStateUpdate<'a> {
|
||||
last_seen_block_hash: self.hash(),
|
||||
last_seen_block_number: self.number(),
|
||||
pending_basefee: self.pending_block_base_fee,
|
||||
pending_blob_fee: self.pending_block_blob_fee,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for CanonicalStateUpdate<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{{ hash: {}, number: {}, pending_block_base_fee: {}, changed_accounts: {}, mined_transactions: {} }}",
|
||||
self.hash(), self.number(), self.pending_block_base_fee, self.changed_accounts.len(), self.mined_transactions.len())
|
||||
write!(f, "{{ hash: {}, number: {}, pending_block_base_fee: {}, pending_block_blob_fee: {:?}, changed_accounts: {}, mined_transactions: {} }}",
|
||||
self.hash(), self.number(), self.pending_block_base_fee, self.pending_block_blob_fee, self.changed_accounts.len(), self.mined_transactions.len())
|
||||
}
|
||||
}
|
||||
|
||||
@ -921,9 +926,14 @@ pub struct BlockInfo {
|
||||
pub last_seen_block_number: u64,
|
||||
/// Currently enforced base fee: the threshold for the basefee sub-pool.
|
||||
///
|
||||
/// Note: this is the derived base fee of the _next_ block that builds on the clock the pool is
|
||||
/// Note: this is the derived base fee of the _next_ block that builds on the block the pool is
|
||||
/// currently tracking.
|
||||
pub pending_basefee: u64,
|
||||
/// Currently enforced blob fee: the threshold for eip-4844 blob transactions.
|
||||
///
|
||||
/// Note: this is the derived blob fee of the _next_ block that builds on the block the pool is
|
||||
/// currently tracking
|
||||
pub pending_blob_fee: Option<u64>,
|
||||
}
|
||||
|
||||
/// The limit to enforce for [TransactionPool::get_pooled_transaction_elements].
|
||||
|
||||
Reference in New Issue
Block a user