aboutsummaryrefslogtreecommitdiffstats
path: root/core/headerchain.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/headerchain.go')
-rw-r--r--core/headerchain.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/core/headerchain.go b/core/headerchain.go
index 6ec44b61d..0e5215293 100644
--- a/core/headerchain.go
+++ b/core/headerchain.go
@@ -267,7 +267,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa
return i, errors.New("aborted")
}
// If the header's already known, skip it, otherwise store
- if hc.GetHeader(header.Hash(), header.Number.Uint64()) != nil {
+ if hc.HasHeader(header.Hash(), header.Number.Uint64()) {
stats.ignored++
continue
}
@@ -361,10 +361,13 @@ func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.Header {
return hc.GetHeader(hash, hc.GetBlockNumber(hash))
}
-// HasHeader checks if a block header is present in the database or not, caching
-// it if present.
-func (hc *HeaderChain) HasHeader(hash common.Hash) bool {
- return hc.GetHeaderByHash(hash) != nil
+// HasHeader checks if a block header is present in the database or not.
+func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool {
+ if hc.numberCache.Contains(hash) || hc.headerCache.Contains(hash) {
+ return true
+ }
+ ok, _ := hc.chainDb.Has(headerKey(hash, number))
+ return ok
}
// GetHeaderByNumber retrieves a block header from the database by number,