From 74cc14d9dec56e2147ff809a8dc073c6ff144e22 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sun, 12 Nov 2023 03:56:27 +0200 Subject: [PATCH] Improve DSN sync security --- .../segment_header_downloader.rs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/subspace-service/src/sync_from_dsn/segment_header_downloader.rs b/crates/subspace-service/src/sync_from_dsn/segment_header_downloader.rs index 69471860cd..78e442c93b 100644 --- a/crates/subspace-service/src/sync_from_dsn/segment_header_downloader.rs +++ b/crates/subspace-service/src/sync_from_dsn/segment_header_downloader.rs @@ -181,24 +181,35 @@ impl<'a> SegmentHeaderDownloader<'a> { let peer_count = peer_segment_headers.len(); if peer_count < required_peers { - if last_peers_count == 0 || last_peers_count != peer_count { + // If we've got nothing, we have to retry + if last_peers_count == 0 { debug!( %peer_count, %required_peers, %retry_attempt, - "Segment headers consensus requires more peers, will retry" + "Segment headers consensus requires some peers, will retry" ); continue; - } else { + } + // If number of peers found increased, but there are still attempts left, do more attempts + if last_peers_count != peer_count && required_peers > 1 { debug!( %peer_count, %required_peers, %retry_attempt, - "Segment headers consensus requires more peers, but result is the same as \ - last time, so continue with what we've got" + "Segment headers consensus requires more peers, will retry" ); + + continue; } + + debug!( + %peer_count, + %required_peers, + %retry_attempt, + "Segment headers consensus requires more peers, but no attempts left, so continue as is" + ); } // Calculate votes