diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 0242a2d76..668750c2d 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -817,9 +817,13 @@ type GenesisValidators struct { Power string `json:"power"` PubKey GenesisValidatorPubKey `json:"pub_key"` } -type GenesisFile struct { +type GenesisConsensus struct { Validators []GenesisValidators `json:"validators"` } +type GenesisFile struct { + V47Validators []GenesisValidators `json:"validators"` // SDK v47 backwards Compatability + Consensus GenesisConsensus `json:"consensus"` // v47+ +} type ValidatorWithIntPower struct { Address string diff --git a/chain/cosmos/cosmos_genesis.go b/chain/cosmos/cosmos_genesis.go index 565dc6901..1ed33d06c 100644 --- a/chain/cosmos/cosmos_genesis.go +++ b/chain/cosmos/cosmos_genesis.go @@ -26,21 +26,19 @@ import ( func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) error { chainCfg := c.Config() - // genesisAmount := types.Coin{ - // Amount: types.NewInt(10_000_000_000_000), - // Denom: chainCfg.Denom, - // } + // call StartWithGenesisFile here instead if something is changed + overGen := chainCfg.OverrideGenesisStart + if overGen.GenesisFilePath != "" { + c.log.Info("Starting with genesis file", zap.String("name", c.cfg.Name), zap.String("path", overGen.GenesisFilePath)) - // genesisSelfDelegation := types.Coin{ - // Amount: types.NewInt(5_000_000_000_000), - // Denom: chainCfg.Denom, - // } + if overGen.Client == nil || overGen.NetworkID == "" { + panic("BUG: OverrideGenesisStart is nil when using GenesisFilePath") + } - // if chainCfg.ModifyGenesisAmounts != nil { - // genesisAmount, genesisSelfDelegation = chainCfg.ModifyGenesisAmounts() - // } + return c.StartWithGenesisFile(ctx, testName, overGen.Client, overGen.NetworkID, overGen.GenesisFilePath) + } - // genesisAmounts := []types.Coin{genesisAmount} + c.log.Info("Starting chain", zap.String("name", c.cfg.Name)) decimalPow := int64(math.Pow10(int(*chainCfg.CoinDecimals))) genesisAmounts := make([][]types.Coin, len(c.Validators)) @@ -60,9 +58,7 @@ func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGene return err } - // TODO: this was changed to chain, we good? if c.cfg.PreGenesis != nil { - // err := c.cfg.PreGenesis(chainCfg) err := c.cfg.PreGenesis(c) if err != nil { return err @@ -133,9 +129,14 @@ func (c *CosmosChain) StartWithGenesisFile( return err } - genesisValidators := genesisFile.Validators + // TODO: SDK v47 check here (genesisFile.V47Validators) + genesisValidators := genesisFile.Consensus.Validators totalPower := int64(0) + if len(genesisValidators) == 0 { + panic("BUG: genesisValidators is empty with custom genesis file start.") + } + validatorsWithPower := make([]ValidatorWithIntPower, 0) for _, genesisValidator := range genesisValidators { @@ -178,6 +179,9 @@ func (c *CosmosChain) StartWithGenesisFile( } c.NumValidators = len(activeVals) + if c.NumValidators == 0 { + panic("BUG: c.NumValidators is 0 with custom genesis file start.") + } if err := c.initializeChainNodes(ctx, testName, client, network); err != nil { return err @@ -313,7 +317,7 @@ func (c *CosmosChain) startWithFinalGenesis(ctx context.Context, genbz []byte) e } // Wait for blocks before considering the chains "started" - return testutil.WaitForBlocks(ctx, 2, c.getFullNode()) + return testutil.WaitForBlocks(ctx, 2, c.GetNode()) } // Bootstraps the chain and starts it from genesis diff --git a/examples/cosmos/delete_me_test.go b/examples/cosmos/delete_me_test.go index 6e49b26e6..a70254e04 100644 --- a/examples/cosmos/delete_me_test.go +++ b/examples/cosmos/delete_me_test.go @@ -23,6 +23,14 @@ func TestSingleValBenchmark(t *testing.T) { ctx := context.Background() + client, network := interchaintest.DockerSetup(t) + icOpts := interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + SkipPathCreation: false, + } + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ { Name: "ibc-go-simd", @@ -34,6 +42,11 @@ func TestSingleValBenchmark(t *testing.T) { CoinType: "118", ModifyGenesis: cosmos.ModifyGenesis(sdk47Genesis), GasAdjustment: 1.5, + OverrideGenesisStart: ibc.GenesisFileStart{ + GenesisFilePath: path.Join(t.Name(), "export.json"), // TODO: if this is not there, do we continue as normal? (or add an option here for PanicOnMissing) + Client: client, + NetworkID: network, + }, }, NumValidators: &numValsOne, NumFullNodes: &numFullNodesZero, @@ -45,8 +58,6 @@ func TestSingleValBenchmark(t *testing.T) { require.NoError(t, err) chainA := chains[0].(*cosmos.CosmosChain) - client, network := interchaintest.DockerSetup(t) - ic := interchaintest.NewInterchain(). AddChain(chainA) @@ -54,12 +65,7 @@ func TestSingleValBenchmark(t *testing.T) { eRep := rep.RelayerExecReporter(t) now = time.Now() - require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ - TestName: t.Name(), - Client: client, - NetworkID: network, - SkipPathCreation: false, - })) + require.NoError(t, ic.Build(ctx, eRep, icOpts)) _, err = performExport(t, ctx, chainA, "export.json") require.NoError(t, err) diff --git a/ibc/types.go b/ibc/types.go index d17415cbd..6bd1650fe 100644 --- a/ibc/types.go +++ b/ibc/types.go @@ -80,6 +80,14 @@ type ChainConfig struct { AdditionalStartArgs []string // Environment variables for chain nodes Env []string + // Genesis file path and information for the chain to start with. + OverrideGenesisStart GenesisFileStart `yaml:"genesis-file-start"` +} + +type GenesisFileStart struct { + GenesisFilePath string `yaml:"genesis-file-path"` + Client *client.Client `yaml:"-" json:"-"` + NetworkID string `yaml:"network-id"` } func (c ChainConfig) Clone() ChainConfig { @@ -231,6 +239,10 @@ func (c ChainConfig) MergeChainSpecConfig(other ChainConfig) ChainConfig { c.InterchainSecurityConfig = other.InterchainSecurityConfig } + if !cmp.Equal(other.OverrideGenesisStart, GenesisFileStart{}) { + c.OverrideGenesisStart = other.OverrideGenesisStart + } + return c }