diff --git a/go/oasis-node/cmd/debug/debug.go b/go/oasis-node/cmd/debug/debug.go index eceb21a9d8e..13e46217261 100644 --- a/go/oasis-node/cmd/debug/debug.go +++ b/go/oasis-node/cmd/debug/debug.go @@ -9,7 +9,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/byzantine" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/control" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/dumpdb" - "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/fixgenesis" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/storage" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/txsource" ) @@ -24,7 +23,6 @@ func Register(parentCmd *cobra.Command) { storage.Register(debugCmd) byzantine.Register(debugCmd) txsource.Register(debugCmd) - fixgenesis.Register(debugCmd) control.Register(debugCmd) dumpdb.Register(debugCmd) beacon.Register(debugCmd) diff --git a/go/oasis-node/cmd/genesis/genesis.go b/go/oasis-node/cmd/genesis/genesis.go index 91ffe9275a1..4d9ca58bb3c 100644 --- a/go/oasis-node/cmd/genesis/genesis.go +++ b/go/oasis-node/cmd/genesis/genesis.go @@ -753,10 +753,14 @@ func Register(parentCmd *cobra.Command) { dumpGenesisCmd.PersistentFlags().AddFlagSet(cmdGrpc.ClientFlags) checkGenesisCmd.Flags().AddFlagSet(checkGenesisFlags) + migrateGenesisCmd.PersistentFlags().AddFlagSet(flags.GenesisFileFlags) + migrateGenesisCmd.PersistentFlags().AddFlagSet(migrateGenesisFlags) + for _, v := range []*cobra.Command{ initGenesisCmd, dumpGenesisCmd, checkGenesisCmd, + migrateGenesisCmd, } { genesisCmd.AddCommand(v) } diff --git a/go/oasis-node/cmd/debug/fixgenesis/fixgenesis.go b/go/oasis-node/cmd/genesis/migrate.go similarity index 93% rename from go/oasis-node/cmd/debug/fixgenesis/fixgenesis.go rename to go/oasis-node/cmd/genesis/migrate.go index 6377f500751..20646a8e424 100644 --- a/go/oasis-node/cmd/debug/fixgenesis/fixgenesis.go +++ b/go/oasis-node/cmd/genesis/migrate.go @@ -1,5 +1,4 @@ -// Package fixgenesis implements the fix-genesis command. -package fixgenesis +package genesis import ( "encoding/json" @@ -15,7 +14,6 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/cbor" "github.com/oasisprotocol/oasis-core/go/common/crypto/signature" "github.com/oasisprotocol/oasis-core/go/common/entity" - "github.com/oasisprotocol/oasis-core/go/common/logging" "github.com/oasisprotocol/oasis-core/go/common/node" genesis "github.com/oasisprotocol/oasis-core/go/genesis/api" keymanager "github.com/oasisprotocol/oasis-core/go/keymanager/api" @@ -33,20 +31,18 @@ const ( ) var ( - fixGenesisCmd = &cobra.Command{ - Use: "fix-genesis", - Short: "fix a genesis document", - Run: doFixGenesis, + migrateGenesisCmd = &cobra.Command{ + Use: "migrate", + Short: "migrate a genesis document from a previous release", + Run: doMigrateGenesis, } - genesisFlags = flag.NewFlagSet("", flag.ContinueOnError) - - logger = logging.GetLogger("cmd/debug/fix-genesis") + migrateGenesisFlags = flag.NewFlagSet("", flag.ContinueOnError) errOldNodeDesc = errors.New("deprecated node descriptor") ) -func doFixGenesis(cmd *cobra.Command, _ []string) { +func doMigrateGenesis(cmd *cobra.Command, _ []string) { if err := cmdCommon.Init(); err != nil { cmdCommon.EarlyLogAndExit(err) } @@ -454,15 +450,8 @@ func fixupBurnAddress(newDoc *genesis.Document) error { return nil } -// Register registers the fix-genesis sub-command and all of it's children. -func Register(parentCmd *cobra.Command) { - fixGenesisCmd.PersistentFlags().AddFlagSet(flags.GenesisFileFlags) - fixGenesisCmd.PersistentFlags().AddFlagSet(genesisFlags) - parentCmd.AddCommand(fixGenesisCmd) -} - func init() { - genesisFlags.String(CfgNewGenesisFile, "genesis_fixed.json", "path to fixed genesis document") - genesisFlags.String(cfgNewChainID, "", "optional new chain ID") - _ = viper.BindPFlags(genesisFlags) + migrateGenesisFlags.String(CfgNewGenesisFile, "genesis_new.json", "path to migrated genesis document") + migrateGenesisFlags.String(cfgNewChainID, "", "optional new chain ID") + _ = viper.BindPFlags(migrateGenesisFlags) } diff --git a/go/oasis-test-runner/oasis/cli/cli.go b/go/oasis-test-runner/oasis/cli/cli.go index 8c948a96bed..919844e67c1 100644 --- a/go/oasis-test-runner/oasis/cli/cli.go +++ b/go/oasis-test-runner/oasis/cli/cli.go @@ -53,7 +53,6 @@ type Helpers struct { Consensus *ConsensusHelpers Registry *RegistryHelpers Keymanager *KeymanagerHelpers - Debug *DebugHelpers Genesis *GenesisHelpers } @@ -70,7 +69,6 @@ func New(env *env.Env, factory Factory, logger *logging.Logger) *Helpers { Consensus: &ConsensusHelpers{base}, Registry: &RegistryHelpers{base}, Keymanager: &KeymanagerHelpers{base}, - Debug: &DebugHelpers{base}, Genesis: &GenesisHelpers{base}, } } diff --git a/go/oasis-test-runner/oasis/cli/debug.go b/go/oasis-test-runner/oasis/cli/debug.go deleted file mode 100644 index 6196485aaf6..00000000000 --- a/go/oasis-test-runner/oasis/cli/debug.go +++ /dev/null @@ -1,36 +0,0 @@ -package cli - -import ( - "fmt" - - "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" - "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" - "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug/fixgenesis" -) - -// DebugHelpers contains the oasis-node debug CLI helpers. -type DebugHelpers struct { - *helpersBase -} - -// FixGenesis is a wrapper for "debug fix-genesis" subcommand. -func (d *DebugHelpers) FixGenesis( - genesisFilePath string, - fixedGenesisFilePath string, -) error { - d.logger.Info("fixing genesis file") - - args := []string{ - "debug", "fix-genesis", - "--" + flags.CfgGenesisFile, genesisFilePath, - "--" + fixgenesis.CfgNewGenesisFile, fixedGenesisFilePath, - "--" + flags.CfgDebugDontBlameOasis, - "--" + common.CfgDebugAllowTestKeys, - } - - if out, err := d.runSubCommandWithOutput("debug-fix-genesis", args); err != nil { - return fmt.Errorf("failed to run 'debug fix-genesis': error: %w output: %s", err, out.String()) - } - - return nil -} diff --git a/go/oasis-test-runner/oasis/cli/genesis.go b/go/oasis-test-runner/oasis/cli/genesis.go index f60cf506a6d..f63549ea827 100644 --- a/go/oasis-test-runner/oasis/cli/genesis.go +++ b/go/oasis-test-runner/oasis/cli/genesis.go @@ -6,6 +6,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/grpc" + "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/genesis" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/stake" ) @@ -54,3 +55,25 @@ func (g *GenesisHelpers) Dump( return nil } + +// Migrate is a wrapper for "genesis migrate" subcommand. +func (g *GenesisHelpers) Migrate( + genesisFilePath string, + newGenesisFilePath string, +) error { + g.logger.Info("migrating genesis file") + + args := []string{ + "genesis", "migrate", + "--" + flags.CfgGenesisFile, genesisFilePath, + "--" + genesis.CfgNewGenesisFile, newGenesisFilePath, + "--" + flags.CfgDebugDontBlameOasis, + "--" + common.CfgDebugAllowTestKeys, + } + + if out, err := g.runSubCommandWithOutput("genesis-migrate", args); err != nil { + return fmt.Errorf("failed to run 'genesis migrate': error: %w output: %s", err, out.String()) + } + + return nil +} diff --git a/go/oasis-test-runner/scenario/e2e/genesis_file.go b/go/oasis-test-runner/scenario/e2e/genesis_file.go index 8d5ecb0670a..12147127974 100644 --- a/go/oasis-test-runner/scenario/e2e/genesis_file.go +++ b/go/oasis-test-runner/scenario/e2e/genesis_file.go @@ -116,7 +116,7 @@ func (s *genesisFileImpl) Run(ctx context.Context, childEnv *env.Env) error { if genesisNeedsUpgrade { // When upgrade is needed, run fix-genesis. latestMainnetGenesisFixed = filepath.Join(childEnv.Dir(), "genesis_mainnet_fixed.json") - if err := cli.Debug.FixGenesis(latestMainnetGenesis, latestMainnetGenesisFixed); err != nil { + if err := cli.Genesis.Migrate(latestMainnetGenesis, latestMainnetGenesisFixed); err != nil { return fmt.Errorf("e2e/genesis-file: failed run fix-genesis on latest Mainnet genesis "+ "file at '%s': %w", genesisURL, err) } diff --git a/tests/upgrade/post/scenario/e2e/genesis.go b/tests/upgrade/post/scenario/e2e/genesis.go index 943f1a5daeb..ae2735127ae 100644 --- a/tests/upgrade/post/scenario/e2e/genesis.go +++ b/tests/upgrade/post/scenario/e2e/genesis.go @@ -24,6 +24,7 @@ func FixExportedGenesisFile(childEnv *env.Env, cli *cli.Helpers, sc *e2e.Scenari sc.Logger.Info("fixing exported genesis file", "path", exportedGenFilePath) fixedGenFilePath := filepath.Join(childEnv.Dir(), "genesis-fixed.json") + // TODO: Change to cli.Genesis.Migrate once merged to master. if err := cli.Debug.FixGenesis(exportedGenFilePath, fixedGenFilePath); err != nil { return "", fmt.Errorf("failed to fix exported genesis file: %+w", err) }