mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
feat(rawdb): skip freezers (#220)
## Why this should be merged As described in https://github.com/ava-labs/coreth/issues/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
This commit is contained in:
parent
9e4c147bf2
commit
f19cd58957
4 changed files with 29 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/ava-labs/libevm/common"
|
"github.com/ava-labs/libevm/common"
|
||||||
"github.com/ava-labs/libevm/ethdb"
|
"github.com/ava-labs/libevm/ethdb"
|
||||||
|
"github.com/ava-labs/libevm/libevm/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tableSize struct {
|
type tableSize struct {
|
||||||
|
|
@ -77,7 +78,10 @@ func inspect(name string, order map[string]bool, reader ethdb.AncientReader) (fr
|
||||||
}
|
}
|
||||||
|
|
||||||
// inspectFreezers inspects all freezers registered in the system.
|
// inspectFreezers inspects all freezers registered in the system.
|
||||||
func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) {
|
func inspectFreezers(db ethdb.Database, opts ...InspectDatabaseOption) ([]freezerInfo, error) {
|
||||||
|
if options.As[inspectDatabaseConfig](opts...).skipFreezers {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
var infos []freezerInfo
|
var infos []freezerInfo
|
||||||
for _, freezer := range freezers {
|
for _, freezer := range freezers {
|
||||||
switch freezer {
|
switch freezer {
|
||||||
|
|
|
||||||
|
|
@ -604,7 +604,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, opts ...Insp
|
||||||
{"Light client", "Bloom trie nodes", bloomTrieNodes.Size(), bloomTrieNodes.Count()},
|
{"Light client", "Bloom trie nodes", bloomTrieNodes.Size(), bloomTrieNodes.Count()},
|
||||||
}
|
}
|
||||||
// Inspect all registered append-only file store then.
|
// Inspect all registered append-only file store then.
|
||||||
ancients, err := inspectFreezers(db)
|
ancients, err := inspectFreezers(db, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ type inspectDatabaseConfig struct {
|
||||||
statRecorders []func([]byte, common.StorageSize) bool
|
statRecorders []func([]byte, common.StorageSize) bool
|
||||||
isMetas []func([]byte) bool
|
isMetas []func([]byte) bool
|
||||||
statsTransformers []func([][]string) [][]string
|
statsTransformers []func([][]string) [][]string
|
||||||
|
skipFreezers bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c inspectDatabaseConfig) recordStat(key []byte, size common.StorageSize) bool {
|
func (c inspectDatabaseConfig) recordStat(key []byte, size common.StorageSize) bool {
|
||||||
|
|
@ -91,3 +92,10 @@ func WithDatabaseStatsTransformer(transform func(rows [][]string) [][]string) In
|
||||||
c.statsTransformers = append(c.statsTransformers, transform)
|
c.statsTransformers = append(c.statsTransformers, transform)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithSkipFreezers returns an option that causes for freezer inspection to be skipped.
|
||||||
|
func WithSkipFreezers() InspectDatabaseOption {
|
||||||
|
return newInspectOpt(func(c *inspectDatabaseConfig) {
|
||||||
|
c.skipFreezers = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/ava-labs/libevm/common"
|
"github.com/ava-labs/libevm/common"
|
||||||
// To ensure that all methods are available to importing packages, this test
|
// To ensure that all methods are available to importing packages, this test
|
||||||
|
|
@ -28,6 +31,18 @@ import (
|
||||||
"github.com/ava-labs/libevm/ethdb"
|
"github.com/ava-labs/libevm/ethdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSkipFreezers(t *testing.T) {
|
||||||
|
require := require.New(t)
|
||||||
|
db := rawdb.NewMemoryDatabase()
|
||||||
|
|
||||||
|
var (
|
||||||
|
keyPrefix []byte
|
||||||
|
keyStart []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
require.NoError(rawdb.InspectDatabase(db, keyPrefix, keyStart, rawdb.WithSkipFreezers()))
|
||||||
|
}
|
||||||
|
|
||||||
// ExampleDatabaseStat demonstrates the method signatures of DatabaseStat, which
|
// ExampleDatabaseStat demonstrates the method signatures of DatabaseStat, which
|
||||||
// exposes an otherwise unexported type that won't have its methods documented.
|
// exposes an otherwise unexported type that won't have its methods documented.
|
||||||
func ExampleDatabaseStat() {
|
func ExampleDatabaseStat() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue