From e9b6032b253982e0c044ae6d2c69e36c54446ad7 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Tue, 29 Nov 2022 15:28:18 +0100 Subject: [PATCH 1/6] feat: move config validators check to validate only when required --- changelog.md | 1 + ignite/config/chainconfig.go | 19 ++++++++- ignite/config/parse.go | 4 -- ignite/services/chain/chain.go | 32 ++++++++++----- ignite/services/chain/faucet.go | 7 +++- ignite/services/chain/runtime.go | 67 ++++++++++++++++++++------------ ignite/services/chain/serve.go | 7 +++- 7 files changed, 94 insertions(+), 43 deletions(-) diff --git a/changelog.md b/changelog.md index 6c71a83674..1af6809368 100644 --- a/changelog.md +++ b/changelog.md @@ -36,6 +36,7 @@ - [#3025](https://github.com/ignite/cli/issues/3025) Improve config version error handling. - [#3084](https://github.com/ignite/cli/pull/3084) Add Ignite Chain documentation. - [#3106](https://github.com/ignite/cli/pull/3106) Add zoom image plugin. +- [#3194](https://github.com/ignite/cli/issues/3194) Move config validators check to validate only when required. ### Breaking Changes diff --git a/ignite/config/chainconfig.go b/ignite/config/chainconfig.go index 87820e2685..7e995cc2e5 100644 --- a/ignite/config/chainconfig.go +++ b/ignite/config/chainconfig.go @@ -60,8 +60,13 @@ var ( } ) -// ChainConfig defines the latest chain config. -type ChainConfig = v1.Config +type ( + // ChainConfig defines the latest chain config. + ChainConfig = v1.Config + + // Validator defines the latest validator settings. + Validator = v1.Validator +) // DefaultChainConfig returns a config for the latest version initialized with default values. func DefaultChainConfig() *ChainConfig { @@ -172,3 +177,13 @@ func Save(c ChainConfig, path string) error { return yaml.NewEncoder(file).Encode(c) } + +// FirstValidator returns the first validator from the validators list. +// An error is returned when there are not validators defined in the config. +func FirstValidator(conf *ChainConfig) (Validator, error) { + if len(conf.Validators) == 0 { + return Validator{}, &ValidationError{"at least one validator is required"} + } + + return conf.Validators[0], nil +} diff --git a/ignite/config/parse.go b/ignite/config/parse.go index 311c38ca2d..a7457e085a 100644 --- a/ignite/config/parse.go +++ b/ignite/config/parse.go @@ -125,10 +125,6 @@ func validateConfig(c *ChainConfig) error { return &ValidationError{"at least one account is required"} } - if len(c.Validators) == 0 { - return &ValidationError{"at least one validator is required"} - } - for _, validator := range c.Validators { if validator.Name == "" { return &ValidationError{"validator 'name' is required"} diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index bb00d5c380..63f45199f3 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -186,7 +186,12 @@ func (c *Chain) RPCPublicAddress() (string, error) { if err != nil { return "", err } - validator := conf.Validators[0] + + validator, err := config.FirstValidator(conf) + if err != nil { + return "", err + } + servers, err := validator.GetServers() if err != nil { return "", err @@ -291,11 +296,16 @@ func (c *Chain) Home() (string, error) { // DefaultHome returns the blockchain node's default home dir when not specified in the app func (c *Chain) DefaultHome() (string, error) { // check if home is defined in config - config, err := c.Config() + cfg, err := c.Config() + if err != nil { + return "", err + } + + validator, err := config.FirstValidator(cfg) if err != nil { return "", err } - validator := config.Validators[0] + if validator.Home != "" { return validator.Home, nil } @@ -364,14 +374,14 @@ func (c *Chain) KeyringBackend() (chaincmd.KeyringBackend, error) { return c.options.keyringBackend, nil } - config, err := c.Config() + // 2nd. + cfg, err := c.Config() if err != nil { return "", err } - // 2nd. - validator := config.Validators[0] - if validator.KeyringBackend != "" { + validator, err := config.FirstValidator(cfg) + if err == nil && validator.KeyringBackend != "" { return chaincmd.KeyringBackendFromString(validator.KeyringBackend) } @@ -431,12 +441,16 @@ func (c *Chain) Commands(ctx context.Context) (chaincmdrunner.Runner, error) { return chaincmdrunner.Runner{}, err } - config, err := c.Config() + cfg, err := c.Config() + if err != nil { + return chaincmdrunner.Runner{}, err + } + + validator, err := config.FirstValidator(cfg) if err != nil { return chaincmdrunner.Runner{}, err } - validator := config.Validators[0] servers, err := validator.GetServers() if err != nil { return chaincmdrunner.Runner{}, err diff --git a/ignite/services/chain/faucet.go b/ignite/services/chain/faucet.go index 219aa10951..9f91e81ce6 100644 --- a/ignite/services/chain/faucet.go +++ b/ignite/services/chain/faucet.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pkg/errors" + "github.com/ignite/cli/ignite/config" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cosmosfaucet" "github.com/ignite/cli/ignite/pkg/xurl" @@ -55,7 +56,11 @@ func (c *Chain) Faucet(ctx context.Context) (cosmosfaucet.Faucet, error) { } // construct faucet options. - validator := conf.Validators[0] + validator, err := config.FirstValidator(conf) + if err != nil { + return cosmosfaucet.Faucet{}, err + } + servers, err := validator.GetServers() if err != nil { return cosmosfaucet.Faucet{}, err diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index 96dc6cc325..7c24644222 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -37,7 +37,11 @@ func (c Chain) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Valida // Start wraps the "appd start" command to begin running a chain from the daemon func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *config.ChainConfig) error { - validator := cfg.Validators[0] + validator, err := config.FirstValidator(cfg) + if err != nil { + return err + } + servers, err := validator.GetServers() if err != nil { return err @@ -60,14 +64,18 @@ func (c Chain) Configure(homePath string, cfg *config.ChainConfig) error { } func (c Chain) appTOML(homePath string, cfg *config.ChainConfig) error { + validator, err := config.FirstValidator(cfg) + if err != nil { + return err + } + // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/app.toml") - config, err := toml.LoadFile(path) + appConfig, err := toml.LoadFile(path) if err != nil { return err } - validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { return err @@ -79,22 +87,22 @@ func (c Chain) appTOML(homePath string, cfg *config.ChainConfig) error { } // Set default config values - config.Set("api.enable", true) - config.Set("api.enabled-unsafe-cors", true) - config.Set("rpc.cors_allowed_origins", []string{"*"}) + appConfig.Set("api.enable", true) + appConfig.Set("api.enabled-unsafe-cors", true) + appConfig.Set("rpc.cors_allowed_origins", []string{"*"}) // Update config values with the validator's Cosmos SDK app config - updateTomlTreeValues(config, validator.App) + updateTomlTreeValues(appConfig, validator.App) // Make sure the API address have the protocol prefix - config.Set("api.address", apiAddr) + appConfig.Set("api.address", apiAddr) staked, err := sdktypes.ParseCoinNormalized(validator.Bonded) if err != nil { return err } gas := sdktypes.NewInt64Coin(staked.Denom, 0) - config.Set("minimum-gas-prices", gas.String()) + appConfig.Set("minimum-gas-prices", gas.String()) file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0o644) if err != nil { @@ -102,19 +110,23 @@ func (c Chain) appTOML(homePath string, cfg *config.ChainConfig) error { } defer file.Close() - _, err = config.WriteTo(file) + _, err = appConfig.WriteTo(file) return err } func (c Chain) configTOML(homePath string, cfg *config.ChainConfig) error { + validator, err := config.FirstValidator(cfg) + if err != nil { + return err + } + // TODO find a better way in order to not delete comments in the toml.yml path := filepath.Join(homePath, "config/config.toml") - config, err := toml.LoadFile(path) + tmConfig, err := toml.LoadFile(path) if err != nil { return err } - validator := cfg.Validators[0] servers, err := validator.GetServers() if err != nil { return err @@ -131,17 +143,17 @@ func (c Chain) configTOML(homePath string, cfg *config.ChainConfig) error { } // Set default config values - config.Set("mode", "validator") - config.Set("rpc.cors_allowed_origins", []string{"*"}) - config.Set("consensus.timeout_commit", "1s") - config.Set("consensus.timeout_propose", "1s") + tmConfig.Set("mode", "validator") + tmConfig.Set("rpc.cors_allowed_origins", []string{"*"}) + tmConfig.Set("consensus.timeout_commit", "1s") + tmConfig.Set("consensus.timeout_propose", "1s") // Update config values with the validator's Tendermint config - updateTomlTreeValues(config, validator.Config) + updateTomlTreeValues(tmConfig, validator.Config) // Make sure the addresses have the protocol prefix - config.Set("rpc.laddr", rpcAddr) - config.Set("p2p.laddr", p2pAddr) + tmConfig.Set("rpc.laddr", rpcAddr) + tmConfig.Set("p2p.laddr", p2pAddr) file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0o644) if err != nil { @@ -149,13 +161,18 @@ func (c Chain) configTOML(homePath string, cfg *config.ChainConfig) error { } defer file.Close() - _, err = config.WriteTo(file) + _, err = tmConfig.WriteTo(file) return err } func (c Chain) clientTOML(homePath string, cfg *config.ChainConfig) error { + validator, err := config.FirstValidator(cfg) + if err != nil { + return err + } + path := filepath.Join(homePath, "config/client.toml") - config, err := toml.LoadFile(path) + tmConfig, err := toml.LoadFile(path) if os.IsNotExist(err) { return nil } @@ -165,11 +182,11 @@ func (c Chain) clientTOML(homePath string, cfg *config.ChainConfig) error { } // Set default config values - config.Set("keyring-backend", "test") - config.Set("broadcast-mode", "block") + tmConfig.Set("keyring-backend", "test") + tmConfig.Set("broadcast-mode", "block") // Update config values with the validator's client config - updateTomlTreeValues(config, cfg.Validators[0].Client) + updateTomlTreeValues(tmConfig, validator.Client) file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0o644) if err != nil { @@ -177,7 +194,7 @@ func (c Chain) clientTOML(homePath string, cfg *config.ChainConfig) error { } defer file.Close() - _, err = config.WriteTo(file) + _, err = tmConfig.WriteTo(file) return err } diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 138a2970ec..a0d50e09e1 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -461,8 +461,11 @@ func (c *Chain) start(ctx context.Context, cfg *config.ChainConfig) error { // set the app as being served c.served = true - // Get the first validator - validator := cfg.Validators[0] + validator, err := config.FirstValidator(cfg) + if err != nil { + return err + } + servers, err := validator.GetServers() if err != nil { return err From 01473b6ec82165197e6f892f4660b6bc94209d6c Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Tue, 29 Nov 2022 15:36:01 +0100 Subject: [PATCH 2/6] chore: remove unnecessary error check --- ignite/services/chain/chain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 63f45199f3..aaf05b183c 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -380,8 +380,8 @@ func (c *Chain) KeyringBackend() (chaincmd.KeyringBackend, error) { return "", err } - validator, err := config.FirstValidator(cfg) - if err == nil && validator.KeyringBackend != "" { + validator, _ := config.FirstValidator(cfg) + if validator.KeyringBackend != "" { return chaincmd.KeyringBackendFromString(validator.KeyringBackend) } From 59fd322b45af691429a3082b72a6f638a618f491 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Tue, 29 Nov 2022 16:34:20 +0100 Subject: [PATCH 3/6] fix: change `Chain.RPCPublicAddress` to return default address on error --- ignite/config/chain/base/config.go | 20 +++++++++++ ignite/config/chain/v1/config.go | 25 ++++++------- ignite/config/chain/v1/config_test.go | 40 ++++++++++----------- ignite/config/chain/v1/validator_servers.go | 32 ++++------------- ignite/services/chain/chain.go | 4 ++- 5 files changed, 63 insertions(+), 58 deletions(-) diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index bb38d92198..d9dd180276 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -7,6 +7,26 @@ import ( xyaml "github.com/ignite/cli/ignite/pkg/yaml" ) +var ( + // DefaultGRPCAddress is the default GRPC address. + DefaultGRPCAddress = "0.0.0.0:9090" + + // DefaultGRPCWebAddress is the default GRPC-Web address. + DefaultGRPCWebAddress = "0.0.0.0:9091" + + // DefaultAPIAddress is the default API address. + DefaultAPIAddress = "0.0.0.0:1317" + + // DefaultRPCAddress is the default RPC address. + DefaultRPCAddress = "0.0.0.0:26657" + + // DefaultP2PAddress is the default P2P address. + DefaultP2PAddress = "0.0.0.0:26656" + + // DefaultPProfAddress is the default Prof address. + DefaultPProfAddress = "0.0.0.0:6060" +) + // Account holds the options related to setting up Cosmos wallets. type Account struct { Name string `yaml:"name"` diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index d5b09a73b0..3cd269f246 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -8,6 +8,7 @@ import ( chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" + baseconfig "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -111,43 +112,43 @@ func (c *Config) updateValidatorAddresses() (err error) { func incrementDefaultServerPortsBy(s Servers, inc uint64) (Servers, error) { var err error - if s.GRPC.Address == DefaultGRPCAddress { - s.GRPC.Address, err = xnet.IncreasePortBy(DefaultGRPCAddress, inc) + if s.GRPC.Address == baseconfig.DefaultGRPCAddress { + s.GRPC.Address, err = xnet.IncreasePortBy(baseconfig.DefaultGRPCAddress, inc) if err != nil { return Servers{}, err } } - if s.GRPCWeb.Address == DefaultGRPCWebAddress { - s.GRPCWeb.Address, err = xnet.IncreasePortBy(DefaultGRPCWebAddress, inc) + if s.GRPCWeb.Address == baseconfig.DefaultGRPCWebAddress { + s.GRPCWeb.Address, err = xnet.IncreasePortBy(baseconfig.DefaultGRPCWebAddress, inc) if err != nil { return Servers{}, err } } - if s.API.Address == DefaultAPIAddress { - s.API.Address, err = xnet.IncreasePortBy(DefaultAPIAddress, inc) + if s.API.Address == baseconfig.DefaultAPIAddress { + s.API.Address, err = xnet.IncreasePortBy(baseconfig.DefaultAPIAddress, inc) if err != nil { return Servers{}, err } } - if s.P2P.Address == DefaultP2PAddress { - s.P2P.Address, err = xnet.IncreasePortBy(DefaultP2PAddress, inc) + if s.P2P.Address == baseconfig.DefaultP2PAddress { + s.P2P.Address, err = xnet.IncreasePortBy(baseconfig.DefaultP2PAddress, inc) if err != nil { return Servers{}, err } } - if s.RPC.Address == DefaultRPCAddress { - s.RPC.Address, err = xnet.IncreasePortBy(DefaultRPCAddress, inc) + if s.RPC.Address == baseconfig.DefaultRPCAddress { + s.RPC.Address, err = xnet.IncreasePortBy(baseconfig.DefaultRPCAddress, inc) if err != nil { return Servers{}, err } } - if s.RPC.PProfAddress == DefaultPProfAddress { - s.RPC.PProfAddress, err = xnet.IncreasePortBy(DefaultPProfAddress, inc) + if s.RPC.PProfAddress == baseconfig.DefaultPProfAddress { + s.RPC.PProfAddress, err = xnet.IncreasePortBy(baseconfig.DefaultPProfAddress, inc) if err != nil { return Servers{}, err } diff --git a/ignite/config/chain/v1/config_test.go b/ignite/config/chain/v1/config_test.go index da2992c7e9..19f5c7849f 100644 --- a/ignite/config/chain/v1/config_test.go +++ b/ignite/config/chain/v1/config_test.go @@ -108,12 +108,12 @@ func TestConfigValidatorDefaultServers(t *testing.T) { require.NoError(t, err) // Assert - require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v1.DefaultAPIAddress, servers.API.Address) - require.Equal(t, v1.DefaultRPCAddress, servers.RPC.Address) - require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, base.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, base.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, base.DefaultAPIAddress, servers.API.Address) + require.Equal(t, base.DefaultRPCAddress, servers.RPC.Address) + require.Equal(t, base.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, base.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorWithExistingServers(t *testing.T) { @@ -150,10 +150,10 @@ func TestConfigValidatorWithExistingServers(t *testing.T) { // Assert require.Equal(t, rpcAddr, servers.RPC.Address) require.Equal(t, apiAddr, servers.API.Address) - require.Equal(t, v1.DefaultGRPCAddress, servers.GRPC.Address) - require.Equal(t, v1.DefaultGRPCWebAddress, servers.GRPCWeb.Address) - require.Equal(t, v1.DefaultP2PAddress, servers.P2P.Address) - require.Equal(t, v1.DefaultPProfAddress, servers.RPC.PProfAddress) + require.Equal(t, base.DefaultGRPCAddress, servers.GRPC.Address) + require.Equal(t, base.DefaultGRPCWebAddress, servers.GRPCWeb.Address) + require.Equal(t, base.DefaultP2PAddress, servers.P2P.Address) + require.Equal(t, base.DefaultPProfAddress, servers.RPC.PProfAddress) } func TestConfigValidatorsWithExistingServers(t *testing.T) { @@ -197,10 +197,10 @@ func TestConfigValidatorsWithExistingServers(t *testing.T) { require.Equal(t, apiAddr, servers.API.Address) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestConfigValidatorsDefaultServers(t *testing.T) { @@ -230,12 +230,12 @@ func TestConfigValidatorsDefaultServers(t *testing.T) { require.NoError(t, err) // Assert: The second validator should have the ports incremented by 10 - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCAddress, inc), servers.GRPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultAPIAddress, inc), servers.API.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultRPCAddress, inc), servers.RPC.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultP2PAddress, inc), servers.P2P.Address) - require.Equal(t, xnet.MustIncreasePortBy(v1.DefaultPProfAddress, inc), servers.RPC.PProfAddress) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultGRPCAddress, inc), servers.GRPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultGRPCWebAddress, inc), servers.GRPCWeb.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultAPIAddress, inc), servers.API.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultRPCAddress, inc), servers.RPC.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultP2PAddress, inc), servers.P2P.Address) + require.Equal(t, xnet.MustIncreasePortBy(base.DefaultPProfAddress, inc), servers.RPC.PProfAddress) } func TestClone(t *testing.T) { diff --git a/ignite/config/chain/v1/validator_servers.go b/ignite/config/chain/v1/validator_servers.go index 1f69245024..6682d8abb1 100644 --- a/ignite/config/chain/v1/validator_servers.go +++ b/ignite/config/chain/v1/validator_servers.go @@ -4,36 +4,18 @@ import ( "fmt" "github.com/mitchellh/mapstructure" -) - -var ( - // DefaultGRPCAddress is the default GRPC address. - DefaultGRPCAddress = "0.0.0.0:9090" - - // DefaultGRPCWebAddress is the default GRPC-Web address. - DefaultGRPCWebAddress = "0.0.0.0:9091" - - // DefaultAPIAddress is the default API address. - DefaultAPIAddress = "0.0.0.0:1317" - - // DefaultRPCAddress is the default RPC address. - DefaultRPCAddress = "0.0.0.0:26657" - - // DefaultP2PAddress is the default P2P address. - DefaultP2PAddress = "0.0.0.0:26656" - // DefaultPProfAddress is the default Prof address. - DefaultPProfAddress = "0.0.0.0:6060" + baseconfig "github.com/ignite/cli/ignite/config/chain/base" ) func DefaultServers() Servers { s := Servers{} - s.GRPC.Address = DefaultGRPCAddress - s.GRPCWeb.Address = DefaultGRPCWebAddress - s.API.Address = DefaultAPIAddress - s.P2P.Address = DefaultP2PAddress - s.RPC.Address = DefaultRPCAddress - s.RPC.PProfAddress = DefaultPProfAddress + s.GRPC.Address = baseconfig.DefaultGRPCAddress + s.GRPCWeb.Address = baseconfig.DefaultGRPCWebAddress + s.API.Address = baseconfig.DefaultAPIAddress + s.P2P.Address = baseconfig.DefaultP2PAddress + s.RPC.Address = baseconfig.DefaultRPCAddress + s.RPC.PProfAddress = baseconfig.DefaultPProfAddress return s } diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index aaf05b183c..405ae85e40 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -9,6 +9,7 @@ import ( "github.com/tendermint/spn/pkg/chainid" "github.com/ignite/cli/ignite/config" + baseconfig "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" "github.com/ignite/cli/ignite/pkg/cliui/colors" @@ -189,7 +190,8 @@ func (c *Chain) RPCPublicAddress() (string, error) { validator, err := config.FirstValidator(conf) if err != nil { - return "", err + // When there are no validators return the default RPC address + return baseconfig.DefaultRPCAddress, err } servers, err := validator.GetServers() From a0236944015ccfaaaa06f597a912d97a215696bf Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Tue, 29 Nov 2022 16:38:17 +0100 Subject: [PATCH 4/6] chore: fix duplicated import import --- ignite/config/chain/v1/config.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ignite/config/chain/v1/config.go b/ignite/config/chain/v1/config.go index 3cd269f246..a5de4ba167 100644 --- a/ignite/config/chain/v1/config.go +++ b/ignite/config/chain/v1/config.go @@ -8,7 +8,6 @@ import ( chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/config/chain/base" - baseconfig "github.com/ignite/cli/ignite/config/chain/base" "github.com/ignite/cli/ignite/pkg/xnet" ) @@ -112,43 +111,43 @@ func (c *Config) updateValidatorAddresses() (err error) { func incrementDefaultServerPortsBy(s Servers, inc uint64) (Servers, error) { var err error - if s.GRPC.Address == baseconfig.DefaultGRPCAddress { - s.GRPC.Address, err = xnet.IncreasePortBy(baseconfig.DefaultGRPCAddress, inc) + if s.GRPC.Address == base.DefaultGRPCAddress { + s.GRPC.Address, err = xnet.IncreasePortBy(base.DefaultGRPCAddress, inc) if err != nil { return Servers{}, err } } - if s.GRPCWeb.Address == baseconfig.DefaultGRPCWebAddress { - s.GRPCWeb.Address, err = xnet.IncreasePortBy(baseconfig.DefaultGRPCWebAddress, inc) + if s.GRPCWeb.Address == base.DefaultGRPCWebAddress { + s.GRPCWeb.Address, err = xnet.IncreasePortBy(base.DefaultGRPCWebAddress, inc) if err != nil { return Servers{}, err } } - if s.API.Address == baseconfig.DefaultAPIAddress { - s.API.Address, err = xnet.IncreasePortBy(baseconfig.DefaultAPIAddress, inc) + if s.API.Address == base.DefaultAPIAddress { + s.API.Address, err = xnet.IncreasePortBy(base.DefaultAPIAddress, inc) if err != nil { return Servers{}, err } } - if s.P2P.Address == baseconfig.DefaultP2PAddress { - s.P2P.Address, err = xnet.IncreasePortBy(baseconfig.DefaultP2PAddress, inc) + if s.P2P.Address == base.DefaultP2PAddress { + s.P2P.Address, err = xnet.IncreasePortBy(base.DefaultP2PAddress, inc) if err != nil { return Servers{}, err } } - if s.RPC.Address == baseconfig.DefaultRPCAddress { - s.RPC.Address, err = xnet.IncreasePortBy(baseconfig.DefaultRPCAddress, inc) + if s.RPC.Address == base.DefaultRPCAddress { + s.RPC.Address, err = xnet.IncreasePortBy(base.DefaultRPCAddress, inc) if err != nil { return Servers{}, err } } - if s.RPC.PProfAddress == baseconfig.DefaultPProfAddress { - s.RPC.PProfAddress, err = xnet.IncreasePortBy(baseconfig.DefaultPProfAddress, inc) + if s.RPC.PProfAddress == base.DefaultPProfAddress { + s.RPC.PProfAddress, err = xnet.IncreasePortBy(base.DefaultPProfAddress, inc) if err != nil { return Servers{}, err } From 6a5c955b0de24f988b720f0ffc49f12b15eb31bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Albi?= Date: Fri, 9 Dec 2022 17:57:20 +0100 Subject: [PATCH 5/6] chore: fix typo Co-authored-by: Alex Johnson --- ignite/config/chain/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/config/chain/config.go b/ignite/config/chain/config.go index d80aa0fa94..238011113f 100644 --- a/ignite/config/chain/config.go +++ b/ignite/config/chain/config.go @@ -166,7 +166,7 @@ func Save(c Config, path string) error { } // FirstValidator returns the first validator from the validators list. -// An error is returned when there are not validators defined in the config. +// An error is returned when there are no validators defined in the config. func FirstValidator(conf *Config) (Validator, error) { if len(conf.Validators) == 0 { return Validator{}, &ValidationError{"at least one validator is required"} From 6f34c37c8a5cedad3c0ab08c8ea767e15815a7bf Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Tue, 13 Dec 2022 10:28:13 +0100 Subject: [PATCH 6/6] chore: changes from review Co-authored-by: Alex Johnson --- ignite/services/chain/chain.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 2091554e3d..a8d9e238cd 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -352,12 +352,13 @@ func (c *Chain) ClientTOMLPath() (string, error) { // KeyringBackend returns the keyring backend chosen for the chain. func (c *Chain) KeyringBackend() (chaincmd.KeyringBackend, error) { - // 1st. + // When keyring backend is initialized as a chain + // option it overrides any configured backends. if c.options.keyringBackend != "" { return c.options.keyringBackend, nil } - // 2nd. + // Try to get keyring backend from the first configured validator cfg, err := c.Config() if err != nil { return "", err @@ -372,7 +373,7 @@ func (c *Chain) KeyringBackend() (chaincmd.KeyringBackend, error) { } } - // 3rd. + // Try to get keyring backend from client.toml config file configTOMLPath, err := c.ClientTOMLPath() if err != nil { return "", err @@ -388,7 +389,7 @@ func (c *Chain) KeyringBackend() (chaincmd.KeyringBackend, error) { return chaincmd.KeyringBackendFromString(conf.KeyringBackend) } - // 4th. + // Use test backend as default when none is configured return chaincmd.KeyringBackendTest, nil } @@ -426,7 +427,7 @@ func (c *Chain) Commands(ctx context.Context) (chaincmdrunner.Runner, error) { servers := chainconfigv1.DefaultServers() if len(cfg.Validators) > 0 { - validator := cfg.Validators[0] + validator, _ := chainconfig.FirstValidator(cfg) servers, err = validator.GetServers() if err != nil { return chaincmdrunner.Runner{}, err