Skip to content

Commit 3e99307

Browse files
committed
f avoid racy double insert
1 parent 191c335 commit 3e99307

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lightning-block-sync/src/gossip.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,18 @@ impl<S: FutureSpawner,
167167
process_block!(block);
168168
{
169169
let mut recent_blocks = block_cache.lock().unwrap();
170-
if recent_blocks.len() >= BLOCK_CACHE_SIZE {
171-
recent_blocks.pop_front();
170+
let mut insert = true;
171+
for (height, _) in recent_blocks.iter() {
172+
if *height == block_height {
173+
insert = false;
174+
}
175+
}
176+
if insert {
177+
if recent_blocks.len() >= BLOCK_CACHE_SIZE {
178+
recent_blocks.pop_front();
179+
}
180+
recent_blocks.push_back((block_height, block));
172181
}
173-
recent_blocks.push_back((block_height, block));
174182
}
175183
break 'tx_found;
176184
};

0 commit comments

Comments
 (0)