From 18e74e9448ab7c372aa8a631fe3a8118e0ca0d16 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Tue, 19 Nov 2019 16:04:20 +0800 Subject: [PATCH] core/rawdb: calculate the hash in the fly --- core/rawdb/accessors_chain.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 2a5c72dedc..4d064a3390 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -23,6 +23,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" @@ -177,11 +178,8 @@ func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValu // comparison is necessary since ancient database only maintains // the canonical data. data, _ := db.Ancient(freezerHeaderTable, number) - if len(data) > 0 { - h, _ := db.Ancient(freezerHashTable, number) - if common.BytesToHash(h) == hash { - return data - } + if len(data) > 0 && crypto.Keccak256Hash(data) == hash { + return data } // Then try to look up the data in leveldb. data, _ = db.Get(headerKey(number, hash)) @@ -193,11 +191,8 @@ func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValu // but when we reach into leveldb, the data was already moved. That would // result in a not found error. data, _ = db.Ancient(freezerHeaderTable, number) - if len(data) > 0 { - h, _ := db.Ancient(freezerHashTable, number) - if common.BytesToHash(h) == hash { - return data - } + if len(data) > 0 && crypto.Keccak256Hash(data) == hash { + return data } return nil // Can't find the data anywhere. }