From 28412748e293eec207f43c31d06248c7e266b905 Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Sun, 29 Jan 2023 23:00:02 +0100 Subject: [PATCH 1/3] Add support for genesis sub commands --- chain/cosmos/chain_node.go | 32 +++++++++++++++++++++++++------- chainspec.go | 10 +++++++--- ibc/types.go | 2 ++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index d3b2090d6..9170bc26b 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -556,7 +556,17 @@ func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, gene ctx, cancel := context.WithTimeout(ctx, time.Minute) defer cancel() - _, _, err := tn.ExecBin(ctx, "add-genesis-account", address, amount) + var command []string + if tn.Chain.Config().UsingNewGenesisCommand { + tn.logger().Info("add-genesis-account with new genesis command") + command = append(command, "genesis") + } else { + tn.logger().Info("add-genesis-account WITHOUT new genesis command") + } + + command = append(command, "add-genesis-account", address, amount) + _, _, err := tn.ExecBin(ctx, command...) + return err } @@ -565,20 +575,28 @@ func (tn *ChainNode) Gentx(ctx context.Context, name string, genesisSelfDelegati tn.lock.Lock() defer tn.lock.Unlock() - _, _, err := tn.ExecBin(ctx, - "gentx", valKey, fmt.Sprintf("%d%s", genesisSelfDelegation.Amount.Int64(), genesisSelfDelegation.Denom), + var command []string + if tn.Chain.Config().UsingNewGenesisCommand { + command = append(command, "genesis") + } + + command = append(command, "gentx", valKey, fmt.Sprintf("%d%s", genesisSelfDelegation.Amount.Int64(), genesisSelfDelegation.Denom), "--keyring-backend", keyring.BackendTest, - "--chain-id", tn.Chain.Config().ChainID, - ) + "--chain-id", tn.Chain.Config().ChainID) + + _, _, err := tn.ExecBin(ctx, command...) return err } // CollectGentxs runs collect gentxs on the node's home folders func (tn *ChainNode) CollectGentxs(ctx context.Context) error { - command := []string{tn.Chain.Config().Bin, "collect-gentxs", - "--home", tn.HomeDir(), + command := []string{tn.Chain.Config().Bin} + if tn.Chain.Config().UsingNewGenesisCommand { + command = append(command, "genesis") } + command = append(command, "collect-gentxs", "--home", tn.HomeDir()) + tn.lock.Lock() defer tn.lock.Unlock() diff --git a/chainspec.go b/chainspec.go index efc68590b..ba2c86fe1 100644 --- a/chainspec.go +++ b/chainspec.go @@ -28,10 +28,11 @@ type ChainSpec struct { // Must be set. Version string - // GasAdjustment and NoHostMount are pointers in ChainSpec + // GasAdjustment, NoHostMount and UsingNewGenesisCommand are pointers in ChainSpec // so zero-overrides can be detected from omitted overrides. - GasAdjustment *float64 - NoHostMount *bool + GasAdjustment *float64 + NoHostMount *bool + UsingNewGenesisCommand *bool // Embedded ChainConfig to allow for simple JSON definition of a ChainSpec. ibc.ChainConfig @@ -141,6 +142,9 @@ func (s *ChainSpec) applyConfigOverrides(cfg ibc.ChainConfig) (*ibc.ChainConfig, if s.ModifyGenesis != nil { cfg.ModifyGenesis = s.ModifyGenesis } + if s.UsingNewGenesisCommand != nil { + cfg.UsingNewGenesisCommand = *s.UsingNewGenesisCommand + } // Set the version depending on the chain type. switch cfg.Type { diff --git a/ibc/types.go b/ibc/types.go index 0f6f4c2e8..3a25d4aed 100644 --- a/ibc/types.go +++ b/ibc/types.go @@ -40,6 +40,8 @@ type ChainConfig struct { ConfigFileOverrides map[string]any // Non-nil will override the encoding config, used for cosmos chains only. EncodingConfig *testutil.TestEncodingConfig + + UsingNewGenesisCommand bool `yaml:"using-new-genesis-command"` } func (c ChainConfig) Clone() ChainConfig { From ebae4ae49729b12d12662db89dea56a25824d529 Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Sun, 29 Jan 2023 23:59:06 +0100 Subject: [PATCH 2/3] Remove logging and add some basic documentation for UsingNewGenesisCommand --- chain/cosmos/chain_node.go | 3 --- ibc/types.go | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 9170bc26b..bfe9b2492 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -558,10 +558,7 @@ func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, gene var command []string if tn.Chain.Config().UsingNewGenesisCommand { - tn.logger().Info("add-genesis-account with new genesis command") command = append(command, "genesis") - } else { - tn.logger().Info("add-genesis-account WITHOUT new genesis command") } command = append(command, "add-genesis-account", address, amount) diff --git a/ibc/types.go b/ibc/types.go index 3a25d4aed..810d17e32 100644 --- a/ibc/types.go +++ b/ibc/types.go @@ -40,7 +40,7 @@ type ChainConfig struct { ConfigFileOverrides map[string]any // Non-nil will override the encoding config, used for cosmos chains only. EncodingConfig *testutil.TestEncodingConfig - + // Required when the chain uses the new sub commands for genesis (https://github.com/cosmos/cosmos-sdk/pull/14149) UsingNewGenesisCommand bool `yaml:"using-new-genesis-command"` } From 8d829262478eaa1f1094b63a0e5b44f1ada63b5e Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Thu, 23 Feb 2023 15:29:04 +0100 Subject: [PATCH 3/3] Remove UsingNewGenesisCommand from chainspec + add test --- chainspec.go | 11 ++++------- chainspec_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/chainspec.go b/chainspec.go index e4be7ead1..d40beb214 100644 --- a/chainspec.go +++ b/chainspec.go @@ -28,11 +28,10 @@ type ChainSpec struct { // Must be set. Version string - // GasAdjustment, NoHostMount and UsingNewGenesisCommand are pointers in ChainSpec + // GasAdjustment and NoHostMount are pointers in ChainSpec // so zero-overrides can be detected from omitted overrides. - GasAdjustment *float64 - NoHostMount *bool - UsingNewGenesisCommand *bool + GasAdjustment *float64 + NoHostMount *bool // Embedded ChainConfig to allow for simple JSON definition of a ChainSpec. ibc.ChainConfig @@ -142,9 +141,7 @@ func (s *ChainSpec) applyConfigOverrides(cfg ibc.ChainConfig) (*ibc.ChainConfig, if s.ModifyGenesis != nil { cfg.ModifyGenesis = s.ModifyGenesis } - if s.UsingNewGenesisCommand != nil { - cfg.UsingNewGenesisCommand = *s.UsingNewGenesisCommand - } + cfg.UsingNewGenesisCommand = s.UsingNewGenesisCommand // Set the version depending on the chain type. switch cfg.Type { diff --git a/chainspec_test.go b/chainspec_test.go index cbf0b21b5..24e25f2a3 100644 --- a/chainspec_test.go +++ b/chainspec_test.go @@ -133,6 +133,18 @@ func TestChainSpec_Config(t *testing.T) { require.Equal(t, m, cfg.NoHostMount) }) + + t.Run("UsingNewGenesisCommand", func(t *testing.T) { + require.False(t, baseCfg.UsingNewGenesisCommand) + + s := baseSpec + s.UsingNewGenesisCommand = true + + cfg, err := s.Config(zaptest.NewLogger(t)) + require.NoError(t, err) + + require.True(t, cfg.UsingNewGenesisCommand) + }) }) t.Run("error cases", func(t *testing.T) {