Skip to content

Commit 493100b

Browse files
committed
consensus/ethash: less lookups of block data
1 parent b68929c commit 493100b

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎consensus/ethash/consensus.go‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,23 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo
204204

205205
number, parent := block.NumberU64()-1, block.ParentHash()
206206
for i := 0; i < 7; i++ {
207-
ancestor := chain.GetBlock(parent, number)
208-
if ancestor == nil {
207+
ancestorHeader := chain.GetHeader(parent, number)
208+
if ancestorHeader == nil {
209209
break
210210
}
211-
ancestors[ancestor.Hash()] = ancestor.Header()
212-
for _, uncle := range ancestor.Uncles() {
213-
uncles.Add(uncle.Hash())
211+
ancestors[parent] = ancestorHeader
212+
// If the ancestor doesn't have any uncles, we don't have to iterate them
213+
if ancestorHeader.UncleHash != types.EmptyUncleHash {
214+
// Need to add those uncles to the blacklist too
215+
ancestor := chain.GetBlock(parent, number)
216+
if ancestor == nil {
217+
break
218+
}
219+
for _, uncle := range ancestor.Uncles() {
220+
uncles.Add(uncle.Hash())
221+
}
214222
}
215-
parent, number = ancestor.ParentHash(), number-1
223+
parent, number = ancestorHeader.ParentHash, number-1
216224
}
217225
ancestors[block.Hash()] = block.Header()
218226
uncles.Add(block.Hash())

0 commit comments

Comments
 (0)