fix(txpool): notify subscribers when set_block_info promotes transaction (#22243)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
drhgencer
2026-02-18 14:38:16 +05:30
committed by GitHub
parent 734ec4ffe6
commit 8861e2724f
3 changed files with 26 additions and 10 deletions

View File

@@ -204,9 +204,15 @@ where
pub fn block_info(&self) -> BlockInfo {
self.get_pool_data().block_info()
}
/// Sets the currently tracked block
/// Sets the currently tracked block.
///
/// This will also notify subscribers about any transactions that were promoted to the pending
/// pool due to fee changes.
pub fn set_block_info(&self, info: BlockInfo) {
self.pool.write().set_block_info(info)
let outcome = self.pool.write().set_block_info(info);
// Notify subscribers about promoted transactions due to fee changes
self.notify_on_transaction_updates(outcome.promoted, outcome.discarded);
}
/// Returns the internal [`SenderId`] for this address

View File

@@ -351,15 +351,25 @@ impl<T: TransactionOrdering> TxPool<T> {
/// Sets the current block info for the pool.
///
/// This will also apply updates to the pool based on the new base fee and blob fee
pub fn set_block_info(&mut self, info: BlockInfo) {
// first update the subpools based on the new values
let basefee_ordering = self.update_basefee(info.pending_basefee, |_| {});
/// This will also apply updates to the pool based on the new base fee and blob fee.
///
/// Returns the outcome containing any transactions that were promoted due to fee changes.
pub fn set_block_info(&mut self, info: BlockInfo) -> UpdateOutcome<T::Transaction> {
let mut outcome = UpdateOutcome::default();
// first update the subpools based on the new values, collecting promoted transactions
let basefee_ordering = self.update_basefee(info.pending_basefee, |tx| {
outcome.promoted.push(tx.clone());
});
if let Some(blob_fee) = info.pending_blob_fee {
self.update_blob_fee(blob_fee, basefee_ordering, |_| {})
self.update_blob_fee(blob_fee, basefee_ordering, |tx| {
outcome.promoted.push(tx.clone());
})
}
// then update tracked values
self.all_transactions.set_block_info(info);
outcome
}
/// Returns an iterator that yields transactions that are ready to be included in the block with

View File

@@ -35,11 +35,11 @@ impl From<SubPool> for Destination {
/// Tracks the result after updating the pool
#[derive(Debug)]
pub(crate) struct UpdateOutcome<T: PoolTransaction> {
pub struct UpdateOutcome<T: PoolTransaction> {
/// transactions promoted to the pending pool
pub(crate) promoted: Vec<Arc<ValidPoolTransaction<T>>>,
pub promoted: Vec<Arc<ValidPoolTransaction<T>>>,
/// transaction that failed and were discarded
pub(crate) discarded: Vec<Arc<ValidPoolTransaction<T>>>,
pub discarded: Vec<Arc<ValidPoolTransaction<T>>>,
}
impl<T: PoolTransaction> Default for UpdateOutcome<T> {