x/ibc: update error messages (#6659)

* update errors in 02-client

* update errors in 03-connection

* update 04-channel errors + fixes to 03 changes

* update ibc handler errors

* tm, commitment, and verify error updates

* update ics20

* remove unnecessary wrapping

* fix various build issues
This commit is contained in:
colin axner 2020-07-09 18:06:08 +02:00 committed by GitHub
parent a940214a49
commit 03fdc9d744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 187 additions and 174 deletions

View File

@ -32,7 +32,7 @@ func (k Keeper) SendTransfer(
) error {
sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel)
if !found {
return sdkerrors.Wrap(channeltypes.ErrChannelNotFound, sourceChannel)
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel)
}
destinationPort := sourceChannelEnd.GetCounterparty().GetPortID()

View File

@ -195,12 +195,12 @@ func (am AppModule) OnChanOpenInit(
}
if version != types.Version {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid version: %s, expected %s", version, "ics20-1")
return sdkerrors.Wrapf(types.ErrInvalidVersion, "got: %s, expected %s", version, types.Version)
}
// Claim channel capability passed back by IBC module
if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, err.Error())
return err
}
// TODO: escrow
@ -227,16 +227,16 @@ func (am AppModule) OnChanOpenTry(
}
if version != types.Version {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid version: %s, expected %s", version, "ics20-1")
return sdkerrors.Wrapf(types.ErrInvalidVersion, "got: %s, expected %s", version, types.Version)
}
if counterpartyVersion != types.Version {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid counterparty version: %s, expected %s", counterpartyVersion, "ics20-1")
return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: got: %s, expected %s", counterpartyVersion, types.Version)
}
// Claim channel capability passed back by IBC module
if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, err.Error())
return err
}
// TODO: escrow
@ -250,7 +250,7 @@ func (am AppModule) OnChanOpenAck(
counterpartyVersion string,
) error {
if counterpartyVersion != types.Version {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid counterparty version: %s, expected %s", counterpartyVersion, "ics20-1")
return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version)
}
return nil
}

View File

@ -9,4 +9,5 @@ var (
ErrInvalidPacketTimeout = sdkerrors.Register(ModuleName, 2, "invalid packet timeout")
ErrOnlyOneDenomAllowed = sdkerrors.Register(ModuleName, 3, "only one denom allowed")
ErrInvalidDenomForTransfer = sdkerrors.Register(ModuleName, 4, "invalid denomination for cross-chain transfer")
ErrInvalidVersion = sdkerrors.Register(ModuleName, 5, "invalid version")
)

View File

@ -27,7 +27,7 @@ func HandleMsgCreateClient(ctx sdk.Context, k keeper.Keeper, msg exported.MsgCre
case exported.Tendermint:
tmMsg, ok := msg.(ibctmtypes.MsgCreateClient)
if !ok {
return nil, sdkerrors.Wrap(types.ErrInvalidClientType, "Msg is not a Tendermint CreateClient msg")
return nil, sdkerrors.Wrapf(types.ErrInvalidClientType, "got %T, expected %T", msg, ibctmtypes.MsgCreateClient{})
}
var err error
@ -41,7 +41,7 @@ func HandleMsgCreateClient(ctx sdk.Context, k keeper.Keeper, msg exported.MsgCre
clientState = localhosttypes.NewClientState(ctx.ChainID(), ctx.BlockHeight())
consensusHeight = uint64(ctx.BlockHeight())
default:
return nil, sdkerrors.Wrap(types.ErrInvalidClientType, msg.GetClientType())
return nil, sdkerrors.Wrapf(types.ErrInvalidClientType, "unsupported client type (%s)", msg.GetClientType())
}
_, err := k.CreateClient(

View File

@ -51,7 +51,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
// check that the header consensus matches the client one
// NOTE: not checked for localhost client
if header != nil && clientType != exported.Localhost && header.ClientType() != clientType {
return nil, sdkerrors.Wrapf(types.ErrInvalidConsensus, "cannot update client with ID %s", clientID)
return nil, sdkerrors.Wrapf(types.ErrInvalidHeader, "header client type (%s) does not match expected client type (%s) for client with ID %s", header.ClientType(), clientType, clientID)
}
clientState, found := k.GetClientState(ctx, clientID)
@ -59,7 +59,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
return nil, sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID)
}
// addittion to spec: prevent update if the client is frozen
// addition to spec: prevent update if the client is frozen
if clientState.IsFrozen() {
return nil, sdkerrors.Wrapf(types.ErrClientFrozen, "cannot update client with ID %s", clientID)
}
@ -128,12 +128,12 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour exported.Misbehaviour) error {
clientState, found := k.GetClientState(ctx, misbehaviour.GetClientID())
if !found {
return sdkerrors.Wrap(types.ErrClientNotFound, misbehaviour.GetClientID())
return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot check misbehaviour for client with ID %s", misbehaviour.GetClientID())
}
consensusState, found := k.GetClientConsensusStateLTE(ctx, misbehaviour.GetClientID(), uint64(misbehaviour.GetHeight()))
if !found {
return sdkerrors.Wrap(types.ErrConsensusStateNotFound, misbehaviour.GetClientID())
return sdkerrors.Wrapf(types.ErrConsensusStateNotFound, "cannot check misbehaviour for client with ID %s", misbehaviour.GetClientID())
}
var err error

View File

@ -14,7 +14,7 @@ var (
ErrClientTypeNotFound = sdkerrors.Register(SubModuleName, 7, "client type not found")
ErrInvalidClientType = sdkerrors.Register(SubModuleName, 8, "invalid client type")
ErrRootNotFound = sdkerrors.Register(SubModuleName, 9, "commitment root not found")
ErrInvalidHeader = sdkerrors.Register(SubModuleName, 10, "invalid block header")
ErrInvalidHeader = sdkerrors.Register(SubModuleName, 10, "invalid client header")
ErrInvalidEvidence = sdkerrors.Register(SubModuleName, 11, "invalid light client misbehaviour evidence")
ErrFailedClientConsensusStateVerification = sdkerrors.Register(SubModuleName, 12, "client consensus state verification failed")
ErrFailedConnectionStateVerification = sdkerrors.Register(SubModuleName, 13, "connection state verification failed")

View File

@ -53,17 +53,17 @@ func DefaultGenesisState() GenesisState {
func (gs GenesisState) Validate() error {
for i, client := range gs.Clients {
if err := client.Validate(); err != nil {
return fmt.Errorf("invalid client %d: %w", i, err)
return fmt.Errorf("invalid client %v index %d: %w", client, i, err)
}
}
for i, cs := range gs.ClientsConsensus {
if err := host.ClientIdentifierValidator(cs.ClientID); err != nil {
return fmt.Errorf("invalid client consensus state %d: %w", i, err)
return fmt.Errorf("invalid client consensus state identifier %s index %d: %w", cs.ClientID, i, err)
}
for _, consensusState := range cs.ConsensusStates {
if err := consensusState.ValidateBasic(); err != nil {
return fmt.Errorf("invalid client consensus state %d: %w", i, err)
return fmt.Errorf("invalid client consensus state %v index %d: %w", consensusState, i, err)
}
}
}

View File

@ -2,6 +2,7 @@ package connection
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
)
@ -11,7 +12,7 @@ func HandleMsgConnectionOpenInit(ctx sdk.Context, k keeper.Keeper, msg *types.Ms
if err := k.ConnOpenInit(
ctx, msg.ConnectionID, msg.ClientID, msg.Counterparty,
); err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "connection handshake open init failed")
}
ctx.EventManager().EmitEvents(sdk.Events{
@ -40,7 +41,7 @@ func HandleMsgConnectionOpenTry(ctx sdk.Context, k keeper.Keeper, msg *types.Msg
msg.CounterpartyVersions, msg.ProofInit, msg.ProofConsensus,
msg.ProofHeight, msg.ConsensusHeight,
); err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "connection handshake open try failed")
}
ctx.EventManager().EmitEvents(sdk.Events{
@ -68,7 +69,7 @@ func HandleMsgConnectionOpenAck(ctx sdk.Context, k keeper.Keeper, msg *types.Msg
ctx, msg.ConnectionID, msg.Version, msg.ProofTry, msg.ProofConsensus,
msg.ProofHeight, msg.ConsensusHeight,
); err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "connection handshake open ack failed")
}
connectionEnd, _ := k.GetConnection(ctx, msg.ConnectionID)
@ -97,7 +98,7 @@ func HandleMsgConnectionOpenConfirm(ctx sdk.Context, k keeper.Keeper, msg *types
if err := k.ConnOpenConfirm(
ctx, msg.ConnectionID, msg.ProofAck, msg.ProofHeight,
); err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "connection handshake open confirm failed")
}
connectionEnd, _ := k.GetConnection(ctx, msg.ConnectionID)

View File

@ -22,7 +22,7 @@ func (k Keeper) ConnOpenInit(
) error {
_, found := k.GetConnection(ctx, connectionID)
if found {
return sdkerrors.Wrap(types.ErrConnectionExists, "cannot initialize connection")
return types.ErrConnectionExists
}
// connection defines chain A's ConnectionEnd
@ -30,7 +30,7 @@ func (k Keeper) ConnOpenInit(
k.SetConnection(ctx, connectionID, connection)
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
return sdkerrors.Wrap(err, "cannot initialize connection")
return err
}
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: NONE -> INIT", connectionID))
@ -113,11 +113,11 @@ func (k Keeper) ConnOpenTry(
// Set connection state to TRYOPEN and store in chainB state
connection.State = types.TRYOPEN
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
return sdkerrors.Wrap(err, "cannot relay connection attempt")
return sdkerrors.Wrapf(err, "failed to add connection with ID %s to client with ID %s", connectionID, clientID)
}
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: NONE -> TRYOPEN ", connectionID))
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: %s -> TRYOPEN ", connectionID, previousConnection.State))
return nil
}
@ -145,14 +145,14 @@ func (k Keeper) ConnOpenAck(
// Retrieve connection
connection, found := k.GetConnection(ctx, connectionID)
if !found {
return sdkerrors.Wrap(types.ErrConnectionNotFound, "cannot relay ACK of open attempt")
return sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID)
}
// Check connection on ChainA is on correct state: INIT or TRYOPEN
if connection.State != types.INIT && connection.State != types.TRYOPEN {
return sdkerrors.Wrapf(
types.ErrInvalidConnectionState,
"connection state is not INIT (got %s)", connection.State.String(),
"connection state is not INIT or TRYOPEN (got %s)", connection.State.String(),
)
}
@ -198,11 +198,12 @@ func (k Keeper) ConnOpenAck(
return err
}
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: %s -> OPEN ", connectionID, connection.State))
// Update connection state to Open
connection.State = types.OPEN
connection.Versions = []string{version}
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: INIT -> OPEN ", connectionID))
return nil
}
@ -219,7 +220,7 @@ func (k Keeper) ConnOpenConfirm(
// Retrieve connection
connection, found := k.GetConnection(ctx, connectionID)
if !found {
return sdkerrors.Wrap(types.ErrConnectionNotFound, "cannot relay ACK of open attempt")
return sdkerrors.Wrap(types.ErrConnectionNotFound, connectionID)
}
// Check that connection state on ChainB is on state: TRYOPEN

View File

@ -159,7 +159,7 @@ func (k Keeper) GetAllConnections(ctx sdk.Context) (connections []types.Connecti
func (k Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID string) error {
_, found := k.clientKeeper.GetClientState(ctx, clientID)
if !found {
return clienttypes.ErrClientNotFound
return sdkerrors.Wrap(clienttypes.ErrClientNotFound, clientID)
}
conns, found := k.GetClientConnectionPaths(ctx, clientID)

View File

@ -30,10 +30,14 @@ func (k Keeper) VerifyClientConsensusState(
return sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "clientID: %s with height: %d", clientID, height)
}
return clientState.VerifyClientConsensusState(
if err := clientState.VerifyClientConsensusState(
k.clientKeeper.ClientStore(ctx, clientID), k.cdc, k.aminoCdc, targetConsState.GetRoot(), height,
connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed consensus state verification")
}
return nil
}
// VerifyConnectionState verifies a proof of the connection state of the
@ -62,10 +66,14 @@ func (k Keeper) VerifyConnectionState(
)
}
return clientState.VerifyConnectionState(
if err := clientState.VerifyConnectionState(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, connectionID, connectionEnd, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed connection state verification")
}
return nil
}
// VerifyChannelState verifies a proof of the channel state of the specified
@ -95,11 +103,15 @@ func (k Keeper) VerifyChannelState(
)
}
return clientState.VerifyChannelState(
if err := clientState.VerifyChannelState(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof,
portID, channelID, channel, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed channel state verification")
}
return nil
}
// VerifyPacketCommitment verifies a proof of an outgoing packet commitment at
@ -130,11 +142,15 @@ func (k Keeper) VerifyPacketCommitment(
)
}
return clientState.VerifyPacketCommitment(
if err := clientState.VerifyPacketCommitment(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
sequence, commitmentBytes, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed packet commitment verification")
}
return nil
}
// VerifyPacketAcknowledgement verifies a proof of an incoming packet
@ -165,11 +181,15 @@ func (k Keeper) VerifyPacketAcknowledgement(
)
}
return clientState.VerifyPacketAcknowledgement(
if err := clientState.VerifyPacketAcknowledgement(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
sequence, acknowledgement, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed packet acknowledgement verification")
}
return nil
}
// VerifyPacketAcknowledgementAbsence verifies a proof of the absence of an
@ -200,11 +220,15 @@ func (k Keeper) VerifyPacketAcknowledgementAbsence(
)
}
return clientState.VerifyPacketAcknowledgementAbsence(
if err := clientState.VerifyPacketAcknowledgementAbsence(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
sequence, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed packet acknowledgement absence verification")
}
return nil
}
// VerifyNextSequenceRecv verifies a proof of the next sequence number to be
@ -234,9 +258,13 @@ func (k Keeper) VerifyNextSequenceRecv(
)
}
return clientState.VerifyNextSequenceRecv(
if err := clientState.VerifyNextSequenceRecv(
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
nextSequenceRecv, consensusState,
)
); err != nil {
return sdkerrors.Wrap(err, "failed next sequence receive verification")
}
return nil
}

View File

@ -51,13 +51,13 @@ func (c ConnectionEnd) GetVersions() []string {
// counterparty's.
func (c ConnectionEnd) ValidateBasic() error {
if err := host.ConnectionIdentifierValidator(c.ID); err != nil {
return sdkerrors.Wrapf(err, "invalid connection ID: %s", c.ID)
return sdkerrors.Wrap(err, "invalid connection ID")
}
if err := host.ClientIdentifierValidator(c.ClientID); err != nil {
return sdkerrors.Wrapf(err, "invalid client ID: %s", c.ClientID)
return sdkerrors.Wrap(err, "invalid client ID")
}
if len(c.Versions) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "missing connection versions")
return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "empty connection versions")
}
for _, version := range c.Versions {
if err := host.ConnectionVersionValidator(version); err != nil {

View File

@ -43,7 +43,7 @@ func DefaultGenesisState() GenesisState {
func (gs GenesisState) Validate() error {
for i, conn := range gs.Connections {
if err := conn.ValidateBasic(); err != nil {
return fmt.Errorf("invalid connection %d: %w", i, err)
return fmt.Errorf("invalid connection %v index %d: %w", conn, i, err)
}
}

View File

@ -37,10 +37,10 @@ func (msg MsgConnectionOpenInit) Type() string {
// ValidateBasic implements sdk.Msg
func (msg MsgConnectionOpenInit) ValidateBasic() error {
if err := host.ConnectionIdentifierValidator(msg.ConnectionID); err != nil {
return sdkerrors.Wrapf(err, "invalid connection ID: %s", msg.ConnectionID)
return sdkerrors.Wrap(err, "invalid connection ID")
}
if err := host.ClientIdentifierValidator(msg.ClientID); err != nil {
return sdkerrors.Wrapf(err, "invalid client ID: %s", msg.ClientID)
return sdkerrors.Wrap(err, "invalid client ID")
}
if msg.Signer.Empty() {
return sdkerrors.ErrInvalidAddress
@ -94,13 +94,13 @@ func (msg MsgConnectionOpenTry) Type() string {
// ValidateBasic implements sdk.Msg
func (msg MsgConnectionOpenTry) ValidateBasic() error {
if err := host.ConnectionIdentifierValidator(msg.ConnectionID); err != nil {
return sdkerrors.Wrapf(err, "invalid connection ID: %s", msg.ConnectionID)
return sdkerrors.Wrap(err, "invalid connection ID")
}
if err := host.ClientIdentifierValidator(msg.ClientID); err != nil {
return sdkerrors.Wrapf(err, "invalid client ID: %s", msg.ClientID)
return sdkerrors.Wrap(err, "invalid client ID")
}
if len(msg.CounterpartyVersions) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "missing counterparty versions")
return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "empty counterparty versions")
}
for _, version := range msg.CounterpartyVersions {
if err := host.ConnectionVersionValidator(version); err != nil {

View File

@ -4,6 +4,7 @@ import (
"strings"
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/cosmos-sdk/x/ibc/04-channel/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
@ -16,7 +17,7 @@ func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, portCap *capabil
portCap, msg.Channel.Counterparty, msg.Channel.Version,
)
if err != nil {
return nil, nil, err
return nil, nil, sdkerrors.Wrap(err, "channel handshake open init failed")
}
ctx.EventManager().EmitEvents(sdk.Events{
@ -45,7 +46,7 @@ func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, portCap *capabili
portCap, msg.Channel.Counterparty, msg.Channel.Version, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight,
)
if err != nil {
return nil, nil, err
return nil, nil, sdkerrors.Wrap(err, "channel handshake open try failed")
}
ctx.EventManager().EmitEvents(sdk.Events{
@ -74,7 +75,7 @@ func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capab
ctx, msg.PortID, msg.ChannelID, channelCap, msg.CounterpartyVersion, msg.ProofTry, msg.ProofHeight,
)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel handshake open ack failed")
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
@ -103,7 +104,7 @@ func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capab
func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelOpenConfirm) (*sdk.Result, error) {
err := k.ChanOpenConfirm(ctx, msg.PortID, msg.ChannelID, channelCap, msg.ProofAck, msg.ProofHeight)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed")
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
@ -132,7 +133,7 @@ func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *c
func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelCloseInit) (*sdk.Result, error) {
err := k.ChanCloseInit(ctx, msg.PortID, msg.ChannelID, channelCap)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel handshake close init failed")
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
@ -161,7 +162,7 @@ func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *cap
func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelCloseConfirm) (*sdk.Result, error) {
err := k.ChanCloseConfirm(ctx, msg.PortID, msg.ChannelID, channelCap, msg.ProofInit, msg.ProofHeight)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed")
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)

View File

@ -44,7 +44,7 @@ func (k Keeper) ChanOpenInit(
// channel identifier and connection hop length checked on msg.ValidateBasic()
_, found := k.GetChannel(ctx, portID, channelID)
if found {
return nil, sdkerrors.Wrap(types.ErrChannelExists, channelID)
return nil, sdkerrors.Wrapf(types.ErrChannelExists, "port ID (%s) channel ID (%s)", portID, channelID)
}
connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0])
@ -53,10 +53,7 @@ func (k Keeper) ChanOpenInit(
}
if connectionEnd.GetState() == int32(connectiontypes.UNINITIALIZED) {
return nil, sdkerrors.Wrap(
connectiontypes.ErrInvalidConnectionState,
"connection state cannot be UNINITIALIZED",
)
return nil, connectiontypes.ErrInvalidConnectionState
}
if len(connectionEnd.GetVersions()) != 1 {
@ -76,7 +73,7 @@ func (k Keeper) ChanOpenInit(
}
if !k.portKeeper.Authenticate(ctx, portCap, portID) {
return nil, sdkerrors.Wrap(porttypes.ErrInvalidPort, "caller does not own port capability")
return nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID)
}
channel := types.NewChannel(types.INIT, order, counterparty, connectionHops, version)
@ -84,7 +81,7 @@ func (k Keeper) ChanOpenInit(
capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID))
if err != nil {
return nil, sdkerrors.Wrap(types.ErrInvalidChannelCapability, err.Error())
return nil, sdkerrors.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID)
}
k.SetNextSequenceSend(ctx, portID, channelID, 1)
@ -122,7 +119,7 @@ func (k Keeper) ChanOpenTry(
}
if !k.portKeeper.Authenticate(ctx, portCap, portID) {
return nil, sdkerrors.Wrap(porttypes.ErrInvalidPort, "caller does not own port capability")
return nil, sdkerrors.Wrapf(porttypes.ErrInvalidPort, "caller does not own port capability for port ID %s", portID)
}
connectionEnd, found := k.connectionKeeper.GetConnection(ctx, connectionHops[0])
@ -182,7 +179,7 @@ func (k Keeper) ChanOpenTry(
capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID))
if err != nil {
return nil, sdkerrors.Wrap(types.ErrInvalidChannelCapability, err.Error())
return nil, sdkerrors.Wrapf(err, "could not create channel capability for port ID %s and channel ID %s", portID, channelID)
}
k.SetNextSequenceSend(ctx, portID, channelID, 1)
@ -206,7 +203,7 @@ func (k Keeper) ChanOpenAck(
) error {
channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
return sdkerrors.Wrap(types.ErrChannelNotFound, channelID)
return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
if !(channel.State == types.INIT || channel.State == types.TRYOPEN) {
@ -217,7 +214,7 @@ func (k Keeper) ChanOpenAck(
}
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel")
return sdkerrors.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])
@ -253,11 +250,12 @@ func (k Keeper) ChanOpenAck(
return err
}
k.Logger(ctx).Info(fmt.Sprintf("channel (port-id: %s, channel-id: %s) state updated: %s -> OPEN", portID, channelID, channel.State))
channel.State = types.OPEN
channel.Version = counterpartyVersion
k.SetChannel(ctx, portID, channelID, channel)
k.Logger(ctx).Info(fmt.Sprintf("channel (port-id: %s, channel-id: %s) state updated: INIT -> OPEN", portID, channelID))
return nil
}
@ -273,7 +271,7 @@ func (k Keeper) ChanOpenConfirm(
) error {
channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
return sdkerrors.Wrap(types.ErrChannelNotFound, channelID)
return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
if channel.State != types.TRYOPEN {
@ -284,7 +282,7 @@ func (k Keeper) ChanOpenConfirm(
}
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel")
return sdkerrors.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])
@ -340,12 +338,12 @@ func (k Keeper) ChanCloseInit(
chanCap *capabilitytypes.Capability,
) error {
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel")
return sdkerrors.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.Wrap(types.ErrChannelNotFound, channelID)
return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
if channel.State == types.CLOSED {
@ -383,12 +381,12 @@ func (k Keeper) ChanCloseConfirm(
proofHeight uint64,
) error {
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel")
return sdkerrors.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.Wrap(types.ErrChannelNotFound, channelID)
return sdkerrors.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
if channel.State == types.CLOSED {

View File

@ -24,7 +24,7 @@ func (k Keeper) SendPacket(
packet exported.PacketI,
) error {
if err := packet.ValidateBasic(); err != nil {
return err
return sdkerrors.Wrap(err, "packet failed basic validation")
}
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
@ -40,7 +40,7 @@ func (k Keeper) SendPacket(
}
if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())) {
return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel")
return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel())
}
if packet.GetDestPort() != channel.Counterparty.PortID {
@ -267,9 +267,9 @@ func (k Keeper) PacketExecuted(
capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel())
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) {
return sdkerrors.Wrap(
return sdkerrors.Wrapf(
types.ErrInvalidChannelCapability,
"channel capability failed authentication",
"channel capability failed authentication for capability name %s", capName,
)
}
@ -336,7 +336,7 @@ func (k Keeper) AcknowledgePacket(
if !found {
return sdkerrors.Wrapf(
types.ErrChannelNotFound,
packet.GetSourcePort(), packet.GetSourceChannel(),
"port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel(),
)
}
@ -381,14 +381,14 @@ func (k Keeper) AcknowledgePacket(
// verify we sent the packet and haven't cleared it out yet
if !bytes.Equal(commitment, types.CommitPacket(packet)) {
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
return sdkerrors.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", types.CommitPacket(packet), commitment)
}
if err := k.connectionKeeper.VerifyPacketAcknowledgement(
ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(),
packet.GetSequence(), acknowledgement,
); err != nil {
return sdkerrors.Wrap(err, "invalid acknowledgement on counterparty chain")
return sdkerrors.Wrap(err, "packet acknowledgement verification failed")
}
// assert packets acknowledged in order
@ -426,15 +426,15 @@ func (k Keeper) AcknowledgementExecuted(
if !found {
return sdkerrors.Wrapf(
types.ErrChannelNotFound,
packet.GetSourcePort(), packet.GetSourceChannel(),
"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.Wrap(
return sdkerrors.Wrapf(
types.ErrInvalidChannelCapability,
"channel capability failed authentication",
"channel capability failed authentication for capability name %s", capName,
)
}

View File

@ -30,7 +30,7 @@ func (k Keeper) TimeoutPacket(
if !found {
return sdkerrors.Wrapf(
types.ErrChannelNotFound,
packet.GetSourcePort(), packet.GetSourceChannel(),
"port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel(),
)
}
@ -81,14 +81,17 @@ func (k Keeper) TimeoutPacket(
// verify we sent the packet and haven't cleared it out yet
if !bytes.Equal(commitment, types.CommitPacket(packet)) {
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, types.CommitPacket(packet))
}
switch channel.Ordering {
case types.ORDERED:
// check that packet has not been received
if nextSequenceRecv > packet.GetSequence() {
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
return sdkerrors.Wrapf(
types.ErrInvalidPacket,
"packet already received, next sequence receive > packet sequence (%d > %d)", nextSequenceRecv, packet.GetSequence(),
)
}
// check that the recv sequence is as claimed
@ -124,14 +127,14 @@ func (k Keeper) TimeoutExecuted(
) error {
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
if !found {
return sdkerrors.Wrapf(types.ErrChannelNotFound, packet.GetSourcePort(), packet.GetSourceChannel())
return sdkerrors.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.Wrap(
return sdkerrors.Wrapf(
types.ErrChannelCapabilityNotFound,
"caller does not own capability for channel",
"caller does not own capability for channel with capability name %s", capName,
)
}
@ -175,14 +178,14 @@ func (k Keeper) TimeoutOnClose(
) error {
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
if !found {
return sdkerrors.Wrapf(types.ErrChannelNotFound, packet.GetSourcePort(), packet.GetSourceChannel())
return sdkerrors.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.Wrap(
return sdkerrors.Wrapf(
types.ErrInvalidChannelCapability,
"channel capability failed authentication",
"channel capability failed authentication with capability name %s", capName,
)
}
@ -209,7 +212,7 @@ func (k Keeper) TimeoutOnClose(
// verify we sent the packet and haven't cleared it out yet
if !bytes.Equal(commitment, types.CommitPacket(packet)) {
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet hasn't been sent")
return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, types.CommitPacket(packet))
}
counterpartyHops, found := k.CounterpartyHops(ctx, channel)
@ -237,7 +240,7 @@ func (k Keeper) TimeoutOnClose(
case types.ORDERED:
// check that packet has not been received
if nextSequenceRecv > packet.GetSequence() {
return sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
return sdkerrors.Wrapf(types.ErrInvalidPacket, "packet already received, next sequence receive > packet sequence (%d > %d", nextSequenceRecv, packet.GetSequence())
}
// check that the recv sequence is as claimed

View File

@ -58,28 +58,22 @@ func (ch Channel) GetVersion() string {
// ValidateBasic performs a basic validation of the channel fields
func (ch Channel) ValidateBasic() error {
if ch.State.String() == "" {
return sdkerrors.Wrap(ErrInvalidChannel, ErrInvalidChannelState.Error())
return ErrInvalidChannelState
}
if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) {
return sdkerrors.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String())
}
if len(ch.ConnectionHops) != 1 {
return sdkerrors.Wrap(
ErrInvalidChannel,
sdkerrors.Wrap(ErrTooManyConnectionHops, "IBC v1.0 only supports one connection hop").Error(),
ErrTooManyConnectionHops,
"current IBC version only supports one connection hop",
)
}
if err := host.ConnectionIdentifierValidator(ch.ConnectionHops[0]); err != nil {
return sdkerrors.Wrap(
ErrInvalidChannel,
sdkerrors.Wrap(err, "invalid connection hop ID").Error(),
)
return sdkerrors.Wrap(err, "invalid connection hop ID")
}
if strings.TrimSpace(ch.Version) == "" {
return sdkerrors.Wrap(
ErrInvalidChannel,
sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "channel version can't be blank").Error(),
)
return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "channel version can't be blank")
}
return ch.Counterparty.ValidateBasic()
}
@ -105,16 +99,10 @@ 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(
ErrInvalidCounterparty,
sdkerrors.Wrap(err, "invalid counterparty connection ID").Error(),
)
return sdkerrors.Wrap(err, "invalid counterparty port ID")
}
if err := host.ChannelIdentifierValidator(c.ChannelID); err != nil {
return sdkerrors.Wrap(
ErrInvalidCounterparty,
sdkerrors.Wrap(err, "invalid counterparty client ID").Error(),
)
return sdkerrors.Wrap(err, "invalid counterparty channel ID")
}
return nil
}
@ -135,10 +123,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(ErrInvalidChannel, err.Error())
return sdkerrors.Wrap(err, "invalid channel ID")
}
if err := host.PortIdentifierValidator(ic.PortID); err != nil {
return sdkerrors.Wrap(ErrInvalidChannel, err.Error())
return sdkerrors.Wrap(err, "invalid port ID")
}
channel := NewChannel(ic.State, ic.Ordering, ic.Counterparty, ic.ConnectionHops, ic.Version)
return channel.ValidateBasic()

View File

@ -91,37 +91,37 @@ func DefaultGenesisState() GenesisState {
func (gs GenesisState) Validate() error {
for i, channel := range gs.Channels {
if err := channel.ValidateBasic(); err != nil {
return fmt.Errorf("invalid channel %d: %w", i, err)
return fmt.Errorf("invalid channel %v channel index %d: %w", channel, i, err)
}
}
for i, ack := range gs.Acknowledgements {
if err := ack.Validate(); err != nil {
return fmt.Errorf("invalid acknowledgement %d: %w", i, err)
return fmt.Errorf("invalid acknowledgement %v ack index %d: %w", ack, i, err)
}
}
for i, commitment := range gs.Commitments {
if err := commitment.Validate(); err != nil {
return fmt.Errorf("invalid commitment %d: %w", i, err)
return fmt.Errorf("invalid commitment %v index %d: %w", commitment, i, err)
}
}
for i, ss := range gs.SendSequences {
if err := ss.Validate(); err != nil {
return fmt.Errorf("invalid send sequence %d: %w", i, err)
return fmt.Errorf("invalid send sequence %v index %d: %w", ss, i, err)
}
}
for i, rs := range gs.RecvSequences {
if err := rs.Validate(); err != nil {
return fmt.Errorf("invalid receive sequence %d: %w", i, err)
return fmt.Errorf("invalid receive sequence %v index %d: %w", rs, i, err)
}
}
for i, as := range gs.AckSequences {
if err := as.Validate(); err != nil {
return fmt.Errorf("invalid acknowledgement sequence %d: %w", i, err)
return fmt.Errorf("invalid acknowledgement sequence %v index %d: %w", as, i, err)
}
}
@ -130,10 +130,10 @@ func (gs GenesisState) Validate() error {
func validateGenFields(portID, channelID string, sequence uint64) error {
if err := host.PortIdentifierValidator(portID); err != nil {
return err
return fmt.Errorf("invalid port ID: %w", err)
}
if err := host.ChannelIdentifierValidator(channelID); err != nil {
return err
return fmt.Errorf("invalid channel ID: %w", err)
}
if sequence == 0 {
return errors.New("sequence cannot be 0")

View File

@ -72,28 +72,16 @@ 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.Wrapf(
ErrInvalidPacket,
sdkerrors.Wrapf(err, "invalid source port ID: %s", p.SourcePort).Error(),
)
return sdkerrors.Wrap(err, "invalid source port ID")
}
if err := host.PortIdentifierValidator(p.DestinationPort); err != nil {
return sdkerrors.Wrapf(
ErrInvalidPacket,
sdkerrors.Wrapf(err, "invalid destination port ID: %s", p.DestinationPort).Error(),
)
return sdkerrors.Wrap(err, "invalid destination port ID")
}
if err := host.ChannelIdentifierValidator(p.SourceChannel); err != nil {
return sdkerrors.Wrapf(
ErrInvalidPacket,
sdkerrors.Wrapf(err, "invalid source channel ID: %s", p.SourceChannel).Error(),
)
return sdkerrors.Wrap(err, "invalid source channel ID")
}
if err := host.ChannelIdentifierValidator(p.DestinationChannel); err != nil {
return sdkerrors.Wrapf(
ErrInvalidPacket,
sdkerrors.Wrapf(err, "invalid destination channel ID: %s", p.DestinationChannel).Error(),
)
return sdkerrors.Wrap(err, "invalid destination channel ID")
}
if p.Sequence == 0 {
return sdkerrors.Wrap(ErrInvalidPacket, "packet sequence cannot be 0")

View File

@ -28,7 +28,7 @@ func CheckMisbehaviourAndUpdateState(
// cast the interface to specific types before checking for misbehaviour
tmClientState, ok := clientState.(types.ClientState)
if !ok {
return nil, sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "client state type is not Tendermint")
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", types.ClientState{}, clientState)
}
// If client is already frozen at earlier height than evidence, return with error
@ -39,12 +39,12 @@ func CheckMisbehaviourAndUpdateState(
tmConsensusState, ok := consensusState.(types.ConsensusState)
if !ok {
return nil, sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "consensus state is not Tendermint")
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", consensusState, types.ConsensusState{})
}
tmEvidence, ok := misbehaviour.(types.Evidence)
if !ok {
return nil, sdkerrors.Wrap(clienttypes.ErrInvalidClientType, "evidence type is not Tendermint")
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "expected type %T, got %T", misbehaviour, types.Evidence{})
}
if err := checkMisbehaviour(

View File

@ -196,7 +196,7 @@ func (cs ClientState) VerifyClientConsensusState(
}
if err := merkleProof.VerifyMembership(cs.ProofSpecs, provingRoot, path, bz); err != nil {
return sdkerrors.Wrap(clienttypes.ErrFailedClientConsensusStateVerification, err.Error())
return err
}
return nil
@ -235,7 +235,7 @@ func (cs ClientState) VerifyConnectionState(
}
if err := merkleProof.VerifyMembership(cs.ProofSpecs, consensusState.GetRoot(), path, bz); err != nil {
return sdkerrors.Wrap(clienttypes.ErrFailedConnectionStateVerification, err.Error())
return err
}
return nil
@ -275,7 +275,7 @@ func (cs ClientState) VerifyChannelState(
}
if err := merkleProof.VerifyMembership(cs.ProofSpecs, consensusState.GetRoot(), path, bz); err != nil {
return sdkerrors.Wrap(clienttypes.ErrFailedChannelStateVerification, err.Error())
return err
}
return nil
@ -337,7 +337,7 @@ func (cs ClientState) VerifyPacketAcknowledgement(
}
if err := merkleProof.VerifyMembership(cs.ProofSpecs, consensusState.GetRoot(), path, channeltypes.CommitAcknowledgement(acknowledgement)); err != nil {
return sdkerrors.Wrap(clienttypes.ErrFailedPacketAckVerification, err.Error())
return err
}
return nil
@ -368,7 +368,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence(
}
if err := merkleProof.VerifyNonMembership(cs.ProofSpecs, consensusState.GetRoot(), path); err != nil {
return sdkerrors.Wrap(clienttypes.ErrFailedPacketAckAbsenceVerification, err.Error())
return err
}
return nil
@ -400,7 +400,7 @@ func (cs ClientState) VerifyNextSequenceRecv(
bz := sdk.Uint64ToBigEndian(nextSequenceRecv)
if err := merkleProof.VerifyMembership(cs.ProofSpecs, consensusState.GetRoot(), path, bz); err != nil {
return sdkerrors.Wrap(clienttypes.ErrFailedNextSeqRecvVerification, err.Error())
return err
}
return nil

View File

@ -85,7 +85,7 @@ func (ev Evidence) GetTime() time.Time {
// ValidateBasic implements Evidence interface
func (ev Evidence) ValidateBasic() error {
if err := host.ClientIdentifierValidator(ev.ClientID); err != nil {
return sdkerrors.Wrap(clienttypes.ErrInvalidEvidence, err.Error())
return sdkerrors.Wrap(err, "evidence client ID is invalid")
}
// ValidateBasic on both validators

View File

@ -46,7 +46,7 @@ func (h Header) GetHeight() uint64 {
// and checks that validatorsets are not nil
func (h Header) ValidateBasic(chainID string) error {
if err := h.SignedHeader.ValidateBasic(chainID); err != nil {
return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, err.Error())
return sdkerrors.Wrap(err, "header failed basic validation")
}
if h.ValidatorSet == nil {
return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "validator set is nil")

View File

@ -27,15 +27,15 @@ func CheckValidityAndUpdateState(
) (clientexported.ClientState, clientexported.ConsensusState, error) {
tmClientState, ok := clientState.(types.ClientState)
if !ok {
return nil, nil, sdkerrors.Wrap(
clienttypes.ErrInvalidClientType, "light client is not from Tendermint",
return nil, nil, sdkerrors.Wrapf(
clienttypes.ErrInvalidClientType, "expected type %T, got %T", types.ClientState{}, clientState,
)
}
tmHeader, ok := header.(types.Header)
if !ok {
return nil, nil, sdkerrors.Wrap(
clienttypes.ErrInvalidHeader, "header is not from Tendermint",
return nil, nil, sdkerrors.Wrapf(
clienttypes.ErrInvalidHeader, "expected type %T, got %T", types.Header{}, header,
)
}
@ -94,7 +94,7 @@ func checkValidity(
clientState.TrustingPeriod, currentTimestamp, clientState.MaxClockDrift, clientState.TrustLevel,
)
if err != nil {
return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, err.Error())
return sdkerrors.Wrap(err, "failed to verify header")
}
return nil
}

View File

@ -230,7 +230,7 @@ func (proof MerkleProof) BatchVerifyMembership(specs []*ics23.ProofSpec, root ex
// of all subroots up to final root
subroot, err := proofs[0].Calculate()
if err != nil {
sdkerrors.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0. %v", err)
return sdkerrors.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0: %v", err)
}
if ok := ics23.BatchVerifyMembership(specs[0], subroot, proofs[0], items); !ok {
return sdkerrors.Wrapf(ErrInvalidProof, "could not verify batch items")
@ -281,7 +281,7 @@ func (proof MerkleProof) BatchVerifyNonMembership(specs []*ics23.ProofSpec, root
// of all subroots up to final root
subroot, err := proofs[0].Calculate()
if err != nil {
sdkerrors.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0. %v", err)
return sdkerrors.Wrapf(ErrInvalidProof, "could not calculate root for proof index 0: %v", err)
}
if ok := ics23.BatchVerifyNonMembership(specs[0], subroot, proofs[0], items); !ok {
return sdkerrors.Wrapf(ErrInvalidProof, "could not verify batch items")
@ -336,8 +336,8 @@ func verifyChainedMembershipProof(root []byte, specs []*ics23.ProofSpec, proofs
// from the proofs and specs which are lowest to highest
key := keys.GetKey(-1 * (i + 1))
if ok := ics23.VerifyMembership(specs[i], subroot, proofs[i], key, value); !ok {
return sdkerrors.Wrapf(ErrInvalidProof, "chained membership proof failed to verify membership of value: %X in subroot %X at index %d",
value, subroot, i)
return sdkerrors.Wrapf(ErrInvalidProof, "chained membership proof failed to verify membership of value: %X in subroot %X at index %d for proof %v",
value, subroot, i, proofs[i])
}
// Set value to subroot so that we verify next proof in chain commits to this subroot
value = subroot
@ -379,8 +379,12 @@ 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() || root == nil || root.Empty() {
return sdkerrors.Wrap(ErrInvalidMerkleProof, "empty params or proof")
if proof.Empty() {
return sdkerrors.Wrap(ErrInvalidMerkleProof, "proof cannot be empty")
}
if root == nil || root.Empty() {
return sdkerrors.Wrap(ErrInvalidMerkleProof, "root cannot be empty")
}
if len(specs) != len(proof.Proof.Ops) {

View File

@ -58,7 +58,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
}
err = cbs.OnChanOpenInit(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortID, msg.ChannelID, cap, msg.Channel.Counterparty, msg.Channel.Version)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel open init callback failed")
}
return res, nil
@ -80,7 +80,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
}
err = cbs.OnChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortID, msg.ChannelID, cap, msg.Channel.Counterparty, msg.Channel.Version, msg.CounterpartyVersion)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel open try callback failed")
}
return res, nil
@ -99,7 +99,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
err = cbs.OnChanOpenAck(ctx, msg.PortID, msg.ChannelID, msg.CounterpartyVersion)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel open ack callback failed")
}
return channel.HandleMsgChannelOpenAck(ctx, k.ChannelKeeper, cap, msg)
@ -117,7 +117,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
err = cbs.OnChanOpenConfirm(ctx, msg.PortID, msg.ChannelID)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel open confirm callback failed")
}
return channel.HandleMsgChannelOpenConfirm(ctx, k.ChannelKeeper, cap, msg)
@ -135,7 +135,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
err = cbs.OnChanCloseInit(ctx, msg.PortID, msg.ChannelID)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel close init callback failed")
}
return channel.HandleMsgChannelCloseInit(ctx, k.ChannelKeeper, cap, msg)
@ -153,7 +153,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
err = cbs.OnChanCloseConfirm(ctx, msg.PortID, msg.ChannelID)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "channel close confirm callback failed")
}
return channel.HandleMsgChannelCloseConfirm(ctx, k.ChannelKeeper, cap, msg)
@ -174,7 +174,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// Perform application logic callback
res, ack, err := cbs.OnRecvPacket(ctx, msg.Packet)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "receive packet callback failed")
}
// Set packet acknowledgement
@ -200,7 +200,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// Perform application logic callback
res, err := cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "acknowledge packet callback failed")
}
// Delete packet commitment
@ -226,7 +226,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// Perform application logic callback
res, err := cbs.OnTimeoutPacket(ctx, msg.Packet)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(err, "timeout packet callback failed")
}
// Delete packet commitment