Skip to content

Commit b1b3485

Browse files
committed
perf: use a blocking task in sync_ledger_with_block_without_bft
Signed-off-by: ljedrz <ljedrz@gmail.com>
1 parent dca89af commit b1b3485

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

node/bft/src/sync/mod.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,21 @@ impl<N: Network> Sync<N> {
325325
// Acquire the sync lock.
326326
let _lock = self.sync_lock.lock().await;
327327

328-
// Check the next block.
329-
self.ledger.check_next_block(&block)?;
330-
// Attempt to advance to the next block.
331-
self.ledger.advance_to_next_block(&block)?;
332-
333-
// Sync the height with the block.
334-
self.storage.sync_height_with_block(block.height());
335-
// Sync the round with the block.
336-
self.storage.sync_round_with_block(block.round());
337-
338-
Ok(())
328+
let self_ = self.clone();
329+
tokio::task::spawn_blocking(move || {
330+
// Check the next block.
331+
self_.ledger.check_next_block(&block)?;
332+
// Attempt to advance to the next block.
333+
self_.ledger.advance_to_next_block(&block)?;
334+
335+
// Sync the height with the block.
336+
self_.storage.sync_height_with_block(block.height());
337+
// Sync the round with the block.
338+
self_.storage.sync_round_with_block(block.round());
339+
340+
Ok(())
341+
})
342+
.await?
339343
}
340344

341345
/// Syncs the storage with the given blocks.

0 commit comments

Comments
 (0)