We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8cf0271 commit d626657Copy full SHA for d626657
lightning-block-sync/src/gossip.rs
@@ -209,11 +209,14 @@ impl<S: FutureSpawner,
209
}
210
{
211
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;
+ let pos_opt = recent_blocks.iter().position(|(height, _)| *height == block_height);
+ if let Some(pos) = pos_opt {
+ if pos != recent_blocks.len() - 1 {
+ // Push the block to the end of the LRU queue
216
+ core::mem::swap(&mut recent_blocks.last_mut().unwrap(), &mut recent_blocks[pos]);
217
218
+ process_block!(recent_blocks.last().unwrap().1);
219
+ break 'tx_found;
220
221
222
0 commit comments