Skip to content

Commit

Permalink
Fixes to new downloader (erigontech#1599)
Browse files Browse the repository at this point in the history
* Fix for prefetched bodies

* Do not reset headers stage to 0

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
  • Loading branch information
2 people authored and sam committed Apr 5, 2021
1 parent f6bfd54 commit fb17cde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions eth/stagedsync/stage_headers_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions turbo/stages/bodydownload/body_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -105,25 +106,28 @@ 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 {
var doubleHash DoubleHash
copy(doubleHash[:], header.UncleHash.Bytes())
copy(doubleHash[common.HashLength:], header.TxHash.Bytes())
bd.requestedMap[doubleHash] = blockNum
} else {
request = false
}
}
}
}
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)
}
}
Expand Down

0 comments on commit fb17cde

Please sign in to comment.