diff --git a/app/consumer/app.go b/app/consumer/app.go index 8ea0a77a30..f06246f38d 100644 --- a/app/consumer/app.go +++ b/app/consumer/app.go @@ -101,11 +101,32 @@ import ( ) const ( - AppName = "interchain-security-c" - upgradeName = "ics-v1-to-v2" - AccountAddressPrefix = "cosmos" + AppName = "interchain-security-c" + upgradeName = "ics-v1-to-v2" + + Bech32MainPrefix = "consumer" + Bech32PrefixAccAddr = Bech32MainPrefix + Bech32PrefixAccPub = Bech32MainPrefix + sdk.PrefixPublic + Bech32PrefixValAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + Bech32PrefixValPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic + Bech32PrefixConsAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + Bech32PrefixConsPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic ) +func init() { + userHomeDir, err := os.UserHomeDir() + if err != nil { + stdlog.Println("Failed to get home dir %2", err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName) + cfg := sdk.GetConfig() + cfg.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32MainPrefix+"pub") + cfg.SetBech32PrefixForValidator(Bech32MainPrefix+"valoper", Bech32MainPrefix+"valoperpub") + cfg.SetBech32PrefixForConsensusNode(Bech32MainPrefix+"valcons", Bech32MainPrefix+"valconspub") + cfg.Seal() +} + var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -194,15 +215,6 @@ type App struct { // nolint: golint configurator module.Configurator } -func init() { - userHomeDir, err := os.UserHomeDir() - if err != nil { - stdlog.Println("Failed to get home dir %2", err) - } - - DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName) -} - // New returns a reference to an initialized App. func New( logger log.Logger, @@ -281,8 +293,8 @@ func New( runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, - authcodec.NewBech32Codec(sdk.Bech32MainPrefix), - sdk.Bech32MainPrefix, + authcodec.NewBech32Codec(Bech32MainPrefix), + Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) @@ -388,8 +400,8 @@ func New( app.IBCKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), - authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), - authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + authcodec.NewBech32Codec(Bech32PrefixValAddr), + authcodec.NewBech32Codec(Bech32PrefixConsAddr), ) // register slashing module Slashing hooks to the consumer keeper @@ -799,9 +811,9 @@ func (app *App) AutoCliOpts() autocli.AppOptions { return autocli.AppOptions{ Modules: modules, - AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), - ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), - ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + AddressCodec: authcodec.NewBech32Codec(Bech32PrefixAccAddr), + ValidatorAddressCodec: authcodec.NewBech32Codec(Bech32PrefixValAddr), + ConsensusAddressCodec: authcodec.NewBech32Codec(Bech32PrefixConsAddr), } } diff --git a/cmd/interchain-security-cd/cmd/root.go b/cmd/interchain-security-cd/cmd/root.go index 7166dc0f8b..6b8c397cad 100644 --- a/cmd/interchain-security-cd/cmd/root.go +++ b/cmd/interchain-security-cd/cmd/root.go @@ -21,7 +21,6 @@ import ( serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -195,9 +194,6 @@ lru_size = 0` } func initRootCmd(rootCmd *cobra.Command, encodingConfig appencoding.EncodingConfig) { - cfg := sdk.GetConfig() - cfg.Seal() - rootCmd.AddCommand( genutilcli.InitCmd(consumer.ModuleBasics, consumer.DefaultNodeHome), debug.Cmd(), diff --git a/cmd/interchain-security-pd/cmd/root.go b/cmd/interchain-security-pd/cmd/root.go index 5299eeb983..79856c9399 100644 --- a/cmd/interchain-security-pd/cmd/root.go +++ b/cmd/interchain-security-pd/cmd/root.go @@ -65,7 +65,7 @@ func NewRootCmd() *cobra.Command { rootCmd := &cobra.Command{ Use: "simd", Short: "simulation app", - SilenceErrors: false, + SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { // set the default command outputs cmd.SetOut(cmd.OutOrStdout()) diff --git a/x/ccv/consumer/keeper/relay.go b/x/ccv/consumer/keeper/relay.go index 0b59e2de06..da412e982c 100644 --- a/x/ccv/consumer/keeper/relay.go +++ b/x/ccv/consumer/keeper/relay.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "strconv" @@ -217,7 +218,7 @@ func (k Keeper) SendPackets(ctx sdk.Context) { k.GetCCVTimeoutPeriod(ctx), ) if err != nil { - if clienttypes.ErrClientNotActive.Is(err) { + if errors.Is(err, clienttypes.ErrClientNotActive) { // IBC client is expired! // leave the packet data stored to be sent once the client is upgraded k.Logger(ctx).Info("IBC client is expired, cannot send IBC packet; leaving packet data stored:", "type", p.Type.String()) diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index a9c492b150..d1167903a5 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "strconv" "time" @@ -261,7 +262,7 @@ func (k Keeper) MakeConsumerGenesis( } val, err := k.stakingKeeper.GetValidator(ctx, addr) - if err != nil && stakingtypes.ErrNoValidatorFound.Is(err) { + if err != nil && errors.Is(err, stakingtypes.ErrNoValidatorFound) { return gen, nil, errorsmod.Wrapf(stakingtypes.ErrNoValidatorFound, "error getting validator from LastValidatorPowers") } else if err != nil { return gen, nil, errorsmod.Wrapf(err, "error getting validator from LastValidatorPowers") diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 659831f8d4..ab594f6928 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "strconv" @@ -88,10 +89,10 @@ func (k Keeper) completeMaturedUnbondingOps(ctx sdk.Context) { // Attempt to complete unbonding in staking module err := k.stakingKeeper.UnbondingCanComplete(ctx, id) if err != nil { - if stakingtypes.ErrUnbondingNotFound.Is(err) { + if errors.Is(err, stakingtypes.ErrNoUnbondingDelegation) { // The unbonding was not found. - unbondingType, err := k.stakingKeeper.GetUnbondingType(ctx, id) - if err == nil && unbondingType == stakingtypes.UnbondingType_UnbondingDelegation { + unbondingType, errGet := k.stakingKeeper.GetUnbondingType(ctx, id) + if errGet == nil && unbondingType == stakingtypes.UnbondingType_UnbondingDelegation { // If this is an unbonding delegation, it may have been removed // after through a CancelUnbondingDelegation message k.Logger(ctx).Debug("unbonding delegation was already removed:", "unbondingID", id) @@ -185,7 +186,7 @@ func (k Keeper) SendVSCPacketsToChain(ctx sdk.Context, chainID, channelID string k.GetCCVTimeoutPeriod(ctx), ) if err != nil { - if clienttypes.ErrClientNotActive.Is(err) { + if errors.Is(err, clienttypes.ErrClientNotActive) { // IBC client is expired! // leave the packet data stored to be sent once the client is upgraded // the client cannot expire during iteration (in the middle of a block) @@ -393,7 +394,7 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data ccv.Slas // Obtain validator from staking keeper validator, err := k.stakingKeeper.GetValidatorByConsAddr(ctx, providerConsAddr.ToSdkConsAddr()) - if err != nil && stakingtypes.ErrNoValidatorFound.Is(err) { + if err != nil && errors.Is(err, stakingtypes.ErrNoValidatorFound) { k.Logger(ctx).Error("validator not found or is unbonded", "validator", providerConsAddr.String()) return } @@ -474,7 +475,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { "chainID", initTimeoutTimestamp.ChainId) err := k.StopConsumerChain(ctx, initTimeoutTimestamp.ChainId, false) if err != nil { - if providertypes.ErrConsumerChainNotFound.Is(err) { + if errors.Is(err, providertypes.ErrConsumerChainNotFound) { // consumer chain not found continue } @@ -501,7 +502,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { ) err := k.StopConsumerChain(ctx, channelToChain.ChainId, true) if err != nil { - if providertypes.ErrConsumerChainNotFound.Is(err) { + if errors.Is(err, providertypes.ErrConsumerChainNotFound) { // consumer chain not found continue }