From 3fdfcb3179adb89cc77d87257e8b2a42e47987d7 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 24 Aug 2020 22:09:41 +1000 Subject: [PATCH] fix: remove old tips that are behind new tips This change makes sync less reliant on the exact order of ObtainTips and ExtendTips responses. --- zebrad/src/commands/start/sync.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zebrad/src/commands/start/sync.rs b/zebrad/src/commands/start/sync.rs index 866fcafd..6f0413f9 100644 --- a/zebrad/src/commands/start/sync.rs +++ b/zebrad/src/commands/start/sync.rs @@ -226,8 +226,13 @@ where continue; }; + // Make sure we get the same tips, regardless of the + // order of peer responses if !download_set.contains(&new_tip.expected_next) { - tracing::debug!(?new_tip, "adding new prospective tip"); + tracing::debug!(?new_tip, + "adding new prospective tip, and removing existing tips in the new block hash list"); + self.prospective_tips + .retain(|t| !unknown_hashes.contains(&t.expected_next)); self.prospective_tips.insert(new_tip); } else { tracing::debug!(?new_tip, "discarding tip already queued for download"); @@ -305,8 +310,13 @@ where tracing::trace!(?hashes); + // Make sure we get the same tips, regardless of the + // order of peer responses if !download_set.contains(&new_tip.expected_next) { - tracing::debug!(?new_tip, "adding new prospective tip"); + tracing::debug!(?new_tip, + "adding new prospective tip, and removing any existing tips in the new block hash list"); + self.prospective_tips + .retain(|t| !unknown_hashes.contains(&t.expected_next)); self.prospective_tips.insert(new_tip); } else { tracing::debug!(?new_tip, "discarding tip already queued for download");