Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tracing.workspace = true
bytes.workspace = true
hex.workspace = true
rustc-hash.workspace = true
tokio = { workspace = true, features = ["time", "rt"] }
tokio = { workspace = true, features = ["time", "rt", "sync", "macros"] }
tokio-util.workspace = true

[dev-dependencies]
Expand Down
11 changes: 11 additions & 0 deletions crates/blockchain/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,23 @@ impl MempoolInner {
#[derive(Debug, Default)]
pub struct Mempool {
inner: RwLock<MempoolInner>,
/// Signaled on every transaction insertion so the payload builder can
/// await new work instead of busy-looping.
tx_added: tokio::sync::Notify,
}

impl Mempool {
pub fn new(max_mempool_size: usize) -> Self {
Mempool {
inner: RwLock::new(MempoolInner::new(max_mempool_size)),
tx_added: tokio::sync::Notify::new(),
}
}

pub(crate) fn tx_added(&self) -> &tokio::sync::Notify {
&self.tx_added
}

fn write(&self) -> Result<std::sync::RwLockWriteGuard<'_, MempoolInner>, StoreError> {
self.inner
.write()
Expand Down Expand Up @@ -123,6 +131,9 @@ impl Mempool {
.insert((sender, transaction.nonce()), hash);
inner.transaction_pool.insert(hash, transaction);
inner.broadcast_pool.insert(hash);
// Drop the write lock before notifying to avoid holding it while waking waiters
drop(inner);
self.tx_added.notify_one();

Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ impl Blockchain {
// TODO(#4997): start with an empty block
let mut res = self.build_payload(payload.clone())?;
while start.elapsed() < SECONDS_PER_SLOT && !cancel_token.is_cancelled() {
// Wait for new transactions, cancellation, or slot deadline before rebuilding
let remaining = SECONDS_PER_SLOT.saturating_sub(start.elapsed());
let notified = self.mempool.tx_added().notified();
tokio::select! {
_ = notified => {}
_ = cancel_token.cancelled() => break,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the cancel_token.cancelled() branch here is redundant with the while !cancel_token.is_cancelled() loop condition — if the token fires, the next iteration's condition will catch it anyway. Not harmful (it exits one iteration earlier), but it could be removed for clarity since the sleep branch already provides the timeout exit.

Copy link
Contributor Author

@avilagaston9 avilagaston9 Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but I think the branch is actually needed: without it, if getPayload fires the cancel token while we're blocked in the select!, we'd be stuck waiting for either a notification or the sleep timeout before exiting. The while condition only checks between iterations, so the cancelled() branch gives us immediate responsiveness to cancellation.

_ = tokio::time::sleep(remaining) => break,
}
let payload = payload.clone();
let self_clone = self.clone();
let building_task =
Expand Down
12 changes: 12 additions & 0 deletions crates/vm/levm/bench/revm_comparison/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading