From 47a686107ef6a3da1eca13543713772148c2c7b6 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Wed, 8 Nov 2023 17:25:58 +0530 Subject: [PATCH 1/4] export refactor --- app/export.go | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/app/export.go b/app/export.go index 156f53a60..2598cce96 100644 --- a/app/export.go +++ b/app/export.go @@ -1,6 +1,7 @@ package app import ( + "fmt" "encoding/json" "log" @@ -34,15 +35,12 @@ func (a *App) ExportAppStateAndValidators( } validators, err := staking.WriteValidators(ctx, a.StakingKeeper) - if err != nil { - return servertypes.ExportedApp{}, err - } return servertypes.ExportedApp{ AppState: appState, Validators: validators, Height: height, ConsensusParams: a.BaseApp.GetConsensusParams(ctx), - }, nil + }, err } // prepare for fresh start at zero height @@ -74,20 +72,21 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin // withdraw all validator commission a.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, err := a.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) - if err != nil { - panic(err) - } + _, _ = a.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) return false }) // withdraw all delegator rewards dels := a.StakingKeeper.GetAllDelegations(ctx) for _, delegation := range dels { - _, err := a.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr()) + valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) if err != nil { panic(err) } + + delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) + + _, _ = a.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) } // clear validator slash events @@ -108,14 +107,29 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) a.DistrKeeper.SetFeePool(ctx, feePool) - a.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) + if err := a.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err !=nil { + panic(err) + } return false }) // reinitialize all delegations for _, del := range dels { - a.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) - a.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) + if err != nil { + panic(err) + } + delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress) + + if err := a.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil { + // never called as BeforeDelegationCreated always returns nil + panic(fmt.Errorf("error while incrementing period: %w", err)) + } + + if err := a.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil { + // never called as AfterDelegationModified always returns nil + panic(fmt.Errorf("error while creating a new delegation period record: %w", err)) + } } // reset context height @@ -148,7 +162,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin counter := int16(0) for ; iter.Valid(); iter.Next() { - addr := sdk.ValAddress(iter.Key()[1:]) + addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) validator, found := a.StakingKeeper.GetValidator(ctx, addr) if !found { panic("expected validator, not found") @@ -163,13 +177,14 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin counter++ } - err := iter.Close() - if err != nil { + if err := iter.Close(); err != nil { + a.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err) return } - if _, err := a.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil { - panic(err) + _, err := a.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) + if err != nil { + log.Fatal(err) } /* Handle slashing state. */ From 5e3797b0105cc659dcc13beb33df8d94b6f21077 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Wed, 8 Nov 2023 17:27:20 +0530 Subject: [PATCH 2/4] commit timeout added --- cmd/comdex/root.go | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/cmd/comdex/root.go b/cmd/comdex/root.go index 20c205d0b..8523642bc 100644 --- a/cmd/comdex/root.go +++ b/cmd/comdex/root.go @@ -5,9 +5,11 @@ import ( "io" "os" "path/filepath" + "time" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/prometheus/client_golang/prometheus" tmdb "github.com/cometbft/cometbft-db" @@ -24,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" @@ -72,11 +75,16 @@ func NewRootCmd() (*cobra.Command, comdex.EncodingConfig) { if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } + // 2 seconds + 1 second tendermint = 3 second blocks + timeoutCommit := 2 * time.Second - // bump47: recheck if customTMConfig is required, else replace with nil - customTMConfig := initTendermintConfig() + customAppTemplate, customAppConfig := initAppConfig() + customTMConfig := initTendermintConfig(timeoutCommit) - return server.InterceptConfigsPreRunHandler(cmd, "", nil, customTMConfig) + // Force faster block times + os.Setenv("COMDEX_CONSENSUS_TIMEOUT_COMMIT", cast.ToString(timeoutCommit)) + + return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) }, } @@ -84,16 +92,42 @@ func NewRootCmd() (*cobra.Command, comdex.EncodingConfig) { return root, encodingConfig } -func initTendermintConfig() *tmcfg.Config { +func initTendermintConfig(timeoutCommit time.Duration) *tmcfg.Config { cfg := tmcfg.DefaultConfig() // these values put a higher strain on node memory // cfg.P2P.MaxNumInboundPeers = 100 // cfg.P2P.MaxNumOutboundPeers = 40 + // While this is set, it only applies to new configs. + cfg.Consensus.TimeoutCommit = timeoutCommit + return cfg } +// initAppConfig helps to override default appConfig template and configs. +// return "", nil if no custom configuration is required for the application. +func initAppConfig() (string, interface{}) { + type CustomAppConfig struct { + serverconfig.Config + + Wasm wasmtypes.WasmConfig `mapstructure:"wasm"` + } + + // Optionally allow the chain developer to overwrite the SDK's default + // server config. + srvCfg := serverconfig.DefaultConfig() + + customAppConfig := CustomAppConfig{ + Config: *srvCfg, + Wasm: wasmtypes.DefaultWasmConfig(), + } + + customAppTemplate := serverconfig.DefaultConfigTemplate + wasmtypes.DefaultConfigTemplate() + + return customAppTemplate, customAppConfig +} + func initRootCmd(rootCmd *cobra.Command, encoding comdex.EncodingConfig) { cfg := sdk.GetConfig() cfg.Seal() From bab152e961b40600cb73cfcce9ed26ca11df31c7 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Wed, 8 Nov 2023 18:19:09 +0530 Subject: [PATCH 3/4] v13 testnet plan name changed --- app/upgrades/testnet/v13/constants.go | 2 +- app/upgrades/testnet/v13/upgrades.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/upgrades/testnet/v13/constants.go b/app/upgrades/testnet/v13/constants.go index 58c139077..907aeb69b 100644 --- a/app/upgrades/testnet/v13/constants.go +++ b/app/upgrades/testnet/v13/constants.go @@ -1,7 +1,7 @@ package v13 const ( - UpgradeName = "v13.0.0" + UpgradeName = "v13.1.0" UpgradeHeight = "" UpgradeInfo = `'{ "binaries": { diff --git a/app/upgrades/testnet/v13/upgrades.go b/app/upgrades/testnet/v13/upgrades.go index b46db93d2..a76cd8fed 100644 --- a/app/upgrades/testnet/v13/upgrades.go +++ b/app/upgrades/testnet/v13/upgrades.go @@ -41,7 +41,7 @@ func CreateUpgradeHandlerV13( bandoracleKeeper bandoraclemodulekeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Applying test net upgrade - v.13.0.0") + ctx.Logger().Info("Applying test net upgrade - v.13.1.0") logger := ctx.Logger().With("upgrade", UpgradeName) // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. From fc04056dc5f0200d0f008a92e103f69eef9f54dd Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Wed, 8 Nov 2023 20:29:02 +0530 Subject: [PATCH 4/4] desc updated --- cmd/comdex/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/comdex/root.go b/cmd/comdex/root.go index 8523642bc..edae184a6 100644 --- a/cmd/comdex/root.go +++ b/cmd/comdex/root.go @@ -61,7 +61,7 @@ func NewRootCmd() (*cobra.Command, comdex.EncodingConfig) { cobra.EnableCommandSorting = false root := &cobra.Command{ Use: "comdex", - Short: "Comdex - Decentralised Synthetic Asset Exchange", + Short: "Comdex - DeFi Infrastructure layer for the Cosmos ecosystem", PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) if err != nil {