Skip to content

Commit 99df0e9

Browse files
committed
Make sure we have at least 5 heights to compare
1 parent 6543591 commit 99df0e9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

netsync/manager.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const (
2929
// more.
3030
minInFlightBlocks = 10
3131

32+
// minSyncPeerMedianHeights is the minimum number of valid sync
33+
// peer candidates to trust for updating the sync peer due
34+
// to it being behind.
35+
minSyncPeerMedianHeights = 5
36+
3237
// maxNetworkViolations is the max number of network violations a
3338
// sync peer can have before a new sync peer is found.
3439
maxNetworkViolations = 3
@@ -579,9 +584,9 @@ func (sm *SyncManager) medianSyncPeerCandidateBlockHeight() int32 {
579584
heights = append(heights, topBlock)
580585
}
581586

582-
// If we don't have any sync peer candidate heights, return 0.
583-
// This is just to protect from a panic below.
584-
if len(heights) < 1 {
587+
// Make sure we have enough heights to trust the data.
588+
// If we only have 1 or 2 that could be gamed easily!
589+
if len(heights) < minSyncPeerMedianHeights {
585590
return 0
586591
}
587592

0 commit comments

Comments
 (0)