From ea15c4a4fd0789c5745989d7fdc36d053356cca1 Mon Sep 17 00:00:00 2001 From: ledgerwatch Date: Wed, 24 Mar 2021 22:37:29 +0000 Subject: [PATCH] Fixes to new downloader (#1599) * Fix for prefetched bodies * Do not reset headers stage to 0 Co-authored-by: Alexey Sharp --- eth/stagedsync/stage_headers_new.go | 8 +++++--- turbo/stages/bodydownload/body_algos.go | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/eth/stagedsync/stage_headers_new.go b/eth/stagedsync/stage_headers_new.go index cdc695176..a0e37a166 100644 --- a/eth/stagedsync/stage_headers_new.go +++ b/eth/stagedsync/stage_headers_new.go @@ -74,7 +74,7 @@ func HeadersForward( logEvery := time.NewTicker(logInterval) defer logEvery.Stop() - localTd, err1 := rawdb.ReadTd(tx, headHash, headerProgress) + localTd, err1 := rawdb.ReadTd(tx, hash, headerProgress) if err1 != nil { return err1 } @@ -150,8 +150,10 @@ func HeadersForward( break } } - if err := s.Update(tx, headerInserter.GetHighest()); err != nil { - return err + if headerInserter.AnythingDone() { + if err := s.Update(tx, headerInserter.GetHighest()); err != nil { + return err + } } if headerInserter.UnwindPoint() < headerProgress { if err := u.UnwindTo(headerInserter.UnwindPoint(), batch); err != nil { diff --git a/turbo/stages/bodydownload/body_algos.go b/turbo/stages/bodydownload/body_algos.go index c3ea23b74..df102029c 100644 --- a/turbo/stages/bodydownload/body_algos.go +++ b/turbo/stages/bodydownload/body_algos.go @@ -90,6 +90,7 @@ func (bd *BodyDownload) RequestMoreBodies(db ethdb.Database, blockNum uint64, cu var hash common.Hash var header *types.Header var err error + request := true if bd.deliveries[blockNum-bd.requestedLow] != nil { // If this block was requested before, we don't need to fetch the headers from the database the second time header = bd.deliveries[blockNum-bd.requestedLow].Header() @@ -105,6 +106,7 @@ func (bd *BodyDownload) RequestMoreBodies(db ethdb.Database, blockNum uint64, cu if block := bd.prefetchedBlocks.Pop(hash); block != nil { // Block is prefetched, no need to request bd.deliveries[blockNum-bd.requestedLow] = block + request = false } else { bd.deliveries[blockNum-bd.requestedLow] = types.NewBlockWithHeader(header) // Block without uncles and transactions if header.UncleHash != types.EmptyUncleHash || header.TxHash != types.EmptyRootHash { @@ -112,6 +114,8 @@ func (bd *BodyDownload) RequestMoreBodies(db ethdb.Database, blockNum uint64, cu copy(doubleHash[:], header.UncleHash.Bytes()) copy(doubleHash[common.HashLength:], header.TxHash.Bytes()) bd.requestedMap[doubleHash] = blockNum + } else { + request = false } } } @@ -119,11 +123,11 @@ func (bd *BodyDownload) RequestMoreBodies(db ethdb.Database, blockNum uint64, cu if header == nil { log.Error("Header not found", "block number", blockNum) panic("") - } else if header.UncleHash != types.EmptyUncleHash || header.TxHash != types.EmptyRootHash { + } else if request { blockNums = append(blockNums, blockNum) hashes = append(hashes, hash) } else { - // Both uncleHash and txHash are empty, no need to request + // Both uncleHash and txHash are empty (or block is prefetched), no need to request bd.delivered.Add(blockNum) } }