genesis switch db (#2038)

* genesis switch db

* genesis switch db
This commit is contained in:
Alex Sharov 2021-05-28 19:55:48 +07:00 committed by GitHub
parent 6b826174c1
commit 60e8a31fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -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 {

View File

@ -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)")
}
}
func (db *MdbxKV) CollectMetrics() {

View File

@ -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