2020-07-14 01:56:29 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2020-10-13 22:42:04 +00:00
|
|
|
"github.com/c2h5oh/datasize"
|
2020-07-14 01:56:29 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/utils"
|
2020-08-05 10:13:35 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2020-07-14 01:56:29 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/internal/debug"
|
2020-08-05 10:13:35 +00:00
|
|
|
"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-08-05 10:13:35 +00:00
|
|
|
if len(chaindata) > 0 {
|
2020-10-13 22:42:04 +00:00
|
|
|
db := openDatabase()
|
2020-08-05 10:13:35 +00:00
|
|
|
defer db.Close()
|
2020-10-17 13:00:12 +00:00
|
|
|
if cmd != cmdPrintMigrations && cmd != cmdPrintStages && cmd != cmdRemoveMigration {
|
|
|
|
if err := migrations.NewMigrator().Apply(db, datadir); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-08-05 10:13:35 +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
|
|
|
|
|
|
|
func openDatabase() *ethdb.ObjectDatabase {
|
2020-10-17 13:00:12 +00:00
|
|
|
opts := ethdb.NewLMDB().Path(chaindata)
|
2020-10-13 22:42:04 +00:00
|
|
|
if mapSizeStr != "" {
|
|
|
|
var mapSize datasize.ByteSize
|
|
|
|
must(mapSize.UnmarshalText([]byte(mapSizeStr)))
|
2020-10-17 13:00:12 +00:00
|
|
|
opts = opts.MapSize(mapSize)
|
|
|
|
}
|
|
|
|
if freelistReuse > 0 {
|
|
|
|
opts = opts.MaxFreelistReuse(uint(freelistReuse))
|
2020-10-13 22:42:04 +00:00
|
|
|
}
|
2020-10-17 13:00:12 +00:00
|
|
|
return ethdb.NewObjectDatabase(opts.MustOpen())
|
2020-10-13 22:42:04 +00:00
|
|
|
}
|