From 1e4f29920e937a9a2252f96f4e6ef2c701e4b1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 11 Jan 2022 21:09:00 +0200 Subject: [PATCH] eth/downloader: use a non-nil pivot even in degenerate sync requests --- eth/downloader/downloader.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 13e0b4f11191f..1b38274bc775f 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -469,13 +469,6 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I if err != nil { return err } - if mode == SnapSync && pivot == nil { - // If no pivot block was returned, the head is below the min full block - // threshold (i.e. new chain). In that case we won't really snap sync - // anyway, but still need a valid pivot block to avoid some code hitting - // nil panics on an access. - pivot = d.blockchain.CurrentBlock().Header() - } } else { // In beacon mode, user the skeleton chain to retrieve the headers from latest, err = d.skeleton.Head() @@ -489,6 +482,13 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I // to special case everything internally. pivot = d.skeleton.Header(latest.Number.Uint64() - 1) } + // If no pivot block was returned, the head is below the min full block + // threshold (i.e. new chain). In that case we won't really snap sync + // anyway, but still need a valid pivot block to avoid some code hitting + // nil panics on access. + if mode == SnapSync && pivot == nil { + pivot = d.blockchain.CurrentBlock().Header() + } height := latest.Number.Uint64() var origin uint64