Skip to content

Commit

Permalink
Perf: hold read lock over block_cache for longer
Browse files Browse the repository at this point in the history
  • Loading branch information
vicsn committed Nov 19, 2024
1 parent f7e924f commit bb00286
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions node/bft/ledger-service/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,16 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
let start_height = heights.start;
// Prepare missing heights to collect.
let mut missing_heights = BTreeSet::from_iter(heights.clone());
// For each height in the range, check if the block is in the cache.
for height in heights {
if let Some(block) = self.block_cache.read().get(&height) {
let index = block.height().saturating_sub(start_height) as usize;
blocks.insert(index, block.clone());
missing_heights.remove(&height);
{
// Obtain a read lock on the block cache.
let block_cache = self.block_cache.read();
// For each height in the range, check if the block is in the cache.
for height in heights {
if let Some(block) = block_cache.get(&height) {
let index = block.height().saturating_sub(start_height) as usize;
blocks.insert(index, block.clone());
missing_heights.remove(&height);
}
}
}
// Check if there are any blocks not found in the cache.
Expand Down

0 comments on commit bb00286

Please sign in to comment.