erigon-pulse/cmd/integration/commands/root.go

79 lines
1.8 KiB
Go
Raw Normal View History

2020-07-14 01:56:29 +00:00
package commands
import (
"github.com/c2h5oh/datasize"
2020-07-14 01:56:29 +00:00
"github.com/ledgerwatch/turbo-geth/cmd/utils"
"github.com/ledgerwatch/turbo-geth/ethdb"
2020-07-14 01:56:29 +00:00
"github.com/ledgerwatch/turbo-geth/internal/debug"
"github.com/ledgerwatch/turbo-geth/migrations"
2020-07-14 01:56:29 +00:00
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "integration",
Short: "long and heavy integration tests for turbo-geth",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
2020-08-20 03:52:27 +00:00
if err := utils.SetupCobra(cmd); err != nil {
panic(err)
}
2020-07-14 01:56:29 +00:00
},
2020-08-20 03:52:27 +00:00
PersistentPostRun: func(cmd *cobra.Command, args []string) {
defer utils.StopDebug()
},
2020-07-14 01:56:29 +00:00
}
func RootCommand() *cobra.Command {
utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricFlags...))
return rootCmd
2020-07-14 01:56:29 +00:00
}
2020-10-28 03:18:10 +00:00
func openDatabase(path string, applyMigrations bool) *ethdb.ObjectDatabase {
if applyMigrations {
db := ethdb.NewObjectDatabase(openKV(path, true))
if err := migrations.NewMigrator().Apply(db, datadir); err != nil {
panic(err)
}
db.Close()
}
db := ethdb.NewObjectDatabase(openKV(path, false))
err := SetSnapshotKV(db, snapshotDir, snapshotMode)
if err != nil {
panic(err)
}
return db
}
func openKV(path string, exclusive bool) ethdb.KV {
2020-10-28 03:18:10 +00:00
if database == "mdbx" {
opts := ethdb.NewMDBX().Path(path)
if exclusive {
opts = opts.Exclusive()
2020-10-28 03:18:10 +00:00
}
if mapSizeStr != "" {
var mapSize datasize.ByteSize
must(mapSize.UnmarshalText([]byte(mapSizeStr)))
opts = opts.MapSize(mapSize)
}
if freelistReuse > 0 {
opts = opts.MaxFreelistReuse(uint(freelistReuse))
}
return opts.MustOpen()
}
2020-10-28 03:18:10 +00:00
opts := ethdb.NewLMDB().Path(path)
if exclusive {
opts = opts.Exclusive()
}
if mapSizeStr != "" {
var mapSize datasize.ByteSize
must(mapSize.UnmarshalText([]byte(mapSizeStr)))
opts = opts.MapSize(mapSize)
2020-10-28 03:18:10 +00:00
}
if freelistReuse > 0 {
opts = opts.MaxFreelistReuse(uint(freelistReuse))
}
return opts.MustOpen()
}