Skip to content

Commit

Permalink
core: unit test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed Feb 27, 2024
1 parent 1219fad commit 3c82f4b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ func (fb *filterBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts
}

func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
number := rawdb.ReadHeaderNumber(fb.db, hash)
number := rawdb.ReadHeaderNumber(fb.db.BlockStore(), hash)
if number == nil {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth
arg := ctx.Args().First()
if hashish(arg) {
hash := common.HexToHash(arg)
if number := rawdb.ReadHeaderNumber(db, hash); number != nil {
if number := rawdb.ReadHeaderNumber(db.BlockStore(), hash); number != nil {
header = rawdb.ReadHeader(db, hash, *number)
} else {
return nil, nil, common.Hash{}, fmt.Errorf("block %x not found", hash)
Expand Down
4 changes: 2 additions & 2 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func inspectTrie(ctx *cli.Context) error {
if ctx.NArg() >= 1 {
if ctx.Args().Get(0) == "latest" {
headerHash := rawdb.ReadHeadHeaderHash(db)
blockNumber = *(rawdb.ReadHeaderNumber(db, headerHash))
blockNumber = *(rawdb.ReadHeaderNumber(db.BlockStore(), headerHash))
} else if ctx.Args().Get(0) == "snapshot" {
trieRootHash = rawdb.ReadSnapshotRoot(db)
blockNumber = math.MaxUint64
Expand Down Expand Up @@ -1051,7 +1051,7 @@ func hbss2pbss(ctx *cli.Context) error {
defer triedb.Close()

headerHash := rawdb.ReadHeadHeaderHash(db)
blockNumber := rawdb.ReadHeaderNumber(db, headerHash)
blockNumber := rawdb.ReadHeaderNumber(db.BlockStore(), headerHash)
if blockNumber == nil {
log.Error("read header number failed.")
return fmt.Errorf("read header number failed")
Expand Down
6 changes: 3 additions & 3 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64) rlp.RawValue {
// Block is not in ancients, read from leveldb by hash and number.
// Note: ReadCanonicalHash cannot be used here because it also
// calls ReadAncients internally.
hash, _ := db.BlockStoreReader().Get(headerHashKey(number))
hash, _ := db.Get(headerHashKey(number))
data, _ = db.BlockStoreReader().Get(blockBodyKey(number, common.BytesToHash(hash)))
return nil
})
Expand Down Expand Up @@ -996,7 +996,7 @@ func ReadHeadHeader(db ethdb.Reader) *types.Header {
if headHeaderHash == (common.Hash{}) {
return nil
}
headHeaderNumber := ReadHeaderNumber(db, headHeaderHash)
headHeaderNumber := ReadHeaderNumber(db.BlockStoreReader(), headHeaderHash)
if headHeaderNumber == nil {
return nil
}
Expand All @@ -1009,7 +1009,7 @@ func ReadHeadBlock(db ethdb.Reader) *types.Block {
if headBlockHash == (common.Hash{}) {
return nil
}
headBlockNumber := ReadHeaderNumber(db, headBlockHash)
headBlockNumber := ReadHeaderNumber(db.BlockStoreReader(), headBlockHash)
if headBlockNumber == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/accessors_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64 {
}
// Database v4-v5 tx lookup format just stores the hash
if len(data) == common.HashLength {
return ReadHeaderNumber(db, common.BytesToHash(data))
return ReadHeaderNumber(db.BlockStoreReader(), common.BytesToHash(data))
}
// Finally try database v3 tx lookup format
var entry LegacyTxLookupEntry
Expand Down
11 changes: 9 additions & 2 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func NewDatabaseWithFreezer(db, blockstore ethdb.KeyValueStore, ancient string,
if kvhash, _ := db.Get(headerHashKey(frozen)); len(kvhash) == 0 {
// Subsequent header after the freezer limit is missing from the database.
// Reject startup if the database has a more recent head.
if head := *ReadHeaderNumber(db, ReadHeadHeaderHash(db)); head > frozen-1 {
if head := *ReadHeaderNumber(blockstore, ReadHeadHeaderHash(db)); head > frozen-1 {
// Find the smallest block stored in the key-value store
// in range of [frozen, head]
var number uint64
Expand Down Expand Up @@ -587,7 +587,14 @@ func Open(o OpenOptions) (ethdb.Database, error) {
if len(o.AncientsDirectory) == 0 {
return kvdb, nil
}
frdb, err := NewDatabaseWithFreezer(kvdb, o.BlockStore, o.AncientsDirectory, o.Namespace, o.ReadOnly, o.DisableFreeze, o.IsLastOffset, o.PruneAncientData)

var blockstore ethdb.KeyValueStore
if o.BlockStore != nil {
blockstore = o.BlockStore
} else {
blockstore = kvdb
}
frdb, err := NewDatabaseWithFreezer(kvdb, blockstore, o.AncientsDirectory, o.Namespace, o.ReadOnly, o.DisableFreeze, o.IsLastOffset, o.PruneAncientData)
if err != nil {
kvdb.Close()
return nil, err
Expand Down

0 comments on commit 3c82f4b

Please sign in to comment.