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

[Optimize] Further blocking tweaks #3148

Merged
merged 3 commits into from Mar 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions node/bft/src/sync/mod.rs
Expand Up @@ -309,17 +309,21 @@ impl<N: Network> Sync<N> {
// Acquire the sync lock.
let _lock = self.sync_lock.lock().await;

// Check the next block.
self.ledger.check_next_block(&block)?;
// Attempt to advance to the next block.
self.ledger.advance_to_next_block(&block)?;

// Sync the height with the block.
self.storage.sync_height_with_block(block.height());
// Sync the round with the block.
self.storage.sync_round_with_block(block.round());

Ok(())
let self_ = self.clone();
tokio::task::spawn_blocking(move || {
// Check the next block.
self_.ledger.check_next_block(&block)?;
// Attempt to advance to the next block.
self_.ledger.advance_to_next_block(&block)?;

// Sync the height with the block.
self_.storage.sync_height_with_block(block.height());
// Sync the round with the block.
self_.storage.sync_round_with_block(block.round());

Ok(())
})
.await?
}

/// Syncs the storage with the given blocks.
Expand Down
7 changes: 6 additions & 1 deletion node/bft/src/worker.rs
Expand Up @@ -15,6 +15,7 @@
use crate::{
events::{Event, TransmissionRequest, TransmissionResponse},
helpers::{fmt_id, max_redundant_requests, Pending, Ready, Storage, WorkerReceiver},
spawn_blocking,
ProposedBatch,
Transport,
MAX_FETCH_TIMEOUT_IN_MS,
Expand Down Expand Up @@ -376,7 +377,11 @@ impl<N: Network> Worker<N> {
self.spawn(async move {
while let Some((peer_ip, transmission_response)) = rx_transmission_response.recv().await {
// Process the transmission response.
self_.finish_transmission_request(peer_ip, transmission_response);
let self__ = self_.clone();
let _ = spawn_blocking!({
self__.finish_transmission_request(peer_ip, transmission_response);
Ok(())
});
}
});
}
Expand Down