Fixes to new downloader (#1599)

* Fix for prefetched bodies

* Do not reset headers stage to 0

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2021-03-24 22:37:29 +00:00 committed by GitHub
parent 1b7867b26c
commit ea15c4a4fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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 {

View File

@ -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)
}
}