Skip to content

Commit

Permalink
OverrideGenesisStart
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 13, 2024
1 parent 8be1345 commit e560a39
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
6 changes: 5 additions & 1 deletion chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 20 additions & 16 deletions chain/cosmos/cosmos_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions examples/cosmos/delete_me_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -45,21 +58,14 @@ func TestSingleValBenchmark(t *testing.T) {
require.NoError(t, err)
chainA := chains[0].(*cosmos.CosmosChain)

client, network := interchaintest.DockerSetup(t)

ic := interchaintest.NewInterchain().
AddChain(chainA)

rep := testreporter.NewNopReporter()
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)
Expand Down
12 changes: 12 additions & 0 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit e560a39

Please sign in to comment.