From fddda46d4f6c12a1f49635f259047eb34613baa4 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Tue, 15 Dec 2020 10:37:35 +0200 Subject: [PATCH] Fix infinite loop on antiPastHashesBetween (#1226) * Fix infinite loop on antiPastHashesBetween * Get rid of highBlockBlueScore and lowBlockBlueScore --- .../consensus/processes/syncmanager/antipast.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/domain/consensus/processes/syncmanager/antipast.go b/domain/consensus/processes/syncmanager/antipast.go index 14d2406be..feb33c4d3 100644 --- a/domain/consensus/processes/syncmanager/antipast.go +++ b/domain/consensus/processes/syncmanager/antipast.go @@ -16,19 +16,17 @@ func (sm *syncManager) antiPastHashesBetween(lowHash, highHash *externalapi.Doma if err != nil { return nil, err } - lowBlockBlueScore := lowBlockGHOSTDAGData.BlueScore() highBlockGHOSTDAGData, err := sm.ghostdagDataStore.Get(sm.databaseContext, highHash) if err != nil { return nil, err } - highBlockBlueScore := highBlockGHOSTDAGData.BlueScore() - if lowBlockBlueScore >= highBlockBlueScore { + if lowBlockGHOSTDAGData.BlueScore() >= highBlockGHOSTDAGData.BlueScore() { return nil, errors.Errorf("low hash blueScore >= high hash blueScore (%d >= %d)", - lowBlockBlueScore, highBlockBlueScore) + lowBlockGHOSTDAGData.BlueScore(), highBlockGHOSTDAGData.BlueScore()) } // In order to get no more then maxHashesInAntiPastHashesBetween - // blocks from th future of the lowHash (including itself), + // blocks from the future of the lowHash (including itself), // we iterate the selected parent chain of the highNode and // stop once we reach // highBlockBlueScore-lowBlockBlueScore+1 <= maxHashesInAntiPastHashesBetween. @@ -36,8 +34,13 @@ func (sm *syncManager) antiPastHashesBetween(lowHash, highHash *externalapi.Doma // Using blueScore as an approximation is considered to be // fairly accurate because we presume that most DAG blocks are // blue. - for highBlockBlueScore-lowBlockBlueScore+1 > maxHashesInAntiPastHashesBetween { + for highBlockGHOSTDAGData.BlueScore()-lowBlockGHOSTDAGData.BlueScore()+1 > maxHashesInAntiPastHashesBetween { highHash = highBlockGHOSTDAGData.SelectedParent() + var err error + highBlockGHOSTDAGData, err = sm.ghostdagDataStore.Get(sm.databaseContext, highHash) + if err != nil { + return nil, err + } } // Collect every node in highHash's past (including itself) but