From dca89af8efc0e923e788bf03d239735166849534 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 4 Mar 2024 11:52:50 +0100 Subject: [PATCH 1/2] perf: use a blocking task to process transmission responses in the worker Signed-off-by: ljedrz --- node/bft/src/worker.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/node/bft/src/worker.rs b/node/bft/src/worker.rs index 428f9e378f..7e6f886dda 100644 --- a/node/bft/src/worker.rs +++ b/node/bft/src/worker.rs @@ -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, @@ -376,7 +377,11 @@ impl Worker { 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(()) + }); } }); } From b1b348577e31a3089126e99b5b4e3ad046e84a48 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 4 Mar 2024 14:39:37 +0100 Subject: [PATCH 2/2] perf: use a blocking task in sync_ledger_with_block_without_bft Signed-off-by: ljedrz --- node/bft/src/sync/mod.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/node/bft/src/sync/mod.rs b/node/bft/src/sync/mod.rs index 153e6556b3..608e152417 100644 --- a/node/bft/src/sync/mod.rs +++ b/node/bft/src/sync/mod.rs @@ -325,17 +325,21 @@ impl Sync { // 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.