Skip to content

Commit

Permalink
go/oasis-node: Move "fix-genesis" to "genesis migrate"
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Sep 8, 2023
1 parent 0a98d4e commit b7365ba
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 62 deletions.
2 changes: 0 additions & 2 deletions go/oasis-node/cmd/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions go/oasis-node/cmd/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package fixgenesis implements the fix-genesis command.
package fixgenesis
package genesis

import (
"encoding/json"
Expand All @@ -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"
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
2 changes: 0 additions & 2 deletions go/oasis-test-runner/oasis/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type Helpers struct {
Consensus *ConsensusHelpers
Registry *RegistryHelpers
Keymanager *KeymanagerHelpers
Debug *DebugHelpers
Genesis *GenesisHelpers
}

Expand All @@ -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},
}
}
Expand Down
36 changes: 0 additions & 36 deletions go/oasis-test-runner/oasis/cli/debug.go

This file was deleted.

23 changes: 23 additions & 0 deletions go/oasis-test-runner/oasis/cli/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/genesis_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions tests/upgrade/post/scenario/e2e/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b7365ba

Please sign in to comment.