mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/rawdb: calculate the hash in the fly
This commit is contained in:
parent
59a0610670
commit
18e74e9448
1 changed files with 5 additions and 10 deletions
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
|
@ -177,12 +178,9 @@ func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValu
|
||||||
// comparison is necessary since ancient database only maintains
|
// comparison is necessary since ancient database only maintains
|
||||||
// the canonical data.
|
// the canonical data.
|
||||||
data, _ := db.Ancient(freezerHeaderTable, number)
|
data, _ := db.Ancient(freezerHeaderTable, number)
|
||||||
if len(data) > 0 {
|
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
|
||||||
h, _ := db.Ancient(freezerHashTable, number)
|
|
||||||
if common.BytesToHash(h) == hash {
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Then try to look up the data in leveldb.
|
// Then try to look up the data in leveldb.
|
||||||
data, _ = db.Get(headerKey(number, hash))
|
data, _ = db.Get(headerKey(number, hash))
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
|
|
@ -193,12 +191,9 @@ 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
|
// but when we reach into leveldb, the data was already moved. That would
|
||||||
// result in a not found error.
|
// result in a not found error.
|
||||||
data, _ = db.Ancient(freezerHeaderTable, number)
|
data, _ = db.Ancient(freezerHeaderTable, number)
|
||||||
if len(data) > 0 {
|
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
|
||||||
h, _ := db.Ancient(freezerHashTable, number)
|
|
||||||
if common.BytesToHash(h) == hash {
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil // Can't find the data anywhere.
|
return nil // Can't find the data anywhere.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue