From e1a2b8e8d6939d71a03aeee6ac02f95ef74970c0 Mon Sep 17 00:00:00 2001 From: joeycli Date: Mon, 12 Aug 2024 15:26:45 +0800 Subject: [PATCH] feat: init genesis --- core/blockchain.go | 3 +++ core/genesis.go | 2 +- core/state/caching_versa_db.go | 4 ++-- go.mod | 2 +- triedb/database.go | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 5119129596..fdd34158b1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -196,6 +196,9 @@ func (c *CacheConfig) triedbConfig() *triedb.Config { JournalFile: c.JournalFile, } } + if c.StateScheme == rawdb.VersionScheme { + config.IsVersion = true + } return config } diff --git a/core/genesis.go b/core/genesis.go index c13f4abb5c..7418aacafd 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -174,7 +174,7 @@ func flushAlloc(ga *types.GenesisAlloc, db ethdb.Database, triedb *triedb.Databa return err } // Commit newly generated states into disk if it's not empty. - if root != types.EmptyRootHash { + if root != types.EmptyRootHash && triedb.Scheme() != rawdb.VersionScheme { if err := triedb.Commit(root, true); err != nil { return err } diff --git a/core/state/caching_versa_db.go b/core/state/caching_versa_db.go index 9559f31cb1..5e33b501d1 100644 --- a/core/state/caching_versa_db.go +++ b/core/state/caching_versa_db.go @@ -52,8 +52,8 @@ func (cv *cachingVersaDB) OpenTrie(root common.Hash) (Trie, error) { panic("account tree has open") } - // TODO:: if root tree, versa db shouldb ignore check version - state, err := cv.versionDB.OpenState(0, root, cv.mode) + // TODO:: if root tree, versa db should ignore check version, temp use -1 + state, err := cv.versionDB.OpenState(-1, root, cv.mode) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index c17d26c0da..2d4e4ed423 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/route53 v1.30.2 github.com/bnb-chain/fastssz v0.1.2 github.com/bnb-chain/ics23 v0.1.0 - github.com/bnb-chain/versioned-state-database v0.0.0-20240809035848-76ffc0e09a92 + github.com/bnb-chain/versioned-state-database v0.0.0-00010101000000-000000000000 github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.79.0 diff --git a/triedb/database.go b/triedb/database.go index 0a0628dd88..3d9dc43ab8 100644 --- a/triedb/database.go +++ b/triedb/database.go @@ -96,7 +96,7 @@ type Database struct { // NewDatabase initializes the trie database with default settings, note // the legacy hash-based scheme is used by default. func NewDatabase(diskdb ethdb.Database, config *Config) *Database { - if config.IsVersion { + if config != nil && config.IsVersion { // TODO:: Wait for debugging to stabilize, and then consider initialization compatibility with other databases db := &Database{ config: config,