Skip to content
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

Run verifier in blocking pool #20812

Merged
merged 1 commit into from
Jan 10, 2025
Merged
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
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(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spawn_blocking? To keep the long running cpu work out of the async thread pool.

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
Loading