Skip to content

Commit

Permalink
fix ancient block (ethereum#60)
Browse files Browse the repository at this point in the history
* fix ancient block

* handle error

* fix error

* modify

* fix

Co-authored-by: blockchaindevsh <[email protected]>
  • Loading branch information
blockchaindevsh and blockchaindevsh authored Mar 22, 2022
1 parent 8eeee0f commit 7fdd02d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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"
Expand Down Expand Up @@ -332,18 +331,28 @@ func ReadHeaderRange(db ethdb.Reader, number uint64, count uint64) []rlp.RawValu
// ReadHeaderRLP retrieves a block header in its raw RLP database encoding.
func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
var data []byte
db.ReadAncients(func(reader ethdb.AncientReader) error {
err := db.ReadAncients(func(reader ethdb.AncientReader) error {
// First try to look up the data in ancient database. Extra hash
// comparison is necessary since ancient database only maintains
// the canonical data.
data, _ = reader.Ancient(freezerHeaderTable, number)
if len(data) > 0 && crypto.Keccak256Hash(data) == hash {
return nil
if len(data) > 0 {
var header *types.Header
err := rlp.DecodeBytes(data, &header)
if err != nil {
return err
}
if header != nil && header.Hash() == hash {
return nil
}
}
// If not, try reading from leveldb
data, _ = db.Get(headerKey(number, hash))
return nil
})
if err != nil {
return nil
}
return data
}

Expand Down

0 comments on commit 7fdd02d

Please sign in to comment.