Skip to content

Commit

Permalink
perf: use a blocking task in sync_ledger_with_block_without_bft
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <ljedrz@gmail.com>
  • Loading branch information
ljedrz committed Mar 4, 2024
1 parent 0d98b73 commit 0dfccdb
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions node/bft/src/sync/mod.rs
Expand Up @@ -325,17 +325,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

0 comments on commit 0dfccdb

Please sign in to comment.