Skip to content

Commit f19cd58

Browse files
feat(rawdb): skip freezers (#220)
## Why this should be merged As described in ava-labs/coreth#1137, database inspection of a Coreth chain database fails because `InspectDatabase()` expects for freezers to be used. This PR fixes this bug by adding an option to skip freezer inspection. This PR should be followed with a downstream PR in Coreth to pass in an option to skip freezer inspection during database inspection. ## How this works Extends `inspectDatabaseConfig` with a `skipFreezers` field and adds the associated option function for it. ## How this was tested CI + ran `InspectDatabase()` against Coreth locally
1 parent 9e4c147 commit f19cd58

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

core/rawdb/ancient_utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/ava-labs/libevm/common"
2424
"github.com/ava-labs/libevm/ethdb"
25+
"github.com/ava-labs/libevm/libevm/options"
2526
)
2627

2728
type tableSize struct {
@@ -77,7 +78,10 @@ func inspect(name string, order map[string]bool, reader ethdb.AncientReader) (fr
7778
}
7879

7980
// inspectFreezers inspects all freezers registered in the system.
80-
func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) {
81+
func inspectFreezers(db ethdb.Database, opts ...InspectDatabaseOption) ([]freezerInfo, error) {
82+
if options.As[inspectDatabaseConfig](opts...).skipFreezers {
83+
return nil, nil
84+
}
8185
var infos []freezerInfo
8286
for _, freezer := range freezers {
8387
switch freezer {

core/rawdb/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, opts ...Insp
604604
{"Light client", "Bloom trie nodes", bloomTrieNodes.Size(), bloomTrieNodes.Count()},
605605
}
606606
// Inspect all registered append-only file store then.
607-
ancients, err := inspectFreezers(db)
607+
ancients, err := inspectFreezers(db, opts...)
608608
if err != nil {
609609
return err
610610
}

core/rawdb/database.libevm.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type inspectDatabaseConfig struct {
2828
statRecorders []func([]byte, common.StorageSize) bool
2929
isMetas []func([]byte) bool
3030
statsTransformers []func([][]string) [][]string
31+
skipFreezers bool
3132
}
3233

3334
func (c inspectDatabaseConfig) recordStat(key []byte, size common.StorageSize) bool {
@@ -91,3 +92,10 @@ func WithDatabaseStatsTransformer(transform func(rows [][]string) [][]string) In
9192
c.statsTransformers = append(c.statsTransformers, transform)
9293
})
9394
}
95+
96+
// WithSkipFreezers returns an option that causes for freezer inspection to be skipped.
97+
func WithSkipFreezers() InspectDatabaseOption {
98+
return newInspectOpt(func(c *inspectDatabaseConfig) {
99+
c.skipFreezers = true
100+
})
101+
}

core/rawdb/database.libevm_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"bytes"
2121
"fmt"
2222
"sort"
23+
"testing"
24+
25+
"github.com/stretchr/testify/require"
2326

2427
"github.com/ava-labs/libevm/common"
2528
// To ensure that all methods are available to importing packages, this test
@@ -28,6 +31,18 @@ import (
2831
"github.com/ava-labs/libevm/ethdb"
2932
)
3033

34+
func TestSkipFreezers(t *testing.T) {
35+
require := require.New(t)
36+
db := rawdb.NewMemoryDatabase()
37+
38+
var (
39+
keyPrefix []byte
40+
keyStart []byte
41+
)
42+
43+
require.NoError(rawdb.InspectDatabase(db, keyPrefix, keyStart, rawdb.WithSkipFreezers()))
44+
}
45+
3146
// ExampleDatabaseStat demonstrates the method signatures of DatabaseStat, which
3247
// exposes an otherwise unexported type that won't have its methods documented.
3348
func ExampleDatabaseStat() {

0 commit comments

Comments
 (0)