Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 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 transaction and blobs bundle insertions so payload
/// builders 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_waiters();

Ok(())
}
Expand Down Expand Up @@ -157,6 +168,9 @@ impl Mempool {
self.write()?
.blobs_bundle_pool
.insert(tx_hash, blobs_bundle);
// Notify after the bundle is inserted so builders that woke up from
// add_transaction see the complete blob data.
self.tx_added.notify_waiters();
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,
_ = 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.