Skip to content

Commit

Permalink
Merge pull request #21467 from holiman/minor_ethashfix
Browse files Browse the repository at this point in the history
consensus/ethash: less lookups of block data
  • Loading branch information
karalabe committed Apr 27, 2021
2 parents a3f0da1 + 493100b commit 85a0bab
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,23 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo

number, parent := block.NumberU64()-1, block.ParentHash()
for i := 0; i < 7; i++ {
ancestor := chain.GetBlock(parent, number)
if ancestor == nil {
ancestorHeader := chain.GetHeader(parent, number)
if ancestorHeader == nil {
break
}
ancestors[ancestor.Hash()] = ancestor.Header()
for _, uncle := range ancestor.Uncles() {
uncles.Add(uncle.Hash())
ancestors[parent] = ancestorHeader
// If the ancestor doesn't have any uncles, we don't have to iterate them
if ancestorHeader.UncleHash != types.EmptyUncleHash {
// Need to add those uncles to the blacklist too
ancestor := chain.GetBlock(parent, number)
if ancestor == nil {
break
}
for _, uncle := range ancestor.Uncles() {
uncles.Add(uncle.Hash())
}
}
parent, number = ancestor.ParentHash(), number-1
parent, number = ancestorHeader.ParentHash, number-1
}
ancestors[block.Hash()] = block.Header()
uncles.Add(block.Hash())
Expand Down

0 comments on commit 85a0bab

Please sign in to comment.