From 72577bb37e0a5652d7816b0ab9e23e0bcb8000c5 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 28 Apr 2026 17:08:51 +0200 Subject: [PATCH] fix crash in tests --- core/bintrie_witness_test.go | 2 ++ core/genesis_test.go | 5 +++-- core/state/database_ubt.go | 2 +- core/state/reader.go | 2 +- triedb/database.go | 12 ++++++++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/bintrie_witness_test.go b/core/bintrie_witness_test.go index 1b033151d3..1a20063b5a 100644 --- a/core/bintrie_witness_test.go +++ b/core/bintrie_witness_test.go @@ -92,6 +92,7 @@ func TestProcessUBT(t *testing.T) { // genesis := gspec.MustCommit(bcdb, triedb) options := DefaultConfig().WithStateScheme(rawdb.PathScheme) options.SnapshotLimit = 0 + options.BinTrieGroupDepth = 8 blockchain, _ := NewBlockChain(bcdb, gspec, beacon.New(ethash.NewFaker()), options) defer blockchain.Stop() @@ -218,6 +219,7 @@ func TestProcessParentBlockHash(t *testing.T) { t.Run("UBT", func(t *testing.T) { db := rawdb.NewMemoryDatabase() cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme) + cacheConfig.BinTrieGroupDepth = 8 cacheConfig.SnapshotLimit = 0 triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true)) statedb, _ := state.New(types.EmptyBinaryHash, state.NewDatabase(triedb, nil)) diff --git a/core/genesis_test.go b/core/genesis_test.go index e15ad00222..37b6870b55 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -320,8 +320,9 @@ func TestVerkleGenesisCommit(t *testing.T) { config.NoAsyncFlush = true triedb := triedb.NewDatabase(db, &triedb.Config{ - IsUBT: true, - PathDB: &config, + IsUBT: true, + PathDB: &config, + BinTrieGroupDepth: 8, }) block := genesis.MustCommit(db, triedb) if !bytes.Equal(block.Root().Bytes(), expected) { diff --git a/core/state/database_ubt.go b/core/state/database_ubt.go index 6bf7a07317..16579f6d6a 100644 --- a/core/state/database_ubt.go +++ b/core/state/database_ubt.go @@ -96,7 +96,7 @@ func (db *UBTDatabase) ReadersWithCacheStats(stateRoot common.Hash) (Reader, Rea // OpenTrie opens the main account trie at a specific root hash. 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, diff --git a/core/state/reader.go b/core/state/reader.go index 0aabff8d69..be07cec0f9 100644 --- a/core/state/reader.go +++ b/core/state/reader.go @@ -255,7 +255,7 @@ type ubtTrieReader struct { // 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. 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 { return nil, binErr } diff --git a/triedb/database.go b/triedb/database.go index b7ebb6acb3..3cc7dea5d7 100644 --- a/triedb/database.go +++ b/triedb/database.go @@ -86,7 +86,7 @@ type backend interface { // relevant with trie nodes and node preimages. type Database struct { disk ethdb.Database - Config *Config // Configuration for trie database + config *Config // Configuration for trie database preimages *preimageStore // The store for caching preimages backend backend // The backend for managing trie nodes } @@ -104,7 +104,7 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database { } db := &Database{ disk: diskdb, - Config: config, + config: config, preimages: preimages, } 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. func (db *Database) Scheme() string { - if db.Config.PathDB != nil { + if db.config.PathDB != nil { return rawdb.PathScheme } 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. func (db *Database) IsUBT() bool { - return db.Config.IsUBT + return db.config.IsUBT } // Disk returns the underlying disk database. @@ -395,3 +395,7 @@ func (db *Database) SnapshotCompleted() bool { } return pdb.SnapshotCompleted() } + +func (db *Database) BinTrieGroupDepth() int { + return db.config.BinTrieGroupDepth +}