Skip to content

Commit

Permalink
fix(cosmos): don't twiddle the genesis params, set them explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Dec 9, 2021
1 parent 71f8101 commit c9c8d81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
31 changes: 2 additions & 29 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/rakyll/statik/fs"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -610,43 +611,15 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R
return app.mm.EndBlock(ctx, req)
}

func updateTransferPort(gs GenesisState, reservedPort, newPort string) error {
var transferGenesis ibctransfertypes.GenesisState
if err := json.Unmarshal(gs[ibctransfertypes.ModuleName], &transferGenesis); err != nil {
return err
}
if len(transferGenesis.PortId) > 0 && transferGenesis.PortId != reservedPort {
// Already not the reserved port name.
return nil
}
// Change the listening IBC port to avoid conflict.
transferGenesis.PortId = newPort
transferGenesisBytes, err := json.Marshal(transferGenesis)
if err != nil {
return err
}
gs[ibctransfertypes.ModuleName] = transferGenesisBytes
return nil
}

// InitChainer application update at chain initialization
func (app *GaiaApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
if err := updateTransferPort(genesisState, "transfer", "cosmos-transfer"); err != nil {
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
res := app.mm.InitGenesis(ctx, app.appCodec, genesisState)

// Set Historical infos in InitChain to ignore genesis params
// This is needed for IBC connections not to time out easily
stakingParams := app.StakingKeeper.GetParams(ctx)
stakingParams.HistoricalEntries = 10000
app.StakingKeeper.SetParams(ctx, stakingParams)

// Agoric: report the genesis time explicitly.
genTime := req.GetTime()
if genTime.After(time.Now()) {
Expand Down
16 changes: 16 additions & 0 deletions packages/agoric-cli/src/chain-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ export const CENTRAL_DENOM = 'urun';
export const MINT_DENOM = 'ubld';
export const STAKING_DENOM = 'ubld';
export const STAKING_MAX_VALIDATORS = 150;
// Required for IBC connections not to time out.
export const STAKING_MIN_HISTORICAL_ENTRIES = 10000;

// We reserve the default `transfer` IBC port for Pegasus (JS-level ERTP
// assets). The `cosmos-transfer` IBC port is used for ibc-go (Cosmos-level
// prefixed string token denominations).
export const COSMOS_TRANSFER_PORT_ID = 'cosmos-transfer';

export const DENOM_METADATA = [
{
Expand Down Expand Up @@ -178,6 +185,15 @@ export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {

genesis.app_state.staking.params.bond_denom = STAKING_DENOM;
genesis.app_state.staking.params.max_validators = STAKING_MAX_VALIDATORS;
const {
historical_entries: existingHistoricalEntries = 0,
} = genesis.app_state.staking.params;
genesis.app_state.staking.params.historical_entries = Math.max(
existingHistoricalEntries,
STAKING_MIN_HISTORICAL_ENTRIES,
);

genesis.app_state.transfer.port_id = COSMOS_TRANSFER_PORT_ID;

// We scale this parameter according to our own block cadence, so
// that we tolerate the same downtime as the old genesis.
Expand Down

0 comments on commit c9c8d81

Please sign in to comment.