diff --git a/x/ibc/07-tendermint/types/misbehaviour.go b/x/ibc/07-tendermint/types/misbehaviour.go index 6d01a8ae7..c1c320034 100644 --- a/x/ibc/07-tendermint/types/misbehaviour.go +++ b/x/ibc/07-tendermint/types/misbehaviour.go @@ -8,7 +8,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // CheckMisbehaviourAndUpdateState determines whether or not two conflicting @@ -40,31 +39,15 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState( // and unmarshal from clientStore // Get consensus bytes from clientStore - consBytes1 := clientStore.Get(host.KeyConsensusState(tmEvidence.Header1.TrustedHeight)) - if consBytes1 == nil { - return nil, sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, - "could not find trusted consensus state at height %d", tmEvidence.Header1.TrustedHeight) - } - // Unmarshal consensus bytes into clientexported.ConensusState - consensusState1 := clienttypes.MustUnmarshalConsensusState(cdc, consBytes1) - // Cast to tendermint-specific type - tmConsensusState1, ok := consensusState1.(*ConsensusState) - if !ok { - return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "invalid consensus state type for first header: expected type %T, got %T", &ConsensusState{}, consensusState1) + tmConsensusState1, err := GetConsensusState(clientStore, cdc, tmEvidence.Header1.TrustedHeight) + if err != nil { + return nil, sdkerrors.Wrapf(err, "could not get trusted consensus state from clientStore for Header1 at TrustedHeight: %d", tmEvidence.Header1.TrustedHeight) } // Get consensus bytes from clientStore - consBytes2 := clientStore.Get(host.KeyConsensusState(tmEvidence.Header2.TrustedHeight)) - if consBytes2 == nil { - return nil, sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, - "could not find trusted consensus state at height %d", tmEvidence.Header2.TrustedHeight) - } - // Unmarshal consensus bytes into clientexported.ConensusState - consensusState2 := clienttypes.MustUnmarshalConsensusState(cdc, consBytes2) - // Cast to tendermint-specific type - tmConsensusState2, ok := consensusState2.(*ConsensusState) - if !ok { - return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidClientType, "invalid consensus state for second header: expected type %T, got %T", &ConsensusState{}, consensusState2) + tmConsensusState2, err := GetConsensusState(clientStore, cdc, tmEvidence.Header2.TrustedHeight) + if err != nil { + return nil, sdkerrors.Wrapf(err, "could not get trusted consensus state from clientStore for Header2 at TrustedHeight: %d", tmEvidence.Header2.TrustedHeight) } // calculate the age of the misbehaviour evidence diff --git a/x/ibc/07-tendermint/types/store.go b/x/ibc/07-tendermint/types/store.go index d07607783..e218c3b97 100644 --- a/x/ibc/07-tendermint/types/store.go +++ b/x/ibc/07-tendermint/types/store.go @@ -22,7 +22,7 @@ func GetConsensusState(store sdk.KVStore, cdc codec.BinaryMarshaler, height uint var consensusStateI clientexported.ConsensusState if err := codec.UnmarshalAny(cdc, &consensusStateI, bz); err != nil { - return nil, err + return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "unmarshal error: %v", err) } consensusState, ok := consensusStateI.(*ConsensusState) diff --git a/x/ibc/07-tendermint/types/update.go b/x/ibc/07-tendermint/types/update.go index f77fd5586..6f49c7bec 100644 --- a/x/ibc/07-tendermint/types/update.go +++ b/x/ibc/07-tendermint/types/update.go @@ -13,7 +13,6 @@ import ( clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // CheckHeaderAndUpdateState checks if the provided header is valid, and if valid it will: @@ -47,19 +46,10 @@ func (cs ClientState) CheckHeaderAndUpdateState( } // Get consensus bytes from clientStore - consBytes := clientStore.Get(host.KeyConsensusState(tmHeader.TrustedHeight)) - if consBytes == nil { + tmConsState, err := GetConsensusState(clientStore, cdc, tmHeader.TrustedHeight) + if err != nil { return nil, nil, sdkerrors.Wrapf( - clienttypes.ErrConsensusStateNotFound, "consensus state not found for trusted height %d", tmHeader.TrustedHeight, - ) - } - // Unmarshal consensus bytes into clientexported.ConensusState - consState := clienttypes.MustUnmarshalConsensusState(cdc, consBytes) - // Cast to tendermint-specific type - tmConsState, ok := consState.(*ConsensusState) - if !ok { - return nil, nil, sdkerrors.Wrapf( - clienttypes.ErrInvalidConsensus, "expected type %T, got %T", ConsensusState{}, consState, + err, "could not get consensus state from clientstore at TrustedHeight: %d", tmHeader.TrustedHeight, ) }