From 60e8a31fe3a10ac7be6a2339897bcff65dc0ac4b Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Fri, 28 May 2021 19:55:48 +0700 Subject: [PATCH] genesis switch db (#2038) * genesis switch db * genesis switch db --- core/genesis.go | 9 ++++++++- ethdb/kv_mdbx.go | 3 ++- turbo/node/node.go | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index a2872cf30..8be0ee46e 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -48,6 +48,8 @@ import ( //go:embed allocs var allocs embed.FS +var UseMDBX = true + var ErrGenesisNoConfig = errors.New("genesis has no chain configuration") // Genesis specifies the header fields, state of a genesis block. It also defines hard @@ -262,7 +264,12 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig { // ToBlock creates the genesis block and writes state of a genesis specification // to the given database (or discards it if nil). func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) { - tmpDB := ethdb.NewLMDB().InMem().MustOpen() + var tmpDB ethdb.RwKV + if UseMDBX { + tmpDB = ethdb.NewMDBX().InMem().MustOpen() + } else { + tmpDB = ethdb.NewLMDB().InMem().MustOpen() + } defer tmpDB.Close() tx, err := tmpDB.BeginRw(context.Background()) if err != nil { diff --git a/ethdb/kv_mdbx.go b/ethdb/kv_mdbx.go index ea3a4be6f..9f2251ed3 100644 --- a/ethdb/kv_mdbx.go +++ b/ethdb/kv_mdbx.go @@ -309,8 +309,9 @@ func (db *MdbxKV) Close() { if err := os.RemoveAll(db.opts.path); err != nil { db.log.Warn("failed to remove in-mem db file", "err", err) } + } else { + db.log.Info("database closed (MDBX)") } - db.log.Info("database closed (MDBX)") } func (db *MdbxKV) CollectMetrics() { diff --git a/turbo/node/node.go b/turbo/node/node.go index f6b39da3d..37d490f26 100644 --- a/turbo/node/node.go +++ b/turbo/node/node.go @@ -7,6 +7,7 @@ import ( "github.com/ledgerwatch/erigon/cmd/utils" "github.com/ledgerwatch/erigon/common/dbutils" + "github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/eth" "github.com/ledgerwatch/erigon/eth/ethconfig" "github.com/ledgerwatch/erigon/eth/stagedsync" @@ -78,6 +79,7 @@ func New( node := makeConfigNode(nodeConfig) enode.UseMDBX = nodeConfig.MDBX + core.UseMDBX = nodeConfig.MDBX ethConfig := makeEthConfig(ctx, node) ethConfig.StagedSync = sync