Files
coreth/plugin/evm/customrawdb/database_ext.go
zeekay cdd1e95a26 Replace luxfi/geth imports with luxfi packages where available
- Replace github.com/luxfi/geth/metrics with github.com/luxfi/metrics
- Replace github.com/luxfi/geth/crypto with github.com/luxfi/crypto
- Keep github.com/luxfi/geth/log due to API incompatibility with luxfi/log v0.1.1
- Update eth-allowed-packages.txt to reflect new imports
- Update go.mod dependencies

This change externalizes metrics and crypto packages to use the shared luxfi
implementations across all projects. The log package remains from geth due to
API differences that would require more extensive refactoring.

Sync with latest ava-labs/coreth semantics and test patterns.
2025-08-02 22:33:17 +00:00

88 lines
2.7 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package customrawdb
import (
"fmt"
"github.com/luxfi/geth/core/rawdb"
"github.com/luxfi/geth/ethdb"
)
// InspectDatabase traverses the entire database and checks the size
// of all different categories of data.
// TODO: Temporarily disabled - needs updated rawdb API
/*
func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
type stat = rawdb.DatabaseStat
stats := []struct {
name string
keyLen int
keyPrefix []byte
stat *stat
}{
{"Trie segments", syncSegmentsKeyLength, syncSegmentsPrefix, &stat{}},
{"Storage tries to fetch", syncStorageTriesKeyLength, syncStorageTriesPrefix, &stat{}},
{"Code to fetch", codeToFetchKeyLength, CodeToFetchPrefix, &stat{}},
{"Block numbers synced to", syncPerformedKeyLength, syncPerformedPrefix, &stat{}},
}
options := []rawdb.InspectDatabaseOption{
rawdb.WithDatabaseMetadataKeys(func(key []byte) bool {
return bytes.Equal(key, snapshotBlockHashKey) ||
bytes.Equal(key, syncRootKey)
}),
rawdb.WithDatabaseStatRecorder(func(key []byte, size common.StorageSize) bool {
for _, s := range stats {
if len(key) == s.keyLen && bytes.HasPrefix(key, s.keyPrefix) {
s.stat.Add(size)
return true
}
}
return false
}),
rawdb.WithDatabaseStatsTransformer(func(rows [][]string) [][]string {
newRows := make([][]string, 0, len(rows))
for _, row := range rows {
switch db, cat := row[0], row[1]; {
// Discard rows specific to geth (geth) but irrelevant to coreth.
case db == "Key-Value store" && (cat == "Difficulties" || cat == "Beacon sync headers"):
case db == "Ancient store (Chain)":
default:
newRows = append(newRows, row)
}
}
for _, s := range stats {
newRows = append(newRows, []string{"State sync", s.name, s.stat.Size(), s.stat.Count()})
}
return newRows
}),
}
return rawdb.InspectDatabase(db, keyPrefix, keyStart, options...)
}
*/
// Temporary stub
func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
// TODO: Implement when rawdb API is updated
return nil
}
// ParseStateSchemeExt parses the state scheme from the provided string.
func ParseStateSchemeExt(provided string, disk ethdb.Database) (string, error) {
// Check for custom scheme
if provided == DatabaseScheme {
if diskScheme := rawdb.ReadStateScheme(disk); diskScheme != "" {
// Valid scheme on disk mismatched
return "", fmt.Errorf("State scheme %s already set on disk, can't use Database", diskScheme)
}
// If no conflicting scheme is found, is valid.
return DatabaseScheme, nil
}
// Check for valid eth scheme
return rawdb.ParseStateScheme(provided, disk)
}