Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cmd): rename genesis-raw flag and files to genesis, allow raw and human-readable genesis to be passed to it #1500

Merged
merged 6 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ build-debug:

## init: Initialize gossamer using the default genesis and toml configuration files
init:
./bin/gossamer --key alice init --genesis-raw chain/gssmr/genesis-raw.json --force
./bin/gossamer --key alice init --genesis chain/gssmr/genesis.json --force

## init-repo: Set initial configuration for the repo
init-repo:
Expand Down
2 changes: 1 addition & 1 deletion chain/gssmr/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ grandpa = ""
sync = ""

[init]
genesis-raw = "./chain/gssmr/genesis-raw.json"
genesis = "./chain/gssmr/genesis.json"

[account]
key = ""
Expand Down
4 changes: 2 additions & 2 deletions chain/gssmr/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var (

// InitConfig

// DefaultGenesisRaw Default genesis configuration path
DefaultGenesisRaw = string("./chain/gssmr/genesis-raw.json")
// DefaultGenesis is the default genesis configuration path
DefaultGenesis = string("./chain/gssmr/genesis.json")

// AccountConfig

Expand Down
43 changes: 0 additions & 43 deletions chain/gssmr/genesis-raw.json

This file was deleted.

140 changes: 140 additions & 0 deletions chain/gssmr/genesis-spec.json

Large diffs are not rendered by default.

181 changes: 42 additions & 139 deletions chain/gssmr/genesis.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chain/kusama/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ grandpa = ""
sync = ""

[init]
genesis-raw = "./chain/kusama/genesis-raw.json"
genesis = "./chain/kusama/genesis.json"

[account]
key = ""
Expand Down
4 changes: 2 additions & 2 deletions chain/kusama/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var (

// InitConfig

// DefaultGenesisRaw Default genesis configuration path
DefaultGenesisRaw = string("./chain/kusama/genesis-raw.json")
// DefaultGenesis is the default genesis configuration path
DefaultGenesis = string("./chain/kusama/genesis.json")

// AccountConfig

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion chain/polkadot/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ grandpa = ""
sync = ""

[init]
genesis-raw = "./chain/polkadot/genesis-raw.json"
genesis = "./chain/polkadot/genesis.json"

[account]
key = ""
Expand Down
4 changes: 2 additions & 2 deletions chain/polkadot/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var (

// InitConfig

// DefaultGenesisRaw Default genesis configuration path
DefaultGenesisRaw = string("./chain/polkadot/genesis-raw.json")
// DefaultGenesis is the default genesis configuration path
DefaultGenesis = string("./chain/polkadot/genesis.json")

// AccountConfig

Expand Down
File renamed without changes.
24 changes: 12 additions & 12 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,18 @@ func setLogConfig(ctx *cli.Context, cfg *ctoml.Config, globalCfg *dot.GlobalConf

// setDotInitConfig sets dot.InitConfig using flag values from the cli context
func setDotInitConfig(ctx *cli.Context, tomlCfg ctoml.InitConfig, cfg *dot.InitConfig) {
if tomlCfg.GenesisRaw != "" {
cfg.GenesisRaw = tomlCfg.GenesisRaw
if tomlCfg.Genesis != "" {
cfg.Genesis = tomlCfg.Genesis
}

// check --genesis-raw flag and update init configuration
if genesis := ctx.String(GenesisRawFlag.Name); genesis != "" {
cfg.GenesisRaw = genesis
// check --genesis flag and update init configuration
if genesis := ctx.String(GenesisFlag.Name); genesis != "" {
cfg.Genesis = genesis
}

logger.Debug(
"init configuration",
"genesis-raw", cfg.GenesisRaw,
"genesis", cfg.Genesis,
)
}

Expand Down Expand Up @@ -687,15 +687,15 @@ func updateDotConfigFromGenesisJSONRaw(tomlCfg ctoml.Config, cfg *dot.Config) {
cfg.Core.BabeAuthority = tomlCfg.Core.Roles == types.AuthorityRole
cfg.Core.GrandpaAuthority = tomlCfg.Core.Roles == types.AuthorityRole

// use default genesis-raw file if genesis configuration not provided, for example,
// if we load a toml configuration file without a defined genesis-raw init value or
// if we pass an empty string as the genesis init value using the --geneis-raw flag
if cfg.Init.GenesisRaw == "" {
cfg.Init.GenesisRaw = DefaultCfg().Init.GenesisRaw
// use default genesis file if genesis configuration not provided, for example,
// if we load a toml configuration file without a defined genesis init value or
// if we pass an empty string as the genesis init value using the --genesis flag
if cfg.Init.Genesis == "" {
cfg.Init.Genesis = DefaultCfg().Init.Genesis
}

// load Genesis from genesis configuration file
gen, err := genesis.NewGenesisFromJSONRaw(cfg.Init.GenesisRaw)
gen, err := genesis.NewGenesisFromJSONRaw(cfg.Init.Genesis)
if err != nil {
logger.Error("failed to load genesis from file", "error", err)
return // exit
Expand Down
20 changes: 10 additions & 10 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func TestInitConfigFromFlags(t *testing.T) {
expected dot.InitConfig
}{
{
"Test gossamer --genesis-raw",
[]string{"config", "genesis-raw"},
"Test gossamer --genesis",
[]string{"config", "genesis"},
[]interface{}{testCfgFile.Name(), "test_genesis"},
dot.InitConfig{
GenesisRaw: "test_genesis",
Genesis: "test_genesis",
},
},
}
Expand Down Expand Up @@ -650,7 +650,7 @@ func TestUpdateConfigFromGenesisJSON(t *testing.T) {

ctx, err := newTestContext(
t.Name(),
[]string{"config", "genesis-raw"},
[]string{"config", "genesis"},
[]interface{}{testCfgFile.Name(), genFile.Name()},
)
require.Nil(t, err)
Expand All @@ -675,7 +675,7 @@ func TestUpdateConfigFromGenesisJSON(t *testing.T) {
FinalityGadgetLvl: log.LvlInfo,
},
Init: dot.InitConfig{
GenesisRaw: genFile.Name(),
Genesis: genFile.Name(),
},
Account: testCfg.Account,
Core: testCfg.Core,
Expand All @@ -687,7 +687,7 @@ func TestUpdateConfigFromGenesisJSON(t *testing.T) {
cfg, err := createDotConfig(ctx)
require.Nil(t, err)

cfg.Init.GenesisRaw = genFile.Name()
cfg.Init.Genesis = genFile.Name()
updateDotConfigFromGenesisJSONRaw(*dotConfigToToml(testCfg), cfg)
require.Equal(t, expected, cfg)
}
Expand All @@ -702,7 +702,7 @@ func TestUpdateConfigFromGenesisJSON_Default(t *testing.T) {

ctx, err := newTestContext(
t.Name(),
[]string{"config", "genesis-raw"},
[]string{"config", "genesis"},
[]interface{}{testCfgFile.Name(), ""},
)
require.Nil(t, err)
Expand All @@ -727,7 +727,7 @@ func TestUpdateConfigFromGenesisJSON_Default(t *testing.T) {
FinalityGadgetLvl: log.LvlInfo,
},
Init: dot.InitConfig{
GenesisRaw: DefaultCfg().Init.GenesisRaw,
Genesis: DefaultCfg().Init.Genesis,
},
Account: testCfg.Account,
Core: testCfg.Core,
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
FinalityGadgetLvl: log.LvlInfo,
},
Init: dot.InitConfig{
GenesisRaw: genFile.Name(),
Genesis: genFile.Name(),
},
Account: testCfg.Account,
Core: testCfg.Core,
Expand All @@ -796,7 +796,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
cfg, err := createDotConfig(ctx)
require.Nil(t, err)

cfg.Init.GenesisRaw = genFile.Name()
cfg.Init.Genesis = genFile.Name()
expected.Core.BabeThresholdNumerator = 0
expected.Core.BabeThresholdDenominator = 0

Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
}

cfg.Init = ctoml.InitConfig{
GenesisRaw: dcfg.Init.GenesisRaw,
Genesis: dcfg.Init.Genesis,
}

cfg.Account = ctoml.AccountConfig{
Expand Down
18 changes: 9 additions & 9 deletions cmd/gossamer/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func TestExportCommand(t *testing.T) {
expected *dot.Config
}{
{
"Test gossamer export --config --genesis-raw --basepath --name --log --force",
[]string{"config", "genesis-raw", "basepath", "name", "log", "force"},
"Test gossamer export --config --genesis --basepath --name --log --force",
[]string{"config", "genesis", "basepath", "name", "log", "force"},
[]interface{}{testConfig, genFile.Name(), testDir, testName, log.LvlInfo.String(), "true"},
&dot.Config{
Global: dot.GlobalConfig{
Expand All @@ -75,7 +75,7 @@ func TestExportCommand(t *testing.T) {
FinalityGadgetLvl: log.LvlInfo,
},
Init: dot.InitConfig{
GenesisRaw: genFile.Name(),
Genesis: genFile.Name(),
},
Account: testCfg.Account,
Core: testCfg.Core,
Expand All @@ -90,13 +90,13 @@ func TestExportCommand(t *testing.T) {
},
},
{
"Test gossamer export --config --genesis-raw --bootnodes --log --force",
[]string{"config", "genesis-raw", "bootnodes", "name", "force"},
"Test gossamer export --config --genesis --bootnodes --log --force",
[]string{"config", "genesis", "bootnodes", "name", "force"},
[]interface{}{testConfig, genFile.Name(), testBootnode, "Gossamer", "true"},
&dot.Config{
Global: testCfg.Global,
Init: dot.InitConfig{
GenesisRaw: genFile.Name(),
Genesis: genFile.Name(),
},
Log: dot.LogConfig{
CoreLvl: log.LvlInfo,
Expand All @@ -121,13 +121,13 @@ func TestExportCommand(t *testing.T) {
},
},
{
"Test gossamer export --config --genesis-raw --protocol --log --force",
[]string{"config", "genesis-raw", "protocol", "force"},
"Test gossamer export --config --genesis --protocol --log --force",
[]string{"config", "genesis", "protocol", "force"},
[]interface{}{testConfig, genFile.Name(), testProtocol, "true"},
&dot.Config{
Global: testCfg.Global,
Init: dot.InitConfig{
GenesisRaw: genFile.Name(),
Genesis: genFile.Name(),
},
Log: dot.LogConfig{
CoreLvl: log.LvlInfo,
Expand Down
18 changes: 9 additions & 9 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ var (

// Initialization-only flags
var (
// GenesisRawFlag Path to raw genesis JSON file
GenesisRawFlag = cli.StringFlag{
Name: "genesis-raw",
Usage: "Path to raw genesis JSON file",
// GenesisFlag is the path to a genesis JSON file
GenesisFlag = cli.StringFlag{
Name: "genesis",
Usage: "Path to genesis JSON file",
}
)

Expand All @@ -131,8 +131,8 @@ var (
Name: "raw",
Usage: "Output as raw genesis JSON",
}
GenesisFlag = cli.StringFlag{
Name: "genesis",
GenesisSpecFlag = cli.StringFlag{
Name: "genesis-spec",
Usage: "Path to human-readable genesis JSON file",
}
)
Expand Down Expand Up @@ -306,18 +306,18 @@ var (
// InitFlags are flags that are valid for use with the init subcommand
InitFlags = append([]cli.Flag{
ForceFlag,
GenesisRawFlag,
GenesisFlag,
}, GlobalFlags...)

BuildSpecFlags = append([]cli.Flag{
RawFlag,
GenesisFlag,
GenesisSpecFlag,
}, GlobalFlags...)

// ExportFlags are the flags that are valid for use with the export subcommand
ExportFlags = append([]cli.Flag{
ForceFlag,
GenesisRawFlag,
GenesisFlag,
}, append(GlobalFlags, StartupFlags...)...)

// AccountFlags are flags that are valid for use with the account subcommand
Expand Down
16 changes: 8 additions & 8 deletions cmd/gossamer/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ func TestFixFlagOrder(t *testing.T) {
values []interface{}
}{
{
"Test gossamer --config --genesis-raw --log --force",
[]string{"config", "genesis-raw", "log", "force"},
"Test gossamer --config --genesis --log --force",
[]string{"config", "genesis", "log", "force"},
[]interface{}{testConfig.Name(), genFile.Name(), "trace", true},
},
{
"Test gossamer --config --genesis-raw --force --log",
[]string{"config", "genesis-raw", "force", "log"},
"Test gossamer --config --genesis --force --log",
[]string{"config", "genesis", "force", "log"},
[]interface{}{testConfig.Name(), genFile.Name(), true, "trace"},
},
{
"Test gossamer --config --force --genesis-raw --log",
[]string{"config", "force", "genesis-raw", "log"},
"Test gossamer --config --force --genesis --log",
[]string{"config", "force", "genesis", "log"},
[]interface{}{testConfig.Name(), true, genFile.Name(), "trace"},
},
{
"Test gossamer --force --config --genesis-raw --log",
[]string{"force", "config", "genesis-raw", "log"},
"Test gossamer --force --config --genesis --log",
[]string{"force", "config", "genesis", "log"},
[]interface{}{true, testConfig.Name(), genFile.Name(), "trace"},
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/import_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/ChainSafe/gossamer/lib/genesis"
)

var defaultGenesisSpecPath = "./chain/gssmr/genesis.json"
var defaultGenesisSpecPath = "./chain/gssmr/genesis-spec.json"

func createGenesisWithRuntime(fp string) (string, error) {
runtime, err := ioutil.ReadFile(filepath.Clean(fp))
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/import_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestCreateGenesisWithRuntime(t *testing.T) {
defaultGenesisSpecPath = "../../chain/gssmr/genesis.json"
defaultGenesisSpecPath = "../../chain/gssmr/genesis-spec.json"

testCode := []byte("somecode")
testHex := common.BytesToHex(testCode)
Expand Down
10 changes: 5 additions & 5 deletions cmd/gossamer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ var (
ArgsUsage: "",
Flags: InitFlags,
Category: "INIT",
Description: "The init command initializes the node databases and loads the genesis data from the raw genesis configuration file to state.\n" +
"\tUsage: gossamer init --genesis-raw genesis.json",
Description: "The init command initializes the node databases and loads the genesis data from the genesis file to state.\n" +
"\tUsage: gossamer init --genesis genesis.json",
}
// accountCommand defines the "account" subcommand (ie, `gossamer account`)
accountCommand = cli.Command{
Expand All @@ -79,8 +79,8 @@ var (
Category: "BUILD-SPEC",
Description: "The build-spec command outputs current genesis JSON data.\n" +
"\tUsage: gossamer build-spec\n" +
"\tTo generate raw genesis file from default: gossamer build-spec --raw > genesis-raw.json" +
"\tTo generate raw genesis file from specific genesis file: gossamer build-spec --raw --genesis genesis.json > genesis-raw.json",
"\tTo generate raw genesis file from default: gossamer build-spec --raw > genesis.json" +
"\tTo generate raw genesis file from specific genesis file: gossamer build-spec --raw --genesis genesis-spec.json > genesis.json",
}

// importRuntime generates a genesis file given a .wasm runtime binary.
Expand Down Expand Up @@ -353,7 +353,7 @@ func buildSpecAction(ctx *cli.Context) error {
}

var bs *dot.BuildSpec
if genesis := ctx.String(GenesisFlag.Name); genesis != "" {
if genesis := ctx.String(GenesisSpecFlag.Name); genesis != "" {
bspec, e := dot.BuildFromGenesis(genesis, 0)
if e != nil {
return e
Expand Down
Loading