diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 5fc09e5e028..56a0d529a8a 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -1,10 +1,11 @@ package controller import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -84,7 +85,7 @@ func (im IBCMiddleware) OnChanOpenTry( counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanOpenAck implements the IBCMiddleware interface @@ -127,7 +128,7 @@ func (im IBCMiddleware) OnChanOpenConfirm( portID, channelID string, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanCloseInit implements the IBCMiddleware interface @@ -137,7 +138,7 @@ func (im IBCMiddleware) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for interchain account channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCMiddleware interface @@ -168,7 +169,7 @@ func (im IBCMiddleware) OnRecvPacket( packet channeltypes.Packet, _ sdk.AccAddress, ) ibcexported.Acknowledgement { - err := sdkerrors.Wrapf(icatypes.ErrInvalidChannelFlow, "cannot receive packet on controller chain") + err := errorsmod.Wrapf(icatypes.ErrInvalidChannelFlow, "cannot receive packet on controller chain") ack := channeltypes.NewErrorAcknowledgement(err) keeper.EmitAcknowledgementEvent(ctx, packet, ack, err) return ack diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index c1418595508..5044e50b962 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -1,10 +1,11 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/internal/logging" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -34,7 +35,7 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, } if k.IsMiddlewareDisabled(ctx, portID, connectionID) && !k.IsActiveChannelClosed(ctx, connectionID, portID) { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") } k.SetMiddlewareEnabled(ctx, portID, connectionID) @@ -53,16 +54,16 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, // if there is an active channel for this portID / connectionID return an error activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if found { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s on connection %s", activeChannelID, portID, connectionID) + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s on connection %s", activeChannelID, portID, connectionID) } switch { case k.portKeeper.IsBound(ctx, portID) && !k.IsBound(ctx, portID): - return "", sdkerrors.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) + return "", errorsmod.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) case !k.portKeeper.IsBound(ctx, portID): cap := k.BindPort(ctx, portID) if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil { - return "", sdkerrors.Wrapf(err, "unable to bind to newly generated portID: %s", portID) + return "", errorsmod.Wrapf(err, "unable to bind to newly generated portID: %s", portID) } } @@ -82,7 +83,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, firstMsgResponse := res.MsgResponses[0] channelOpenInitResponse, ok := firstMsgResponse.GetCachedValue().(*channeltypes.MsgChannelOpenInitResponse) if !ok { - return "", sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "failed to covert %T message response to %T", firstMsgResponse.GetCachedValue(), &channeltypes.MsgChannelOpenInitResponse{}) + return "", errorsmod.Wrapf(ibcerrors.ErrInvalidType, "failed to covert %T message response to %T", firstMsgResponse.GetCachedValue(), &channeltypes.MsgChannelOpenInitResponse{}) } return channelOpenInitResponse.ChannelId, nil diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 51644e4050e..916f32382f2 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -30,15 +30,15 @@ func (k Keeper) OnChanOpenInit( version string, ) (string, error) { if order != channeltypes.ORDERED { - return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) } if !strings.HasPrefix(portID, icatypes.ControllerPortPrefix) { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) + return "", errorsmod.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) } if counterparty.PortId != icatypes.HostPortID { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, counterparty.PortId) + return "", errorsmod.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, counterparty.PortId) } var metadata icatypes.Metadata @@ -51,7 +51,7 @@ func (k Keeper) OnChanOpenInit( metadata = icatypes.NewDefaultMetadata(connectionHops[0], connection.GetCounterparty().GetConnectionID()) } else { if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(version), &metadata); err != nil { - return "", sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") + return "", errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") } } @@ -67,7 +67,7 @@ func (k Keeper) OnChanOpenInit( } if channel.State == channeltypes.OPEN { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) @@ -76,7 +76,7 @@ func (k Keeper) OnChanOpenInit( } if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") + return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") } } @@ -92,25 +92,25 @@ func (k Keeper) OnChanOpenAck( counterpartyVersion string, ) error { if portID == icatypes.HostPortID { - return sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "portID cannot be host chain port ID: %s", icatypes.HostPortID) + return errorsmod.Wrapf(icatypes.ErrInvalidControllerPort, "portID cannot be host chain port ID: %s", icatypes.HostPortID) } if !strings.HasPrefix(portID, icatypes.ControllerPortPrefix) { - return sdkerrors.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) + return errorsmod.Wrapf(icatypes.ErrInvalidControllerPort, "expected %s{owner-account-address}, got %s", icatypes.ControllerPortPrefix, portID) } var metadata icatypes.Metadata if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &metadata); err != nil { - return sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") + return errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") } if activeChannelID, found := k.GetOpenActiveChannel(ctx, metadata.ControllerConnectionId, portID); found { - return sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s", activeChannelID, portID) + return errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s", activeChannelID, portID) } channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) } if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, channel.ConnectionHops, metadata); err != nil { @@ -118,7 +118,7 @@ func (k Keeper) OnChanOpenAck( } if strings.TrimSpace(metadata.Address) == "" { - return sdkerrors.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be empty") + return errorsmod.Wrap(icatypes.ErrInvalidAccountAddress, "interchain account address cannot be empty") } k.SetActiveChannelID(ctx, metadata.ControllerConnectionId, portID, channelID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 5e576bba2a8..061a20a233c 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -5,10 +5,10 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" @@ -69,7 +69,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { func (k Keeper) GetConnectionID(ctx sdk.Context, portID, channelID string) (string, error) { channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { - return "", sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return "", errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } return channel.ConnectionHops[0], nil } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go index 0b9dae6cbcb..92a3a21d8e3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/migrations.go @@ -3,8 +3,8 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" @@ -33,13 +33,13 @@ func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error { capability, found := m.keeper.scopedKeeper.GetCapability(ctx, name) if !found { logger.Error(fmt.Sprintf("failed to find capability: %s", name)) - return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) + return errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) } isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, capability, name) if !isAuthenticated { logger.Error(fmt.Sprintf("expected capability owner: %s", controllertypes.SubModuleName)) - return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", controllertypes.SubModuleName) + return errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", controllertypes.SubModuleName) } m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ConnectionHops[0]) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go index ed953fd8c1e..a41eae140a3 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/msg_server.go @@ -3,8 +3,8 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -32,7 +32,7 @@ func (s msgServer) RegisterInterchainAccount(goCtx context.Context, msg *types.M } if s.IsMiddlewareEnabled(ctx, portID, msg.ConnectionId) && !s.IsActiveChannelClosed(ctx, msg.ConnectionId, portID) { - return nil, sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") + return nil, errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel is already active or a handshake is in flight") } s.SetMiddlewareDisabled(ctx, portID, msg.ConnectionId) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index cb2f85dcaf8..b8a5996a5a0 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -1,8 +1,8 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -28,12 +28,12 @@ func (k Keeper) SendTx(ctx sdk.Context, _ *capabilitytypes.Capability, connectio func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) if !found { - return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) + return 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) } chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, activeChannelID)) if !found { - return 0, sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", host.ChannelCapabilityPath(portID, activeChannelID)) + return 0, errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", host.ChannelCapabilityPath(portID, activeChannelID)) } if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp { @@ -41,7 +41,7 @@ func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketDa } if err := icaPacketData.ValidateBasic(); err != nil { - return 0, sdkerrors.Wrap(err, "invalid interchain account packet data") + return 0, errorsmod.Wrap(err, "invalid interchain account packet data") } sequence, err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes()) diff --git a/modules/apps/27-interchain-accounts/controller/types/errors.go b/modules/apps/27-interchain-accounts/controller/types/errors.go index 3a0ade00fe1..2f2d5595e21 100644 --- a/modules/apps/27-interchain-accounts/controller/types/errors.go +++ b/modules/apps/27-interchain-accounts/controller/types/errors.go @@ -1,10 +1,10 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // ICA Controller sentinel errors var ( - ErrControllerSubModuleDisabled = sdkerrors.Register(SubModuleName, 2, "controller submodule is disabled") + ErrControllerSubModuleDisabled = errorsmod.Register(SubModuleName, 2, "controller submodule is disabled") ) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index e01a3798203..5837b76a01b 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -24,11 +25,11 @@ func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRe // ValidateBasic implements sdk.Msg func (msg MsgRegisterInterchainAccount) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(msg.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid connection ID") + return errorsmod.Wrap(err, "invalid connection ID") } if strings.TrimSpace(msg.Owner) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "owner address cannot be empty") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "owner address cannot be empty") } return nil @@ -57,19 +58,19 @@ func NewMsgSendTx(owner, connectionID string, relativeTimeoutTimestamp uint64, p // ValidateBasic implements sdk.Msg func (msg MsgSendTx) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(msg.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid connection ID") + return errorsmod.Wrap(err, "invalid connection ID") } if strings.TrimSpace(msg.Owner) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "owner address cannot be empty") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "owner address cannot be empty") } if err := msg.PacketData.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "invalid interchain account packet data") + return errorsmod.Wrap(err, "invalid interchain account packet data") } if msg.RelativeTimeout == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "relative timeout cannot be zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "relative timeout cannot be zero") } return nil diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 153a15d3758..1620ce87bc5 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -3,10 +3,11 @@ package host import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -37,7 +38,7 @@ func (im IBCModule) OnChanOpenInit( counterparty channeltypes.Counterparty, version string, ) (string, error) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanOpenTry implements the IBCModule interface @@ -66,7 +67,7 @@ func (im IBCModule) OnChanOpenAck( counterpartyChannelID string, counterpartyVersion string, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") } // OnChanOpenAck implements the IBCModule interface @@ -89,7 +90,7 @@ func (im IBCModule) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for interchain account channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCModule interface @@ -136,7 +137,7 @@ func (im IBCModule) OnAcknowledgementPacket( acknowledgement []byte, relayer sdk.AccAddress, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "cannot receive acknowledgement on a host channel end, a host chain does not send a packet over the channel") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "cannot receive acknowledgement on a host channel end, a host chain does not send a packet over the channel") } // OnTimeoutPacket implements the IBCModule interface @@ -145,5 +146,5 @@ func (im IBCModule) OnTimeoutPacket( packet channeltypes.Packet, relayer sdk.AccAddress, ) error { - return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "cannot cause a packet timeout on a host channel end, a host chain does not send a packet over the channel") + return errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "cannot cause a packet timeout on a host channel end, a host chain does not send a packet over the channel") } diff --git a/modules/apps/27-interchain-accounts/host/keeper/account.go b/modules/apps/27-interchain-accounts/host/keeper/account.go index 7af16d0911a..3b02d3c7cae 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/account.go +++ b/modules/apps/27-interchain-accounts/host/keeper/account.go @@ -1,8 +1,8 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -15,7 +15,7 @@ func (k Keeper) createInterchainAccount(ctx sdk.Context, connectionID, controlle accAddress := icatypes.GenerateAddress(ctx, connectionID, controllerPortID) if acc := k.accountKeeper.GetAccount(ctx, accAddress); acc != nil { - return nil, sdkerrors.Wrapf(icatypes.ErrAccountAlreadyExist, "existing account for newly generated interchain account address %s", accAddress) + return nil, errorsmod.Wrapf(icatypes.ErrAccountAlreadyExist, "existing account for newly generated interchain account address %s", accAddress) } interchainAccount := icatypes.NewInterchainAccount( diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 9f31c787ff3..8f3f4a0ccff 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -3,8 +3,8 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" @@ -27,16 +27,16 @@ func (k Keeper) OnChanOpenTry( counterpartyVersion string, ) (string, error) { if order != channeltypes.ORDERED { - return "", sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order) } if portID != icatypes.HostPortID { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, portID) + return "", errorsmod.Wrapf(icatypes.ErrInvalidHostPort, "expected %s, got %s", icatypes.HostPortID, portID) } var metadata icatypes.Metadata if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &metadata); err != nil { - return "", sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") + return "", errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") } if err := icatypes.ValidateHostMetadata(ctx, k.channelKeeper, connectionHops, metadata); err != nil { @@ -51,7 +51,7 @@ func (k Keeper) OnChanOpenTry( } if channel.State == channeltypes.OPEN { - return "", sdkerrors.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) + return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) @@ -60,14 +60,14 @@ func (k Keeper) OnChanOpenTry( } if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { - return "", sdkerrors.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") + return "", errorsmod.Wrap(icatypes.ErrInvalidVersion, "previous active channel metadata does not match provided version") } } // On the host chain the capability may only be claimed during the OnChanOpenTry // The capability being claimed in OpenInit is for a controller chain (the port is different) if err := k.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { - return "", sdkerrors.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) + return "", errorsmod.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID) } var ( @@ -81,7 +81,7 @@ func (k Keeper) OnChanOpenTry( k.Logger(ctx).Info("reopening existing interchain account", "address", interchainAccAddr) accAddress = sdk.MustAccAddressFromBech32(interchainAccAddr) if _, ok := k.accountKeeper.GetAccount(ctx, accAddress).(*icatypes.InterchainAccount); !ok { - return "", sdkerrors.Wrapf(icatypes.ErrInvalidAccountReopening, "existing account address %s, does not have interchain account type", accAddress) + return "", errorsmod.Wrapf(icatypes.ErrInvalidAccountReopening, "existing account address %s, does not have interchain account type", accAddress) } } else { @@ -109,7 +109,7 @@ func (k Keeper) OnChanOpenConfirm( ) error { channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) + return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "failed to retrieve channel %s on port %s", channelID, portID) } // It is assumed the controller chain will not allow multiple active channels to be created for the same connectionID/portID diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index 2d3c7eafcff..4e620291a6b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -1,11 +1,12 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/gogoproto/proto" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -18,19 +19,19 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byt if err := icatypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { // UnmarshalJSON errors are indeterminate and therefore are not wrapped and included in failed acks - return nil, sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data") + return nil, errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data") } switch data.Type { case icatypes.EXECUTE_TX: msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data) if err != nil { - return nil, sdkerrors.Wrapf(err, "failed to deserialize interchain account transaction") + return nil, errorsmod.Wrapf(err, "failed to deserialize interchain account transaction") } txResponse, err := k.executeTx(ctx, packet.SourcePort, packet.DestinationPort, packet.DestinationChannel, msgs) if err != nil { - return nil, sdkerrors.Wrapf(err, "failed to execute interchain account transaction") + return nil, errorsmod.Wrapf(err, "failed to execute interchain account transaction") } return txResponse, nil default: @@ -76,7 +77,7 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str txResponse, err := proto.Marshal(txMsgData) if err != nil { - return nil, sdkerrors.Wrap(err, "failed to marshal tx data") + return nil, errorsmod.Wrap(err, "failed to marshal tx data") } return txResponse, nil @@ -87,18 +88,18 @@ func (k Keeper) executeTx(ctx sdk.Context, sourcePort, destPort, destChannel str func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, connectionID, portID string) error { interchainAccountAddr, found := k.GetInterchainAccountAddress(ctx, connectionID, portID) if !found { - return sdkerrors.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) + return errorsmod.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) } allowMsgs := k.GetAllowMessages(ctx) for _, msg := range msgs { if !types.ContainsMsgType(allowMsgs, msg) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg)) + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg)) } for _, signer := range msg.GetSigners() { if interchainAccountAddr != signer.String() { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "unexpected signer address: expected %s, got %s", interchainAccountAddr, signer.String()) + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "unexpected signer address: expected %s, got %s", interchainAccountAddr, signer.String()) } } } @@ -125,7 +126,7 @@ func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error // Each individual sdk.Result has exactly one Msg response. We aggregate here. msgResponse := res.MsgResponses[0] if msgResponse == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "got nil Msg response for msg %s", sdk.MsgTypeURL(msg)) + return nil, errorsmod.Wrapf(ibcerrors.ErrLogic, "got nil Msg response for msg %s", sdk.MsgTypeURL(msg)) } return msgResponse, nil diff --git a/modules/apps/27-interchain-accounts/host/types/errors.go b/modules/apps/27-interchain-accounts/host/types/errors.go index b16b4093e5e..adba00f6596 100644 --- a/modules/apps/27-interchain-accounts/host/types/errors.go +++ b/modules/apps/27-interchain-accounts/host/types/errors.go @@ -1,10 +1,10 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // ICA Host sentinel errors var ( - ErrHostSubModuleDisabled = sdkerrors.Register(SubModuleName, 2, "host submodule is disabled") + ErrHostSubModuleDisabled = errorsmod.Register(SubModuleName, 2, "host submodule is disabled") ) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index 8c44b277a9f..472b509818c 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -5,10 +5,10 @@ import ( "regexp" "strings" + errorsmod "cosmossdk.io/errors" crypto "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkaddress "github.com/cosmos/cosmos-sdk/types/address" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" yaml "gopkg.in/yaml.v2" ) @@ -56,7 +56,7 @@ func GenerateAddress(ctx sdk.Context, connectionID, portID string) sdk.AccAddres // on address length and character set func ValidateAccountAddress(addr string) error { if !isValidAddr(addr) || len(addr) > DefaultMaxAddrLength { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidAccountAddress, "address must contain strictly alphanumeric characters, not exceeding %d characters in length", DefaultMaxAddrLength, @@ -76,18 +76,18 @@ func NewInterchainAccount(ba *authtypes.BaseAccount, accountOwner string) *Inter // SetPubKey implements the authtypes.AccountI interface func (ia InterchainAccount) SetPubKey(pubKey crypto.PubKey) error { - return sdkerrors.Wrap(ErrUnsupported, "cannot set public key for interchain account") + return errorsmod.Wrap(ErrUnsupported, "cannot set public key for interchain account") } // SetSequence implements the authtypes.AccountI interface func (ia InterchainAccount) SetSequence(seq uint64) error { - return sdkerrors.Wrap(ErrUnsupported, "cannot set sequence number for interchain account") + return errorsmod.Wrap(ErrUnsupported, "cannot set sequence number for interchain account") } // Validate implements basic validation of the InterchainAccount func (ia InterchainAccount) Validate() error { if strings.TrimSpace(ia.AccountOwner) == "" { - return sdkerrors.Wrap(ErrInvalidAccountAddress, "AccountOwner cannot be empty") + return errorsmod.Wrap(ErrInvalidAccountAddress, "AccountOwner cannot be empty") } return ia.BaseAccount.Validate() diff --git a/modules/apps/27-interchain-accounts/types/codec.go b/modules/apps/27-interchain-accounts/types/codec.go index f91d3f0ed1a..b0ba7b8902b 100644 --- a/modules/apps/27-interchain-accounts/types/codec.go +++ b/modules/apps/27-interchain-accounts/types/codec.go @@ -1,10 +1,10 @@ package types import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/gogoproto/proto" ) @@ -29,7 +29,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { func SerializeCosmosTx(cdc codec.BinaryCodec, msgs []proto.Message) (bz []byte, err error) { // only ProtoCodec is supported if _, ok := cdc.(*codec.ProtoCodec); !ok { - return nil, sdkerrors.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") + return nil, errorsmod.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") } msgAnys := make([]*codectypes.Any, len(msgs)) @@ -59,7 +59,7 @@ func SerializeCosmosTx(cdc codec.BinaryCodec, msgs []proto.Message) (bz []byte, func DeserializeCosmosTx(cdc codec.BinaryCodec, data []byte) ([]sdk.Msg, error) { // only ProtoCodec is supported if _, ok := cdc.(*codec.ProtoCodec); !ok { - return nil, sdkerrors.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") + return nil, errorsmod.Wrap(ErrInvalidCodec, "only ProtoCodec is supported for receiving messages on the host chain") } var cosmosTx CosmosTx diff --git a/modules/apps/27-interchain-accounts/types/errors.go b/modules/apps/27-interchain-accounts/types/errors.go index 5c80da561bc..06989327dfb 100644 --- a/modules/apps/27-interchain-accounts/types/errors.go +++ b/modules/apps/27-interchain-accounts/types/errors.go @@ -1,26 +1,26 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) var ( - ErrUnknownDataType = sdkerrors.Register(ModuleName, 2, "unknown data type") - ErrAccountAlreadyExist = sdkerrors.Register(ModuleName, 3, "account already exist") - ErrPortAlreadyBound = sdkerrors.Register(ModuleName, 4, "port is already bound") - ErrInvalidChannelFlow = sdkerrors.Register(ModuleName, 5, "invalid message sent to channel end") - ErrInvalidOutgoingData = sdkerrors.Register(ModuleName, 6, "invalid outgoing data") - ErrInvalidRoute = sdkerrors.Register(ModuleName, 7, "invalid route") - ErrInterchainAccountNotFound = sdkerrors.Register(ModuleName, 8, "interchain account not found") - ErrInterchainAccountAlreadySet = sdkerrors.Register(ModuleName, 9, "interchain account is already set") - ErrActiveChannelAlreadySet = sdkerrors.Register(ModuleName, 10, "active channel already set for this owner") - ErrActiveChannelNotFound = sdkerrors.Register(ModuleName, 11, "no active channel for this owner") - ErrInvalidVersion = sdkerrors.Register(ModuleName, 12, "invalid interchain accounts version") - ErrInvalidAccountAddress = sdkerrors.Register(ModuleName, 13, "invalid account address") - ErrUnsupported = sdkerrors.Register(ModuleName, 14, "interchain account does not support this action") - ErrInvalidControllerPort = sdkerrors.Register(ModuleName, 15, "invalid controller port") - ErrInvalidHostPort = sdkerrors.Register(ModuleName, 16, "invalid host port") - ErrInvalidTimeoutTimestamp = sdkerrors.Register(ModuleName, 17, "timeout timestamp must be in the future") - ErrInvalidCodec = sdkerrors.Register(ModuleName, 18, "codec is not supported") - ErrInvalidAccountReopening = sdkerrors.Register(ModuleName, 19, "invalid account reopening") + ErrUnknownDataType = errorsmod.Register(ModuleName, 2, "unknown data type") + ErrAccountAlreadyExist = errorsmod.Register(ModuleName, 3, "account already exist") + ErrPortAlreadyBound = errorsmod.Register(ModuleName, 4, "port is already bound") + ErrInvalidChannelFlow = errorsmod.Register(ModuleName, 5, "invalid message sent to channel end") + ErrInvalidOutgoingData = errorsmod.Register(ModuleName, 6, "invalid outgoing data") + ErrInvalidRoute = errorsmod.Register(ModuleName, 7, "invalid route") + ErrInterchainAccountNotFound = errorsmod.Register(ModuleName, 8, "interchain account not found") + ErrInterchainAccountAlreadySet = errorsmod.Register(ModuleName, 9, "interchain account is already set") + ErrActiveChannelAlreadySet = errorsmod.Register(ModuleName, 10, "active channel already set for this owner") + ErrActiveChannelNotFound = errorsmod.Register(ModuleName, 11, "no active channel for this owner") + ErrInvalidVersion = errorsmod.Register(ModuleName, 12, "invalid interchain accounts version") + ErrInvalidAccountAddress = errorsmod.Register(ModuleName, 13, "invalid account address") + ErrUnsupported = errorsmod.Register(ModuleName, 14, "interchain account does not support this action") + ErrInvalidControllerPort = errorsmod.Register(ModuleName, 15, "invalid controller port") + ErrInvalidHostPort = errorsmod.Register(ModuleName, 16, "invalid host port") + ErrInvalidTimeoutTimestamp = errorsmod.Register(ModuleName, 17, "timeout timestamp must be in the future") + ErrInvalidCodec = errorsmod.Register(ModuleName, 18, "codec is not supported") + ErrInvalidAccountReopening = errorsmod.Register(ModuleName, 19, "invalid account reopening") ) diff --git a/modules/apps/27-interchain-accounts/types/metadata.go b/modules/apps/27-interchain-accounts/types/metadata.go index c2d06976da2..ee986a006f9 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.go +++ b/modules/apps/27-interchain-accounts/types/metadata.go @@ -1,8 +1,8 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ) @@ -67,11 +67,11 @@ func IsPreviousMetadataEqual(previousVersion string, metadata Metadata) bool { // ValidateControllerMetadata performs validation of the provided ICS27 controller metadata parameters func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { if !isSupportedEncoding(metadata.Encoding) { - return sdkerrors.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) + return errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) } if !isSupportedTxType(metadata.TxType) { - return sdkerrors.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) + return errorsmod.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) } connection, err := channelKeeper.GetConnection(ctx, connectionHops[0]) @@ -90,7 +90,7 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co } if metadata.Version != Version { - return sdkerrors.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) + return errorsmod.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) } return nil @@ -99,11 +99,11 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co // ValidateHostMetadata performs validation of the provided ICS27 host metadata parameters func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { if !isSupportedEncoding(metadata.Encoding) { - return sdkerrors.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) + return errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) } if !isSupportedTxType(metadata.TxType) { - return sdkerrors.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) + return errorsmod.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) } connection, err := channelKeeper.GetConnection(ctx, connectionHops[0]) @@ -122,7 +122,7 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti } if metadata.Version != Version { - return sdkerrors.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) + return errorsmod.Wrapf(ErrInvalidVersion, "expected %s, got %s", Version, metadata.Version) } return nil @@ -163,11 +163,11 @@ func getSupportedTxTypes() []string { // validateConnectionParams compares the given the controller and host connection IDs to those set in the provided ICS27 Metadata func validateConnectionParams(metadata Metadata, controllerConnectionID, hostConnectionID string) error { if metadata.ControllerConnectionId != controllerConnectionID { - return sdkerrors.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", controllerConnectionID, metadata.ControllerConnectionId) + return errorsmod.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", controllerConnectionID, metadata.ControllerConnectionId) } if metadata.HostConnectionId != hostConnectionID { - return sdkerrors.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", hostConnectionID, metadata.HostConnectionId) + return errorsmod.Wrapf(connectiontypes.ErrInvalidConnection, "expected %s, got %s", hostConnectionID, metadata.HostConnectionId) } return nil diff --git a/modules/apps/27-interchain-accounts/types/packet.go b/modules/apps/27-interchain-accounts/types/packet.go index 383b192507f..f7d1c6648be 100644 --- a/modules/apps/27-interchain-accounts/types/packet.go +++ b/modules/apps/27-interchain-accounts/types/packet.go @@ -3,9 +3,9 @@ package types import ( "time" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // MaxMemoCharLength defines the maximum length for the InterchainAccountPacketData memo field @@ -28,15 +28,15 @@ var ( // The memo may be empty. func (iapd InterchainAccountPacketData) ValidateBasic() error { if iapd.Type == UNSPECIFIED { - return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified") + return errorsmod.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified") } if len(iapd.Data) == 0 { - return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty") + return errorsmod.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty") } if len(iapd.Memo) > MaxMemoCharLength { - return sdkerrors.Wrapf(ErrInvalidOutgoingData, "packet data memo cannot be greater than %d characters", MaxMemoCharLength) + return errorsmod.Wrapf(ErrInvalidOutgoingData, "packet data memo cannot be greater than %d characters", MaxMemoCharLength) } return nil diff --git a/modules/apps/27-interchain-accounts/types/port.go b/modules/apps/27-interchain-accounts/types/port.go index f1b9ebed825..ee814279cf8 100644 --- a/modules/apps/27-interchain-accounts/types/port.go +++ b/modules/apps/27-interchain-accounts/types/port.go @@ -4,13 +4,13 @@ import ( "fmt" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // NewControllerPortID creates and returns a new prefixed controller port identifier using the provided owner string func NewControllerPortID(owner string) (string, error) { if strings.TrimSpace(owner) == "" { - return "", sdkerrors.Wrap(ErrInvalidAccountAddress, "owner address cannot be empty") + return "", errorsmod.Wrap(ErrInvalidAccountAddress, "owner address cannot be empty") } return fmt.Sprint(ControllerPortPrefix, owner), nil diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 22290392848..9ac7eec370c 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -3,8 +3,8 @@ package fee import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" @@ -62,7 +62,7 @@ func (im IBCMiddleware) OnChanOpenInit( } if versionMetadata.FeeVersion != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) } appVersion, err := im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, versionMetadata.AppVersion) @@ -104,7 +104,7 @@ func (im IBCMiddleware) OnChanOpenTry( } if versionMetadata.FeeVersion != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion) } im.keeper.SetFeeEnabled(ctx, portID, channelID) @@ -137,11 +137,11 @@ func (im IBCMiddleware) OnChanOpenAck( if im.keeper.IsFeeEnabled(ctx, portID, channelID) { var versionMetadata types.Metadata if err := types.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &versionMetadata); err != nil { - return sdkerrors.Wrapf(err, "failed to unmarshal ICS29 counterparty version metadata: %s", counterpartyVersion) + return errorsmod.Wrapf(err, "failed to unmarshal ICS29 counterparty version metadata: %s", counterpartyVersion) } if versionMetadata.FeeVersion != types.Version { - return sdkerrors.Wrapf(types.ErrInvalidVersion, "expected counterparty fee version: %s, got: %s", types.Version, versionMetadata.FeeVersion) + return errorsmod.Wrapf(types.ErrInvalidVersion, "expected counterparty fee version: %s, got: %s", types.Version, versionMetadata.FeeVersion) } // call underlying app's OnChanOpenAck callback with the counterparty app version. @@ -251,7 +251,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket( var ack types.IncentivizedAcknowledgement if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { - return sdkerrors.Wrapf(err, "cannot unmarshal ICS-29 incentivized packet acknowledgement: %v", ack) + return errorsmod.Wrapf(err, "cannot unmarshal ICS-29 incentivized packet acknowledgement: %v", ack) } if im.keeper.IsLocked(ctx) { @@ -283,7 +283,7 @@ func (im IBCMiddleware) OnAcknowledgementPacket( payeeAddr, err := sdk.AccAddressFromBech32(payee) if err != nil { - return sdkerrors.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) + return errorsmod.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) } im.keeper.DistributePacketFeesOnAcknowledgement(ctx, ack.ForwardRelayerAddress, payeeAddr, feesInEscrow.PacketFees, packetID) @@ -325,7 +325,7 @@ func (im IBCMiddleware) OnTimeoutPacket( payeeAddr, err := sdk.AccAddressFromBech32(payee) if err != nil { - return sdkerrors.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) + return errorsmod.Wrapf(err, "failed to create sdk.Address from payee: %s", payee) } im.keeper.DistributePacketFeesOnTimeout(ctx, payeeAddr, feesInEscrow.PacketFees, packetID) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index d32ec6baae4..b526bdfcea1 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -21,7 +21,7 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, refundAcc := k.authKeeper.GetAccount(ctx, refundAddr) if refundAcc == nil { - return sdkerrors.Wrapf(types.ErrRefundAccNotFound, "account with address: %s not found", packetFee.RefundAddress) + return errorsmod.Wrapf(types.ErrRefundAccNotFound, "account with address: %s not found", packetFee.RefundAddress) } coins := packetFee.Fee.Total() diff --git a/modules/apps/29-fee/keeper/grpc_query.go b/modules/apps/29-fee/keeper/grpc_query.go index a1485824a4d..021459e864a 100644 --- a/modules/apps/29-fee/keeper/grpc_query.go +++ b/modules/apps/29-fee/keeper/grpc_query.go @@ -3,9 +3,9 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -57,7 +57,7 @@ func (k Keeper) IncentivizedPacket(goCtx context.Context, req *types.QueryIncent if !exists { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error()) + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error()) } return &types.QueryIncentivizedPacketResponse{ @@ -107,7 +107,7 @@ func (k Keeper) TotalRecvFees(goCtx context.Context, req *types.QueryTotalRecvFe if !found { return nil, status.Errorf( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), ) } @@ -133,7 +133,7 @@ func (k Keeper) TotalAckFees(goCtx context.Context, req *types.QueryTotalAckFees if !found { return nil, status.Errorf( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), ) } @@ -159,7 +159,7 @@ func (k Keeper) TotalTimeoutFees(goCtx context.Context, req *types.QueryTotalTim if !found { return nil, status.Errorf( codes.NotFound, - sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), + errorsmod.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(), ) } diff --git a/modules/apps/29-fee/keeper/msg_server.go b/modules/apps/29-fee/keeper/msg_server.go index 96a2ece8b55..8fe0aed2f04 100644 --- a/modules/apps/29-fee/keeper/msg_server.go +++ b/modules/apps/29-fee/keeper/msg_server.go @@ -3,9 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -26,7 +27,7 @@ func (k Keeper) RegisterPayee(goCtx context.Context, msg *types.MsgRegisterPayee } if k.bankKeeper.BlockedAddr(payee) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not authorized to be a payee", payee) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not authorized to be a payee", payee) } // only register payee address if the channel exists and is fee enabled @@ -97,7 +98,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee) } if k.bankKeeper.BlockedAddr(refundAcc) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) } // get the next sequence @@ -142,12 +143,12 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket } if k.bankKeeper.BlockedAddr(refundAcc) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to escrow fees", refundAcc) } nextSeqSend, found := k.GetNextSequenceSend(ctx, msg.PacketId.PortId, msg.PacketId.ChannelId) if !found { - return nil, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "channel does not exist, portID: %s, channelID: %s", msg.PacketId.PortId, msg.PacketId.ChannelId) + return nil, errorsmod.Wrapf(channeltypes.ErrSequenceSendNotFound, "channel does not exist, portID: %s, channelID: %s", msg.PacketId.PortId, msg.PacketId.ChannelId) } // only allow incentivizing of packets which have been sent @@ -157,7 +158,7 @@ func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacket // only allow incentivizng of packets which have not completed the packet life cycle if bz := k.GetPacketCommitment(ctx, msg.PacketId.PortId, msg.PacketId.ChannelId, msg.PacketId.Sequence); len(bz) == 0 { - return nil, sdkerrors.Wrapf(channeltypes.ErrPacketCommitmentNotFound, "packet has already been acknowledged or timed out") + return nil, errorsmod.Wrapf(channeltypes.ErrPacketCommitmentNotFound, "packet has already been acknowledged or timed out") } if err := k.escrowPacketFee(ctx, msg.PacketId, msg.PacketFee); err != nil { diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 1c10a46645b..556e056c22d 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -3,8 +3,8 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" @@ -39,7 +39,7 @@ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.C // retrieve the forward relayer that was stored in `onRecvPacket` relayer, found := k.GetRelayerAddressForAsyncAck(ctx, packetID) if !found { - return sdkerrors.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "no relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetID.PortId, packetID.ChannelId, packetID.Sequence) + return errorsmod.Wrapf(types.ErrRelayerNotFoundForAsyncAck, "no relayer address stored for async acknowledgement for packet with portID: %s, channelID: %s, sequence: %d", packetID.PortId, packetID.ChannelId, packetID.Sequence) } // it is possible that a relayer has not registered a counterparty address. diff --git a/modules/apps/29-fee/types/errors.go b/modules/apps/29-fee/types/errors.go index 700864b9a33..26167c71016 100644 --- a/modules/apps/29-fee/types/errors.go +++ b/modules/apps/29-fee/types/errors.go @@ -1,19 +1,19 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // 29-fee sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 2, "invalid ICS29 middleware version") - ErrRefundAccNotFound = sdkerrors.Register(ModuleName, 3, "no account found for given refund address") - ErrBalanceNotFound = sdkerrors.Register(ModuleName, 4, "balance not found for given account address") - ErrFeeNotFound = sdkerrors.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") - ErrRelayersNotEmpty = sdkerrors.Register(ModuleName, 6, "relayers must not be set. This feature is not supported") - ErrCounterpartyPayeeEmpty = sdkerrors.Register(ModuleName, 7, "counterparty payee must not be empty") - ErrForwardRelayerAddressNotFound = sdkerrors.Register(ModuleName, 8, "forward relayer address not found") - ErrFeeNotEnabled = sdkerrors.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") - ErrRelayerNotFoundForAsyncAck = sdkerrors.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") - ErrFeeModuleLocked = sdkerrors.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected") + ErrInvalidVersion = errorsmod.Register(ModuleName, 2, "invalid ICS29 middleware version") + ErrRefundAccNotFound = errorsmod.Register(ModuleName, 3, "no account found for given refund address") + ErrBalanceNotFound = errorsmod.Register(ModuleName, 4, "balance not found for given account address") + ErrFeeNotFound = errorsmod.Register(ModuleName, 5, "there is no fee escrowed for the given packetID") + ErrRelayersNotEmpty = errorsmod.Register(ModuleName, 6, "relayers must not be set. This feature is not supported") + ErrCounterpartyPayeeEmpty = errorsmod.Register(ModuleName, 7, "counterparty payee must not be empty") + ErrForwardRelayerAddressNotFound = errorsmod.Register(ModuleName, 8, "forward relayer address not found") + ErrFeeNotEnabled = errorsmod.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") + ErrRelayerNotFoundForAsyncAck = errorsmod.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") + ErrFeeModuleLocked = errorsmod.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected") ) diff --git a/modules/apps/29-fee/types/fee.go b/modules/apps/29-fee/types/fee.go index 59f7ad657c1..81948ebdcbc 100644 --- a/modules/apps/29-fee/types/fee.go +++ b/modules/apps/29-fee/types/fee.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -22,7 +23,7 @@ func NewPacketFee(fee Fee, refundAddr string, relayers []string) PacketFee { func (p PacketFee) Validate() error { _, err := sdk.AccAddressFromBech32(p.RefundAddress) if err != nil { - return sdkerrors.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert RefundAddress into sdk.AccAddress") } // enforce relayers are not set @@ -80,12 +81,12 @@ func (f Fee) Validate() error { } if len(errFees) > 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "contains invalid fees: %s", strings.Join(errFees, " , ")) + return errorsmod.Wrapf(ibcerrors.ErrInvalidCoins, "contains invalid fees: %s", strings.Join(errFees, " , ")) } // if all three fee's are zero or empty return an error if f.AckFee.IsZero() && f.RecvFee.IsZero() && f.TimeoutFee.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "all fees are zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "all fees are zero") } return nil diff --git a/modules/apps/29-fee/types/genesis.go b/modules/apps/29-fee/types/genesis.go index a265c297d40..e08d457367d 100644 --- a/modules/apps/29-fee/types/genesis.go +++ b/modules/apps/29-fee/types/genesis.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -56,36 +57,36 @@ func (gs GenesisState) Validate() error { // Validate FeeEnabledChannels for _, feeCh := range gs.FeeEnabledChannels { if err := host.PortIdentifierValidator(feeCh.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(feeCh.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } } // Validate RegisteredPayees for _, registeredPayee := range gs.RegisteredPayees { if registeredPayee.Relayer == registeredPayee.Payee { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "relayer address and payee address must not be equal") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "relayer address and payee address must not be equal") } if _, err := sdk.AccAddressFromBech32(registeredPayee.Relayer); err != nil { - return sdkerrors.Wrap(err, "failed to convert relayer address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert relayer address into sdk.AccAddress") } if _, err := sdk.AccAddressFromBech32(registeredPayee.Payee); err != nil { - return sdkerrors.Wrap(err, "failed to convert payee address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert payee address into sdk.AccAddress") } if err := host.ChannelIdentifierValidator(registeredPayee.ChannelId); err != nil { - return sdkerrors.Wrapf(err, "invalid channel identifier: %s", registeredPayee.ChannelId) + return errorsmod.Wrapf(err, "invalid channel identifier: %s", registeredPayee.ChannelId) } } // Validate RegisteredCounterpartyPayees for _, registeredCounterpartyPayee := range gs.RegisteredCounterpartyPayees { if _, err := sdk.AccAddressFromBech32(registeredCounterpartyPayee.Relayer); err != nil { - return sdkerrors.Wrap(err, "failed to convert relayer address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert relayer address into sdk.AccAddress") } if strings.TrimSpace(registeredCounterpartyPayee.CounterpartyPayee) == "" { @@ -93,14 +94,14 @@ func (gs GenesisState) Validate() error { } if err := host.ChannelIdentifierValidator(registeredCounterpartyPayee.ChannelId); err != nil { - return sdkerrors.Wrapf(err, "invalid channel identifier: %s", registeredCounterpartyPayee.ChannelId) + return errorsmod.Wrapf(err, "invalid channel identifier: %s", registeredCounterpartyPayee.ChannelId) } } // Validate ForwardRelayers for _, rel := range gs.ForwardRelayers { if _, err := sdk.AccAddressFromBech32(rel.Address); err != nil { - return sdkerrors.Wrap(err, "failed to convert forward relayer address into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert forward relayer address into sdk.AccAddress") } if err := rel.PacketId.Validate(); err != nil { diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 78113ba365e..823fe951071 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -5,8 +5,9 @@ import ( "strconv" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -58,13 +59,13 @@ func KeyFeeEnabled(portID, channelID string) []byte { func ParseKeyFeeEnabled(key string) (portID, channelID string, err error) { keySplit := strings.Split(key, "/") if len(keySplit) != 3 { - return "", "", sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), + return "", "", errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), ) } if keySplit[0] != FeeEnabledKeyPrefix { - return "", "", sdkerrors.Wrapf(sdkerrors.ErrLogic, "key prefix is incorrect: expected %s, got %s", FeeEnabledKeyPrefix, keySplit[0]) + return "", "", errorsmod.Wrapf(ibcerrors.ErrLogic, "key prefix is incorrect: expected %s, got %s", FeeEnabledKeyPrefix, keySplit[0]) } portID = keySplit[1] @@ -82,8 +83,8 @@ func KeyPayee(relayerAddr, channelID string) []byte { func ParseKeyPayeeAddress(key string) (relayerAddr, channelID string, err error) { keySplit := strings.Split(key, "/") if len(keySplit) != 3 { - return "", "", sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), + return "", "", errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), ) } @@ -99,8 +100,8 @@ func KeyCounterpartyPayee(address, channelID string) []byte { func ParseKeyCounterpartyPayee(key string) (address string, channelID string, error error) { keySplit := strings.Split(key, "/") if len(keySplit) != 3 { - return "", "", sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), + return "", "", errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), ) } @@ -116,8 +117,8 @@ func KeyRelayerAddressForAsyncAck(packetID channeltypes.PacketId) []byte { func ParseKeyRelayerAddressForAsyncAck(key string) (channeltypes.PacketId, error) { keySplit := strings.Split(key, "/") if len(keySplit) != 4 { - return channeltypes.PacketId{}, sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), + return channeltypes.PacketId{}, errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), ) } @@ -139,8 +140,8 @@ func KeyFeesInEscrow(packetID channeltypes.PacketId) []byte { func ParseKeyFeesInEscrow(key string) (channeltypes.PacketId, error) { keySplit := strings.Split(key, "/") if len(keySplit) != 4 { - return channeltypes.PacketId{}, sdkerrors.Wrapf( - sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), + return channeltypes.PacketId{}, errorsmod.Wrapf( + ibcerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 4, len(keySplit), ) } diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index 047b48b9ec1..0828beba868 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -31,17 +32,17 @@ func (msg MsgRegisterPayee) ValidateBasic() error { } if msg.Relayer == msg.Payee { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "relayer address and payee must not be equal") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "relayer address and payee must not be equal") } _, err := sdk.AccAddressFromBech32(msg.Relayer) if err != nil { - return sdkerrors.Wrap(err, "failed to create sdk.AccAddress from relayer address") + return errorsmod.Wrap(err, "failed to create sdk.AccAddress from relayer address") } _, err = sdk.AccAddressFromBech32(msg.Payee) if err != nil { - return sdkerrors.Wrap(err, "failed to create sdk.AccAddress from payee address") + return errorsmod.Wrap(err, "failed to create sdk.AccAddress from payee address") } return nil @@ -79,7 +80,7 @@ func (msg MsgRegisterCounterpartyPayee) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Relayer) if err != nil { - return sdkerrors.Wrap(err, "failed to create sdk.AccAddress from relayer address") + return errorsmod.Wrap(err, "failed to create sdk.AccAddress from relayer address") } if strings.TrimSpace(msg.CounterpartyPayee) == "" { @@ -124,7 +125,7 @@ func (msg MsgPayPacketFee) ValidateBasic() error { // signer check if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { - return sdkerrors.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") + return errorsmod.Wrap(err, "failed to convert msg.Signer into sdk.AccAddress") } // enforce relayer is not set diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index b7595ca77c1..3503f51da20 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -5,10 +5,11 @@ import ( "math" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -46,16 +47,16 @@ func ValidateTransferChannelParams( return err } if channelSequence > uint64(math.MaxUint32) { - return sdkerrors.Wrapf(types.ErrMaxTransferChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, uint64(math.MaxUint32)) + return errorsmod.Wrapf(types.ErrMaxTransferChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, uint64(math.MaxUint32)) } if order != channeltypes.UNORDERED { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s ", channeltypes.UNORDERED, order) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s ", channeltypes.UNORDERED, order) } // Require portID is the portID transfer module is bound to boundPort := keeper.GetPort(ctx) if boundPort != portID { - return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort) + return errorsmod.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort) } return nil @@ -81,7 +82,7 @@ func (im IBCModule) OnChanOpenInit( } if version != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "got %s, expected %s", version, types.Version) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "got %s, expected %s", version, types.Version) } // Claim channel capability passed back by IBC module @@ -108,7 +109,7 @@ func (im IBCModule) OnChanOpenTry( } if counterpartyVersion != types.Version { - return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version) + return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version) } // OpenTry must claim the channelCapability that IBC passes into the callback @@ -128,7 +129,7 @@ func (im IBCModule) OnChanOpenAck( counterpartyVersion string, ) error { if counterpartyVersion != types.Version { - return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) + return errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) } return nil } @@ -149,7 +150,7 @@ func (im IBCModule) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for transfer channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCModule interface @@ -175,7 +176,7 @@ func (im IBCModule) OnRecvPacket( var data types.FungibleTokenPacketData var ackErr error if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - ackErr = sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ICS-20 transfer packet data") + ackErr = errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot unmarshal ICS-20 transfer packet data") logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence)) ack = channeltypes.NewErrorAcknowledgement(ackErr) } @@ -227,11 +228,11 @@ func (im IBCModule) OnAcknowledgementPacket( ) error { var ack channeltypes.Acknowledgement if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) } var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } if err := im.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil { @@ -279,7 +280,7 @@ func (im IBCModule) OnTimeoutPacket( ) error { var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } // refund tokens if err := im.keeper.OnTimeoutPacket(ctx, packet, data); err != nil { diff --git a/modules/apps/transfer/keeper/grpc_query.go b/modules/apps/transfer/keeper/grpc_query.go index 869daf20758..d6a1eaefdaa 100644 --- a/modules/apps/transfer/keeper/grpc_query.go +++ b/modules/apps/transfer/keeper/grpc_query.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -33,7 +33,7 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest) if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrTraceNotFound, req.Hash).Error(), + errorsmod.Wrap(types.ErrTraceNotFound, req.Hash).Error(), ) } @@ -100,7 +100,7 @@ func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) ( if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrTraceNotFound, req.Trace).Error(), + errorsmod.Wrap(types.ErrTraceNotFound, req.Trace).Error(), ) } diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 92e190ce9b3..ef016dff3c3 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -11,11 +11,12 @@ import ( "strconv" "strings" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/crypto" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -270,7 +271,7 @@ func (suite *KeeperTestSuite) CheckBankBalances(chain *ibctesting.TestChain, ban diff := bankChange.Sub(expectedBankChange) NonZeroString := diff.NonZeroString() if len(NonZeroString) != 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Unexpected changes in the bank: \n"+NonZeroString) + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "Unexpected changes in the bank: \n"+NonZeroString) } return nil } diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 26b0c05f963..8eb436ba6ec 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -3,9 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ) @@ -25,11 +26,11 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. } if !k.bankKeeper.IsSendEnabledCoin(ctx, msg.Token) { - return nil, sdkerrors.Wrapf(types.ErrSendDisabled, "%s transfers are currently disabled", msg.Token.Denom) + return nil, errorsmod.Wrapf(types.ErrSendDisabled, "%s transfers are currently disabled", msg.Token.Denom) } if k.bankKeeper.BlockedAddr(sender) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } sequence, err := k.sendTransfer( diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 18b7a095ab5..62d4135e072 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -4,11 +4,12 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -61,7 +62,7 @@ func (k Keeper) sendTransfer( ) (uint64, error) { channel, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return 0, sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } destinationPort := channel.GetCounterparty().GetPortID() @@ -71,7 +72,7 @@ func (k Keeper) sendTransfer( // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) if !ok { - return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return 0, errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } // NOTE: denomination and hex hash correctness checked during msg.ValidateBasic @@ -165,7 +166,7 @@ func (k Keeper) sendTransfer( func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error { // validate packet data upon receiving if err := data.ValidateBasic(); err != nil { - return sdkerrors.Wrapf(err, "error validating ICS-20 transfer packet data") + return errorsmod.Wrapf(err, "error validating ICS-20 transfer packet data") } if !k.GetReceiveEnabled(ctx) { @@ -175,13 +176,13 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // decode the receiver address receiver, err := sdk.AccAddressFromBech32(data.Receiver) if err != nil { - return sdkerrors.Wrapf(err, "failed to decode receiver address: %s", data.Receiver) + return errorsmod.Wrapf(err, "failed to decode receiver address: %s", data.Receiver) } // parse the transfer amount transferAmount, ok := sdk.NewIntFromString(data.Amount) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", data.Amount) + return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", data.Amount) } labels := []metrics.Label{ @@ -216,7 +217,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t token := sdk.NewCoin(denom, transferAmount) if k.bankKeeper.BlockedAddr(receiver) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) } // unescrow tokens @@ -226,7 +227,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // counterparty module. The bug may occur in bank or any part of the code that allows // the escrow address to be drained. A malicious counterparty module could drain the // escrow address by allowing more tokens to be sent back then were escrowed. - return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") + return errorsmod.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") } defer func() { @@ -279,14 +280,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t if err := k.bankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins(voucher), ); err != nil { - return sdkerrors.Wrapf(err, "failed to mint IBC tokens") + return errorsmod.Wrap(err, "failed to mint IBC tokens") } // send to receiver if err := k.bankKeeper.SendCoinsFromModuleToAccount( ctx, types.ModuleName, receiver, sdk.NewCoins(voucher), ); err != nil { - return sdkerrors.Wrapf(err, "failed to send coins to receiver %s", receiver.String()) + return errorsmod.Wrapf(err, "failed to send coins to receiver %s", receiver.String()) } defer func() { @@ -344,7 +345,7 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // parse the transfer amount transferAmount, ok := sdk.NewIntFromString(data.Amount) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", data.Amount) + return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", data.Amount) } token := sdk.NewCoin(trace.IBCDenom(), transferAmount) @@ -362,7 +363,7 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // counterparty module. The bug may occur in bank or any part of the code that allows // the escrow address to be drained. A malicious counterparty module could drain the // escrow address by allowing more tokens to be sent back then were escrowed. - return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") + return errorsmod.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module") } return nil @@ -390,12 +391,12 @@ func (k Keeper) DenomPathFromHash(ctx sdk.Context, denom string) (string, error) hash, err := types.ParseHexHash(hexHash) if err != nil { - return "", sdkerrors.Wrap(types.ErrInvalidDenomForTransfer, err.Error()) + return "", errorsmod.Wrap(types.ErrInvalidDenomForTransfer, err.Error()) } denomTrace, found := k.GetDenomTrace(ctx, hash) if !found { - return "", sdkerrors.Wrap(types.ErrTraceNotFound, hexHash) + return "", errorsmod.Wrap(types.ErrTraceNotFound, hexHash) } fullDenomPath := denomTrace.GetFullDenomPath() diff --git a/modules/apps/transfer/types/errors.go b/modules/apps/transfer/types/errors.go index d4f85cf4fa7..d62134b27cd 100644 --- a/modules/apps/transfer/types/errors.go +++ b/modules/apps/transfer/types/errors.go @@ -1,18 +1,18 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC transfer sentinel errors var ( - ErrInvalidPacketTimeout = sdkerrors.Register(ModuleName, 2, "invalid packet timeout") - ErrInvalidDenomForTransfer = sdkerrors.Register(ModuleName, 3, "invalid denomination for cross-chain transfer") - ErrInvalidVersion = sdkerrors.Register(ModuleName, 4, "invalid ICS20 version") - ErrInvalidAmount = sdkerrors.Register(ModuleName, 5, "invalid token amount") - ErrTraceNotFound = sdkerrors.Register(ModuleName, 6, "denomination trace not found") - ErrSendDisabled = sdkerrors.Register(ModuleName, 7, "fungible token transfers from this chain are disabled") - ErrReceiveDisabled = sdkerrors.Register(ModuleName, 8, "fungible token transfers to this chain are disabled") - ErrMaxTransferChannels = sdkerrors.Register(ModuleName, 9, "max transfer channels") - ErrInvalidAuthorization = sdkerrors.Register(ModuleName, 10, "invalid transfer authorization") + ErrInvalidPacketTimeout = errorsmod.Register(ModuleName, 2, "invalid packet timeout") + ErrInvalidDenomForTransfer = errorsmod.Register(ModuleName, 3, "invalid denomination for cross-chain transfer") + ErrInvalidVersion = errorsmod.Register(ModuleName, 4, "invalid ICS20 version") + ErrInvalidAmount = errorsmod.Register(ModuleName, 5, "invalid token amount") + ErrTraceNotFound = errorsmod.Register(ModuleName, 6, "denomination trace not found") + ErrSendDisabled = errorsmod.Register(ModuleName, 7, "fungible token transfers from this chain are disabled") + ErrReceiveDisabled = errorsmod.Register(ModuleName, 8, "fungible token transfers to this chain are disabled") + ErrMaxTransferChannels = errorsmod.Register(ModuleName, 9, "max transfer channels") + ErrInvalidAuthorization = errorsmod.Register(ModuleName, 10, "invalid transfer authorization") ) diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index d6c70fec93a..de573544257 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -42,24 +43,24 @@ func (MsgTransfer) Route() string { // the chain is not known to IBC. func (msg MsgTransfer) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.SourcePort); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(msg.SourceChannel); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } if !msg.Token.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Token.String()) + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, msg.Token.String()) } if !msg.Token.IsPositive() { - return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, msg.Token.String()) + return errorsmod.Wrap(ibcerrors.ErrInsufficientFunds, msg.Token.String()) } // NOTE: sender format must be validated as it is required by the GetSigners function. _, err := sdk.AccAddressFromBech32(msg.Sender) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } if strings.TrimSpace(msg.Receiver) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "missing recipient address") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "missing recipient address") } return ValidateIBCDenom(msg.Token.Denom) } diff --git a/modules/apps/transfer/types/packet.go b/modules/apps/transfer/types/packet.go index aed80c6043b..ec795fa2482 100644 --- a/modules/apps/transfer/types/packet.go +++ b/modules/apps/transfer/types/packet.go @@ -4,8 +4,10 @@ import ( "strings" "time" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" ) var ( @@ -42,16 +44,16 @@ func NewFungibleTokenPacketData( func (ftpd FungibleTokenPacketData) ValidateBasic() error { amount, ok := sdk.NewIntFromString(ftpd.Amount) if !ok { - return sdkerrors.Wrapf(ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", ftpd.Amount) + return errorsmod.Wrapf(ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", ftpd.Amount) } if !amount.IsPositive() { - return sdkerrors.Wrapf(ErrInvalidAmount, "amount must be strictly positive: got %d", amount) + return errorsmod.Wrapf(ErrInvalidAmount, "amount must be strictly positive: got %d", amount) } if strings.TrimSpace(ftpd.Sender) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be blank") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "sender address cannot be blank") } if strings.TrimSpace(ftpd.Receiver) == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "receiver address cannot be blank") + return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "receiver address cannot be blank") } return ValidatePrefixedDenom(ftpd.Denom) } diff --git a/modules/apps/transfer/types/trace.go b/modules/apps/transfer/types/trace.go index 7123e5eed68..7145ff15d96 100644 --- a/modules/apps/transfer/types/trace.go +++ b/modules/apps/transfer/types/trace.go @@ -7,8 +7,8 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" @@ -113,10 +113,10 @@ func validateTraceIdentifiers(identifiers []string) error { // validate correctness of port and channel identifiers for i := 0; i < len(identifiers); i += 2 { if err := host.PortIdentifierValidator(identifiers[i]); err != nil { - return sdkerrors.Wrapf(err, "invalid port ID at position %d", i) + return errorsmod.Wrapf(err, "invalid port ID at position %d", i) } if err := host.ChannelIdentifierValidator(identifiers[i+1]); err != nil { - return sdkerrors.Wrapf(err, "invalid channel ID at position %d", i) + return errorsmod.Wrapf(err, "invalid channel ID at position %d", i) } } return nil @@ -151,7 +151,7 @@ func (t Traces) Validate() error { } if err := trace.Validate(); err != nil { - return sdkerrors.Wrapf(err, "failed denom trace %d validation", i) + return errorsmod.Wrapf(err, "failed denom trace %d validation", i) } seenTraces[hash] = true } @@ -190,7 +190,7 @@ func ValidatePrefixedDenom(denom string) error { } if strings.TrimSpace(denomSplit[len(denomSplit)-1]) == "" { - return sdkerrors.Wrap(ErrInvalidDenomForTransfer, "base denomination cannot be blank") + return errorsmod.Wrap(ErrInvalidDenomForTransfer, "base denomination cannot be blank") } path, _ := extractPathAndBaseFromFullDenom(denomSplit) @@ -216,15 +216,15 @@ func ValidateIBCDenom(denom string) error { switch { case denom == DenomPrefix: - return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) + return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) case len(denomSplit) == 2 && denomSplit[0] == DenomPrefix: if strings.TrimSpace(denomSplit[1]) == "" { - return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) + return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) } if _, err := ParseHexHash(denomSplit[1]); err != nil { - return sdkerrors.Wrapf(err, "invalid denom trace hash %s", denomSplit[1]) + return errorsmod.Wrapf(err, "invalid denom trace hash %s", denomSplit[1]) } } diff --git a/modules/apps/transfer/types/transfer_authorization.go b/modules/apps/transfer/types/transfer_authorization.go index fed33b0a909..709972afc49 100644 --- a/modules/apps/transfer/types/transfer_authorization.go +++ b/modules/apps/transfer/types/transfer_authorization.go @@ -1,10 +1,11 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -29,18 +30,18 @@ func (a TransferAuthorization) MsgTypeURL() string { func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { msgTransfer, ok := msg.(*MsgTransfer) if !ok { - return authz.AcceptResponse{}, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "type mismatch") + return authz.AcceptResponse{}, errorsmod.Wrap(ibcerrors.ErrInvalidType, "type mismatch") } for index, allocation := range a.Allocations { if allocation.SourceChannel == msgTransfer.SourceChannel && allocation.SourcePort == msgTransfer.SourcePort { limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token) if isNegative { - return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "requested amount is more than spend limit") + return authz.AcceptResponse{}, errorsmod.Wrapf(ibcerrors.ErrInsufficientFunds, "requested amount is more than spend limit") } if !isAllowedAddress(ctx, msgTransfer.Receiver, allocation.AllowList) { - return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "not allowed address for transfer") + return authz.AcceptResponse{}, errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "not allowed address for transfer") } if limitLeft.IsZero() { @@ -64,44 +65,44 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep }}, nil } } - return authz.AcceptResponse{}, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "requested port and channel allocation does not exist") + return authz.AcceptResponse{}, errorsmod.Wrapf(ibcerrors.ErrNotFound, "requested port and channel allocation does not exist") } // ValidateBasic implements Authorization.ValidateBasic. func (a TransferAuthorization) ValidateBasic() error { if len(a.Allocations) == 0 { - return sdkerrors.Wrap(ErrInvalidAuthorization, "allocations cannot be empty") + return errorsmod.Wrap(ErrInvalidAuthorization, "allocations cannot be empty") } foundChannels := make(map[string]bool, 0) for _, allocation := range a.Allocations { if _, found := foundChannels[allocation.SourceChannel]; found { - return sdkerrors.Wrapf(channeltypes.ErrInvalidChannel, "duplicate source channel ID: %s", allocation.SourceChannel) + return errorsmod.Wrapf(channeltypes.ErrInvalidChannel, "duplicate source channel ID: %s", allocation.SourceChannel) } foundChannels[allocation.SourceChannel] = true if allocation.SpendLimit == nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "spend limit cannot be nil") + return errorsmod.Wrap(ibcerrors.ErrInvalidCoins, "spend limit cannot be nil") } if err := allocation.SpendLimit.Validate(); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, err.Error()) + return errorsmod.Wrapf(ibcerrors.ErrInvalidCoins, err.Error()) } if err := host.PortIdentifierValidator(allocation.SourcePort); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(allocation.SourceChannel); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } found := make(map[string]bool, 0) for i := 0; i < len(allocation.AllowList); i++ { if found[allocation.AllowList[i]] { - return sdkerrors.Wrapf(ErrInvalidAuthorization, "duplicate entry in allow list %s") + return errorsmod.Wrapf(ErrInvalidAuthorization, "duplicate entry in allow list %s", allocation.AllowList[i]) } found[allocation.AllowList[i]] = true } diff --git a/modules/core/02-client/client/utils/utils.go b/modules/core/02-client/client/utils/utils.go index 18fecf9d8e2..9dd2675087a 100644 --- a/modules/core/02-client/client/utils/utils.go +++ b/modules/core/02-client/client/utils/utils.go @@ -3,9 +3,9 @@ package utils import ( "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -46,7 +46,7 @@ func QueryClientStateABCI( // check if client exists if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrClientNotFound, clientID) + return nil, errorsmod.Wrap(types.ErrClientNotFound, clientID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) @@ -99,7 +99,7 @@ func QueryConsensusStateABCI( // check if consensus state exists if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrConsensusStateNotFound, clientID) + return nil, errorsmod.Wrap(types.ErrConsensusStateNotFound, clientID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index fd260d65d98..8076d380320 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -1,10 +1,10 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -18,7 +18,7 @@ func (k Keeper) CreateClient( ) (string, error) { params := k.GetParams(ctx) if !params.IsAllowedClient(clientState.ClientType()) { - return "", sdkerrors.Wrapf( + return "", errorsmod.Wrapf( types.ErrInvalidClientType, "client state type %s is not registered in the allowlist", clientState.ClientType(), ) @@ -48,13 +48,13 @@ func (k Keeper) CreateClient( func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error { clientState, found := k.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) + return errorsmod.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) } clientStore := k.ClientStore(ctx, clientID) if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) } if err := clientState.VerifyClientMessage(ctx, k.cdc, clientStore, clientMsg); err != nil { @@ -109,19 +109,19 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e ) error { clientState, found := k.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) + return errorsmod.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID) } clientStore := k.ClientStore(ctx, clientID) if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status) } if err := clientState.VerifyUpgradeAndUpdateState(ctx, k.cdc, clientStore, upgradedClient, upgradedConsState, proofUpgradeClient, proofUpgradeConsState, ); err != nil { - return sdkerrors.Wrapf(err, "cannot upgrade client with ID %s", clientID) + return errorsmod.Wrapf(err, "cannot upgrade client with ID %s", clientID) } k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", upgradedClient.GetLatestHeight().String()) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index 84a38304d74..5f575303c02 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -7,9 +7,9 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -36,7 +36,7 @@ func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateReques if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrClientNotFound, req.ClientId).Error(), + errorsmod.Wrap(types.ErrClientNotFound, req.ClientId).Error(), ) } @@ -127,7 +127,7 @@ func (q Keeper) ConsensusState(c context.Context, req *types.QueryConsensusState if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrConsensusStateNotFound, "client-id: %s, height: %s", req.ClientId, height).Error(), + errorsmod.Wrapf(types.ErrConsensusStateNotFound, "client-id: %s, height: %s", req.ClientId, height).Error(), ) } @@ -241,7 +241,7 @@ func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequ if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrClientNotFound, req.ClientId).Error(), + errorsmod.Wrap(types.ErrClientNotFound, req.ClientId).Error(), ) } diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 55c577d609d..aa0eea8c194 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -5,16 +5,17 @@ import ( "reflect" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/light" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -173,7 +174,7 @@ func (k Keeper) GetAllClientMetadata(ctx sdk.Context, genClients []types.Identif for i, metadata := range gms { cmd, ok := metadata.(types.GenesisMetadata) if !ok { - return nil, sdkerrors.Wrapf(types.ErrInvalidClientMetadata, "expected metadata type: %T, got: %T", + return nil, errorsmod.Wrapf(types.ErrInvalidClientMetadata, "expected metadata type: %T, got: %T", types.GenesisMetadata{}, cmd) } clientMetadata[i] = cmd @@ -245,16 +246,16 @@ func (k Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { selfHeight, ok := height.(types.Height) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", types.Height{}, height) + return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", types.Height{}, height) } // check that height revision matches chainID revision revision := types.ParseChainID(ctx.ChainID()) if revision != height.GetRevisionNumber() { - return nil, sdkerrors.Wrapf(types.ErrInvalidHeight, "chainID revision number does not match height revision number: expected %d, got %d", revision, height.GetRevisionNumber()) + return nil, errorsmod.Wrapf(types.ErrInvalidHeight, "chainID revision number does not match height revision number: expected %d, got %d", revision, height.GetRevisionNumber()) } histInfo, found := k.stakingKeeper.GetHistoricalInfo(ctx, int64(selfHeight.RevisionHeight)) if !found { - return nil, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "no historical info found at height %d", selfHeight.RevisionHeight) + return nil, errorsmod.Wrapf(ibcerrors.ErrNotFound, "no historical info found at height %d", selfHeight.RevisionHeight) } consensusState := &ibctm.ConsensusState{ @@ -271,7 +272,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) ( func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { tmClient, ok := clientState.(*ibctm.ClientState) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", + return errorsmod.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", &ibctm.ClientState{}, tmClient) } @@ -280,7 +281,7 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS } if ctx.ChainID() != tmClient.ChainId { - return sdkerrors.Wrapf(types.ErrInvalidClient, "invalid chain-id. expected: %s, got: %s", + return errorsmod.Wrapf(types.ErrInvalidClient, "invalid chain-id. expected: %s, got: %s", ctx.ChainID(), tmClient.ChainId) } @@ -288,34 +289,34 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS // client must be in the same revision as executing chain if tmClient.LatestHeight.RevisionNumber != revision { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client is not in the same revision as the chain. expected revision: %d, got: %d", + return errorsmod.Wrapf(types.ErrInvalidClient, "client is not in the same revision as the chain. expected revision: %d, got: %d", tmClient.LatestHeight.RevisionNumber, revision) } selfHeight := types.NewHeight(revision, uint64(ctx.BlockHeight())) if tmClient.LatestHeight.GTE(selfHeight) { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client has LatestHeight %d greater than or equal to chain height %d", + return errorsmod.Wrapf(types.ErrInvalidClient, "client has LatestHeight %d greater than or equal to chain height %d", tmClient.LatestHeight, selfHeight) } expectedProofSpecs := commitmenttypes.GetSDKSpecs() if !reflect.DeepEqual(expectedProofSpecs, tmClient.ProofSpecs) { - return sdkerrors.Wrapf(types.ErrInvalidClient, "client has invalid proof specs. expected: %v got: %v", + return errorsmod.Wrapf(types.ErrInvalidClient, "client has invalid proof specs. expected: %v got: %v", expectedProofSpecs, tmClient.ProofSpecs) } if err := light.ValidateTrustLevel(tmClient.TrustLevel.ToTendermint()); err != nil { - return sdkerrors.Wrapf(types.ErrInvalidClient, "trust-level invalid: %v", err) + return errorsmod.Wrapf(types.ErrInvalidClient, "trust-level invalid: %v", err) } expectedUbdPeriod := k.stakingKeeper.UnbondingTime(ctx) if expectedUbdPeriod != tmClient.UnbondingPeriod { - return sdkerrors.Wrapf(types.ErrInvalidClient, "invalid unbonding period. expected: %s, got: %s", + return errorsmod.Wrapf(types.ErrInvalidClient, "invalid unbonding period. expected: %s, got: %s", expectedUbdPeriod, tmClient.UnbondingPeriod) } if tmClient.UnbondingPeriod < tmClient.TrustingPeriod { - return sdkerrors.Wrapf(types.ErrInvalidClient, "unbonding period must be greater than trusting period. unbonding period (%d) < trusting period (%d)", + return errorsmod.Wrapf(types.ErrInvalidClient, "unbonding period must be greater than trusting period. unbonding period (%d) < trusting period (%d)", tmClient.UnbondingPeriod, tmClient.TrustingPeriod) } @@ -323,7 +324,7 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS // For now, SDK IBC implementation assumes that upgrade path (if defined) is defined by SDK upgrade module expectedUpgradePath := []string{upgradetypes.StoreKey, upgradetypes.KeyUpgradedIBCState} if !reflect.DeepEqual(expectedUpgradePath, tmClient.UpgradePath) { - return sdkerrors.Wrapf(types.ErrInvalidClient, "upgrade path must be the upgrade path defined by upgrade module. expected %v, got %v", + return errorsmod.Wrapf(types.ErrInvalidClient, "upgrade path must be the upgrade path defined by upgrade module. expected %v, got %v", expectedUpgradePath, tmClient.UpgradePath) } } diff --git a/modules/core/02-client/keeper/proposal.go b/modules/core/02-client/keeper/proposal.go index a8c0d072ab3..960e6744fd1 100644 --- a/modules/core/02-client/keeper/proposal.go +++ b/modules/core/02-client/keeper/proposal.go @@ -1,10 +1,10 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -20,28 +20,28 @@ import ( func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdateProposal) error { subjectClientState, found := k.GetClientState(ctx, p.SubjectClientId) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "subject client with ID %s", p.SubjectClientId) + return errorsmod.Wrapf(types.ErrClientNotFound, "subject client with ID %s", p.SubjectClientId) } subjectClientStore := k.ClientStore(ctx, p.SubjectClientId) if status := subjectClientState.Status(ctx, subjectClientStore, k.cdc); status == exported.Active { - return sdkerrors.Wrap(types.ErrInvalidUpdateClientProposal, "cannot update Active subject client") + return errorsmod.Wrap(types.ErrInvalidUpdateClientProposal, "cannot update Active subject client") } substituteClientState, found := k.GetClientState(ctx, p.SubstituteClientId) if !found { - return sdkerrors.Wrapf(types.ErrClientNotFound, "substitute client with ID %s", p.SubstituteClientId) + return errorsmod.Wrapf(types.ErrClientNotFound, "substitute client with ID %s", p.SubstituteClientId) } if subjectClientState.GetLatestHeight().GTE(substituteClientState.GetLatestHeight()) { - return sdkerrors.Wrapf(types.ErrInvalidHeight, "subject client state latest height is greater or equal to substitute client state latest height (%s >= %s)", subjectClientState.GetLatestHeight(), substituteClientState.GetLatestHeight()) + return errorsmod.Wrapf(types.ErrInvalidHeight, "subject client state latest height is greater or equal to substitute client state latest height (%s >= %s)", subjectClientState.GetLatestHeight(), substituteClientState.GetLatestHeight()) } substituteClientStore := k.ClientStore(ctx, p.SubstituteClientId) if status := substituteClientState.Status(ctx, substituteClientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(types.ErrClientNotActive, "substitute client is not Active, status is %s", status) + return errorsmod.Wrapf(types.ErrClientNotActive, "substitute client is not Active, status is %s", status) } if err := subjectClientState.CheckSubstituteAndUpdateState(ctx, k.cdc, subjectClientStore, substituteClientStore, substituteClientState); err != nil { @@ -75,14 +75,14 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo func (k Keeper) HandleUpgradeProposal(ctx sdk.Context, p *types.UpgradeProposal) error { clientState, err := types.UnpackClientState(p.UpgradedClientState) if err != nil { - return sdkerrors.Wrap(err, "could not unpack UpgradedClientState") + return errorsmod.Wrap(err, "could not unpack UpgradedClientState") } // zero out any custom fields before setting cs := clientState.ZeroCustomFields() bz, err := types.MarshalClientState(k.cdc, cs) if err != nil { - return sdkerrors.Wrap(err, "could not marshal UpgradedClientState") + return errorsmod.Wrap(err, "could not marshal UpgradedClientState") } if err := k.upgradeKeeper.ScheduleUpgrade(ctx, p.Plan); err != nil { diff --git a/modules/core/02-client/migrations/v7/genesis.go b/modules/core/02-client/migrations/v7/genesis.go index 9cbafa37029..e2f803dd35d 100644 --- a/modules/core/02-client/migrations/v7/genesis.go +++ b/modules/core/02-client/migrations/v7/genesis.go @@ -1,8 +1,8 @@ package v7 import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -31,7 +31,7 @@ func MigrateGenesis(clientGenState *clienttypes.GenesisState, cdc codec.ProtoCod case exported.Solomachine: var clientState ClientState if err := cdc.Unmarshal(client.ClientState.Value, &clientState); err != nil { - return nil, sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + return nil, errorsmod.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") } updatedClientState := migrateSolomachine(clientState) diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go index b70e541e671..56afc9e0c8b 100644 --- a/modules/core/02-client/migrations/v7/store.go +++ b/modules/core/02-client/migrations/v7/store.go @@ -4,12 +4,13 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -59,17 +60,17 @@ func handleSolomachineMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bi bz := clientStore.Get(host.ClientStateKey()) if len(bz) == 0 { - return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) + return errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) } var any codectypes.Any if err := cdc.Unmarshal(bz, &any); err != nil { - return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + return errorsmod.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") } var clientState ClientState if err := cdc.Unmarshal(any.Value, &clientState); err != nil { - return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + return errorsmod.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") } updatedClientState := migrateSolomachine(clientState) @@ -96,7 +97,7 @@ func handleTendermintMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bin } if len(clients) > 1 { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "more than one Tendermint client collected") + return errorsmod.Wrap(ibcerrors.ErrLogic, "more than one Tendermint client collected") } clientID := clients[0] @@ -105,12 +106,12 @@ func handleTendermintMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bin // in GetClientState clientState, ok := clientKeeper.GetClientState(ctx, clientID) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) + return errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) } _, ok = clientState.(*ibctm.ClientState) if !ok { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } return nil diff --git a/modules/core/02-client/proposal_handler.go b/modules/core/02-client/proposal_handler.go index 33c27e0f23c..3d9f6002118 100644 --- a/modules/core/02-client/proposal_handler.go +++ b/modules/core/02-client/proposal_handler.go @@ -1,10 +1,11 @@ package client import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ) @@ -19,7 +20,7 @@ func NewClientProposalHandler(k keeper.Keeper) govtypes.Handler { return k.HandleUpgradeProposal(ctx, c) default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c) + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c) } } } diff --git a/modules/core/02-client/types/client.go b/modules/core/02-client/types/client.go index b60e9237e07..86039dc5847 100644 --- a/modules/core/02-client/types/client.go +++ b/modules/core/02-client/types/client.go @@ -6,8 +6,8 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" proto "github.com/cosmos/gogoproto/proto" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -89,7 +89,7 @@ func (cswh ConsensusStateWithHeight) UnpackInterfaces(unpacker codectypes.AnyUnp // client identifier when used with '0' or the maximum uint64 as the sequence. func ValidateClientType(clientType string) error { if strings.TrimSpace(clientType) == "" { - return sdkerrors.Wrap(ErrInvalidClientType, "client type cannot be blank") + return errorsmod.Wrap(ErrInvalidClientType, "client type cannot be blank") } smallestPossibleClientID := FormatClientIdentifier(clientType, 0) @@ -97,14 +97,14 @@ func ValidateClientType(clientType string) error { // IsValidClientID will check client type format and if the sequence is a uint64 if !IsValidClientID(smallestPossibleClientID) { - return sdkerrors.Wrap(ErrInvalidClientType, "") + return errorsmod.Wrap(ErrInvalidClientType, "") } if err := host.ClientIdentifierValidator(smallestPossibleClientID); err != nil { - return sdkerrors.Wrap(err, "client type results in smallest client identifier being invalid") + return errorsmod.Wrap(err, "client type results in smallest client identifier being invalid") } if err := host.ClientIdentifierValidator(largestPossibleClientID); err != nil { - return sdkerrors.Wrap(err, "client type results in largest client identifier being invalid") + return errorsmod.Wrap(err, "client type results in largest client identifier being invalid") } return nil diff --git a/modules/core/02-client/types/codec.go b/modules/core/02-client/types/codec.go index 926e5d7fda6..766f414e376 100644 --- a/modules/core/02-client/types/codec.go +++ b/modules/core/02-client/types/codec.go @@ -1,13 +1,14 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/msgservice" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" proto "github.com/cosmos/gogoproto/proto" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -56,12 +57,12 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { func PackClientState(clientState exported.ClientState) (*codectypes.Any, error) { msg, ok := clientState.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", clientState) + return nil, errorsmod.Wrapf(ibcerrors.ErrPackAny, "cannot proto marshal %T", clientState) } anyClientState, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errorsmod.Wrap(ibcerrors.ErrPackAny, err.Error()) } return anyClientState, nil @@ -71,12 +72,12 @@ func PackClientState(clientState exported.ClientState) (*codectypes.Any, error) // client state can't be unpacked into a ClientState. func UnpackClientState(any *codectypes.Any) (exported.ClientState, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errorsmod.Wrap(ibcerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } clientState, ok := any.GetCachedValue().(exported.ClientState) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into ClientState %T", any) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnpackAny, "cannot unpack Any into ClientState %T", any) } return clientState, nil @@ -88,12 +89,12 @@ func UnpackClientState(any *codectypes.Any) (exported.ClientState, error) { func PackConsensusState(consensusState exported.ConsensusState) (*codectypes.Any, error) { msg, ok := consensusState.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", consensusState) + return nil, errorsmod.Wrapf(ibcerrors.ErrPackAny, "cannot proto marshal %T", consensusState) } anyConsensusState, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errorsmod.Wrap(ibcerrors.ErrPackAny, err.Error()) } return anyConsensusState, nil @@ -113,12 +114,12 @@ func MustPackConsensusState(consensusState exported.ConsensusState) *codectypes. // consensus state can't be unpacked into a ConsensusState. func UnpackConsensusState(any *codectypes.Any) (exported.ConsensusState, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errorsmod.Wrap(ibcerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } consensusState, ok := any.GetCachedValue().(exported.ConsensusState) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into ConsensusState %T", any) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnpackAny, "cannot unpack Any into ConsensusState %T", any) } return consensusState, nil @@ -130,12 +131,12 @@ func UnpackConsensusState(any *codectypes.Any) (exported.ConsensusState, error) func PackClientMessage(clientMessage exported.ClientMessage) (*codectypes.Any, error) { msg, ok := clientMessage.(proto.Message) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", clientMessage) + return nil, errorsmod.Wrapf(ibcerrors.ErrPackAny, "cannot proto marshal %T", clientMessage) } protoAny, err := codectypes.NewAnyWithValue(msg) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error()) + return nil, errorsmod.Wrap(ibcerrors.ErrPackAny, err.Error()) } return protoAny, nil @@ -145,12 +146,12 @@ func PackClientMessage(clientMessage exported.ClientMessage) (*codectypes.Any, e // consensus state can't be unpacked into a ClientMessage. func UnpackClientMessage(any *codectypes.Any) (exported.ClientMessage, error) { if any == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnpackAny, "protobuf Any message cannot be nil") + return nil, errorsmod.Wrap(ibcerrors.ErrUnpackAny, "protobuf Any message cannot be nil") } clientMessage, ok := any.GetCachedValue().(exported.ClientMessage) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnpackAny, "cannot unpack Any into Header %T", any) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnpackAny, "cannot unpack Any into Header %T", any) } return clientMessage, nil diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 0c2bd65f339..a0fa91e8dac 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -1,37 +1,37 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC client sentinel errors var ( - ErrClientExists = sdkerrors.Register(SubModuleName, 2, "light client already exists") - ErrInvalidClient = sdkerrors.Register(SubModuleName, 3, "light client is invalid") - ErrClientNotFound = sdkerrors.Register(SubModuleName, 4, "light client not found") - ErrClientFrozen = sdkerrors.Register(SubModuleName, 5, "light client is frozen due to misbehaviour") - ErrInvalidClientMetadata = sdkerrors.Register(SubModuleName, 6, "invalid client metadata") - ErrConsensusStateNotFound = sdkerrors.Register(SubModuleName, 7, "consensus state not found") - ErrInvalidConsensus = sdkerrors.Register(SubModuleName, 8, "invalid consensus state") - ErrClientTypeNotFound = sdkerrors.Register(SubModuleName, 9, "client type not found") - ErrInvalidClientType = sdkerrors.Register(SubModuleName, 10, "invalid client type") - ErrRootNotFound = sdkerrors.Register(SubModuleName, 11, "commitment root not found") - ErrInvalidHeader = sdkerrors.Register(SubModuleName, 12, "invalid client header") - ErrInvalidMisbehaviour = sdkerrors.Register(SubModuleName, 13, "invalid light client misbehaviour") - ErrFailedClientStateVerification = sdkerrors.Register(SubModuleName, 14, "client state verification failed") - ErrFailedClientConsensusStateVerification = sdkerrors.Register(SubModuleName, 15, "client consensus state verification failed") - ErrFailedConnectionStateVerification = sdkerrors.Register(SubModuleName, 16, "connection state verification failed") - ErrFailedChannelStateVerification = sdkerrors.Register(SubModuleName, 17, "channel state verification failed") - ErrFailedPacketCommitmentVerification = sdkerrors.Register(SubModuleName, 18, "packet commitment verification failed") - ErrFailedPacketAckVerification = sdkerrors.Register(SubModuleName, 19, "packet acknowledgement verification failed") - ErrFailedPacketReceiptVerification = sdkerrors.Register(SubModuleName, 20, "packet receipt verification failed") - ErrFailedNextSeqRecvVerification = sdkerrors.Register(SubModuleName, 21, "next sequence receive verification failed") - ErrSelfConsensusStateNotFound = sdkerrors.Register(SubModuleName, 22, "self consensus state not found") - ErrUpdateClientFailed = sdkerrors.Register(SubModuleName, 23, "unable to update light client") - ErrInvalidUpdateClientProposal = sdkerrors.Register(SubModuleName, 24, "invalid update client proposal") - ErrInvalidUpgradeClient = sdkerrors.Register(SubModuleName, 25, "invalid client upgrade") - ErrInvalidHeight = sdkerrors.Register(SubModuleName, 26, "invalid height") - ErrInvalidSubstitute = sdkerrors.Register(SubModuleName, 27, "invalid client state substitute") - ErrInvalidUpgradeProposal = sdkerrors.Register(SubModuleName, 28, "invalid upgrade proposal") - ErrClientNotActive = sdkerrors.Register(SubModuleName, 29, "client state is not active") + ErrClientExists = errorsmod.Register(SubModuleName, 2, "light client already exists") + ErrInvalidClient = errorsmod.Register(SubModuleName, 3, "light client is invalid") + ErrClientNotFound = errorsmod.Register(SubModuleName, 4, "light client not found") + ErrClientFrozen = errorsmod.Register(SubModuleName, 5, "light client is frozen due to misbehaviour") + ErrInvalidClientMetadata = errorsmod.Register(SubModuleName, 6, "invalid client metadata") + ErrConsensusStateNotFound = errorsmod.Register(SubModuleName, 7, "consensus state not found") + ErrInvalidConsensus = errorsmod.Register(SubModuleName, 8, "invalid consensus state") + ErrClientTypeNotFound = errorsmod.Register(SubModuleName, 9, "client type not found") + ErrInvalidClientType = errorsmod.Register(SubModuleName, 10, "invalid client type") + ErrRootNotFound = errorsmod.Register(SubModuleName, 11, "commitment root not found") + ErrInvalidHeader = errorsmod.Register(SubModuleName, 12, "invalid client header") + ErrInvalidMisbehaviour = errorsmod.Register(SubModuleName, 13, "invalid light client misbehaviour") + ErrFailedClientStateVerification = errorsmod.Register(SubModuleName, 14, "client state verification failed") + ErrFailedClientConsensusStateVerification = errorsmod.Register(SubModuleName, 15, "client consensus state verification failed") + ErrFailedConnectionStateVerification = errorsmod.Register(SubModuleName, 16, "connection state verification failed") + ErrFailedChannelStateVerification = errorsmod.Register(SubModuleName, 17, "channel state verification failed") + ErrFailedPacketCommitmentVerification = errorsmod.Register(SubModuleName, 18, "packet commitment verification failed") + ErrFailedPacketAckVerification = errorsmod.Register(SubModuleName, 19, "packet acknowledgement verification failed") + ErrFailedPacketReceiptVerification = errorsmod.Register(SubModuleName, 20, "packet receipt verification failed") + ErrFailedNextSeqRecvVerification = errorsmod.Register(SubModuleName, 21, "next sequence receive verification failed") + ErrSelfConsensusStateNotFound = errorsmod.Register(SubModuleName, 22, "self consensus state not found") + ErrUpdateClientFailed = errorsmod.Register(SubModuleName, 23, "unable to update light client") + ErrInvalidUpdateClientProposal = errorsmod.Register(SubModuleName, 24, "invalid update client proposal") + ErrInvalidUpgradeClient = errorsmod.Register(SubModuleName, 25, "invalid client upgrade") + ErrInvalidHeight = errorsmod.Register(SubModuleName, 26, "invalid height") + ErrInvalidSubstitute = errorsmod.Register(SubModuleName, 27, "invalid client state substitute") + ErrInvalidUpgradeProposal = errorsmod.Register(SubModuleName, 28, "invalid upgrade proposal") + ErrClientNotActive = errorsmod.Register(SubModuleName, 29, "client state is not active") ) diff --git a/modules/core/02-client/types/height.go b/modules/core/02-client/types/height.go index 0054cec7baa..b4df09e5324 100644 --- a/modules/core/02-client/types/height.go +++ b/modules/core/02-client/types/height.go @@ -7,9 +7,10 @@ import ( "strconv" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -135,15 +136,15 @@ func MustParseHeight(heightStr string) Height { func ParseHeight(heightStr string) (Height, error) { splitStr := strings.Split(heightStr, "-") if len(splitStr) != 2 { - return Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "expected height string format: {revision}-{height}. Got: %s", heightStr) + return Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "expected height string format: {revision}-{height}. Got: %s", heightStr) } revisionNumber, err := strconv.ParseUint(splitStr[0], 10, 64) if err != nil { - return Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "invalid revision number. parse err: %s", err) + return Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "invalid revision number. parse err: %s", err) } revisionHeight, err := strconv.ParseUint(splitStr[1], 10, 64) if err != nil { - return Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "invalid revision height. parse err: %s", err) + return Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "invalid revision height. parse err: %s", err) } return NewHeight(revisionNumber, revisionHeight), nil } @@ -152,8 +153,8 @@ func ParseHeight(heightStr string) (Height, error) { // in the chainID with the given revision number. func SetRevisionNumber(chainID string, revision uint64) (string, error) { if !IsRevisionFormat(chainID) { - return "", sdkerrors.Wrapf( - sdkerrors.ErrInvalidChainID, "chainID is not in revision format: %s", chainID, + return "", errorsmod.Wrapf( + ibcerrors.ErrInvalidChainID, "chainID is not in revision format: %s", chainID, ) } diff --git a/modules/core/02-client/types/keys.go b/modules/core/02-client/types/keys.go index 1a70f196d5f..12345c46e6c 100644 --- a/modules/core/02-client/types/keys.go +++ b/modules/core/02-client/types/keys.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -50,7 +50,7 @@ func IsValidClientID(clientID string) bool { // ParseClientIdentifier parses the client type and sequence from the client identifier. func ParseClientIdentifier(clientID string) (string, uint64, error) { if !IsClientIDFormat(clientID) { - return "", 0, sdkerrors.Wrapf(host.ErrInvalidID, "invalid client identifier %s is not in format: `{client-type}-{N}`", clientID) + return "", 0, errorsmod.Wrapf(host.ErrInvalidID, "invalid client identifier %s is not in format: `{client-type}-{N}`", clientID) } splitStr := strings.Split(clientID, "-") @@ -58,12 +58,12 @@ func ParseClientIdentifier(clientID string) (string, uint64, error) { clientType := strings.Join(splitStr[:lastIndex], "-") if strings.TrimSpace(clientType) == "" { - return "", 0, sdkerrors.Wrap(host.ErrInvalidID, "client identifier must be in format: `{client-type}-{N}` and client type cannot be blank") + return "", 0, errorsmod.Wrap(host.ErrInvalidID, "client identifier must be in format: `{client-type}-{N}` and client type cannot be blank") } sequence, err := strconv.ParseUint(splitStr[lastIndex], 10, 64) if err != nil { - return "", 0, sdkerrors.Wrap(err, "failed to parse client identifier sequence") + return "", 0, errorsmod.Wrap(err, "failed to parse client identifier sequence") } return clientType, sequence, nil diff --git a/modules/core/02-client/types/msgs.go b/modules/core/02-client/types/msgs.go index 1ae308e1b66..9f2c76f4141 100644 --- a/modules/core/02-client/types/msgs.go +++ b/modules/core/02-client/types/msgs.go @@ -1,10 +1,11 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -48,7 +49,7 @@ func NewMsgCreateClient( func (msg MsgCreateClient) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } clientState, err := UnpackClientState(msg.ClientState) if err != nil { @@ -62,10 +63,10 @@ func (msg MsgCreateClient) ValidateBasic() error { return err } if clientState.ClientType() != consensusState.ClientType() { - return sdkerrors.Wrap(ErrInvalidClientType, "client type for client state and consensus state do not match") + return errorsmod.Wrap(ErrInvalidClientType, "client type for client state and consensus state do not match") } if err := ValidateClientType(clientState.ClientType()); err != nil { - return sdkerrors.Wrap(err, "client type does not meet naming constraints") + return errorsmod.Wrap(err, "client type does not meet naming constraints") } return consensusState.ValidateBasic() } @@ -111,7 +112,7 @@ func NewMsgUpdateClient(id string, clientMsg exported.ClientMessage, signer stri func (msg MsgUpdateClient) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } clientMsg, err := UnpackClientMessage(msg.ClientMessage) if err != nil { @@ -179,18 +180,18 @@ func (msg MsgUpgradeClient) ValidateBasic() error { } if clientState.ClientType() != consensusState.ClientType() { - return sdkerrors.Wrapf(ErrInvalidUpgradeClient, "consensus state's client-type does not match client. expected: %s, got: %s", + return errorsmod.Wrapf(ErrInvalidUpgradeClient, "consensus state's client-type does not match client. expected: %s, got: %s", clientState.ClientType(), consensusState.ClientType()) } if len(msg.ProofUpgradeClient) == 0 { - return sdkerrors.Wrap(ErrInvalidUpgradeClient, "proof of upgrade client cannot be empty") + return errorsmod.Wrap(ErrInvalidUpgradeClient, "proof of upgrade client cannot be empty") } if len(msg.ProofUpgradeConsensusState) == 0 { - return sdkerrors.Wrap(ErrInvalidUpgradeClient, "proof of upgrade consensus state cannot be empty") + return errorsmod.Wrap(ErrInvalidUpgradeClient, "proof of upgrade consensus state cannot be empty") } _, err = sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return host.ClientIdentifierValidator(msg.ClientId) } @@ -236,7 +237,7 @@ func NewMsgSubmitMisbehaviour(clientID string, misbehaviour exported.ClientMessa func (msg MsgSubmitMisbehaviour) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } misbehaviour, err := UnpackClientMessage(msg.Misbehaviour) if err != nil { diff --git a/modules/core/02-client/types/proposal.go b/modules/core/02-client/types/proposal.go index e73c52146af..2e6655d0ce9 100644 --- a/modules/core/02-client/types/proposal.go +++ b/modules/core/02-client/types/proposal.go @@ -4,8 +4,8 @@ import ( "fmt" "reflect" + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -59,7 +59,7 @@ func (cup *ClientUpdateProposal) ValidateBasic() error { } if cup.SubjectClientId == cup.SubstituteClientId { - return sdkerrors.Wrap(ErrInvalidSubstitute, "subject and substitute client identifiers are equal") + return errorsmod.Wrap(ErrInvalidSubstitute, "subject and substitute client identifiers are equal") } if _, _, err := ParseClientIdentifier(cup.SubjectClientId); err != nil { return err @@ -109,16 +109,16 @@ func (up *UpgradeProposal) ValidateBasic() error { } if up.UpgradedClientState == nil { - return sdkerrors.Wrap(ErrInvalidUpgradeProposal, "upgraded client state cannot be nil") + return errorsmod.Wrap(ErrInvalidUpgradeProposal, "upgraded client state cannot be nil") } clientState, err := UnpackClientState(up.UpgradedClientState) if err != nil { - return sdkerrors.Wrap(err, "failed to unpack upgraded client state") + return errorsmod.Wrap(err, "failed to unpack upgraded client state") } if !reflect.DeepEqual(clientState, clientState.ZeroCustomFields()) { - return sdkerrors.Wrap(ErrInvalidUpgradeProposal, "upgraded client state is not zeroed out") + return errorsmod.Wrap(ErrInvalidUpgradeProposal, "upgraded client state is not zeroed out") } return nil diff --git a/modules/core/03-connection/client/utils/utils.go b/modules/core/03-connection/client/utils/utils.go index 2a0aaf7e315..a7cab07d6bf 100644 --- a/modules/core/03-connection/client/utils/utils.go +++ b/modules/core/03-connection/client/utils/utils.go @@ -6,9 +6,9 @@ import ( "fmt" "os" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientutils "github.com/cosmos/ibc-go/v7/modules/core/02-client/client/utils" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -47,7 +47,7 @@ func queryConnectionABCI(clientCtx client.Context, connectionID string) (*types. // check if connection exists if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID) + return nil, errorsmod.Wrap(types.ErrConnectionNotFound, connectionID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) @@ -88,7 +88,7 @@ func queryClientConnectionsABCI(clientCtx client.Context, clientID string) (*typ // check if connection paths exist if len(value) == 0 { - return nil, sdkerrors.Wrap(types.ErrClientConnectionPathsNotFound, clientID) + return nil, errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, clientID) } var paths []string diff --git a/modules/core/03-connection/keeper/grpc_query.go b/modules/core/03-connection/keeper/grpc_query.go index 745dd6eed9f..c2a0afb2bf5 100644 --- a/modules/core/03-connection/keeper/grpc_query.go +++ b/modules/core/03-connection/keeper/grpc_query.go @@ -3,9 +3,9 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -32,7 +32,7 @@ func (q Keeper) Connection(c context.Context, req *types.QueryConnectionRequest) if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrConnectionNotFound, req.ConnectionId).Error(), + errorsmod.Wrap(types.ErrConnectionNotFound, req.ConnectionId).Error(), ) } @@ -94,7 +94,7 @@ func (q Keeper) ClientConnections(c context.Context, req *types.QueryClientConne if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrap(types.ErrClientConnectionPathsNotFound, req.ClientId).Error(), + errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, req.ClientId).Error(), ) } @@ -120,7 +120,7 @@ func (q Keeper) ConnectionClientState(c context.Context, req *types.QueryConnect if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), + errorsmod.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), ) } @@ -128,7 +128,7 @@ func (q Keeper) ConnectionClientState(c context.Context, req *types.QueryConnect if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId).Error(), + errorsmod.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId).Error(), ) } @@ -154,7 +154,7 @@ func (q Keeper) ConnectionConsensusState(c context.Context, req *types.QueryConn if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), + errorsmod.Wrapf(types.ErrConnectionNotFound, "connection-id: %s", req.ConnectionId).Error(), ) } @@ -163,7 +163,7 @@ func (q Keeper) ConnectionConsensusState(c context.Context, req *types.QueryConn if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), + errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), ) } diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index 93fe4a9bf6d..380415177e0 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -1,10 +1,11 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" @@ -26,7 +27,7 @@ func (k Keeper) ConnOpenInit( versions := types.GetCompatibleVersions() if version != nil { if !types.IsSupportedVersion(types.GetCompatibleVersions(), version) { - return "", sdkerrors.Wrap(types.ErrInvalidVersion, "version is not supported") + return "", errorsmod.Wrap(types.ErrInvalidVersion, "version is not supported") } versions = []exported.Version{version} @@ -76,8 +77,8 @@ func (k Keeper) ConnOpenTry( selfHeight := clienttypes.GetSelfHeight(ctx) if consensusHeight.GTE(selfHeight) { - return "", sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return "", errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, ) } @@ -89,7 +90,7 @@ func (k Keeper) ConnOpenTry( expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) if err != nil { - return "", sdkerrors.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) + return "", errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) } // expectedConnection defines Chain A's ConnectionEnd @@ -132,7 +133,7 @@ func (k Keeper) ConnOpenTry( // store connection in chainB state if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { - return "", sdkerrors.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID) + return "", errorsmod.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID) } k.SetConnection(ctx, connectionID, connection) @@ -166,8 +167,8 @@ func (k Keeper) ConnOpenAck( // Check that chainB client hasn't stored invalid height selfHeight := clienttypes.GetSelfHeight(ctx) if consensusHeight.GTE(selfHeight) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "consensus height is greater than or equal to the current block height (%s >= %s)", consensusHeight, selfHeight, ) } @@ -175,12 +176,12 @@ func (k Keeper) ConnOpenAck( // Retrieve connection connection, found := k.GetConnection(ctx, connectionID) if !found { - return sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID) + return errorsmod.Wrap(types.ErrConnectionNotFound, connectionID) } // verify the previously set connection state if connection.State != types.INIT { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidConnectionState, "connection state is not INIT (got %s)", connection.State.String(), ) @@ -188,7 +189,7 @@ func (k Keeper) ConnOpenAck( // ensure selected version is supported if !types.IsSupportedVersion(types.ProtoVersionsToExported(connection.Versions), version) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidConnectionState, "the counterparty selected version %s is not supported by versions selected on INIT", version, ) @@ -202,7 +203,7 @@ func (k Keeper) ConnOpenAck( // Retrieve chainA's consensus state at consensusheight expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) if err != nil { - return sdkerrors.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) + return errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) } prefix := k.GetCommitmentPrefix() @@ -259,12 +260,12 @@ func (k Keeper) ConnOpenConfirm( // Retrieve connection connection, found := k.GetConnection(ctx, connectionID) if !found { - return sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID) + return errorsmod.Wrap(types.ErrConnectionNotFound, connectionID) } // Check that connection state on ChainB is on state: TRYOPEN if connection.State != types.TRYOPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidConnectionState, "connection state is not TRYOPEN (got %s)", connection.State.String(), ) diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 3eb291cf8ad..c38fa2e07df 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -1,10 +1,10 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" @@ -95,7 +95,7 @@ func (k Keeper) SetConnection(ctx sdk.Context, connectionID string, connection t func (k Keeper) GetTimestampAtHeight(ctx sdk.Context, connection types.ConnectionEnd, height exported.Height) (uint64, error) { clientState, found := k.clientKeeper.GetClientState(ctx, connection.GetClientID()) if !found { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( clienttypes.ErrClientNotFound, "clientID (%s)", connection.GetClientID(), ) } @@ -201,7 +201,7 @@ func (k Keeper) GetAllConnections(ctx sdk.Context) (connections []types.Identifi func (k Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID string) error { _, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } conns, found := k.GetClientConnectionPaths(ctx, clientID) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 2a505ec317e..4300ae3fa64 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -3,9 +3,10 @@ package keeper import ( "math" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -28,11 +29,11 @@ func (k Keeper) VerifyClientState( targetClient, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := targetClient.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.GetCounterparty().GetClientID())) @@ -51,7 +52,7 @@ func (k Keeper) VerifyClientState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed client state verification for target client: %s", clientID) + return errorsmod.Wrapf(err, "failed client state verification for target client: %s", clientID) } return nil @@ -72,11 +73,11 @@ func (k Keeper) VerifyClientConsensusState( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.GetCounterparty().GetClientID(), consensusHeight)) @@ -95,7 +96,7 @@ func (k Keeper) VerifyClientConsensusState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed consensus state verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed consensus state verification for client (%s)", clientID) } return nil @@ -116,11 +117,11 @@ func (k Keeper) VerifyConnectionState( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID)) @@ -131,7 +132,7 @@ func (k Keeper) VerifyConnectionState( connectionEnd, ok := counterpartyConnection.(connectiontypes.ConnectionEnd) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection) } bz, err := k.cdc.Marshal(&connectionEnd) @@ -144,7 +145,7 @@ func (k Keeper) VerifyConnectionState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed connection state verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed connection state verification for client (%s)", clientID) } return nil @@ -166,11 +167,11 @@ func (k Keeper) VerifyChannelState( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) @@ -181,7 +182,7 @@ func (k Keeper) VerifyChannelState( channelEnd, ok := channel.(channeltypes.Channel) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid channel type %T", channel) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid channel type %T", channel) } bz, err := k.cdc.Marshal(&channelEnd) @@ -194,7 +195,7 @@ func (k Keeper) VerifyChannelState( 0, 0, // skip delay period checks for non-packet processing verification proof, merklePath, bz, ); err != nil { - return sdkerrors.Wrapf(err, "failed channel state verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed channel state verification for client (%s)", clientID) } return nil @@ -217,11 +218,11 @@ func (k Keeper) VerifyPacketCommitment( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -239,7 +240,7 @@ func (k Keeper) VerifyPacketCommitment( timeDelay, blockDelay, proof, merklePath, commitmentBytes, ); err != nil { - return sdkerrors.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) } return nil @@ -262,11 +263,11 @@ func (k Keeper) VerifyPacketAcknowledgement( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -284,7 +285,7 @@ func (k Keeper) VerifyPacketAcknowledgement( timeDelay, blockDelay, proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement), ); err != nil { - return sdkerrors.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) } return nil @@ -307,11 +308,11 @@ func (k Keeper) VerifyPacketReceiptAbsence( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -329,7 +330,7 @@ func (k Keeper) VerifyPacketReceiptAbsence( timeDelay, blockDelay, proof, merklePath, ); err != nil { - return sdkerrors.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) } return nil @@ -351,11 +352,11 @@ func (k Keeper) VerifyNextSequenceRecv( clientState, found := k.clientKeeper.GetClientState(ctx, clientID) if !found { - return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID) + return errorsmod.Wrap(clienttypes.ErrClientNotFound, clientID) } if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // get time and block delays @@ -373,7 +374,7 @@ func (k Keeper) VerifyNextSequenceRecv( timeDelay, blockDelay, proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv), ); err != nil { - return sdkerrors.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID) + return errorsmod.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID) } return nil diff --git a/modules/core/03-connection/types/connection.go b/modules/core/03-connection/types/connection.go index 5f3a523bb16..eddd471d51a 100644 --- a/modules/core/03-connection/types/connection.go +++ b/modules/core/03-connection/types/connection.go @@ -1,8 +1,9 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -51,10 +52,10 @@ func (c ConnectionEnd) GetDelayPeriod() uint64 { // counterparty's. func (c ConnectionEnd) ValidateBasic() error { if err := host.ClientIdentifierValidator(c.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid client ID") + return errorsmod.Wrap(err, "invalid client ID") } if len(c.Versions) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "empty connection versions") + return errorsmod.Wrap(ibcerrors.ErrInvalidVersion, "empty connection versions") } for _, version := range c.Versions { if err := ValidateVersion(version); err != nil { @@ -94,14 +95,14 @@ func (c Counterparty) GetPrefix() exported.Prefix { func (c Counterparty) ValidateBasic() error { if c.ConnectionId != "" { if err := host.ConnectionIdentifierValidator(c.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty connection ID") + return errorsmod.Wrap(err, "invalid counterparty connection ID") } } if err := host.ClientIdentifierValidator(c.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty client ID") + return errorsmod.Wrap(err, "invalid counterparty client ID") } if c.Prefix.Empty() { - return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty prefix cannot be empty") + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty prefix cannot be empty") } return nil } @@ -121,7 +122,7 @@ func NewIdentifiedConnection(connectionID string, conn ConnectionEnd) Identified // ValidateBasic performs a basic validation of the connection identifier and connection fields. func (ic IdentifiedConnection) ValidateBasic() error { if err := host.ConnectionIdentifierValidator(ic.Id); err != nil { - return sdkerrors.Wrap(err, "invalid connection ID") + return errorsmod.Wrap(err, "invalid connection ID") } connection := NewConnectionEnd(ic.State, ic.ClientId, ic.Counterparty, ic.Versions, ic.DelayPeriod) return connection.ValidateBasic() diff --git a/modules/core/03-connection/types/errors.go b/modules/core/03-connection/types/errors.go index 107a0e087c1..d131db91d93 100644 --- a/modules/core/03-connection/types/errors.go +++ b/modules/core/03-connection/types/errors.go @@ -1,19 +1,19 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC connection sentinel errors var ( - ErrConnectionExists = sdkerrors.Register(SubModuleName, 2, "connection already exists") - ErrConnectionNotFound = sdkerrors.Register(SubModuleName, 3, "connection not found") - ErrClientConnectionPathsNotFound = sdkerrors.Register(SubModuleName, 4, "light client connection paths not found") - ErrConnectionPath = sdkerrors.Register(SubModuleName, 5, "connection path is not associated to the given light client") - ErrInvalidConnectionState = sdkerrors.Register(SubModuleName, 6, "invalid connection state") - ErrInvalidCounterparty = sdkerrors.Register(SubModuleName, 7, "invalid counterparty connection") - ErrInvalidConnection = sdkerrors.Register(SubModuleName, 8, "invalid connection") - ErrInvalidVersion = sdkerrors.Register(SubModuleName, 9, "invalid connection version") - ErrVersionNegotiationFailed = sdkerrors.Register(SubModuleName, 10, "connection version negotiation failed") - ErrInvalidConnectionIdentifier = sdkerrors.Register(SubModuleName, 11, "invalid connection identifier") + ErrConnectionExists = errorsmod.Register(SubModuleName, 2, "connection already exists") + ErrConnectionNotFound = errorsmod.Register(SubModuleName, 3, "connection not found") + ErrClientConnectionPathsNotFound = errorsmod.Register(SubModuleName, 4, "light client connection paths not found") + ErrConnectionPath = errorsmod.Register(SubModuleName, 5, "connection path is not associated to the given light client") + ErrInvalidConnectionState = errorsmod.Register(SubModuleName, 6, "invalid connection state") + ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 7, "invalid counterparty connection") + ErrInvalidConnection = errorsmod.Register(SubModuleName, 8, "invalid connection") + ErrInvalidVersion = errorsmod.Register(SubModuleName, 9, "invalid connection version") + ErrVersionNegotiationFailed = errorsmod.Register(SubModuleName, 10, "connection version negotiation failed") + ErrInvalidConnectionIdentifier = errorsmod.Register(SubModuleName, 11, "invalid connection identifier") ) diff --git a/modules/core/03-connection/types/keys.go b/modules/core/03-connection/types/keys.go index 7037452d83e..1b0b5132d90 100644 --- a/modules/core/03-connection/types/keys.go +++ b/modules/core/03-connection/types/keys.go @@ -4,7 +4,7 @@ import ( "fmt" "regexp" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -50,12 +50,12 @@ func IsValidConnectionID(connectionID string) bool { // ParseConnectionSequence parses the connection sequence from the connection identifier. func ParseConnectionSequence(connectionID string) (uint64, error) { if !IsConnectionIDFormat(connectionID) { - return 0, sdkerrors.Wrap(host.ErrInvalidID, "connection identifier is not in the format: `connection-{N}`") + return 0, errorsmod.Wrap(host.ErrInvalidID, "connection identifier is not in the format: `connection-{N}`") } sequence, err := host.ParseIdentifier(connectionID, ConnectionPrefix) if err != nil { - return 0, sdkerrors.Wrap(err, "invalid connection identifier") + return 0, errorsmod.Wrap(err, "invalid connection identifier") } return sequence, nil diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index 7c559ddabcc..d05efe72758 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -1,10 +1,11 @@ package types import ( + errorsmod "cosmossdk.io/errors" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -44,21 +45,21 @@ func NewMsgConnectionOpenInit( // ValidateBasic implements sdk.Msg. func (msg MsgConnectionOpenInit) ValidateBasic() error { if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid client ID") + return errorsmod.Wrap(err, "invalid client ID") } if msg.Counterparty.ConnectionId != "" { - return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty connection identifier must be empty") + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty connection identifier must be empty") } // NOTE: Version can be nil on MsgConnectionOpenInit if msg.Version != nil { if err := ValidateVersion(msg.Version); err != nil { - return sdkerrors.Wrap(err, "basic validation of the provided version failed") + return errorsmod.Wrap(err, "basic validation of the provided version failed") } } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Counterparty.ValidateBasic() } @@ -103,48 +104,48 @@ func NewMsgConnectionOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgConnectionOpenTry) ValidateBasic() error { if msg.PreviousConnectionId != "" { - return sdkerrors.Wrap(ErrInvalidConnectionIdentifier, "previous connection identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") + return errorsmod.Wrap(ErrInvalidConnectionIdentifier, "previous connection identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { - return sdkerrors.Wrap(err, "invalid client ID") + return errorsmod.Wrap(err, "invalid client ID") } // counterparty validate basic allows empty counterparty connection identifiers if err := host.ConnectionIdentifierValidator(msg.Counterparty.ConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty connection ID") + return errorsmod.Wrap(err, "invalid counterparty connection ID") } if msg.ClientState == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") } clientState, err := clienttypes.UnpackClientState(msg.ClientState) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) } if err := clientState.Validate(); err != nil { - return sdkerrors.Wrap(err, "counterparty client is invalid") + return errorsmod.Wrap(err, "counterparty client is invalid") } if len(msg.CounterpartyVersions) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "empty counterparty versions") + return errorsmod.Wrap(ibcerrors.ErrInvalidVersion, "empty counterparty versions") } for i, version := range msg.CounterpartyVersions { if err := ValidateVersion(version); err != nil { - return sdkerrors.Wrapf(err, "basic validation failed on version with index %d", i) + return errorsmod.Wrapf(err, "basic validation failed on version with index %d", i) } } if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") } if len(msg.ProofClient) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") } if len(msg.ProofConsensus) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") } if msg.ConsensusHeight.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "consensus height must be non-zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "consensus height must be non-zero") } _, err = sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Counterparty.ValidateBasic() } @@ -199,36 +200,36 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { return ErrInvalidConnectionIdentifier } if err := host.ConnectionIdentifierValidator(msg.CounterpartyConnectionId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty connection ID") + return errorsmod.Wrap(err, "invalid counterparty connection ID") } if err := ValidateVersion(msg.Version); err != nil { return err } if msg.ClientState == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "counterparty client is nil") } clientState, err := clienttypes.UnpackClientState(msg.ClientState) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "unpack err: %v", err) } if err := clientState.Validate(); err != nil { - return sdkerrors.Wrap(err, "counterparty client is invalid") + return errorsmod.Wrap(err, "counterparty client is invalid") } if len(msg.ProofTry) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") } if len(msg.ProofClient) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit empty proof client") } if len(msg.ProofConsensus) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of consensus state") } if msg.ConsensusHeight.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "consensus height must be non-zero") + return errorsmod.Wrap(ibcerrors.ErrInvalidHeight, "consensus height must be non-zero") } _, err = sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -263,11 +264,11 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error { return ErrInvalidConnectionIdentifier } if len(msg.ProofAck) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } diff --git a/modules/core/03-connection/types/version.go b/modules/core/03-connection/types/version.go index a9a9f3df699..f986236dc53 100644 --- a/modules/core/03-connection/types/version.go +++ b/modules/core/03-connection/types/version.go @@ -3,7 +3,7 @@ package types import ( "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/ibc-go/v7/modules/core/exported" ) @@ -50,14 +50,14 @@ func (version Version) GetFeatures() []string { // features. It unmarshals the version string into a Version object. func ValidateVersion(version *Version) error { if version == nil { - return sdkerrors.Wrap(ErrInvalidVersion, "version cannot be nil") + return errorsmod.Wrap(ErrInvalidVersion, "version cannot be nil") } if strings.TrimSpace(version.Identifier) == "" { - return sdkerrors.Wrap(ErrInvalidVersion, "version identifier cannot be blank") + return errorsmod.Wrap(ErrInvalidVersion, "version identifier cannot be blank") } for i, feature := range version.Features { if strings.TrimSpace(feature) == "" { - return sdkerrors.Wrapf(ErrInvalidVersion, "feature cannot be blank, index %d", i) + return errorsmod.Wrapf(ErrInvalidVersion, "feature cannot be blank, index %d", i) } } @@ -70,14 +70,14 @@ func ValidateVersion(version *Version) error { // identifier. func (version Version) VerifyProposedVersion(proposedVersion exported.Version) error { if proposedVersion.GetIdentifier() != version.GetIdentifier() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrVersionNegotiationFailed, "proposed version identifier does not equal supported version identifier (%s != %s)", proposedVersion.GetIdentifier(), version.GetIdentifier(), ) } if len(proposedVersion.GetFeatures()) == 0 && !allowNilFeatureSet[proposedVersion.GetIdentifier()] { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrVersionNegotiationFailed, "nil feature sets are not supported for version identifier (%s)", proposedVersion.GetIdentifier(), ) @@ -85,7 +85,7 @@ func (version Version) VerifyProposedVersion(proposedVersion exported.Version) e for _, proposedFeature := range proposedVersion.GetFeatures() { if !contains(proposedFeature, version.GetFeatures()) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrVersionNegotiationFailed, "proposed feature (%s) is not a supported feature set (%s)", proposedFeature, version.GetFeatures(), ) @@ -166,7 +166,7 @@ func PickVersion(supportedVersions, counterpartyVersions []exported.Version) (*V } } - return nil, sdkerrors.Wrapf( + return nil, errorsmod.Wrapf( ErrVersionNegotiationFailed, "failed to find a matching counterparty version (%v) from the supported version list (%v)", counterpartyVersions, supportedVersions, ) diff --git a/modules/core/04-channel/client/utils/utils.go b/modules/core/04-channel/client/utils/utils.go index 24f2d8eb7ad..be06badf011 100644 --- a/modules/core/04-channel/client/utils/utils.go +++ b/modules/core/04-channel/client/utils/utils.go @@ -4,10 +4,11 @@ import ( "context" "encoding/binary" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clientutils "github.com/cosmos/ibc-go/v7/modules/core/02-client/client/utils" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -45,7 +46,7 @@ func queryChannelABCI(clientCtx client.Context, portID, channelID string) (*type // check if channel exists if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) + return nil, errorsmod.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) } cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) @@ -140,7 +141,7 @@ func QueryLatestConsensusState( clientHeight, ok := clientState.GetLatestHeight().(clienttypes.Height) if !ok { - return nil, clienttypes.Height{}, clienttypes.Height{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "invalid height type. expected type: %T, got: %T", + return nil, clienttypes.Height{}, clienttypes.Height{}, errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "invalid height type. expected type: %T, got: %T", clienttypes.Height{}, clientHeight) } res, err := QueryChannelConsensusState(clientCtx, portID, channelID, clientHeight, false) @@ -185,7 +186,7 @@ func queryNextSequenceRecvABCI(clientCtx client.Context, portID, channelID strin // check if next sequence receive exists if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) + return nil, errorsmod.Wrapf(types.ErrChannelNotFound, "portID (%s), channelID (%s)", portID, channelID) } sequence := binary.BigEndian.Uint64(value) @@ -226,7 +227,7 @@ func queryPacketCommitmentABCI( // check if packet commitment exists if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrPacketCommitmentNotFound, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) + return nil, errorsmod.Wrapf(types.ErrPacketCommitmentNotFound, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) } return types.NewQueryPacketCommitmentResponse(value, proofBz, proofHeight), nil @@ -293,7 +294,7 @@ func queryPacketAcknowledgementABCI(clientCtx client.Context, portID, channelID } if len(value) == 0 { - return nil, sdkerrors.Wrapf(types.ErrInvalidAcknowledgement, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) + return nil, errorsmod.Wrapf(types.ErrInvalidAcknowledgement, "portID (%s), channelID (%s), sequence (%d)", portID, channelID, sequence) } return types.NewQueryPacketAcknowledgementResponse(value, proofBz, proofHeight), nil diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 6385076de75..ee11b40251e 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -5,9 +5,9 @@ import ( "strconv" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -35,7 +35,7 @@ func (q Keeper) Channel(c context.Context, req *types.QueryChannelRequest) (*typ if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } @@ -169,7 +169,7 @@ func (q Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannel if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } @@ -177,7 +177,7 @@ func (q Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannel if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]).Error(), + errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]).Error(), ) } @@ -186,7 +186,7 @@ func (q Keeper) ChannelConsensusState(c context.Context, req *types.QueryChannel if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), + errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "client-id: %s", connection.ClientId).Error(), ) } @@ -484,7 +484,7 @@ func (q Keeper) NextSequenceReceive(c context.Context, req *types.QueryNextSeque if !found { return nil, status.Error( codes.NotFound, - sdkerrors.Wrapf(types.ErrSequenceReceiveNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrSequenceReceiveNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 922b681f104..61fb5e18a5d 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -3,9 +3,9 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -30,12 +30,12 @@ func (k Keeper) ChanOpenInit( // connection hop length checked on msg.ValidateBasic() connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0]) if !found { - return "", nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) + return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } getVersions := connectionEnd.GetVersions() if len(getVersions) != 1 { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: %v", getVersions, @@ -43,7 +43,7 @@ func (k Keeper) ChanOpenInit( } if !connectiontypes.VerifySupportedFeature(getVersions[0], order.String()) { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "connection version %s does not support channel ordering: %s", getVersions[0], order.String(), @@ -51,14 +51,14 @@ func (k Keeper) ChanOpenInit( } if !k.portKeeper.Authenticate(ctx, portCap, portID) { - return "", nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) + return "", nil, errorsmod.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) } channelID := k.GenerateChannelIdentifier(ctx) capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { - return "", nil, sdkerrors.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) + return "", nil, errorsmod.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) } return channelID, capKey, nil @@ -107,23 +107,23 @@ func (k Keeper) ChanOpenTry( ) (string, *capabilitytypes.Capability, error) { // connection hops only supports a single connection if len(connectionHops) != 1 { - return "", nil, sdkerrors.Wrapf(types.ErrTooManyConnectionHops, "expected 1, got %d", len(connectionHops)) + return "", nil, errorsmod.Wrapf(types.ErrTooManyConnectionHops, "expected 1, got %d", len(connectionHops)) } // generate a new channel channelID := k.GenerateChannelIdentifier(ctx) if !k.portKeeper.Authenticate(ctx, portCap, portID) { - return "", nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) + return "", nil, errorsmod.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID) } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0]) if !found { - return "", nil, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) + return "", nil, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, connectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -131,7 +131,7 @@ func (k Keeper) ChanOpenTry( getVersions := connectionEnd.GetVersions() if len(getVersions) != 1 { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "single version must be negotiated on connection before opening channel, got: %v", getVersions, @@ -139,7 +139,7 @@ func (k Keeper) ChanOpenTry( } if !connectiontypes.VerifySupportedFeature(getVersions[0], order.String()) { - return "", nil, sdkerrors.Wrapf( + return "", nil, errorsmod.Wrapf( connectiontypes.ErrInvalidVersion, "connection version %s does not support channel ordering: %s", getVersions[0], order.String(), @@ -170,7 +170,7 @@ func (k Keeper) ChanOpenTry( capKey, err = k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { - return "", nil, sdkerrors.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) + return "", nil, errorsmod.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID) } return channelID, capKey, nil @@ -219,24 +219,24 @@ func (k Keeper) ChanOpenAck( ) error { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State != types.INIT { - return sdkerrors.Wrapf(types.ErrInvalidChannelState, "channel state should be INIT (got %s)", channel.State.String()) + return errorsmod.Wrapf(types.ErrInvalidChannelState, "channel state should be INIT (got %s)", channel.State.String()) } if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -302,27 +302,27 @@ func (k Keeper) ChanOpenConfirm( ) error { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State != types.TRYOPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not TRYOPEN (got %s)", channel.State.String(), ) } if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -384,25 +384,25 @@ func (k Keeper) ChanCloseInit( chanCap *capabilitytypes.Capability, ) error { if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID) } channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State == types.CLOSED { - return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") + return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -433,25 +433,25 @@ func (k Keeper) ChanCloseConfirm( proofHeight exported.Height, ) error { if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { - return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)") + return errorsmod.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)") } channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } if channel.State == types.CLOSED { - return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") + return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index b83d6b2f6bf..3c800ad3795 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/tendermint/tendermint/libs/log" db "github.com/tendermint/tm-db" @@ -425,17 +425,17 @@ func (k Keeper) GetAllChannels(ctx sdk.Context) (channels []types.IdentifiedChan func (k Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) (string, exported.ClientState, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return "", nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) + return "", nil, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) } connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return "", nil, sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]) + return "", nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", channel.ConnectionHops[0]) } clientState, found := k.clientKeeper.GetClientState(ctx, connection.ClientId) if !found { - return "", nil, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId) + return "", nil, errorsmod.Wrapf(clienttypes.ErrClientNotFound, "client-id: %s", connection.ClientId) } return connection.ClientId, clientState, nil @@ -445,7 +445,7 @@ func (k Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (exported.ConnectionI, error) { connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { - return nil, sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) + return nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) } return connection, nil @@ -455,14 +455,14 @@ func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (exported.Co func (k Keeper) GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, exported.ConnectionI, error) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - return "", nil, sdkerrors.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) + return "", nil, errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id: %s", portID, channelID) } connectionID := channel.ConnectionHops[0] connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { - return "", nil, sdkerrors.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) + return "", nil, errorsmod.Wrapf(connectiontypes.ErrConnectionNotFound, "connection-id: %s", connectionID) } return connectionID, connection, nil diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 7268c37c574..b8b50d520b2 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -5,8 +5,8 @@ import ( "strconv" "time" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -30,23 +30,23 @@ func (k Keeper) SendPacket( ) (uint64, error) { channel, found := k.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return 0, sdkerrors.Wrap(types.ErrChannelNotFound, sourceChannel) + return 0, errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel) } if channel.State != types.OPEN { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrInvalidChannelState, "channel is not OPEN (got %s)", channel.State.String(), ) } if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) { - return 0, sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, errorsmod.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } sequence, found := k.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrSequenceSendNotFound, "source port: %s, source channel: %s", sourcePort, sourceChannel, ) @@ -57,12 +57,12 @@ func (k Keeper) SendPacket( channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeoutHeight, timeoutTimestamp) if err := packet.ValidateBasic(); err != nil { - return 0, sdkerrors.Wrap(err, "constructed packet failed basic validation") + return 0, errorsmod.Wrap(err, "constructed packet failed basic validation") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return 0, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return 0, errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.GetClientID()) @@ -73,13 +73,13 @@ func (k Keeper) SendPacket( // prevent accidental sends with clients that cannot be updated clientStore := k.clientKeeper.ClientStore(ctx, connectionEnd.GetClientID()) if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return 0, sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) } // check if packet is timed out on the receiving chain latestHeight := clientState.GetLatestHeight() if !timeoutHeight.IsZero() && latestHeight.GTE(timeoutHeight) { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrPacketTimeout, "receiving chain block height >= packet timeout height (%s >= %s)", latestHeight, timeoutHeight, ) @@ -91,7 +91,7 @@ func (k Keeper) SendPacket( } if packet.GetTimeoutTimestamp() != 0 && latestTimestamp >= packet.GetTimeoutTimestamp() { - return 0, sdkerrors.Wrapf( + return 0, errorsmod.Wrapf( types.ErrPacketTimeout, "receiving chain block timestamp >= packet timeout timestamp (%s >= %s)", time.Unix(0, int64(latestTimestamp)), time.Unix(0, int64(packet.GetTimeoutTimestamp())), ) @@ -127,11 +127,11 @@ func (k Keeper) RecvPacket( ) error { channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) + return errorsmod.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -140,7 +140,7 @@ func (k Keeper) RecvPacket( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, ) @@ -148,14 +148,14 @@ func (k Keeper) RecvPacket( // packet must come from the channel's counterparty if packet.GetSourcePort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet source port doesn't match the counterparty's port (%s ≠ %s)", packet.GetSourcePort(), channel.Counterparty.PortId, ) } if packet.GetSourceChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet source channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetSourceChannel(), channel.Counterparty.ChannelId, ) @@ -166,11 +166,11 @@ func (k Keeper) RecvPacket( // connection and channel must both be open connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -180,7 +180,7 @@ func (k Keeper) RecvPacket( selfHeight := clienttypes.GetSelfHeight(ctx) timeoutHeight := packet.GetTimeoutHeight() if !timeoutHeight.IsZero() && selfHeight.GTE(timeoutHeight) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketTimeout, "block height >= packet timeout height (%s >= %s)", selfHeight, timeoutHeight, ) @@ -188,7 +188,7 @@ func (k Keeper) RecvPacket( // check if packet timeouted by comparing it with the latest timestamp of the chain if packet.GetTimeoutTimestamp() != 0 && uint64(ctx.BlockTime().UnixNano()) >= packet.GetTimeoutTimestamp() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketTimeout, "block timestamp >= packet timeout timestamp (%s >= %s)", ctx.BlockTime(), time.Unix(0, int64(packet.GetTimeoutTimestamp())), ) @@ -202,7 +202,7 @@ func (k Keeper) RecvPacket( packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), commitment, ); err != nil { - return sdkerrors.Wrap(err, "couldn't verify counterparty packet commitment") + return errorsmod.Wrap(err, "couldn't verify counterparty packet commitment") } switch channel.Ordering { @@ -227,7 +227,7 @@ func (k Keeper) RecvPacket( // check if the packet is being received in order nextSequenceRecv, found := k.GetNextSequenceRecv(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrSequenceReceiveNotFound, "destination port: %s, destination channel: %s", packet.GetDestPort(), packet.GetDestChannel(), ) @@ -242,7 +242,7 @@ func (k Keeper) RecvPacket( } if packet.GetSequence() != nextSequenceRecv { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketSequenceOutOfOrder, "packet sequence ≠ next receive sequence (%d ≠ %d)", packet.GetSequence(), nextSequenceRecv, ) @@ -293,11 +293,11 @@ func (k Keeper) WriteAcknowledgement( ) error { channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) + return errorsmod.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -306,7 +306,7 @@ func (k Keeper) WriteAcknowledgement( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, ) @@ -320,12 +320,12 @@ func (k Keeper) WriteAcknowledgement( } if acknowledgement == nil { - return sdkerrors.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") + return errorsmod.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") } bz := acknowledgement.Acknowledgement() if len(bz) == 0 { - return sdkerrors.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") + return errorsmod.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") } // set the acknowledgement so that it can be verified on the other side @@ -365,14 +365,14 @@ func (k Keeper) AcknowledgePacket( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel(), ) } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -381,7 +381,7 @@ func (k Keeper) AcknowledgePacket( // Authenticate capability to ensure caller has authority to receive packet on this channel capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication for capability name %s", capName, ) @@ -389,14 +389,14 @@ func (k Keeper) AcknowledgePacket( // packet must have been sent to the channel's counterparty if packet.GetDestPort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, ) } if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, ) @@ -404,11 +404,11 @@ func (k Keeper) AcknowledgePacket( connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } if connectionEnd.GetState() != int32(connectiontypes.OPEN) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( connectiontypes.ErrInvalidConnectionState, "connection state is not OPEN (got %s)", connectiontypes.State(connectionEnd.GetState()).String(), ) @@ -429,7 +429,7 @@ func (k Keeper) AcknowledgePacket( // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) + return errorsmod.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) } if err := k.connectionKeeper.VerifyPacketAcknowledgement( @@ -443,14 +443,14 @@ func (k Keeper) AcknowledgePacket( if channel.Ordering == types.ORDERED { nextSequenceAck, found := k.GetNextSequenceAck(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrSequenceAckNotFound, "source port: %s, source channel: %s", packet.GetSourcePort(), packet.GetSourceChannel(), ) } if packet.GetSequence() != nextSequenceAck { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketSequenceOutOfOrder, "packet sequence ≠ next ack sequence (%d ≠ %d)", packet.GetSequence(), nextSequenceAck, ) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 6302b8d15a9..64a1154a2a2 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - sdkerrors "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -261,7 +261,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path *ibctesting.Path packet exported.PacketI channelCap *capabilitytypes.Capability - expError *sdkerrors.Error + expError *errorsmod.Error ) testCases := []testCase{ @@ -622,7 +622,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { ack = ibcmock.MockAcknowledgement channelCap *capabilitytypes.Capability - expError *sdkerrors.Error + expError *errorsmod.Error ) testCases := []testCase{ diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 3ea9e48317e..fd6686b35b9 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -4,8 +4,8 @@ import ( "bytes" "strconv" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -29,7 +29,7 @@ func (k Keeper) TimeoutPacket( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel(), ) @@ -39,14 +39,14 @@ func (k Keeper) TimeoutPacket( // so the capability authentication can be omitted here if packet.GetDestPort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, ) } if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, ) @@ -54,7 +54,7 @@ func (k Keeper) TimeoutPacket( connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap( + return errorsmod.Wrap( connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0], ) @@ -69,7 +69,7 @@ func (k Keeper) TimeoutPacket( timeoutHeight := packet.GetTimeoutHeight() if (timeoutHeight.IsZero() || proofHeight.LT(timeoutHeight)) && (packet.GetTimeoutTimestamp() == 0 || proofTimestamp < packet.GetTimeoutTimestamp()) { - return sdkerrors.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp") + return errorsmod.Wrap(types.ErrPacketTimeout, "packet timeout has not been reached for height or timestamp") } commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) @@ -84,7 +84,7 @@ func (k Keeper) TimeoutPacket( } if channel.State != types.OPEN { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) @@ -94,14 +94,14 @@ func (k Keeper) TimeoutPacket( // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) } switch channel.Ordering { case types.ORDERED: // check that packet has not been received if nextSequenceRecv > packet.GetSequence() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrPacketReceived, "packet already received, next sequence receive > packet sequence (%d > %d)", nextSequenceRecv, packet.GetSequence(), ) @@ -118,7 +118,7 @@ func (k Keeper) TimeoutPacket( packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ) default: - panic(sdkerrors.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) + panic(errorsmod.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) } if err != nil { @@ -140,12 +140,12 @@ func (k Keeper) TimeoutExecuted( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) } capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrChannelCapabilityNotFound, "caller does not own capability for channel with capability name %s", capName, ) @@ -191,26 +191,26 @@ func (k Keeper) TimeoutOnClose( ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { - return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) + return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) } capName := host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidChannelCapability, "channel capability failed authentication with capability name %s", capName, ) } if packet.GetDestPort() != channel.Counterparty.PortId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, ) } if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidPacket, "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, ) @@ -218,7 +218,7 @@ func (k Keeper) TimeoutOnClose( connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return errorsmod.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) @@ -236,7 +236,7 @@ func (k Keeper) TimeoutOnClose( // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) } counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()} @@ -260,7 +260,7 @@ func (k Keeper) TimeoutOnClose( case types.ORDERED: // check that packet has not been received if nextSequenceRecv > packet.GetSequence() { - return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet already received, next sequence receive > packet sequence (%d > %d", nextSequenceRecv, packet.GetSequence()) + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet already received, next sequence receive > packet sequence (%d > %d", nextSequenceRecv, packet.GetSequence()) } // check that the recv sequence is as claimed @@ -274,7 +274,7 @@ func (k Keeper) TimeoutOnClose( packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ) default: - panic(sdkerrors.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) + panic(errorsmod.Wrapf(types.ErrInvalidChannelOrdering, channel.Ordering.String())) } if err != nil { diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 876cba720ee..e2f8ebc9305 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - sdkerrors "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -24,7 +24,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet types.Packet nextSeqRecv uint64 ordered bool - expError *sdkerrors.Error + expError *errorsmod.Error ) testCases := []testCase{ diff --git a/modules/core/04-channel/types/acknowledgement.go b/modules/core/04-channel/types/acknowledgement.go index 49c795d0d55..3e4d02a1180 100644 --- a/modules/core/04-channel/types/acknowledgement.go +++ b/modules/core/04-channel/types/acknowledgement.go @@ -5,8 +5,8 @@ import ( "reflect" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) const ( @@ -32,7 +32,7 @@ func NewResultAcknowledgement(result []byte) Acknowledgement { func NewErrorAcknowledgement(err error) Acknowledgement { // the ABCI code is included in the abcitypes.ResponseDeliverTx hash // constructed in Tendermint and is therefore deterministic - _, code, _ := sdkerrors.ABCIInfo(err, false) // discard non-determinstic codespace and log values + _, code, _ := errorsmod.ABCIInfo(err, false) // discard non-determinstic codespace and log values return Acknowledgement{ Response: &Acknowledgement_Error{ @@ -46,15 +46,15 @@ func (ack Acknowledgement) ValidateBasic() error { switch resp := ack.Response.(type) { case *Acknowledgement_Result: if len(resp.Result) == 0 { - return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") + return errorsmod.Wrap(ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") } case *Acknowledgement_Error: if strings.TrimSpace(resp.Error) == "" { - return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement error cannot be empty") + return errorsmod.Wrap(ErrInvalidAcknowledgement, "acknowledgement error cannot be empty") } default: - return sdkerrors.Wrapf(ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", resp) + return errorsmod.Wrapf(ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", resp) } return nil } diff --git a/modules/core/04-channel/types/acknowledgement_test.go b/modules/core/04-channel/types/acknowledgement_test.go index 5a08f093500..13ca093fa91 100644 --- a/modules/core/04-channel/types/acknowledgement_test.go +++ b/modules/core/04-channel/types/acknowledgement_test.go @@ -3,11 +3,13 @@ package types_test import ( "fmt" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abcitypes "github.com/tendermint/tendermint/abci/types" tmprotostate "github.com/tendermint/tendermint/proto/tendermint/state" tmstate "github.com/tendermint/tendermint/state" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) @@ -91,11 +93,11 @@ func (suite TypesTestSuite) TestAcknowledgement() { //nolint:govet // this is a // This test acts as an indicator that the ABCI error codes may no longer be deterministic. func (suite *TypesTestSuite) TestABCICodeDeterminism() { // same ABCI error code used - err := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 1") - errSameABCICode := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 2") + err := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 1") + errSameABCICode := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 2") // different ABCI error code used - errDifferentABCICode := sdkerrors.ErrNotFound + errDifferentABCICode := ibcerrors.ErrNotFound deliverTx := sdkerrors.ResponseDeliverTxWithEvents(err, gasUsed, gasWanted, []abcitypes.Event{}, false) responses := tmprotostate.ABCIResponses{ @@ -130,11 +132,11 @@ func (suite *TypesTestSuite) TestABCICodeDeterminism() { // ABCI error code are used in constructing the acknowledgement error string func (suite *TypesTestSuite) TestAcknowledgementError() { // same ABCI error code used - err := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 1") - errSameABCICode := sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "error string 2") + err := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 1") + errSameABCICode := errorsmod.Wrap(ibcerrors.ErrOutOfGas, "error string 2") // different ABCI error code used - errDifferentABCICode := sdkerrors.ErrNotFound + errDifferentABCICode := ibcerrors.ErrNotFound ack := types.NewErrorAcknowledgement(err) ackSameABCICode := types.NewErrorAcknowledgement(errSameABCICode) diff --git a/modules/core/04-channel/types/channel.go b/modules/core/04-channel/types/channel.go index 0251571e3ee..012b571fb07 100644 --- a/modules/core/04-channel/types/channel.go +++ b/modules/core/04-channel/types/channel.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -57,16 +57,16 @@ func (ch Channel) ValidateBasic() error { return ErrInvalidChannelState } if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) { - return sdkerrors.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String()) + return errorsmod.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String()) } if len(ch.ConnectionHops) != 1 { - return sdkerrors.Wrap( + return errorsmod.Wrap( ErrTooManyConnectionHops, "current IBC version only supports one connection hop", ) } if err := host.ConnectionIdentifierValidator(ch.ConnectionHops[0]); err != nil { - return sdkerrors.Wrap(err, "invalid connection hop ID") + return errorsmod.Wrap(err, "invalid connection hop ID") } return ch.Counterparty.ValidateBasic() } @@ -92,11 +92,11 @@ func (c Counterparty) GetChannelID() string { // ValidateBasic performs a basic validation check of the identifiers func (c Counterparty) ValidateBasic() error { if err := host.PortIdentifierValidator(c.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty port ID") + return errorsmod.Wrap(err, "invalid counterparty port ID") } if c.ChannelId != "" { if err := host.ChannelIdentifierValidator(c.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty channel ID") + return errorsmod.Wrap(err, "invalid counterparty channel ID") } } return nil @@ -118,10 +118,10 @@ func NewIdentifiedChannel(portID, channelID string, ch Channel) IdentifiedChanne // ValidateBasic performs a basic validation of the identifiers and channel fields. func (ic IdentifiedChannel) ValidateBasic() error { if err := host.ChannelIdentifierValidator(ic.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid channel ID") + return errorsmod.Wrap(err, "invalid channel ID") } if err := host.PortIdentifierValidator(ic.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } channel := NewChannel(ic.State, ic.Ordering, ic.Counterparty, ic.ConnectionHops, ic.Version) return channel.ValidateBasic() diff --git a/modules/core/04-channel/types/errors.go b/modules/core/04-channel/types/errors.go index e807200c2cd..dfbbf30a1cb 100644 --- a/modules/core/04-channel/types/errors.go +++ b/modules/core/04-channel/types/errors.go @@ -1,43 +1,43 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC channel sentinel errors var ( - ErrChannelExists = sdkerrors.Register(SubModuleName, 2, "channel already exists") - ErrChannelNotFound = sdkerrors.Register(SubModuleName, 3, "channel not found") - ErrInvalidChannel = sdkerrors.Register(SubModuleName, 4, "invalid channel") - ErrInvalidChannelState = sdkerrors.Register(SubModuleName, 5, "invalid channel state") - ErrInvalidChannelOrdering = sdkerrors.Register(SubModuleName, 6, "invalid channel ordering") - ErrInvalidCounterparty = sdkerrors.Register(SubModuleName, 7, "invalid counterparty channel") - ErrInvalidChannelCapability = sdkerrors.Register(SubModuleName, 8, "invalid channel capability") - ErrChannelCapabilityNotFound = sdkerrors.Register(SubModuleName, 9, "channel capability not found") - ErrSequenceSendNotFound = sdkerrors.Register(SubModuleName, 10, "sequence send not found") - ErrSequenceReceiveNotFound = sdkerrors.Register(SubModuleName, 11, "sequence receive not found") - ErrSequenceAckNotFound = sdkerrors.Register(SubModuleName, 12, "sequence acknowledgement not found") - ErrInvalidPacket = sdkerrors.Register(SubModuleName, 13, "invalid packet") - ErrPacketTimeout = sdkerrors.Register(SubModuleName, 14, "packet timeout") - ErrTooManyConnectionHops = sdkerrors.Register(SubModuleName, 15, "too many connection hops") - ErrInvalidAcknowledgement = sdkerrors.Register(SubModuleName, 16, "invalid acknowledgement") - ErrAcknowledgementExists = sdkerrors.Register(SubModuleName, 17, "acknowledgement for packet already exists") - ErrInvalidChannelIdentifier = sdkerrors.Register(SubModuleName, 18, "invalid channel identifier") + ErrChannelExists = errorsmod.Register(SubModuleName, 2, "channel already exists") + ErrChannelNotFound = errorsmod.Register(SubModuleName, 3, "channel not found") + ErrInvalidChannel = errorsmod.Register(SubModuleName, 4, "invalid channel") + ErrInvalidChannelState = errorsmod.Register(SubModuleName, 5, "invalid channel state") + ErrInvalidChannelOrdering = errorsmod.Register(SubModuleName, 6, "invalid channel ordering") + ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 7, "invalid counterparty channel") + ErrInvalidChannelCapability = errorsmod.Register(SubModuleName, 8, "invalid channel capability") + ErrChannelCapabilityNotFound = errorsmod.Register(SubModuleName, 9, "channel capability not found") + ErrSequenceSendNotFound = errorsmod.Register(SubModuleName, 10, "sequence send not found") + ErrSequenceReceiveNotFound = errorsmod.Register(SubModuleName, 11, "sequence receive not found") + ErrSequenceAckNotFound = errorsmod.Register(SubModuleName, 12, "sequence acknowledgement not found") + ErrInvalidPacket = errorsmod.Register(SubModuleName, 13, "invalid packet") + ErrPacketTimeout = errorsmod.Register(SubModuleName, 14, "packet timeout") + ErrTooManyConnectionHops = errorsmod.Register(SubModuleName, 15, "too many connection hops") + ErrInvalidAcknowledgement = errorsmod.Register(SubModuleName, 16, "invalid acknowledgement") + ErrAcknowledgementExists = errorsmod.Register(SubModuleName, 17, "acknowledgement for packet already exists") + ErrInvalidChannelIdentifier = errorsmod.Register(SubModuleName, 18, "invalid channel identifier") // packets already relayed errors - ErrPacketReceived = sdkerrors.Register(SubModuleName, 19, "packet already received") - ErrPacketCommitmentNotFound = sdkerrors.Register(SubModuleName, 20, "packet commitment not found") // may occur for already received acknowledgements or timeouts and in rare cases for packets never sent + ErrPacketReceived = errorsmod.Register(SubModuleName, 19, "packet already received") + ErrPacketCommitmentNotFound = errorsmod.Register(SubModuleName, 20, "packet commitment not found") // may occur for already received acknowledgements or timeouts and in rare cases for packets never sent // ORDERED channel error - ErrPacketSequenceOutOfOrder = sdkerrors.Register(SubModuleName, 21, "packet sequence is out of order") + ErrPacketSequenceOutOfOrder = errorsmod.Register(SubModuleName, 21, "packet sequence is out of order") // Antehandler error - ErrRedundantTx = sdkerrors.Register(SubModuleName, 22, "packet messages are redundant") + ErrRedundantTx = errorsmod.Register(SubModuleName, 22, "packet messages are redundant") // Perform a no-op on the current Msg - ErrNoOpMsg = sdkerrors.Register(SubModuleName, 23, "message is redundant, no-op will be performed") + ErrNoOpMsg = errorsmod.Register(SubModuleName, 23, "message is redundant, no-op will be performed") - ErrInvalidChannelVersion = sdkerrors.Register(SubModuleName, 24, "invalid channel version") - ErrPacketNotSent = sdkerrors.Register(SubModuleName, 25, "packet has not been sent") - ErrInvalidTimeout = sdkerrors.Register(SubModuleName, 26, "invalid packet timeout") + ErrInvalidChannelVersion = errorsmod.Register(SubModuleName, 24, "invalid channel version") + ErrPacketNotSent = errorsmod.Register(SubModuleName, 25, "packet has not been sent") + ErrInvalidTimeout = errorsmod.Register(SubModuleName, 26, "invalid packet timeout") ) diff --git a/modules/core/04-channel/types/keys.go b/modules/core/04-channel/types/keys.go index 48abec46b20..d961abe3dc0 100644 --- a/modules/core/04-channel/types/keys.go +++ b/modules/core/04-channel/types/keys.go @@ -4,7 +4,7 @@ import ( "fmt" "regexp" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ) @@ -50,12 +50,12 @@ func IsValidChannelID(channelID string) bool { // ParseChannelSequence parses the channel sequence from the channel identifier. func ParseChannelSequence(channelID string) (uint64, error) { if !IsChannelIDFormat(channelID) { - return 0, sdkerrors.Wrap(host.ErrInvalidID, "channel identifier is not in the format: `channel-{N}`") + return 0, errorsmod.Wrap(host.ErrInvalidID, "channel identifier is not in the format: `channel-{N}`") } sequence, err := host.ParseIdentifier(channelID, ChannelPrefix) if err != nil { - return 0, sdkerrors.Wrap(err, "invalid channel identifier") + return 0, errorsmod.Wrap(err, "invalid channel identifier") } return sequence, nil diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index b3d9aaf0644..fec50b53b69 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -3,9 +3,10 @@ package types import ( "encoding/base64" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -33,20 +34,20 @@ func NewMsgChannelOpenInit( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenInit) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if msg.Channel.State != INIT { - return sdkerrors.Wrapf(ErrInvalidChannelState, + return errorsmod.Wrapf(ErrInvalidChannelState, "channel state must be INIT in MsgChannelOpenInit. expected: %s, got: %s", INIT, msg.Channel.State, ) } if msg.Channel.Counterparty.ChannelId != "" { - return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty channel identifier must be empty") + return errorsmod.Wrap(ErrInvalidCounterparty, "counterparty channel identifier must be empty") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Channel.ValidateBasic() } @@ -87,28 +88,28 @@ func NewMsgChannelOpenTry( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenTry) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if msg.PreviousChannelId != "" { - return sdkerrors.Wrap(ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") + return errorsmod.Wrap(ErrInvalidChannelIdentifier, "previous channel identifier must be empty, this field has been deprecated as crossing hellos are no longer supported") } if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") } if msg.Channel.State != TRYOPEN { - return sdkerrors.Wrapf(ErrInvalidChannelState, + return errorsmod.Wrapf(ErrInvalidChannelState, "channel state must be TRYOPEN in MsgChannelOpenTry. expected: %s, got: %s", TRYOPEN, msg.Channel.State, ) } // counterparty validate basic allows empty counterparty channel identifiers if err := host.ChannelIdentifierValidator(msg.Channel.Counterparty.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty channel ID") + return errorsmod.Wrap(err, "invalid counterparty channel ID") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Channel.ValidateBasic() } @@ -145,20 +146,20 @@ func NewMsgChannelOpenAck( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenAck) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid counterparty channel ID") + return errorsmod.Wrap(err, "invalid counterparty channel ID") } if len(msg.ProofTry) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof try") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -193,17 +194,17 @@ func NewMsgChannelOpenConfirm( // ValidateBasic implements sdk.Msg func (msg MsgChannelOpenConfirm) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } if len(msg.ProofAck) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof ack") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -235,14 +236,14 @@ func NewMsgChannelCloseInit( // ValidateBasic implements sdk.Msg func (msg MsgChannelCloseInit) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -277,17 +278,17 @@ func NewMsgChannelCloseConfirm( // ValidateBasic implements sdk.Msg func (msg MsgChannelCloseConfirm) ValidateBasic() error { if err := host.PortIdentifierValidator(msg.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid port ID") + return errorsmod.Wrap(err, "invalid port ID") } if !IsValidChannelID(msg.ChannelId) { return ErrInvalidChannelIdentifier } if len(msg.ProofInit) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof init") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return nil } @@ -321,11 +322,11 @@ func NewMsgRecvPacket( // ValidateBasic implements sdk.Msg func (msg MsgRecvPacket) ValidateBasic() error { if len(msg.ProofCommitment) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } @@ -367,14 +368,14 @@ func NewMsgTimeout( // ValidateBasic implements sdk.Msg func (msg MsgTimeout) ValidateBasic() error { if len(msg.ProofUnreceived) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty unreceived proof") } if msg.NextSequenceRecv == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") + return errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } @@ -409,17 +410,17 @@ func NewMsgTimeoutOnClose( // ValidateBasic implements sdk.Msg func (msg MsgTimeoutOnClose) ValidateBasic() error { if msg.NextSequenceRecv == 0 { - return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "next sequence receive cannot be 0") + return errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "next sequence receive cannot be 0") } if len(msg.ProofUnreceived) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if len(msg.ProofClose) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof of closed counterparty channel end") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } @@ -456,14 +457,14 @@ func NewMsgAcknowledgement( // ValidateBasic implements sdk.Msg func (msg MsgAcknowledgement) ValidateBasic() error { if len(msg.ProofAcked) == 0 { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") } if len(msg.Acknowledgement) == 0 { - return sdkerrors.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty") + return errorsmod.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty") } _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Packet.ValidateBasic() } diff --git a/modules/core/04-channel/types/packet.go b/modules/core/04-channel/types/packet.go index 3f2390bd11b..c007f3af9b0 100644 --- a/modules/core/04-channel/types/packet.go +++ b/modules/core/04-channel/types/packet.go @@ -3,9 +3,9 @@ package types import ( "crypto/sha256" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -89,25 +89,25 @@ func (p Packet) GetTimeoutTimestamp() uint64 { return p.TimeoutTimestamp } // ValidateBasic implements PacketI interface func (p Packet) ValidateBasic() error { if err := host.PortIdentifierValidator(p.SourcePort); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.PortIdentifierValidator(p.DestinationPort); err != nil { - return sdkerrors.Wrap(err, "invalid destination port ID") + return errorsmod.Wrap(err, "invalid destination port ID") } if err := host.ChannelIdentifierValidator(p.SourceChannel); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } if err := host.ChannelIdentifierValidator(p.DestinationChannel); err != nil { - return sdkerrors.Wrap(err, "invalid destination channel ID") + return errorsmod.Wrap(err, "invalid destination channel ID") } if p.Sequence == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") + return errorsmod.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") } if p.TimeoutHeight.IsZero() && p.TimeoutTimestamp == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet timeout height and packet timeout timestamp cannot both be 0") + return errorsmod.Wrap(ErrInvalidPacket, "packet timeout height and packet timeout timestamp cannot both be 0") } if len(p.Data) == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty") + return errorsmod.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty") } return nil } @@ -115,15 +115,15 @@ func (p Packet) ValidateBasic() error { // Validates a PacketId func (p PacketId) Validate() error { if err := host.PortIdentifierValidator(p.PortId); err != nil { - return sdkerrors.Wrap(err, "invalid source port ID") + return errorsmod.Wrap(err, "invalid source port ID") } if err := host.ChannelIdentifierValidator(p.ChannelId); err != nil { - return sdkerrors.Wrap(err, "invalid source channel ID") + return errorsmod.Wrap(err, "invalid source channel ID") } if p.Sequence == 0 { - return sdkerrors.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") + return errorsmod.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") } return nil diff --git a/modules/core/05-port/types/errors.go b/modules/core/05-port/types/errors.go index 23a2776f59d..1348dfc83b4 100644 --- a/modules/core/05-port/types/errors.go +++ b/modules/core/05-port/types/errors.go @@ -1,13 +1,13 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC port sentinel errors var ( - ErrPortExists = sdkerrors.Register(SubModuleName, 2, "port is already binded") - ErrPortNotFound = sdkerrors.Register(SubModuleName, 3, "port not found") - ErrInvalidPort = sdkerrors.Register(SubModuleName, 4, "invalid port") - ErrInvalidRoute = sdkerrors.Register(SubModuleName, 5, "route not found") + ErrPortExists = errorsmod.Register(SubModuleName, 2, "port is already binded") + ErrPortNotFound = errorsmod.Register(SubModuleName, 3, "port not found") + ErrInvalidPort = errorsmod.Register(SubModuleName, 4, "invalid port") + ErrInvalidRoute = errorsmod.Register(SubModuleName, 5, "route not found") ) diff --git a/modules/core/23-commitment/types/errors.go b/modules/core/23-commitment/types/errors.go index 7191baef1cc..140ec912b00 100644 --- a/modules/core/23-commitment/types/errors.go +++ b/modules/core/23-commitment/types/errors.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // SubModuleName is the error codespace @@ -9,7 +9,7 @@ const SubModuleName string = "commitment" // IBC connection sentinel errors var ( - ErrInvalidProof = sdkerrors.Register(SubModuleName, 2, "invalid proof") - ErrInvalidPrefix = sdkerrors.Register(SubModuleName, 3, "invalid prefix") - ErrInvalidMerkleProof = sdkerrors.Register(SubModuleName, 4, "invalid merkle proof") + ErrInvalidProof = errorsmod.Register(SubModuleName, 2, "invalid proof") + ErrInvalidPrefix = errorsmod.Register(SubModuleName, 3, "invalid prefix") + ErrInvalidMerkleProof = errorsmod.Register(SubModuleName, 4, "invalid merkle proof") ) diff --git a/modules/core/23-commitment/types/merkle.go b/modules/core/23-commitment/types/merkle.go index 33c6f51dba7..7d15b00a318 100644 --- a/modules/core/23-commitment/types/merkle.go +++ b/modules/core/23-commitment/types/merkle.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/gogoproto/proto" ics23 "github.com/cosmos/ics23/go" tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" @@ -121,7 +121,7 @@ func (mp MerklePath) Empty() bool { // with the given path. func ApplyPrefix(prefix exported.Prefix, path MerklePath) (MerklePath, error) { if prefix == nil || prefix.Empty() { - return MerklePath{}, sdkerrors.Wrap(ErrInvalidPrefix, "prefix can't be empty") + return MerklePath{}, errorsmod.Wrap(ErrInvalidPrefix, "prefix can't be empty") } return NewMerklePath(append([]string{string(prefix.Bytes())}, path.KeyPath...)...), nil } @@ -138,14 +138,14 @@ func (proof MerkleProof) VerifyMembership(specs []*ics23.ProofSpec, root exporte // VerifyMembership specific argument validation mpath, ok := path.(MerklePath) if !ok { - return sdkerrors.Wrapf(ErrInvalidProof, "path %v is not of type MerklePath", path) + return errorsmod.Wrapf(ErrInvalidProof, "path %v is not of type MerklePath", path) } if len(mpath.KeyPath) != len(specs) { - return sdkerrors.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", + return errorsmod.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", len(mpath.KeyPath), len(specs)) } if len(value) == 0 { - return sdkerrors.Wrap(ErrInvalidProof, "empty value in membership proof") + return errorsmod.Wrap(ErrInvalidProof, "empty value in membership proof") } // Since every proof in chain is a membership proof we can use verifyChainedMembershipProof from index 0 @@ -167,10 +167,10 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo // VerifyNonMembership specific argument validation mpath, ok := path.(MerklePath) if !ok { - return sdkerrors.Wrapf(ErrInvalidProof, "path %v is not of type MerkleProof", path) + return errorsmod.Wrapf(ErrInvalidProof, "path %v is not of type MerkleProof", path) } if len(mpath.KeyPath) != len(specs) { - return sdkerrors.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", + return errorsmod.Wrapf(ErrInvalidProof, "path length %d not same as proof %d", len(mpath.KeyPath), len(specs)) } @@ -180,14 +180,14 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo // of all subroots up to final root subroot, err := proof.Proofs[0].Calculate() if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0, merkle tree is likely empty. %v", err) + return errorsmod.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0, merkle tree is likely empty. %v", err) } key, err := mpath.GetKey(uint64(len(mpath.KeyPath) - 1)) if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key: %s", mpath.KeyPath[len(mpath.KeyPath)-1]) + return errorsmod.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key: %s", mpath.KeyPath[len(mpath.KeyPath)-1]) } if ok := ics23.VerifyNonMembership(specs[0], subroot, proof.Proofs[0], key); !ok { - return sdkerrors.Wrapf(ErrInvalidProof, "could not verify absence of key %s. Please ensure that the path is correct.", string(key)) + return errorsmod.Wrapf(ErrInvalidProof, "could not verify absence of key %s. Please ensure that the path is correct.", string(key)) } // Verify chained membership proof starting from index 1 with value = subroot @@ -195,10 +195,10 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo return err } case *ics23.CommitmentProof_Exist: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "got ExistenceProof in VerifyNonMembership. If this is unexpected, please ensure that proof was queried with the correct key.") default: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "expected proof type: %T, got: %T", &ics23.CommitmentProof_Exist{}, proof.Proofs[0].Proof) } return nil @@ -207,13 +207,13 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo // BatchVerifyMembership verifies a group of key value pairs against the given root // NOTE: Currently left unimplemented as it is unused func (proof MerkleProof) BatchVerifyMembership(specs []*ics23.ProofSpec, root exported.Root, path exported.Path, items map[string][]byte) error { - return sdkerrors.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") + return errorsmod.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") } // BatchVerifyNonMembership verifies absence of a group of keys against the given root // NOTE: Currently left unimplemented as it is unused func (proof MerkleProof) BatchVerifyNonMembership(specs []*ics23.ProofSpec, root exported.Root, path exported.Path, items [][]byte) error { - return sdkerrors.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") + return errorsmod.Wrap(ErrInvalidProof, "batch proofs are currently unsupported") } // verifyChainedMembershipProof takes a list of proofs and specs and verifies each proof sequentially ensuring that the value is committed to @@ -235,35 +235,35 @@ func verifyChainedMembershipProof(root []byte, specs []*ics23.ProofSpec, proofs case *ics23.CommitmentProof_Exist: subroot, err = proofs[i].Calculate() if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not calculate proof root at index %d, merkle tree may be empty. %v", i, err) + return errorsmod.Wrapf(ErrInvalidProof, "could not calculate proof root at index %d, merkle tree may be empty. %v", i, err) } // Since keys are passed in from highest to lowest, we must grab their indices in reverse order // from the proofs and specs which are lowest to highest key, err := keys.GetKey(uint64(len(keys.KeyPath) - 1 - i)) if err != nil { - return sdkerrors.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key %s: %v", keys.KeyPath[len(keys.KeyPath)-1-i], err) + return errorsmod.Wrapf(ErrInvalidProof, "could not retrieve key bytes for key %s: %v", keys.KeyPath[len(keys.KeyPath)-1-i], err) } // verify membership of the proof at this index with appropriate key and value if ok := ics23.VerifyMembership(specs[i], subroot, proofs[i], key, value); !ok { - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "chained membership proof failed to verify membership of value: %X in subroot %X at index %d. Please ensure the path and value are both correct.", value, subroot, i) } // Set value to subroot so that we verify next proof in chain commits to this subroot value = subroot case *ics23.CommitmentProof_Nonexist: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "chained membership proof contains nonexistence proof at index %d. If this is unexpected, please ensure that proof was queried from a height that contained the value in store and was queried with the correct key. The key used: %s", i, keys) default: - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "expected proof type: %T, got: %T", &ics23.CommitmentProof_Exist{}, proofs[i].Proof) } } // Check that chained proof root equals passed-in root if !bytes.Equal(root, subroot) { - return sdkerrors.Wrapf(ErrInvalidProof, + return errorsmod.Wrapf(ErrInvalidProof, "proof did not commit to expected root: %X, got: %X. Please ensure proof was submitted with correct proofHeight and to the correct chain.", root, subroot) } @@ -293,22 +293,22 @@ func (proof MerkleProof) ValidateBasic() error { // validateVerificationArgs verifies the proof arguments are valid func (proof MerkleProof) validateVerificationArgs(specs []*ics23.ProofSpec, root exported.Root) error { if proof.Empty() { - return sdkerrors.Wrap(ErrInvalidMerkleProof, "proof cannot be empty") + return errorsmod.Wrap(ErrInvalidMerkleProof, "proof cannot be empty") } if root == nil || root.Empty() { - return sdkerrors.Wrap(ErrInvalidMerkleProof, "root cannot be empty") + return errorsmod.Wrap(ErrInvalidMerkleProof, "root cannot be empty") } if len(specs) != len(proof.Proofs) { - return sdkerrors.Wrapf(ErrInvalidMerkleProof, + return errorsmod.Wrapf(ErrInvalidMerkleProof, "length of specs: %d not equal to length of proof: %d", len(specs), len(proof.Proofs)) } for i, spec := range specs { if spec == nil { - return sdkerrors.Wrapf(ErrInvalidProof, "spec at position %d is nil", i) + return errorsmod.Wrapf(ErrInvalidProof, "spec at position %d is nil", i) } } return nil diff --git a/modules/core/23-commitment/types/utils.go b/modules/core/23-commitment/types/utils.go index e2c4317a9fc..2ad3bcf57dc 100644 --- a/modules/core/23-commitment/types/utils.go +++ b/modules/core/23-commitment/types/utils.go @@ -1,7 +1,7 @@ package types import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ics23 "github.com/cosmos/ics23/go" crypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) @@ -9,7 +9,7 @@ import ( // ConvertProofs converts crypto.ProofOps into MerkleProof func ConvertProofs(tmProof *crypto.ProofOps) (MerkleProof, error) { if tmProof == nil { - return MerkleProof{}, sdkerrors.Wrapf(ErrInvalidMerkleProof, "tendermint proof is nil") + return MerkleProof{}, errorsmod.Wrapf(ErrInvalidMerkleProof, "tendermint proof is nil") } // Unmarshal all proof ops to CommitmentProof proofs := make([]*ics23.CommitmentProof, len(tmProof.Ops)) @@ -17,7 +17,7 @@ func ConvertProofs(tmProof *crypto.ProofOps) (MerkleProof, error) { var p ics23.CommitmentProof err := p.Unmarshal(op.Data) if err != nil || p.Proof == nil { - return MerkleProof{}, sdkerrors.Wrapf(ErrInvalidMerkleProof, "could not unmarshal proof op into CommitmentProof at index %d: %v", i, err) + return MerkleProof{}, errorsmod.Wrapf(ErrInvalidMerkleProof, "could not unmarshal proof op into CommitmentProof at index %d: %v", i, err) } proofs[i] = &p } diff --git a/modules/core/24-host/errors.go b/modules/core/24-host/errors.go index fe8129bde86..742f1779311 100644 --- a/modules/core/24-host/errors.go +++ b/modules/core/24-host/errors.go @@ -1,7 +1,7 @@ package host import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // SubModuleName defines the ICS 24 host @@ -9,7 +9,7 @@ const SubModuleName = "host" // IBC client sentinel errors var ( - ErrInvalidID = sdkerrors.Register(SubModuleName, 2, "invalid identifier") - ErrInvalidPath = sdkerrors.Register(SubModuleName, 3, "invalid path") - ErrInvalidPacket = sdkerrors.Register(SubModuleName, 4, "invalid packet") + ErrInvalidID = errorsmod.Register(SubModuleName, 2, "invalid identifier") + ErrInvalidPath = errorsmod.Register(SubModuleName, 3, "invalid path") + ErrInvalidPacket = errorsmod.Register(SubModuleName, 4, "invalid packet") ) diff --git a/modules/core/24-host/parse.go b/modules/core/24-host/parse.go index ad8f8af90e9..81074bbfcca 100644 --- a/modules/core/24-host/parse.go +++ b/modules/core/24-host/parse.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // ParseIdentifier parses the sequence from the identifier using the provided prefix. This function @@ -12,22 +12,22 @@ import ( // are required to use this format. func ParseIdentifier(identifier, prefix string) (uint64, error) { if !strings.HasPrefix(identifier, prefix) { - return 0, sdkerrors.Wrapf(ErrInvalidID, "identifier doesn't contain prefix `%s`", prefix) + return 0, errorsmod.Wrapf(ErrInvalidID, "identifier doesn't contain prefix `%s`", prefix) } splitStr := strings.Split(identifier, prefix) if len(splitStr) != 2 { - return 0, sdkerrors.Wrapf(ErrInvalidID, "identifier must be in format: `%s{N}`", prefix) + return 0, errorsmod.Wrapf(ErrInvalidID, "identifier must be in format: `%s{N}`", prefix) } // sanity check if splitStr[0] != "" { - return 0, sdkerrors.Wrapf(ErrInvalidID, "identifier must begin with prefix %s", prefix) + return 0, errorsmod.Wrapf(ErrInvalidID, "identifier must begin with prefix %s", prefix) } sequence, err := strconv.ParseUint(splitStr[1], 10, 64) if err != nil { - return 0, sdkerrors.Wrap(err, "failed to parse identifier sequence") + return 0, errorsmod.Wrap(err, "failed to parse identifier sequence") } return sequence, nil } @@ -48,19 +48,19 @@ func MustParseClientStatePath(path string) string { func parseClientStatePath(path string) (string, error) { split := strings.Split(path, "/") if len(split) != 3 { - return "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse client state path %s", path) + return "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse client state path %s", path) } if split[0] != string(KeyClientStorePrefix) { - return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not begin with client store prefix: expected %s, got %s", KeyClientStorePrefix, split[0]) + return "", errorsmod.Wrapf(ErrInvalidPath, "path does not begin with client store prefix: expected %s, got %s", KeyClientStorePrefix, split[0]) } if split[2] != KeyClientState { - return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not end with client state key: expected %s, got %s", KeyClientState, split[2]) + return "", errorsmod.Wrapf(ErrInvalidPath, "path does not end with client state key: expected %s, got %s", KeyClientState, split[2]) } if strings.TrimSpace(split[1]) == "" { - return "", sdkerrors.Wrap(ErrInvalidPath, "clientID is empty") + return "", errorsmod.Wrap(ErrInvalidPath, "clientID is empty") } return split[1], nil @@ -71,7 +71,7 @@ func parseClientStatePath(path string) (string, error) { func ParseConnectionPath(path string) (string, error) { split := strings.Split(path, "/") if len(split) != 2 { - return "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse connection path %s", path) + return "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse connection path %s", path) } return split[1], nil @@ -82,11 +82,11 @@ func ParseConnectionPath(path string) (string, error) { func ParseChannelPath(path string) (string, string, error) { split := strings.Split(path, "/") if len(split) < 5 { - return "", "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) + return "", "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) } if split[1] != KeyPortPrefix || split[3] != KeyChannelPrefix { - return "", "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) + return "", "", errorsmod.Wrapf(ErrInvalidPath, "cannot parse channel path %s", path) } return split[2], split[4], nil diff --git a/modules/core/24-host/validate.go b/modules/core/24-host/validate.go index 23341cec543..e6219d99b40 100644 --- a/modules/core/24-host/validate.go +++ b/modules/core/24-host/validate.go @@ -4,7 +4,7 @@ import ( "regexp" "strings" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // DefaultMaxCharacterLength defines the default maximum character length used @@ -38,19 +38,19 @@ type ValidateFn func(string) error func defaultIdentifierValidator(id string, min, max int) error { if strings.TrimSpace(id) == "" { - return sdkerrors.Wrap(ErrInvalidID, "identifier cannot be blank") + return errorsmod.Wrap(ErrInvalidID, "identifier cannot be blank") } // valid id MUST NOT contain "/" separator if strings.Contains(id, "/") { - return sdkerrors.Wrapf(ErrInvalidID, "identifier %s cannot contain separator '/'", id) + return errorsmod.Wrapf(ErrInvalidID, "identifier %s cannot contain separator '/'", id) } // valid id must fit the length requirements if len(id) < min || len(id) > max { - return sdkerrors.Wrapf(ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", id, len(id), min, max) + return errorsmod.Wrapf(ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", id, len(id), min, max) } // valid id must contain only lower alphabetic characters if !IsValidID(id) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidID, "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'", id, @@ -95,13 +95,13 @@ func NewPathValidator(idValidator ValidateFn) ValidateFn { return func(path string) error { pathArr := strings.Split(path, "/") if len(pathArr) > 0 && pathArr[0] == path { - return sdkerrors.Wrapf(ErrInvalidPath, "path %s doesn't contain any separator '/'", path) + return errorsmod.Wrapf(ErrInvalidPath, "path %s doesn't contain any separator '/'", path) } for _, p := range pathArr { // a path beginning or ending in a separator returns empty string elements. if p == "" { - return sdkerrors.Wrapf(ErrInvalidPath, "path %s cannot begin or end with '/'", path) + return errorsmod.Wrapf(ErrInvalidPath, "path %s cannot begin or end with '/'", path) } if err := idValidator(p); err != nil { @@ -109,7 +109,7 @@ func NewPathValidator(idValidator ValidateFn) ValidateFn { } // Each path element must either be a valid identifier or constant number if err := defaultIdentifierValidator(p, 1, DefaultMaxCharacterLength); err != nil { - return sdkerrors.Wrapf(err, "path %s contains an invalid identifier: '%s'", path, p) + return errorsmod.Wrapf(err, "path %s contains an invalid identifier: '%s'", path, p) } } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 1fd8ec8dcdb..2bf694e1e2f 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -3,10 +3,10 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" metrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -102,7 +102,7 @@ func (k Keeper) ConnectionOpenInit(goCtx context.Context, msg *connectiontypes.M ctx := sdk.UnwrapSDKContext(goCtx) if _, err := k.ConnectionKeeper.ConnOpenInit(ctx, msg.ClientId, msg.Counterparty, msg.Version, msg.DelayPeriod); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open init failed") + return nil, errorsmod.Wrap(err, "connection handshake open init failed") } return &connectiontypes.MsgConnectionOpenInitResponse{}, nil @@ -122,7 +122,7 @@ func (k Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.Ms connectiontypes.ProtoVersionsToExported(msg.CounterpartyVersions), msg.ProofInit, msg.ProofClient, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, ); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open try failed") + return nil, errorsmod.Wrap(err, "connection handshake open try failed") } return &connectiontypes.MsgConnectionOpenTryResponse{}, nil @@ -141,7 +141,7 @@ func (k Keeper) ConnectionOpenAck(goCtx context.Context, msg *connectiontypes.Ms msg.ProofTry, msg.ProofClient, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, ); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open ack failed") + return nil, errorsmod.Wrap(err, "connection handshake open ack failed") } return &connectiontypes.MsgConnectionOpenAckResponse{}, nil @@ -154,7 +154,7 @@ func (k Keeper) ConnectionOpenConfirm(goCtx context.Context, msg *connectiontype if err := k.ConnectionKeeper.ConnOpenConfirm( ctx, msg.ConnectionId, msg.ProofAck, msg.ProofHeight, ); err != nil { - return nil, sdkerrors.Wrap(err, "connection handshake open confirm failed") + return nil, errorsmod.Wrap(err, "connection handshake open confirm failed") } return &connectiontypes.MsgConnectionOpenConfirmResponse{}, nil @@ -169,15 +169,15 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan // Lookup module by port capability module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortId) if err != nil { - ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification @@ -186,15 +186,15 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan portCap, msg.Channel.Counterparty, msg.Channel.Version, ) if err != nil { - ctx.Logger().Error("channel open init callback failed", "error", sdkerrors.Wrap(err, "channel handshake open init failed")) - return nil, sdkerrors.Wrap(err, "channel handshake open init failed") + ctx.Logger().Error("channel open init callback failed", "error", errorsmod.Wrap(err, "channel handshake open init failed")) + return nil, errorsmod.Wrap(err, "channel handshake open init failed") } // Perform application logic callback version, err := cbs.OnChanOpenInit(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, cap, msg.Channel.Counterparty, msg.Channel.Version) if err != nil { ctx.Logger().Error("channel open init callback failed", "port-id", msg.PortId, "channel-id", channelID, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open init callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) + return nil, errorsmod.Wrapf(err, "channel open init callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) } // Write channel into state @@ -217,15 +217,15 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann // Lookup module by port capability module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortId) if err != nil { - ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification @@ -233,15 +233,15 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann portCap, msg.Channel.Counterparty, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, ) if err != nil { - ctx.Logger().Error("channel open try callback failed", "error", sdkerrors.Wrap(err, "channel handshake open try failed")) - return nil, sdkerrors.Wrap(err, "channel handshake open try failed") + ctx.Logger().Error("channel open try callback failed", "error", errorsmod.Wrap(err, "channel handshake open try failed")) + return nil, errorsmod.Wrap(err, "channel handshake open try failed") } // Perform application logic callback version, err := cbs.OnChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, channelID, cap, msg.Channel.Counterparty, msg.CounterpartyVersion) if err != nil { ctx.Logger().Error("channel open try callback failed", "port-id", msg.PortId, "channel-id", channelID, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open try callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) + return nil, errorsmod.Wrapf(err, "channel open try callback failed for port ID: %s, channel ID: %s", msg.PortId, channelID) } // Write channel into state @@ -264,15 +264,15 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open ack callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification @@ -280,7 +280,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann ctx, msg.PortId, msg.ChannelId, cap, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, ); err != nil { ctx.Logger().Error("channel open ack callback failed", "error", err.Error()) - return nil, sdkerrors.Wrap(err, "channel handshake open ack failed") + return nil, errorsmod.Wrap(err, "channel handshake open ack failed") } // Write channel into state @@ -289,7 +289,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann // Perform application logic callback if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelId, msg.CounterpartyVersion); err != nil { ctx.Logger().Error("channel handshake open ack callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open ack callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel open ack callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } ctx.Logger().Info("channel open ack callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -306,21 +306,21 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve application callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel open confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform 04-channel verification if err = k.ChannelKeeper.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, cap, msg.ProofAck, msg.ProofHeight); err != nil { - ctx.Logger().Error("channel open confirm callback failed", "error", sdkerrors.Wrap(err, "channel handshake open confirm failed")) - return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed") + ctx.Logger().Error("channel open confirm callback failed", "error", errorsmod.Wrap(err, "channel handshake open confirm failed")) + return nil, errorsmod.Wrap(err, "channel handshake open confirm failed") } // Write channel into state @@ -329,7 +329,7 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC // Perform application logic callback if err = cbs.OnChanOpenConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel handshake open confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel open confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel open confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } ctx.Logger().Info("channel open confirm callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -343,26 +343,26 @@ func (k Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgCha // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } if err = cbs.OnChanCloseInit(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel close init callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel close init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel close init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } err = k.ChannelKeeper.ChanCloseInit(ctx, msg.PortId, msg.ChannelId, cap) if err != nil { ctx.Logger().Error("channel handshake close init callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrap(err, "channel handshake close init failed") + return nil, errorsmod.Wrap(err, "channel handshake close init failed") } ctx.Logger().Info("channel close init callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -377,26 +377,26 @@ func (k Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Msg // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId) if err != nil { - ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } if err = cbs.OnChanCloseConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { ctx.Logger().Error("channel close confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrapf(err, "channel close confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) + return nil, errorsmod.Wrapf(err, "channel close confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } err = k.ChannelKeeper.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, cap, msg.ProofInit, msg.ProofHeight) if err != nil { ctx.Logger().Error("channel handshake close confirm callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) - return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed") + return nil, errorsmod.Wrap(err, "channel handshake close confirm failed") } ctx.Logger().Info("channel close confirm callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId) @@ -410,22 +410,22 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("receive packet failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("receive packet failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) if err != nil { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -442,8 +442,8 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke // no-ops do not need event emission as they will be ignored return &channeltypes.MsgRecvPacketResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "receive packet verification failed")) - return nil, sdkerrors.Wrap(err, "receive packet verification failed") + ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "receive packet verification failed")) + return nil, errorsmod.Wrap(err, "receive packet verification failed") } // Perform application logic callback @@ -493,22 +493,22 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("timeout failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("timeout failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -525,15 +525,15 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c // no-ops do not need event emission as they will be ignored return &channeltypes.MsgTimeoutResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout packet verification failed")) - return nil, sdkerrors.Wrap(err, "timeout packet verification failed") + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet verification failed")) + return nil, errorsmod.Wrap(err, "timeout packet verification failed") } // Perform application logic callback err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) if err != nil { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout packet callback failed")) - return nil, sdkerrors.Wrap(err, "timeout packet callback failed") + ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet callback failed")) + return nil, errorsmod.Wrap(err, "timeout packet callback failed") } // Delete packet commitment @@ -566,22 +566,22 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("timeout on close failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("timeout on close failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -598,8 +598,8 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo // no-ops do not need event emission as they will be ignored return &channeltypes.MsgTimeoutOnCloseResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout on close packet verification failed")) - return nil, sdkerrors.Wrap(err, "timeout on close packet verification failed") + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout on close packet verification failed")) + return nil, errorsmod.Wrap(err, "timeout on close packet verification failed") } // Perform application logic callback @@ -608,8 +608,8 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo // application logic callback. err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) if err != nil { - ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "timeout packet callback failed")) - return nil, sdkerrors.Wrap(err, "timeout packet callback failed") + ctx.Logger().Error("timeout on close failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet callback failed")) + return nil, errorsmod.Wrap(err, "timeout packet callback failed") } // Delete packet commitment @@ -642,22 +642,22 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn relayer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { - ctx.Logger().Error("acknowledgement failed", "error", sdkerrors.Wrap(err, "Invalid address for msg Signer")) - return nil, sdkerrors.Wrap(err, "Invalid address for msg Signer") + ctx.Logger().Error("acknowledgement failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "could not retrieve module from port-id")) - return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) + return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") } // Retrieve callbacks from router cbs, ok := k.Router.GetRoute(module) if !ok { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) - return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)) + return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } // Perform TAO verification @@ -674,15 +674,15 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn // no-ops do not need event emission as they will be ignored return &channeltypes.MsgAcknowledgementResponse{Result: channeltypes.NOOP}, nil default: - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "acknowledge packet verification failed")) - return nil, sdkerrors.Wrap(err, "acknowledge packet verification failed") + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "acknowledge packet verification failed")) + return nil, errorsmod.Wrap(err, "acknowledge packet verification failed") } // Perform application logic callback err = cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement, relayer) if err != nil { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", sdkerrors.Wrap(err, "acknowledge packet callback failed")) - return nil, sdkerrors.Wrap(err, "acknowledge packet callback failed") + ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "acknowledge packet callback failed")) + return nil, errorsmod.Wrap(err, "acknowledge packet callback failed") } defer func() { diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 24346407da7..2c316dacaec 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -3,12 +3,13 @@ package solomachine import ( "reflect" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -63,10 +64,10 @@ func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) // Validate performs basic validation of the client state fields. func (cs ClientState) Validate() error { if cs.Sequence == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "sequence cannot be 0") + return errorsmod.Wrap(clienttypes.ErrInvalidClient, "sequence cannot be 0") } if cs.ConsensusState == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be nil") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be nil") } return cs.ConsensusState.ValidateBasic() } @@ -80,7 +81,7 @@ func (cs ClientState) ZeroCustomFields() exported.ClientState { // sets the client state in the provided client store. func (cs ClientState) Initialize(_ sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, consState exported.ConsensusState) error { if !reflect.DeepEqual(cs.ConsensusState, consState) { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "consensus state in initial client does not equal initial consensus state. expected: %s, got: %s", + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "consensus state in initial client does not equal initial consensus state. expected: %s, got: %s", cs.ConsensusState, consState) } @@ -99,7 +100,7 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientState, _ exported.ConsensusState, _, _ []byte, ) error { - return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade solomachine client") + return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade solomachine client") } // VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the latest sequence. @@ -122,11 +123,11 @@ func (cs *ClientState) VerifyMembership( merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } if merklePath.Empty() { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "path is empty") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "path is empty") } signBytes := &SignBytes{ @@ -172,7 +173,7 @@ func (cs *ClientState) VerifyNonMembership( merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } signBytes := &SignBytes{ @@ -208,17 +209,17 @@ func produceVerificationArgs( proof []byte, ) (cryptotypes.PubKey, signing.SignatureData, uint64, uint64, error) { if proof == nil { - return nil, nil, 0, 0, sdkerrors.Wrap(ErrInvalidProof, "proof cannot be empty") + return nil, nil, 0, 0, errorsmod.Wrap(ErrInvalidProof, "proof cannot be empty") } var timestampedSigData TimestampedSignatureData if err := cdc.Unmarshal(proof, ×tampedSigData); err != nil { - return nil, nil, 0, 0, sdkerrors.Wrapf(err, "failed to unmarshal proof into type %T", timestampedSigData) + return nil, nil, 0, 0, errorsmod.Wrapf(err, "failed to unmarshal proof into type %T", timestampedSigData) } timestamp := timestampedSigData.Timestamp if len(timestampedSigData.SignatureData) == 0 { - return nil, nil, 0, 0, sdkerrors.Wrap(ErrInvalidProof, "signature data cannot be empty") + return nil, nil, 0, 0, errorsmod.Wrap(ErrInvalidProof, "signature data cannot be empty") } sigData, err := UnmarshalSignatureData(cdc, timestampedSigData.SignatureData) @@ -227,7 +228,7 @@ func produceVerificationArgs( } if cs.ConsensusState.GetTimestamp() > timestamp { - return nil, nil, 0, 0, sdkerrors.Wrapf(ErrInvalidProof, "the consensus state timestamp is greater than the signature timestamp (%d >= %d)", cs.ConsensusState.GetTimestamp(), timestamp) + return nil, nil, 0, 0, errorsmod.Wrapf(ErrInvalidProof, "the consensus state timestamp is greater than the signature timestamp (%d >= %d)", cs.ConsensusState.GetTimestamp(), timestamp) } sequence := cs.GetLatestHeight().GetRevisionHeight() diff --git a/modules/light-clients/06-solomachine/codec.go b/modules/light-clients/06-solomachine/codec.go index 591c94c51c4..e18cd8b563c 100644 --- a/modules/light-clients/06-solomachine/codec.go +++ b/modules/light-clients/06-solomachine/codec.go @@ -1,9 +1,9 @@ package solomachine import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -33,7 +33,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { func UnmarshalSignatureData(cdc codec.BinaryCodec, data []byte) (signing.SignatureData, error) { protoSigData := &signing.SignatureDescriptor_Data{} if err := cdc.Unmarshal(data, protoSigData); err != nil { - return nil, sdkerrors.Wrapf(err, "failed to unmarshal proof into type %T", protoSigData) + return nil, errorsmod.Wrapf(err, "failed to unmarshal proof into type %T", protoSigData) } sigData := signing.SignatureDataFromProto(protoSigData) diff --git a/modules/light-clients/06-solomachine/consensus_state.go b/modules/light-clients/06-solomachine/consensus_state.go index 9aadc567082..ed3bfa55d37 100644 --- a/modules/light-clients/06-solomachine/consensus_state.go +++ b/modules/light-clients/06-solomachine/consensus_state.go @@ -3,8 +3,8 @@ package solomachine import ( "strings" + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -27,12 +27,12 @@ func (cs ConsensusState) GetTimestamp() uint64 { // is not a PubKey. func (cs ConsensusState) GetPubKey() (cryptotypes.PubKey, error) { if cs.PublicKey == nil { - return nil, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey cannot be nil") + return nil, errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey cannot be nil") } publicKey, ok := cs.PublicKey.GetCachedValue().(cryptotypes.PubKey) if !ok { - return nil, sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey is not cryptotypes.PubKey") + return nil, errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey is not cryptotypes.PubKey") } return publicKey, nil @@ -41,15 +41,15 @@ func (cs ConsensusState) GetPubKey() (cryptotypes.PubKey, error) { // ValidateBasic defines basic validation for the solo machine consensus state. func (cs ConsensusState) ValidateBasic() error { if cs.Timestamp == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be 0") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be 0") } if cs.Diversifier != "" && strings.TrimSpace(cs.Diversifier) == "" { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "diversifier cannot contain only spaces") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "diversifier cannot contain only spaces") } publicKey, err := cs.GetPubKey() if err != nil || publicKey == nil || len(publicKey.Bytes()) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "public key cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "public key cannot be empty") } return nil diff --git a/modules/light-clients/06-solomachine/errors.go b/modules/light-clients/06-solomachine/errors.go index 5f5726d42da..91c22286241 100644 --- a/modules/light-clients/06-solomachine/errors.go +++ b/modules/light-clients/06-solomachine/errors.go @@ -1,13 +1,13 @@ package solomachine import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) var ( - ErrInvalidHeader = sdkerrors.Register(ModuleName, 2, "invalid header") - ErrInvalidSequence = sdkerrors.Register(ModuleName, 3, "invalid sequence") - ErrInvalidSignatureAndData = sdkerrors.Register(ModuleName, 4, "invalid signature and data") - ErrSignatureVerificationFailed = sdkerrors.Register(ModuleName, 5, "signature verification failed") - ErrInvalidProof = sdkerrors.Register(ModuleName, 6, "invalid solo machine proof") + ErrInvalidHeader = errorsmod.Register(ModuleName, 2, "invalid header") + ErrInvalidSequence = errorsmod.Register(ModuleName, 3, "invalid sequence") + ErrInvalidSignatureAndData = errorsmod.Register(ModuleName, 4, "invalid signature and data") + ErrSignatureVerificationFailed = errorsmod.Register(ModuleName, 5, "signature verification failed") + ErrInvalidProof = errorsmod.Register(ModuleName, 6, "invalid solo machine proof") ) diff --git a/modules/light-clients/06-solomachine/header.go b/modules/light-clients/06-solomachine/header.go index badfa08c62c..e9dd883f2fd 100644 --- a/modules/light-clients/06-solomachine/header.go +++ b/modules/light-clients/06-solomachine/header.go @@ -3,8 +3,8 @@ package solomachine import ( "strings" + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -25,12 +25,12 @@ func (Header) ClientType() string { // is not a PubKey. func (h Header) GetPubKey() (cryptotypes.PubKey, error) { if h.NewPublicKey == nil { - return nil, sdkerrors.Wrap(ErrInvalidHeader, "header NewPublicKey cannot be nil") + return nil, errorsmod.Wrap(ErrInvalidHeader, "header NewPublicKey cannot be nil") } publicKey, ok := h.NewPublicKey.GetCachedValue().(cryptotypes.PubKey) if !ok { - return nil, sdkerrors.Wrap(ErrInvalidHeader, "header NewPublicKey is not cryptotypes.PubKey") + return nil, errorsmod.Wrap(ErrInvalidHeader, "header NewPublicKey is not cryptotypes.PubKey") } return publicKey, nil @@ -40,20 +40,20 @@ func (h Header) GetPubKey() (cryptotypes.PubKey, error) { // been initialized. func (h Header) ValidateBasic() error { if h.Timestamp == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "timestamp cannot be zero") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "timestamp cannot be zero") } if h.NewDiversifier != "" && strings.TrimSpace(h.NewDiversifier) == "" { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "diversifier cannot contain only spaces") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "diversifier cannot contain only spaces") } if len(h.Signature) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "signature cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "signature cannot be empty") } newPublicKey, err := h.GetPubKey() if err != nil || newPublicKey == nil || len(newPublicKey.Bytes()) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "new public key cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "new public key cannot be empty") } return nil diff --git a/modules/light-clients/06-solomachine/misbehaviour.go b/modules/light-clients/06-solomachine/misbehaviour.go index 6075c63f8b6..8533f0b4fb3 100644 --- a/modules/light-clients/06-solomachine/misbehaviour.go +++ b/modules/light-clients/06-solomachine/misbehaviour.go @@ -3,7 +3,7 @@ package solomachine import ( "bytes" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -24,26 +24,26 @@ func (misbehaviour Misbehaviour) Type() string { // ValidateBasic implements Misbehaviour interface. func (misbehaviour Misbehaviour) ValidateBasic() error { if misbehaviour.Sequence == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "sequence cannot be 0") } if err := misbehaviour.SignatureOne.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "signature one failed basic validation") + return errorsmod.Wrap(err, "signature one failed basic validation") } if err := misbehaviour.SignatureTwo.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "signature two failed basic validation") + return errorsmod.Wrap(err, "signature two failed basic validation") } // misbehaviour signatures cannot be identical. if bytes.Equal(misbehaviour.SignatureOne.Signature, misbehaviour.SignatureTwo.Signature) { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signatures cannot be equal") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signatures cannot be equal") } // message data signed cannot be identical if both paths are the same. if bytes.Equal(misbehaviour.SignatureOne.Path, misbehaviour.SignatureTwo.Path) && bytes.Equal(misbehaviour.SignatureOne.Data, misbehaviour.SignatureTwo.Data) { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signature data must be signed over different messages") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "misbehaviour signature data must be signed over different messages") } return nil @@ -52,16 +52,16 @@ func (misbehaviour Misbehaviour) ValidateBasic() error { // ValidateBasic ensures that the signature and data fields are non-empty. func (sd SignatureAndData) ValidateBasic() error { if len(sd.Signature) == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "signature cannot be empty") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "signature cannot be empty") } if len(sd.Data) == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "data for signature cannot be empty") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "data for signature cannot be empty") } if len(sd.Path) == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "path for signature cannot be empty") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "path for signature cannot be empty") } if sd.Timestamp == 0 { - return sdkerrors.Wrap(ErrInvalidSignatureAndData, "timestamp cannot be 0") + return errorsmod.Wrap(ErrInvalidSignatureAndData, "timestamp cannot be 0") } return nil diff --git a/modules/light-clients/06-solomachine/misbehaviour_handle.go b/modules/light-clients/06-solomachine/misbehaviour_handle.go index 1f4aec41489..7e8b3822410 100644 --- a/modules/light-clients/06-solomachine/misbehaviour_handle.go +++ b/modules/light-clients/06-solomachine/misbehaviour_handle.go @@ -3,8 +3,8 @@ package solomachine import ( "github.com/cosmos/cosmos-sdk/codec" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -24,12 +24,12 @@ func (cs ClientState) verifyMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, // misbehaviour.ValidateBasic which is called by the 02-client keeper. // verify first signature if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureOne); err != nil { - return sdkerrors.Wrap(err, "failed to verify signature one") + return errorsmod.Wrap(err, "failed to verify signature one") } // verify second signature if err := cs.verifySignatureAndData(cdc, misbehaviour, misbehaviour.SignatureTwo); err != nil { - return sdkerrors.Wrap(err, "failed to verify signature two") + return errorsmod.Wrap(err, "failed to verify signature two") } return nil diff --git a/modules/light-clients/06-solomachine/proof.go b/modules/light-clients/06-solomachine/proof.go index 386830340cf..aab15c17d3c 100644 --- a/modules/light-clients/06-solomachine/proof.go +++ b/modules/light-clients/06-solomachine/proof.go @@ -1,9 +1,9 @@ package solomachine import ( + errorsmod "cosmossdk.io/errors" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" ) @@ -17,7 +17,7 @@ func VerifySignature(pubKey cryptotypes.PubKey, signBytes []byte, sigData signin case multisig.PubKey: data, ok := sigData.(*signing.MultiSignatureData) if !ok { - return sdkerrors.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.MultiSignatureData)(nil), data) + return errorsmod.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.MultiSignatureData)(nil), data) } // The function supplied fulfills the VerifyMultisignature interface. No special @@ -31,7 +31,7 @@ func VerifySignature(pubKey cryptotypes.PubKey, signBytes []byte, sigData signin default: data, ok := sigData.(*signing.SingleSignatureData) if !ok { - return sdkerrors.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.SingleSignatureData)(nil), data) + return errorsmod.Wrapf(ErrSignatureVerificationFailed, "invalid signature data type, expected %T, got %T", (*signing.SingleSignatureData)(nil), data) } if !pubKey.VerifySignature(signBytes, data.Signature) { diff --git a/modules/light-clients/06-solomachine/proposal_handle.go b/modules/light-clients/06-solomachine/proposal_handle.go index 86276180147..2e6fdfd7ed8 100644 --- a/modules/light-clients/06-solomachine/proposal_handle.go +++ b/modules/light-clients/06-solomachine/proposal_handle.go @@ -3,9 +3,9 @@ package solomachine import ( "reflect" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -24,21 +24,21 @@ func (cs ClientState) CheckSubstituteAndUpdateState( ) error { substituteClientState, ok := substituteClient.(*ClientState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "substitute client state type %T, expected %T", substituteClient, &ClientState{}) + return errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "substitute client state type %T, expected %T", substituteClient, &ClientState{}) } subjectPublicKey, err := cs.ConsensusState.GetPubKey() if err != nil { - return sdkerrors.Wrap(err, "failed to get consensus public key") + return errorsmod.Wrap(err, "failed to get consensus public key") } substitutePublicKey, err := substituteClientState.ConsensusState.GetPubKey() if err != nil { - return sdkerrors.Wrap(err, "failed to get substitute client public key") + return errorsmod.Wrap(err, "failed to get substitute client public key") } if reflect.DeepEqual(subjectPublicKey, substitutePublicKey) { - return sdkerrors.Wrapf(clienttypes.ErrInvalidHeader, "subject and substitute have the same public key") + return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "subject and substitute have the same public key") } // update to substitute parameters diff --git a/modules/light-clients/06-solomachine/update.go b/modules/light-clients/06-solomachine/update.go index 9f8078f4cb2..8d044e0a2e9 100644 --- a/modules/light-clients/06-solomachine/update.go +++ b/modules/light-clients/06-solomachine/update.go @@ -3,9 +3,9 @@ package solomachine import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -21,14 +21,14 @@ func (cs ClientState) VerifyClientMessage(ctx sdk.Context, cdc codec.BinaryCodec case *Misbehaviour: return cs.verifyMisbehaviour(ctx, cdc, clientStore, msg) default: - return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type of %T or %T, got type %T", Header{}, Misbehaviour{}, msg) + return errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "expected type of %T or %T, got type %T", Header{}, Misbehaviour{}, msg) } } func (cs ClientState) verifyHeader(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, header *Header) error { // assert update timestamp is not less than current consensus state timestamp if header.Timestamp < cs.ConsensusState.Timestamp { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( clienttypes.ErrInvalidHeader, "header timestamp is less than to the consensus state timestamp (%d < %d)", header.Timestamp, cs.ConsensusState.Timestamp, ) @@ -69,7 +69,7 @@ func (cs ClientState) verifyHeader(ctx sdk.Context, cdc codec.BinaryCodec, clien } if err := VerifySignature(publicKey, data, sigData); err != nil { - return sdkerrors.Wrap(ErrInvalidHeader, err.Error()) + return errorsmod.Wrap(ErrInvalidHeader, err.Error()) } return nil diff --git a/modules/light-clients/07-tendermint/client_state.go b/modules/light-clients/07-tendermint/client_state.go index 5b083341415..53daf119393 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -4,13 +4,14 @@ import ( "strings" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ics23 "github.com/cosmos/ics23/go" "github.com/tendermint/tendermint/light" tmtypes "github.com/tendermint/tendermint/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -63,7 +64,7 @@ func (cs ClientState) GetTimestampAtHeight( // get consensus state at height from clientStore to check for expiry consState, found := GetConsensusState(clientStore, cdc, height) if !found { - return 0, sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "height (%s)", height) + return 0, errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "height (%s)", height) } return consState.GetTimestamp(), nil } @@ -110,7 +111,7 @@ func (cs ClientState) IsExpired(latestTimestamp, now time.Time) bool { // Validate performs a basic validation of the client state fields. func (cs ClientState) Validate() error { if strings.TrimSpace(cs.ChainId) == "" { - return sdkerrors.Wrap(ErrInvalidChainID, "chain id cannot be empty string") + return errorsmod.Wrap(ErrInvalidChainID, "chain id cannot be empty string") } // NOTE: the value of tmtypes.MaxChainIDLen may change in the future. @@ -119,49 +120,49 @@ func (cs ClientState) Validate() error { // and the tendermint version used by this light client. // https://github.com/cosmos/ibc-go/issues/177 if len(cs.ChainId) > tmtypes.MaxChainIDLen { - return sdkerrors.Wrapf(ErrInvalidChainID, "chainID is too long; got: %d, max: %d", len(cs.ChainId), tmtypes.MaxChainIDLen) + return errorsmod.Wrapf(ErrInvalidChainID, "chainID is too long; got: %d, max: %d", len(cs.ChainId), tmtypes.MaxChainIDLen) } if err := light.ValidateTrustLevel(cs.TrustLevel.ToTendermint()); err != nil { return err } if cs.TrustingPeriod <= 0 { - return sdkerrors.Wrap(ErrInvalidTrustingPeriod, "trusting period must be greater than zero") + return errorsmod.Wrap(ErrInvalidTrustingPeriod, "trusting period must be greater than zero") } if cs.UnbondingPeriod <= 0 { - return sdkerrors.Wrap(ErrInvalidUnbondingPeriod, "unbonding period must be greater than zero") + return errorsmod.Wrap(ErrInvalidUnbondingPeriod, "unbonding period must be greater than zero") } if cs.MaxClockDrift <= 0 { - return sdkerrors.Wrap(ErrInvalidMaxClockDrift, "max clock drift must be greater than zero") + return errorsmod.Wrap(ErrInvalidMaxClockDrift, "max clock drift must be greater than zero") } // the latest height revision number must match the chain id revision number if cs.LatestHeight.RevisionNumber != clienttypes.ParseChainID(cs.ChainId) { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "latest height revision number must match chain id revision number (%d != %d)", cs.LatestHeight.RevisionNumber, clienttypes.ParseChainID(cs.ChainId)) } if cs.LatestHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "tendermint client's latest height revision height cannot be zero") + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "tendermint client's latest height revision height cannot be zero") } if cs.TrustingPeriod >= cs.UnbondingPeriod { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidTrustingPeriod, "trusting period (%s) should be < unbonding period (%s)", cs.TrustingPeriod, cs.UnbondingPeriod, ) } if cs.ProofSpecs == nil { - return sdkerrors.Wrap(ErrInvalidProofSpecs, "proof specs cannot be nil for tm client") + return errorsmod.Wrap(ErrInvalidProofSpecs, "proof specs cannot be nil for tm client") } for i, spec := range cs.ProofSpecs { if spec == nil { - return sdkerrors.Wrapf(ErrInvalidProofSpecs, "proof spec cannot be nil at index: %d", i) + return errorsmod.Wrapf(ErrInvalidProofSpecs, "proof spec cannot be nil at index: %d", i) } } // UpgradePath may be empty, but if it isn't, each key must be non-empty for i, k := range cs.UpgradePath { if strings.TrimSpace(k) == "" { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "key in upgrade path at index %d cannot be empty", i) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "key in upgrade path at index %d cannot be empty", i) } } @@ -193,7 +194,7 @@ func (cs ClientState) ZeroCustomFields() exported.ClientState { func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, consState exported.ConsensusState) error { consensusState, ok := consState.(*ConsensusState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", &ConsensusState{}, consState) } @@ -219,8 +220,8 @@ func (cs ClientState) VerifyMembership( value []byte, ) error { if cs.GetLatestHeight().LT(height) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "client state height < proof height (%d < %d), please ensure the client has been updated", cs.GetLatestHeight(), height, ) } @@ -231,17 +232,17 @@ func (cs ClientState) VerifyMembership( var merkleProof commitmenttypes.MerkleProof if err := cdc.Unmarshal(proof, &merkleProof); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") } if err := merkleProof.VerifyMembership(cs.ProofSpecs, consensusState.GetRoot(), merklePath, value); err != nil { @@ -265,8 +266,8 @@ func (cs ClientState) VerifyNonMembership( path exported.Path, ) error { if cs.GetLatestHeight().LT(height) { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, + return errorsmod.Wrapf( + ibcerrors.ErrInvalidHeight, "client state height < proof height (%d < %d), please ensure the client has been updated", cs.GetLatestHeight(), height, ) } @@ -277,17 +278,17 @@ func (cs ClientState) VerifyNonMembership( var merkleProof commitmenttypes.MerkleProof if err := cdc.Unmarshal(proof, &merkleProof); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") + return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } merklePath, ok := path.(commitmenttypes.MerklePath) if !ok { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "please ensure the proof was constructed against a height that exists on the client") } if err := merkleProof.VerifyNonMembership(cs.ProofSpecs, consensusState.GetRoot(), merklePath); err != nil { @@ -304,7 +305,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // check that executing chain's timestamp has passed consensusState's processed time + delay time period processedTime, ok := GetProcessedTime(store, proofHeight) if !ok { - return sdkerrors.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) + return errorsmod.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) } currentTimestamp := uint64(ctx.BlockTime().UnixNano()) @@ -312,7 +313,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // NOTE: delay time period is inclusive, so if currentTimestamp is validTime, then we return no error if currentTimestamp < validTime { - return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d", + return errorsmod.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d", validTime, currentTimestamp) } @@ -322,7 +323,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // check that executing chain's height has passed consensusState's processed height + delay block period processedHeight, ok := GetProcessedHeight(store, proofHeight) if !ok { - return sdkerrors.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight) + return errorsmod.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight) } currentHeight := clienttypes.GetSelfHeight(ctx) @@ -330,7 +331,7 @@ func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exp // NOTE: delay block period is inclusive, so if currentHeight is validHeight, then we return no error if currentHeight.LT(validHeight) { - return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until height: %s, current height: %s", + return errorsmod.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until height: %s, current height: %s", validHeight, currentHeight) } } diff --git a/modules/light-clients/07-tendermint/consensus_state.go b/modules/light-clients/07-tendermint/consensus_state.go index 6656bb5ad4c..065c2dfa250 100644 --- a/modules/light-clients/07-tendermint/consensus_state.go +++ b/modules/light-clients/07-tendermint/consensus_state.go @@ -3,7 +3,7 @@ package tendermint import ( "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" @@ -46,13 +46,13 @@ func (cs ConsensusState) GetTimestamp() uint64 { // as opposed to a consensus state constructed by the chain. func (cs ConsensusState) ValidateBasic() error { if cs.Root.Empty() { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "root cannot be empty") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "root cannot be empty") } if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil { - return sdkerrors.Wrap(err, "next validators hash is invalid") + return errorsmod.Wrap(err, "next validators hash is invalid") } if cs.Timestamp.Unix() <= 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time") + return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time") } return nil } diff --git a/modules/light-clients/07-tendermint/errors.go b/modules/light-clients/07-tendermint/errors.go index 7e2b37e59b2..8bbb58ec33a 100644 --- a/modules/light-clients/07-tendermint/errors.go +++ b/modules/light-clients/07-tendermint/errors.go @@ -1,22 +1,22 @@ package tendermint import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // IBC tendermint client sentinel errors var ( - ErrInvalidChainID = sdkerrors.Register(ModuleName, 2, "invalid chain-id") - ErrInvalidTrustingPeriod = sdkerrors.Register(ModuleName, 3, "invalid trusting period") - ErrInvalidUnbondingPeriod = sdkerrors.Register(ModuleName, 4, "invalid unbonding period") - ErrInvalidHeaderHeight = sdkerrors.Register(ModuleName, 5, "invalid header height") - ErrInvalidHeader = sdkerrors.Register(ModuleName, 6, "invalid header") - ErrInvalidMaxClockDrift = sdkerrors.Register(ModuleName, 7, "invalid max clock drift") - ErrProcessedTimeNotFound = sdkerrors.Register(ModuleName, 8, "processed time not found") - ErrProcessedHeightNotFound = sdkerrors.Register(ModuleName, 9, "processed height not found") - ErrDelayPeriodNotPassed = sdkerrors.Register(ModuleName, 10, "packet-specified delay period has not been reached") - ErrTrustingPeriodExpired = sdkerrors.Register(ModuleName, 11, "time since latest trusted state has passed the trusting period") - ErrUnbondingPeriodExpired = sdkerrors.Register(ModuleName, 12, "time since latest trusted state has passed the unbonding period") - ErrInvalidProofSpecs = sdkerrors.Register(ModuleName, 13, "invalid proof specs") - ErrInvalidValidatorSet = sdkerrors.Register(ModuleName, 14, "invalid validator set") + ErrInvalidChainID = errorsmod.Register(ModuleName, 2, "invalid chain-id") + ErrInvalidTrustingPeriod = errorsmod.Register(ModuleName, 3, "invalid trusting period") + ErrInvalidUnbondingPeriod = errorsmod.Register(ModuleName, 4, "invalid unbonding period") + ErrInvalidHeaderHeight = errorsmod.Register(ModuleName, 5, "invalid header height") + ErrInvalidHeader = errorsmod.Register(ModuleName, 6, "invalid header") + ErrInvalidMaxClockDrift = errorsmod.Register(ModuleName, 7, "invalid max clock drift") + ErrProcessedTimeNotFound = errorsmod.Register(ModuleName, 8, "processed time not found") + ErrProcessedHeightNotFound = errorsmod.Register(ModuleName, 9, "processed height not found") + ErrDelayPeriodNotPassed = errorsmod.Register(ModuleName, 10, "packet-specified delay period has not been reached") + ErrTrustingPeriodExpired = errorsmod.Register(ModuleName, 11, "time since latest trusted state has passed the trusting period") + ErrUnbondingPeriodExpired = errorsmod.Register(ModuleName, 12, "time since latest trusted state has passed the unbonding period") + ErrInvalidProofSpecs = errorsmod.Register(ModuleName, 13, "invalid proof specs") + ErrInvalidValidatorSet = errorsmod.Register(ModuleName, 14, "invalid validator set") ) diff --git a/modules/light-clients/07-tendermint/header.go b/modules/light-clients/07-tendermint/header.go index 5db68127d10..e158eaab5d1 100644 --- a/modules/light-clients/07-tendermint/header.go +++ b/modules/light-clients/07-tendermint/header.go @@ -4,7 +4,7 @@ import ( "bytes" "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" tmtypes "github.com/tendermint/tendermint/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -49,34 +49,34 @@ func (h Header) GetTime() time.Time { // with MsgCreateClient func (h Header) ValidateBasic() error { if h.SignedHeader == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "tendermint signed header cannot be nil") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "tendermint signed header cannot be nil") } if h.Header == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "tendermint header cannot be nil") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "tendermint header cannot be nil") } tmSignedHeader, err := tmtypes.SignedHeaderFromProto(h.SignedHeader) if err != nil { - return sdkerrors.Wrap(err, "header is not a tendermint header") + return errorsmod.Wrap(err, "header is not a tendermint header") } if err := tmSignedHeader.ValidateBasic(h.Header.GetChainID()); err != nil { - return sdkerrors.Wrap(err, "header failed basic validation") + return errorsmod.Wrap(err, "header failed basic validation") } // TrustedHeight is less than Header for updates and misbehaviour if h.TrustedHeight.GTE(h.GetHeight()) { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "TrustedHeight %d must be less than header height %d", + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "TrustedHeight %d must be less than header height %d", h.TrustedHeight, h.GetHeight()) } if h.ValidatorSet == nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "validator set is nil") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "validator set is nil") } tmValset, err := tmtypes.ValidatorSetFromProto(h.ValidatorSet) if err != nil { - return sdkerrors.Wrap(err, "validator set is not tendermint validator set") + return errorsmod.Wrap(err, "validator set is not tendermint validator set") } if !bytes.Equal(h.Header.ValidatorsHash, tmValset.Hash()) { - return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "validator set does not match hash") + return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "validator set does not match hash") } return nil } diff --git a/modules/light-clients/07-tendermint/migrations/migrations.go b/modules/light-clients/07-tendermint/migrations/migrations.go index 2c35ecd2b9e..f5d28fe468f 100644 --- a/modules/light-clients/07-tendermint/migrations/migrations.go +++ b/modules/light-clients/07-tendermint/migrations/migrations.go @@ -1,9 +1,9 @@ package migrations import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -28,12 +28,12 @@ func PruneExpiredConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, clientK clientState, ok := clientKeeper.GetClientState(ctx, clientID) if !ok { - return 0, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) } tmClientState, ok := clientState.(*ibctm.ClientState) if !ok { - return 0, sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + return 0, errorsmod.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } totalPruned += ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) diff --git a/modules/light-clients/07-tendermint/misbehaviour.go b/modules/light-clients/07-tendermint/misbehaviour.go index 89722ae415b..827518f6f74 100644 --- a/modules/light-clients/07-tendermint/misbehaviour.go +++ b/modules/light-clients/07-tendermint/misbehaviour.go @@ -3,7 +3,7 @@ package tendermint import ( "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -45,56 +45,56 @@ func (misbehaviour Misbehaviour) GetTime() time.Time { // ValidateBasic implements Misbehaviour interface func (misbehaviour Misbehaviour) ValidateBasic() error { if misbehaviour.Header1 == nil { - return sdkerrors.Wrap(ErrInvalidHeader, "misbehaviour Header1 cannot be nil") + return errorsmod.Wrap(ErrInvalidHeader, "misbehaviour Header1 cannot be nil") } if misbehaviour.Header2 == nil { - return sdkerrors.Wrap(ErrInvalidHeader, "misbehaviour Header2 cannot be nil") + return errorsmod.Wrap(ErrInvalidHeader, "misbehaviour Header2 cannot be nil") } if misbehaviour.Header1.TrustedHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header1 cannot have zero revision height") + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header1 cannot have zero revision height") } if misbehaviour.Header2.TrustedHeight.RevisionHeight == 0 { - return sdkerrors.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header2 cannot have zero revision height") + return errorsmod.Wrapf(ErrInvalidHeaderHeight, "misbehaviour Header2 cannot have zero revision height") } if misbehaviour.Header1.TrustedValidators == nil { - return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header1 cannot be empty") + return errorsmod.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header1 cannot be empty") } if misbehaviour.Header2.TrustedValidators == nil { - return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header2 cannot be empty") + return errorsmod.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header2 cannot be empty") } if misbehaviour.Header1.Header.ChainID != misbehaviour.Header2.Header.ChainID { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers must have identical chainIDs") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers must have identical chainIDs") } if err := host.ClientIdentifierValidator(misbehaviour.ClientId); err != nil { - return sdkerrors.Wrap(err, "misbehaviour client ID is invalid") + return errorsmod.Wrap(err, "misbehaviour client ID is invalid") } // ValidateBasic on both validators if err := misbehaviour.Header1.ValidateBasic(); err != nil { - return sdkerrors.Wrap( + return errorsmod.Wrap( clienttypes.ErrInvalidMisbehaviour, - sdkerrors.Wrap(err, "header 1 failed validation").Error(), + errorsmod.Wrap(err, "header 1 failed validation").Error(), ) } if err := misbehaviour.Header2.ValidateBasic(); err != nil { - return sdkerrors.Wrap( + return errorsmod.Wrap( clienttypes.ErrInvalidMisbehaviour, - sdkerrors.Wrap(err, "header 2 failed validation").Error(), + errorsmod.Wrap(err, "header 2 failed validation").Error(), ) } // Ensure that Height1 is greater than or equal to Height2 if misbehaviour.Header1.GetHeight().LT(misbehaviour.Header2.GetHeight()) { - return sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour, "Header1 height is less than Header2 height (%s < %s)", misbehaviour.Header1.GetHeight(), misbehaviour.Header2.GetHeight()) + return errorsmod.Wrapf(clienttypes.ErrInvalidMisbehaviour, "Header1 height is less than Header2 height (%s < %s)", misbehaviour.Header1.GetHeight(), misbehaviour.Header2.GetHeight()) } blockID1, err := tmtypes.BlockIDFromProto(&misbehaviour.Header1.SignedHeader.Commit.BlockID) if err != nil { - return sdkerrors.Wrap(err, "invalid block ID from header 1 in misbehaviour") + return errorsmod.Wrap(err, "invalid block ID from header 1 in misbehaviour") } blockID2, err := tmtypes.BlockIDFromProto(&misbehaviour.Header2.SignedHeader.Commit.BlockID) if err != nil { - return sdkerrors.Wrap(err, "invalid block ID from header 2 in misbehaviour") + return errorsmod.Wrap(err, "invalid block ID from header 2 in misbehaviour") } if err := validCommit(misbehaviour.Header1.Header.ChainID, *blockID1, @@ -112,15 +112,15 @@ func (misbehaviour Misbehaviour) ValidateBasic() error { func validCommit(chainID string, blockID tmtypes.BlockID, commit *tmproto.Commit, valSet *tmproto.ValidatorSet) (err error) { tmCommit, err := tmtypes.CommitFromProto(commit) if err != nil { - return sdkerrors.Wrap(err, "commit is not tendermint commit type") + return errorsmod.Wrap(err, "commit is not tendermint commit type") } tmValset, err := tmtypes.ValidatorSetFromProto(valSet) if err != nil { - return sdkerrors.Wrap(err, "validator set is not tendermint validator set type") + return errorsmod.Wrap(err, "validator set is not tendermint validator set type") } if err := tmValset.VerifyCommitLight(chainID, blockID, tmCommit.Height, tmCommit); err != nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "validator set did not commit to header") + return errorsmod.Wrap(clienttypes.ErrInvalidMisbehaviour, "validator set did not commit to header") } return nil diff --git a/modules/light-clients/07-tendermint/misbehaviour_handle.go b/modules/light-clients/07-tendermint/misbehaviour_handle.go index 2ef567b70c1..ef3e654179d 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_handle.go +++ b/modules/light-clients/07-tendermint/misbehaviour_handle.go @@ -5,9 +5,9 @@ import ( "reflect" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" tmtypes "github.com/tendermint/tendermint/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -94,12 +94,12 @@ func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore sdk.KVSto // Retrieve trusted consensus states for each Header in misbehaviour tmConsensusState1, found := GetConsensusState(clientStore, cdc, misbehaviour.Header1.TrustedHeight) if !found { - return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %s", misbehaviour.Header1.TrustedHeight) + return errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %s", misbehaviour.Header1.TrustedHeight) } tmConsensusState2, found := GetConsensusState(clientStore, cdc, misbehaviour.Header2.TrustedHeight) if !found { - return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %s", misbehaviour.Header2.TrustedHeight) + return errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %s", misbehaviour.Header2.TrustedHeight) } // Check the validity of the two conflicting headers against their respective @@ -110,12 +110,12 @@ func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore sdk.KVSto if err := checkMisbehaviourHeader( cs, tmConsensusState1, misbehaviour.Header1, ctx.BlockTime(), ); err != nil { - return sdkerrors.Wrap(err, "verifying Header1 in Misbehaviour failed") + return errorsmod.Wrap(err, "verifying Header1 in Misbehaviour failed") } if err := checkMisbehaviourHeader( cs, tmConsensusState2, misbehaviour.Header2, ctx.BlockTime(), ); err != nil { - return sdkerrors.Wrap(err, "verifying Header2 in Misbehaviour failed") + return errorsmod.Wrap(err, "verifying Header2 in Misbehaviour failed") } return nil @@ -128,12 +128,12 @@ func checkMisbehaviourHeader( ) error { tmTrustedValset, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) if err != nil { - return sdkerrors.Wrap(err, "trusted validator set is not tendermint validator set type") + return errorsmod.Wrap(err, "trusted validator set is not tendermint validator set type") } tmCommit, err := tmtypes.CommitFromProto(header.Commit) if err != nil { - return sdkerrors.Wrap(err, "commit is not tendermint commit type") + return errorsmod.Wrap(err, "commit is not tendermint commit type") } // check the trusted fields for the header against ConsensusState @@ -143,7 +143,7 @@ func checkMisbehaviourHeader( // assert that the age of the trusted consensus state is not older than the trusting period if currentTimestamp.Sub(consState.Timestamp) >= clientState.TrustingPeriod { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrTrustingPeriodExpired, "current timestamp minus the latest consensus state timestamp is greater than or equal to the trusting period (%d >= %d)", currentTimestamp.Sub(consState.Timestamp), clientState.TrustingPeriod, @@ -164,7 +164,7 @@ func checkMisbehaviourHeader( if err := tmTrustedValset.VerifyCommitLightTrusting( chainID, tmCommit, clientState.TrustLevel.ToTendermint(), ); err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour, "validator set in header has too much change from trusted validator set: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidMisbehaviour, "validator set in header has too much change from trusted validator set: %v", err) } return nil } diff --git a/modules/light-clients/07-tendermint/proposal_handle.go b/modules/light-clients/07-tendermint/proposal_handle.go index f3a1f4838f2..98b37ebf019 100644 --- a/modules/light-clients/07-tendermint/proposal_handle.go +++ b/modules/light-clients/07-tendermint/proposal_handle.go @@ -4,9 +4,9 @@ import ( "reflect" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -30,11 +30,11 @@ func (cs ClientState) CheckSubstituteAndUpdateState( ) error { substituteClientState, ok := substituteClient.(*ClientState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "expected type %T, got %T", &ClientState{}, substituteClient) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "expected type %T, got %T", &ClientState{}, substituteClient) } if !IsMatchingClientState(cs, *substituteClientState) { - return sdkerrors.Wrap(clienttypes.ErrInvalidSubstitute, "subject client state does not match substitute client state") + return errorsmod.Wrap(clienttypes.ErrInvalidSubstitute, "subject client state does not match substitute client state") } if cs.Status(ctx, subjectClientStore, cdc) == exported.Frozen { @@ -48,7 +48,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState( consensusState, found := GetConsensusState(substituteClientStore, cdc, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "unable to retrieve latest consensus state for substitute client") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "unable to retrieve latest consensus state for substitute client") } setConsensusState(subjectClientStore, cdc, consensusState, height) @@ -56,12 +56,12 @@ func (cs ClientState) CheckSubstituteAndUpdateState( // set metadata stored for the substitute consensus state processedHeight, found := GetProcessedHeight(substituteClientStore, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed height for substitute client latest height") + return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed height for substitute client latest height") } processedTime, found := GetProcessedTime(substituteClientStore, height) if !found { - return sdkerrors.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed time for substitute client latest height") + return errorsmod.Wrap(clienttypes.ErrUpdateClientFailed, "unable to retrieve processed time for substitute client latest height") } setConsensusMetadataWithValues(subjectClientStore, height, processedHeight, processedTime) diff --git a/modules/light-clients/07-tendermint/update.go b/modules/light-clients/07-tendermint/update.go index 2ed995ceb40..fbd70e0fb27 100644 --- a/modules/light-clients/07-tendermint/update.go +++ b/modules/light-clients/07-tendermint/update.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/light" tmtypes "github.com/tendermint/tendermint/types" @@ -48,7 +48,7 @@ func (cs *ClientState) verifyHeader( // Retrieve trusted consensus states for each Header in misbehaviour consState, found := GetConsensusState(clientStore, cdc, header.TrustedHeight) if !found { - return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header at TrustedHeight: %s", header.TrustedHeight) + return errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "could not get trusted consensus state from clientStore for Header at TrustedHeight: %s", header.TrustedHeight) } if err := checkTrustedHeader(header, consState); err != nil { @@ -58,7 +58,7 @@ func (cs *ClientState) verifyHeader( // UpdateClient only accepts updates with a header at the same revision // as the trusted consensus state if header.GetHeight().GetRevisionNumber() != header.TrustedHeight.RevisionNumber { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidHeaderHeight, "header height revision %d does not match trusted header revision %d", header.GetHeight().GetRevisionNumber(), header.TrustedHeight.RevisionNumber, @@ -67,22 +67,22 @@ func (cs *ClientState) verifyHeader( tmTrustedValidators, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) if err != nil { - return sdkerrors.Wrap(err, "trusted validator set in not tendermint validator set type") + return errorsmod.Wrap(err, "trusted validator set in not tendermint validator set type") } tmSignedHeader, err := tmtypes.SignedHeaderFromProto(header.SignedHeader) if err != nil { - return sdkerrors.Wrap(err, "signed header in not tendermint signed header type") + return errorsmod.Wrap(err, "signed header in not tendermint signed header type") } tmValidatorSet, err := tmtypes.ValidatorSetFromProto(header.ValidatorSet) if err != nil { - return sdkerrors.Wrap(err, "validator set in not tendermint validator set type") + return errorsmod.Wrap(err, "validator set in not tendermint validator set type") } // assert header height is newer than consensus state if header.GetHeight().LTE(header.TrustedHeight) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( clienttypes.ErrInvalidHeader, "header height ≤ consensus state height (%s ≤ %s)", header.GetHeight(), header.TrustedHeight, ) @@ -112,7 +112,7 @@ func (cs *ClientState) verifyHeader( cs.TrustingPeriod, currentTimestamp, cs.MaxClockDrift, cs.TrustLevel.ToTendermint(), ) if err != nil { - return sdkerrors.Wrap(err, "failed to verify header") + return errorsmod.Wrap(err, "failed to verify header") } return nil @@ -175,7 +175,7 @@ func (cs ClientState) pruneOldestConsensusState(ctx sdk.Context, cdc codec.Binar consState, found := GetConsensusState(clientStore, cdc, height) // this error should never occur if !found { - panic(sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "failed to retrieve consensus state at height: %s", height)) + panic(errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "failed to retrieve consensus state at height: %s", height)) } if cs.IsExpired(consState.Timestamp, ctx.BlockTime()) { @@ -206,14 +206,14 @@ func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.Binar func checkTrustedHeader(header *Header, consState *ConsensusState) error { tmTrustedValidators, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) if err != nil { - return sdkerrors.Wrap(err, "trusted validator set in not tendermint validator set type") + return errorsmod.Wrap(err, "trusted validator set in not tendermint validator set type") } // assert that trustedVals is NextValidators of last trusted header // to do this, we check that trustedVals.Hash() == consState.NextValidatorsHash tvalHash := tmTrustedValidators.Hash() if !bytes.Equal(consState.NextValidatorsHash, tvalHash) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidValidatorSet, "trusted validators %s, does not hash to latest trusted validators. Expected: %X, got: %X", header.TrustedValidators, consState.NextValidatorsHash, tvalHash, diff --git a/modules/light-clients/07-tendermint/upgrade.go b/modules/light-clients/07-tendermint/upgrade.go index 5e137dad0c5..abbeca91b90 100644 --- a/modules/light-clients/07-tendermint/upgrade.go +++ b/modules/light-clients/07-tendermint/upgrade.go @@ -3,11 +3,12 @@ package tendermint import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -30,14 +31,14 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( proofUpgradeClient, proofUpgradeConsState []byte, ) error { if len(cs.UpgradePath) == 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade client, no upgrade path set") + return errorsmod.Wrap(clienttypes.ErrInvalidUpgradeClient, "cannot upgrade client, no upgrade path set") } // last height of current counterparty chain must be client's latest height lastHeight := cs.GetLatestHeight() if !upgradedClient.GetLatestHeight().GT(lastHeight) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s", + return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s", upgradedClient.GetLatestHeight(), lastHeight) } @@ -46,22 +47,22 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( // counterparty must also commit to the upgraded consensus state at a sub-path under the upgrade path specified tmUpgradeClient, ok := upgradedClient.(*ClientState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "upgraded client must be Tendermint client. expected: %T got: %T", + return errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "upgraded client must be Tendermint client. expected: %T got: %T", &ClientState{}, upgradedClient) } tmUpgradeConsState, ok := upgradedConsState.(*ConsensusState) if !ok { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "upgraded consensus state must be Tendermint consensus state. expected %T, got: %T", + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "upgraded consensus state must be Tendermint consensus state. expected %T, got: %T", &ConsensusState{}, upgradedConsState) } // unmarshal proofs var merkleProofClient, merkleProofConsState commitmenttypes.MerkleProof if err := cdc.Unmarshal(proofUpgradeClient, &merkleProofClient); err != nil { - return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal client merkle proof: %v", err) + return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal client merkle proof: %v", err) } if err := cdc.Unmarshal(proofUpgradeConsState, &merkleProofConsState); err != nil { - return sdkerrors.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal consensus state merkle proof: %v", err) + return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "could not unmarshal consensus state merkle proof: %v", err) } // Must prove against latest consensus state to ensure we are verifying against latest upgrade plan @@ -69,29 +70,29 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( // at this consensus state consState, found := GetConsensusState(clientStore, cdc, lastHeight) if !found { - return sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, "could not retrieve consensus state for lastHeight") + return errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "could not retrieve consensus state for lastHeight") } // Verify client proof bz, err := cdc.MarshalInterface(upgradedClient.ZeroCustomFields()) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidClient, "could not marshal client state: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "could not marshal client state: %v", err) } // construct clientState Merkle path upgradeClientPath := constructUpgradeClientMerklePath(cs.UpgradePath, lastHeight) if err := merkleProofClient.VerifyMembership(cs.ProofSpecs, consState.GetRoot(), upgradeClientPath, bz); err != nil { - return sdkerrors.Wrapf(err, "client state proof failed. Path: %s", upgradeClientPath.Pretty()) + return errorsmod.Wrapf(err, "client state proof failed. Path: %s", upgradeClientPath.Pretty()) } // Verify consensus state proof bz, err = cdc.MarshalInterface(upgradedConsState) if err != nil { - return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "could not marshal consensus state: %v", err) + return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "could not marshal consensus state: %v", err) } // construct consensus state Merkle path upgradeConsStatePath := constructUpgradeConsStateMerklePath(cs.UpgradePath, lastHeight) if err := merkleProofConsState.VerifyMembership(cs.ProofSpecs, consState.GetRoot(), upgradeConsStatePath, bz); err != nil { - return sdkerrors.Wrapf(err, "consensus state proof failed. Path: %s", upgradeConsStatePath.Pretty()) + return errorsmod.Wrapf(err, "consensus state proof failed. Path: %s", upgradeConsStatePath.Pretty()) } // Construct new client state and consensus state @@ -104,7 +105,7 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( ) if err := newClientState.Validate(); err != nil { - return sdkerrors.Wrap(err, "updated client state failed basic validation") + return errorsmod.Wrap(err, "updated client state failed basic validation") } // The new consensus state is merely used as a trusted kernel against which headers on the new diff --git a/testing/chain.go b/testing/chain.go index e1449029811..b82e2cd9823 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -5,12 +5,12 @@ import ( "testing" "time" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" @@ -421,7 +421,7 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa // NextValidatorsHash tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1)) if !ok { - return nil, sdkerrors.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) + return nil, errorsmod.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) } } // inject trusted fields into last header diff --git a/testing/simapp/ante_handler.go b/testing/simapp/ante_handler.go index 5bd7bb567db..1fee5a3a529 100644 --- a/testing/simapp/ante_handler.go +++ b/testing/simapp/ante_handler.go @@ -1,10 +1,11 @@ package simapp import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" "github.com/cosmos/ibc-go/v7/modules/core/keeper" ) @@ -19,13 +20,13 @@ type HandlerOptions struct { // NewAnteHandler creates a new ante handler func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + return nil, errorsmod.Wrap(ibcerrors.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + return nil, errorsmod.Wrap(ibcerrors.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for AnteHandler") + return nil, errorsmod.Wrap(ibcerrors.ErrLogic, "sign mode handler is required for AnteHandler") } anteDecorators := []sdk.AnteDecorator{