core: use numberCache in HasHeader

numberCache has higher capacity, increasing the odds of finding the
header without a database lookup.
This commit is contained in:
Felix Lange 2017-09-07 18:47:27 +02:00
parent d4486f0cb0
commit 1436f5111e

View file

@ -363,7 +363,7 @@ func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.Header {
// HasHeader checks if a block header is present in the database or not. // HasHeader checks if a block header is present in the database or not.
func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool { func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool {
if _, ok := hc.headerCache.Get(hash); ok { if hc.numberCache.Contains(hash) || hc.headerCache.Contains(hash) {
return true return true
} }
ok, _ := hc.chainDb.Has(headerKey(hash, number)) ok, _ := hc.chainDb.Has(headerKey(hash, number))