Skip to content

Commit d626657

Browse files
committed
f make the queue LRU
1 parent 8cf0271 commit d626657

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lightning-block-sync/src/gossip.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,14 @@ impl<S: FutureSpawner,
209209
}
210210
{
211211
let recent_blocks = block_cache.lock().unwrap();
212-
for (height, block) in recent_blocks.iter() {
213-
if *height == block_height {
214-
process_block!(block);
215-
break 'tx_found;
212+
let pos_opt = recent_blocks.iter().position(|(height, _)| *height == block_height);
213+
if let Some(pos) = pos_opt {
214+
if pos != recent_blocks.len() - 1 {
215+
// Push the block to the end of the LRU queue
216+
core::mem::swap(&mut recent_blocks.last_mut().unwrap(), &mut recent_blocks[pos]);
216217
}
218+
process_block!(recent_blocks.last().unwrap().1);
219+
break 'tx_found;
217220
}
218221
}
219222

0 commit comments

Comments
 (0)