fix crash in tests

This commit is contained in:
Guillaume Ballet 2026-04-28 17:08:51 +02:00
parent 7c97633746
commit 72577bb37e
No known key found for this signature in database
5 changed files with 15 additions and 8 deletions

View file

@ -92,6 +92,7 @@ func TestProcessUBT(t *testing.T) {
// genesis := gspec.MustCommit(bcdb, triedb) // genesis := gspec.MustCommit(bcdb, triedb)
options := DefaultConfig().WithStateScheme(rawdb.PathScheme) options := DefaultConfig().WithStateScheme(rawdb.PathScheme)
options.SnapshotLimit = 0 options.SnapshotLimit = 0
options.BinTrieGroupDepth = 8
blockchain, _ := NewBlockChain(bcdb, gspec, beacon.New(ethash.NewFaker()), options) blockchain, _ := NewBlockChain(bcdb, gspec, beacon.New(ethash.NewFaker()), options)
defer blockchain.Stop() defer blockchain.Stop()
@ -218,6 +219,7 @@ func TestProcessParentBlockHash(t *testing.T) {
t.Run("UBT", func(t *testing.T) { t.Run("UBT", func(t *testing.T) {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme) cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme)
cacheConfig.BinTrieGroupDepth = 8
cacheConfig.SnapshotLimit = 0 cacheConfig.SnapshotLimit = 0
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true)) triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true))
statedb, _ := state.New(types.EmptyBinaryHash, state.NewDatabase(triedb, nil)) statedb, _ := state.New(types.EmptyBinaryHash, state.NewDatabase(triedb, nil))

View file

@ -320,8 +320,9 @@ func TestVerkleGenesisCommit(t *testing.T) {
config.NoAsyncFlush = true config.NoAsyncFlush = true
triedb := triedb.NewDatabase(db, &triedb.Config{ triedb := triedb.NewDatabase(db, &triedb.Config{
IsUBT: true, IsUBT: true,
PathDB: &config, PathDB: &config,
BinTrieGroupDepth: 8,
}) })
block := genesis.MustCommit(db, triedb) block := genesis.MustCommit(db, triedb)
if !bytes.Equal(block.Root().Bytes(), expected) { if !bytes.Equal(block.Root().Bytes(), expected) {

View file

@ -96,7 +96,7 @@ func (db *UBTDatabase) ReadersWithCacheStats(stateRoot common.Hash) (Reader, Rea
// OpenTrie opens the main account trie at a specific root hash. // OpenTrie opens the main account trie at a specific root hash.
func (db *UBTDatabase) OpenTrie(root common.Hash) (Trie, error) { func (db *UBTDatabase) OpenTrie(root common.Hash) (Trie, error) {
return bintrie.NewBinaryTrie(root, db.triedb, db.triedb.Config.BinTrieGroupDepth) return bintrie.NewBinaryTrie(root, db.triedb, db.triedb.BinTrieGroupDepth())
} }
// OpenStorageTrie opens the storage trie of an account. In binary trie mode, // OpenStorageTrie opens the storage trie of an account. In binary trie mode,

View file

@ -255,7 +255,7 @@ type ubtTrieReader struct {
// newUBTTrieReader constructs a Unified-binary-trie reader of the specific state. // newUBTTrieReader constructs a Unified-binary-trie reader of the specific state.
// An error will be returned if the associated trie specified by root is not existent. // An error will be returned if the associated trie specified by root is not existent.
func newUBTTrieReader(root common.Hash, db *triedb.Database) (*ubtTrieReader, error) { func newUBTTrieReader(root common.Hash, db *triedb.Database) (*ubtTrieReader, error) {
binTrie, binErr := bintrie.NewBinaryTrie(root, db, db.Config.BinTrieGroupDepth) binTrie, binErr := bintrie.NewBinaryTrie(root, db, db.BinTrieGroupDepth())
if binErr != nil { if binErr != nil {
return nil, binErr return nil, binErr
} }

View file

@ -86,7 +86,7 @@ type backend interface {
// relevant with trie nodes and node preimages. // relevant with trie nodes and node preimages.
type Database struct { type Database struct {
disk ethdb.Database disk ethdb.Database
Config *Config // Configuration for trie database config *Config // Configuration for trie database
preimages *preimageStore // The store for caching preimages preimages *preimageStore // The store for caching preimages
backend backend // The backend for managing trie nodes backend backend // The backend for managing trie nodes
} }
@ -104,7 +104,7 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
} }
db := &Database{ db := &Database{
disk: diskdb, disk: diskdb,
Config: config, config: config,
preimages: preimages, preimages: preimages,
} }
if config.HashDB != nil && config.PathDB != nil { if config.HashDB != nil && config.PathDB != nil {
@ -196,7 +196,7 @@ func (db *Database) Size() (common.StorageSize, common.StorageSize, common.Stora
// Scheme returns the node scheme used in the database. // Scheme returns the node scheme used in the database.
func (db *Database) Scheme() string { func (db *Database) Scheme() string {
if db.Config.PathDB != nil { if db.config.PathDB != nil {
return rawdb.PathScheme return rawdb.PathScheme
} }
return rawdb.HashScheme return rawdb.HashScheme
@ -379,7 +379,7 @@ func (db *Database) IndexProgress() (uint64, uint64, error) {
// IsUBT returns the indicator if the database is holding a verkle tree. // IsUBT returns the indicator if the database is holding a verkle tree.
func (db *Database) IsUBT() bool { func (db *Database) IsUBT() bool {
return db.Config.IsUBT return db.config.IsUBT
} }
// Disk returns the underlying disk database. // Disk returns the underlying disk database.
@ -395,3 +395,7 @@ func (db *Database) SnapshotCompleted() bool {
} }
return pdb.SnapshotCompleted() return pdb.SnapshotCompleted()
} }
func (db *Database) BinTrieGroupDepth() int {
return db.config.BinTrieGroupDepth
}