Skip to content

Commit

Permalink
Run verifier in blocking pool (#20812)
Browse files Browse the repository at this point in the history
Turns out the verifier is running in the async thread pool, which may be
causing thread stalls.
  • Loading branch information
mystenmark authored Jan 10, 2025
1 parent 537c2f8 commit 139a2b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
21 changes: 15 additions & 6 deletions consensus/core/src/commit_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use mysten_metrics::spawn_logged_monitored_task;
use parking_lot::RwLock;
use rand::{prelude::SliceRandom as _, rngs::ThreadRng};
use tokio::{
runtime::Handle,
sync::oneshot,
task::{JoinHandle, JoinSet},
time::{sleep, MissedTickBehavior},
Expand Down Expand Up @@ -499,12 +500,20 @@ impl<C: NetworkClient> CommitSyncer<C> {
// 2. Verify the response contains blocks that can certify the last returned commit,
// and the returned commits are chained by digest, so earlier commits are certified
// as well.
let commits = inner.verify_commits(
target_authority,
commit_range,
serialized_commits,
serialized_blocks,
)?;
let commits = Handle::current()
.spawn_blocking({
let inner = inner.clone();
move || {
inner.verify_commits(
target_authority,
commit_range,
serialized_commits,
serialized_blocks,
)
}
})
.await
.expect("Spawn blocking should not fail")?;

// 3. Fetch blocks referenced by the commits, from the same authority.
let block_refs: Vec<_> = commits.iter().flat_map(|c| c.blocks()).cloned().collect();
Expand Down
15 changes: 9 additions & 6 deletions consensus/core/src/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rand::{prelude::SliceRandom as _, rngs::ThreadRng};
use sui_macros::fail_point_async;
use tap::TapFallible;
use tokio::{
runtime::Handle,
sync::{mpsc::error::TrySendError, oneshot},
task::{JoinError, JoinSet},
time::{sleep, sleep_until, timeout, Instant},
Expand Down Expand Up @@ -510,12 +511,14 @@ impl<C: NetworkClient, V: BlockVerifier, D: CoreThreadDispatcher> Synchronizer<C
}

// Verify all the fetched blocks
let blocks = Self::verify_blocks(
serialized_blocks,
block_verifier.clone(),
&context,
peer_index,
)?;
let blocks = Handle::current()
.spawn_blocking({
let block_verifier = block_verifier.clone();
let context = context.clone();
move || Self::verify_blocks(serialized_blocks, block_verifier, &context, peer_index)
})
.await
.expect("Spawn blocking should not fail")?;

// Get all the ancestors of the requested blocks only
let ancestors = blocks
Expand Down

0 comments on commit 139a2b9

Please sign in to comment.