-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(op, txpool): add additional update routine for conditionals #14497
Changes from 1 commit
d5aeadc
7070e97
77c0033
8124ab4
1f4508e
203e011
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Support for maintaining the state of the transaction pool | ||
|
||
use alloy_consensus::{conditional::BlockConditionalAttributes, BlockHeader}; | ||
use futures_util::{future::BoxFuture, FutureExt, Stream, StreamExt}; | ||
use reth_primitives_traits::NodePrimitives; | ||
use reth_provider::CanonStateNotification; | ||
use reth_transaction_pool::TransactionPool; | ||
|
||
use crate::conditional::MaybeConditionalTransaction; | ||
|
||
/// Returns a spawnable future for maintaining the state of the transaction pool. | ||
pub fn maintain_transaction_pool_future<N, Pool, St>( | ||
pool: Pool, | ||
events: St, | ||
) -> BoxFuture<'static, ()> | ||
where | ||
N: NodePrimitives, | ||
Pool: TransactionPool + 'static, | ||
Pool::Transaction: MaybeConditionalTransaction, | ||
St: Stream<Item = CanonStateNotification<N>> + Send + Unpin + 'static, | ||
{ | ||
async move { | ||
maintain_transaction_pool(pool, events).await; | ||
} | ||
.boxed() | ||
} | ||
|
||
/// Maintains the state of the transaction pool by handling new blocks and reorgs. | ||
/// | ||
/// This listens for any new blocks and reorgs and updates the transaction pool's state accordingly | ||
pub async fn maintain_transaction_pool<N, Pool, St>(pool: Pool, mut events: St) | ||
where | ||
N: NodePrimitives, | ||
Pool: TransactionPool, | ||
Pool::Transaction: MaybeConditionalTransaction, | ||
St: Stream<Item = CanonStateNotification<N>> + Send + Unpin + 'static, | ||
{ | ||
loop { | ||
let Some(event) = events.next().await else { break }; | ||
if let CanonStateNotification::Commit { new } = event { | ||
if !new.is_empty() { | ||
let header = new.tip().clone().into_header(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I blieve there should be clone_header |
||
let mut to_remove = Vec::new(); | ||
for tx in &pool.pooled_transactions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be fine, even with a low blocktime to run every 1-2s @hai-rise is support for 4337 conditionals even relevant for you? if not you can just not spawn this task |
||
if let Some(conditional) = tx.transaction.conditional() { | ||
if conditional.has_exceeded_block_attributes(&BlockConditionalAttributes { | ||
number: header.number(), | ||
timestamp: header.timestamp(), | ||
}) { | ||
to_remove.push(*tx.hash()); | ||
} | ||
} | ||
} | ||
let _ = pool.remove_transactions(to_remove); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also want some metrics for this |
||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this also has access to the enable conditional setting so we can spawn this based on that, I believe we can pass this setting down