Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ethereum/node/tests/e2e/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async fn test_reorg_through_backfill() -> eyre::Result<()> {

// Produce an unfinalized fork chain with 5 blocks
second_node.payload.timestamp = head.header.timestamp;
advance_with_random_transactions(&mut second_node, 5, &mut rng, false).await?;
advance_with_random_transactions(&mut second_node, 10, &mut rng, false).await?;

// Now reorg second node to the finalized canonical head
let head = first_provider.get_block_by_number(100.into()).await?.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/net/p2p/src/headers/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl SyncTarget {
}

/// Represents a gap to sync: from `local_head` to `target`
#[derive(Clone, Debug)]
pub struct HeaderSyncGap<H = Header> {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HeaderSyncGap<H: Sealable = Header> {
/// The local head block. Represents lower bound of sync range.
pub local_head: SealedHeader<H>,

Expand Down
14 changes: 10 additions & 4 deletions crates/stages/stages/src/stages/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ where
let target = SyncTarget::Tip(*self.tip.borrow());
let gap = HeaderSyncGap { local_head, target };
let tip = gap.target.tip();
self.sync_gap = Some(gap.clone());

// Nothing to sync
if gap.is_closed() {
Expand All @@ -232,7 +231,10 @@ where
let local_head_number = gap.local_head.number();

// let the downloader know what to sync
self.downloader.update_sync_gap(gap.local_head, gap.target);
if self.sync_gap != Some(gap.clone()) {
self.sync_gap = Some(gap.clone());
self.downloader.update_sync_gap(gap.local_head, gap.target);
}

// We only want to stop once we have all the headers on ETL filespace (disk).
loop {
Expand Down Expand Up @@ -263,13 +265,17 @@ where
}
Some(Err(HeadersDownloaderError::DetachedHead { local_head, header, error })) => {
error!(target: "sync::stages::headers", %error, "Cannot attach header to head");
self.sync_gap = None;
return Poll::Ready(Err(StageError::DetachedHead {
local_head: Box::new(local_head.block_with_parent()),
header: Box::new(header.block_with_parent()),
error,
}))
}
None => return Poll::Ready(Err(StageError::ChannelClosed)),
None => {
self.sync_gap = None;
return Poll::Ready(Err(StageError::ChannelClosed))
}
}
}
}
Expand All @@ -279,7 +285,7 @@ where
fn execute(&mut self, provider: &Provider, input: ExecInput) -> Result<ExecOutput, StageError> {
let current_checkpoint = input.checkpoint();

if self.sync_gap.as_ref().ok_or(StageError::MissingSyncGap)?.is_closed() {
if self.sync_gap.take().ok_or(StageError::MissingSyncGap)?.is_closed() {
self.is_etl_ready = false;
return Ok(ExecOutput::done(current_checkpoint))
}
Expand Down
Loading