2020-07-14 01:56:29 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-04-19 07:25:26 +00:00
|
|
|
"path"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils"
|
|
|
|
"github.com/ledgerwatch/erigon/ethdb"
|
2021-06-19 08:21:53 +00:00
|
|
|
kv2 "github.com/ledgerwatch/erigon/ethdb/kv"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/internal/debug"
|
|
|
|
"github.com/ledgerwatch/erigon/log"
|
|
|
|
"github.com/ledgerwatch/erigon/migrations"
|
2020-07-14 01:56:29 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "integration",
|
2021-05-26 10:35:39 +00:00
|
|
|
Short: "long and heavy integration tests for Erigon",
|
2020-07-14 01:56:29 +00:00
|
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
2020-08-20 03:52:27 +00:00
|
|
|
if err := utils.SetupCobra(cmd); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-04-19 07:25:26 +00:00
|
|
|
if chaindata == "" {
|
2021-05-26 10:35:39 +00:00
|
|
|
chaindata = path.Join(datadir, "erigon", "chaindata")
|
2021-04-19 07:25:26 +00:00
|
|
|
}
|
|
|
|
if snapshotDir == "" {
|
2021-05-26 10:35:39 +00:00
|
|
|
snapshotDir = path.Join(datadir, "erigon", "snapshot")
|
2021-04-19 07:25:26 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-08-19 11:46:20 +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-13 22:42:04 +00:00
|
|
|
|
2021-06-04 14:56:49 +00:00
|
|
|
func openDB(path string, applyMigrations bool) ethdb.RwKV {
|
|
|
|
label := ethdb.Chain
|
2021-07-04 07:50:32 +00:00
|
|
|
db := openKV(label, path, false)
|
2020-10-28 09:52:15 +00:00
|
|
|
if applyMigrations {
|
2021-07-04 07:50:32 +00:00
|
|
|
has, err := migrations.NewMigrator(label).HasPendingMigrations(db)
|
2021-03-01 04:02:22 +00:00
|
|
|
if err != nil {
|
2020-10-28 09:52:15 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
2021-03-01 04:02:22 +00:00
|
|
|
if has {
|
|
|
|
log.Info("Re-Opening DB in exclusive mode to apply DB migrations")
|
|
|
|
db.Close()
|
2021-07-04 07:50:32 +00:00
|
|
|
db = openKV(label, path, true)
|
2021-06-16 10:57:58 +00:00
|
|
|
if err := migrations.NewMigrator(label).Apply(db, datadir); err != nil {
|
2021-03-01 04:02:22 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
db.Close()
|
2021-07-04 07:50:32 +00:00
|
|
|
db = openKV(label, path, false)
|
2021-03-01 04:02:22 +00:00
|
|
|
}
|
2020-10-28 09:52:15 +00:00
|
|
|
}
|
2021-07-04 07:50:32 +00:00
|
|
|
return db
|
2020-10-28 09:52:15 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 14:56:49 +00:00
|
|
|
func openKV(label ethdb.Label, path string, exclusive bool) ethdb.RwKV {
|
2021-06-19 08:21:53 +00:00
|
|
|
opts := kv2.NewMDBX().Path(path).Label(label)
|
2020-10-28 09:52:15 +00:00
|
|
|
if exclusive {
|
|
|
|
opts = opts.Exclusive()
|
2020-10-13 22:42:04 +00:00
|
|
|
}
|
2021-05-10 15:07:22 +00:00
|
|
|
if databaseVerbosity != -1 {
|
|
|
|
opts = opts.DBVerbosity(ethdb.DBVerbosityLvl(databaseVerbosity))
|
|
|
|
}
|
2021-03-09 06:34:13 +00:00
|
|
|
kv := opts.MustOpen()
|
|
|
|
return kv
|
2020-10-13 22:42:04 +00:00
|
|
|
}
|