From 93865ef916c1337ad2b0a0263f27ea91a46d6f98 Mon Sep 17 00:00:00 2001 From: Chris Evanko <106608356+cjeva10@users.noreply.github.com> Date: Fri, 7 Jul 2023 14:51:34 -0400 Subject: [PATCH] pop duplicates entries when returning downloaded blocks in engine (#3644) Co-authored-by: Matthias Seitz --- crates/consensus/beacon/src/engine/sync.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/consensus/beacon/src/engine/sync.rs b/crates/consensus/beacon/src/engine/sync.rs index 73bb85dbb9..b422583f2d 100644 --- a/crates/consensus/beacon/src/engine/sync.rs +++ b/crates/consensus/beacon/src/engine/sync.rs @@ -13,7 +13,7 @@ use reth_stages::{ControlFlow, Pipeline, PipelineError, PipelineWithResult}; use reth_tasks::TaskSpawner; use std::{ cmp::{Ordering, Reverse}, - collections::BinaryHeap, + collections::{binary_heap::PeekMut, BinaryHeap}, task::{ready, Context, Poll}, }; use tokio::sync::oneshot; @@ -304,6 +304,14 @@ where // drain an element of the block buffer if there are any if let Some(block) = self.range_buffered_blocks.pop() { + // peek ahead and pop duplicates + while let Some(peek) = self.range_buffered_blocks.peek_mut() { + if peek.0 .0.hash() == block.0 .0.hash() { + PeekMut::pop(peek); + } else { + break + } + } return Poll::Ready(EngineSyncEvent::FetchedFullBlock(block.0 .0)) }