Skip to content

Commit

Permalink
updating errors returns in 09-localhost (#3105)
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Feb 6, 2023
1 parent 3715153 commit badc331
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions modules/core/02-client/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ var (
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")
ErrFailedMembershipVerification = sdkerrors.Register(SubModuleName, 30, "membership verification failed")
ErrFailedNonMembershipVerification = sdkerrors.Register(SubModuleName, 31, "non-membership verification failed")
)
17 changes: 7 additions & 10 deletions modules/light-clients/09-localhost/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,21 @@ func (cs ClientState) VerifyMembership(
) error {
merklePath, ok := path.(commitmenttypes.MerklePath)
if !ok {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path)
}

if len(merklePath.GetKeyPath()) != 2 {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath())
}

// The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store
bz := store.Get([]byte(merklePath.KeyPath[1]))
if bz == nil {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path)
}

if !bytes.Equal(bz, value) {
return sdkerrors.Wrapf(
clienttypes.ErrFailedChannelStateVerification,
"todo: update error",
)
return sdkerrors.Wrapf(clienttypes.ErrFailedMembershipVerification, "value provided does not equal value stored at path: %s", path)
}

return nil
Expand All @@ -130,17 +127,17 @@ func (cs ClientState) VerifyNonMembership(
) error {
merklePath, ok := path.(commitmenttypes.MerklePath)
if !ok {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path)
}

if len(merklePath.GetKeyPath()) != 2 {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
return sdkerrors.Wrapf(host.ErrInvalidPath, "path must be of length 2: %s", merklePath.GetKeyPath())
}

// The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store
bz := store.Get([]byte(merklePath.KeyPath[1]))
if bz != nil {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- found for path %s", path)
return sdkerrors.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path)
}

return nil
Expand Down

0 comments on commit badc331

Please sign in to comment.