core: do not use mutex in GetAncestor

This commit is contained in:
Zsolt Felfoldi 2019-09-14 04:17:11 +02:00
parent e5163d1e05
commit 06ee8ab699
2 changed files with 5 additions and 5 deletions

View file

@ -2151,9 +2151,6 @@ func (bc *BlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []com
// //
// Note: ancestor == 0 returns the same block, 1 returns its parent and so on. // Note: ancestor == 0 returns the same block, 1 returns its parent and so on.
func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64) { func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64) {
bc.chainmu.RLock()
defer bc.chainmu.RUnlock()
return bc.hc.GetAncestor(hash, number, ancestor, maxNonCanonical) return bc.hc.GetAncestor(hash, number, ancestor, maxNonCanonical)
} }

View file

@ -349,8 +349,11 @@ func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, ma
} }
for ancestor != 0 { for ancestor != 0 {
if rawdb.ReadCanonicalHash(hc.chainDb, number) == hash { if rawdb.ReadCanonicalHash(hc.chainDb, number) == hash {
number -= ancestor ancestorHash := rawdb.ReadCanonicalHash(hc.chainDb, number-ancestor)
return rawdb.ReadCanonicalHash(hc.chainDb, number), number if rawdb.ReadCanonicalHash(hc.chainDb, number) == hash {
number -= ancestor
return ancestorHash, number
}
} }
if *maxNonCanonical == 0 { if *maxNonCanonical == 0 {
return common.Hash{}, 0 return common.Hash{}, 0