From 905ed109edfda340ccd3641ebad4e0ff5dc73440 Mon Sep 17 00:00:00 2001 From: gary rong Date: Fri, 9 Oct 2020 14:58:30 +0800 Subject: [PATCH] eth/downloader: fix data race around the ancientlimit (#21681) * eth/downloader: fix data race around the ancientlimit * eth/downloader: initialize the ancientlimit as 0 --- eth/downloader/downloader.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index c6ca9af0136a..7c572289b288 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -515,6 +515,8 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I d.ancientLimit = d.checkpoint } else if height > fullMaxForkAncestry+1 { d.ancientLimit = height - fullMaxForkAncestry - 1 + } else { + d.ancientLimit = 0 } frozen, _ := d.stateDB.Ancients() // Ignore the error here since light client can also hit here. @@ -606,9 +608,6 @@ func (d *Downloader) cancel() { func (d *Downloader) Cancel() { d.cancel() d.cancelWg.Wait() - - d.ancientLimit = 0 - log.Debug("Reset ancient limit to zero") } // Terminate interrupts the downloader, canceling all pending operations.