mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-10 04:51:20 +00:00
36e3c94897
added subcommand `state_domains` of `bin/integration` to start processing of existing chaindata with use of state domains and commitment. It creates two directory in `datadir`: `state` and `statedb` for files and mdbx respectively. This version runs blocks one after another and produces merged files. Want to add some metrics to export later.
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/c2h5oh/datasize"
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
|
"github.com/ledgerwatch/log/v3"
|
|
"github.com/spf13/cobra"
|
|
"github.com/torquem-ch/mdbx-go/mdbx"
|
|
"golang.org/x/sync/semaphore"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils"
|
|
"github.com/ledgerwatch/erigon/migrations"
|
|
"github.com/ledgerwatch/erigon/turbo/debug"
|
|
"github.com/ledgerwatch/erigon/turbo/logging"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "integration",
|
|
Short: "long and heavy integration tests for Erigon",
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
if err := debug.SetupCobra(cmd); err != nil {
|
|
panic(err)
|
|
}
|
|
if chaindata == "" {
|
|
chaindata = filepath.Join(datadirCli, "chaindata")
|
|
}
|
|
},
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
defer debug.Exit()
|
|
},
|
|
}
|
|
|
|
func RootCommand() *cobra.Command {
|
|
utils.CobraFlags(rootCmd, debug.Flags, utils.MetricFlags, logging.Flags)
|
|
return rootCmd
|
|
}
|
|
|
|
func dbCfg(label kv.Label, path string) kv2.MdbxOpts {
|
|
const ThreadsLimit = 9_000
|
|
limiterB := semaphore.NewWeighted(ThreadsLimit)
|
|
opts := kv2.NewMDBX(log.New()).Path(path).Label(label).RoTxsLimiter(limiterB)
|
|
if label == kv.ChainDB {
|
|
opts = opts.MapSize(8 * datasize.TB)
|
|
}
|
|
if databaseVerbosity != -1 {
|
|
opts = opts.DBVerbosity(kv.DBVerbosityLvl(databaseVerbosity))
|
|
}
|
|
return opts
|
|
}
|
|
|
|
func openDB(opts kv2.MdbxOpts, applyMigrations bool) kv.RwDB {
|
|
// integration tool don't intent to create db, then easiest way to open db - it's pass mdbx.Accede flag, which allow
|
|
// to read all options from DB, instead of overriding them
|
|
opts = opts.Flags(func(f uint) uint { return f | mdbx.Accede })
|
|
|
|
db := opts.MustOpen()
|
|
if applyMigrations {
|
|
migrator := migrations.NewMigrator(opts.GetLabel())
|
|
has, err := migrator.HasPendingMigrations(db)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if has {
|
|
log.Info("Re-Opening DB in exclusive mode to apply DB migrations")
|
|
db.Close()
|
|
db = opts.Exclusive().MustOpen()
|
|
if err := migrator.Apply(db, datadirCli); err != nil {
|
|
panic(err)
|
|
}
|
|
db.Close()
|
|
db = opts.MustOpen()
|
|
}
|
|
}
|
|
return db
|
|
}
|