diff --git a/x/ibc/02-client/client/utils/utils.go b/x/ibc/02-client/client/utils/utils.go index fc146c57f6ed..f6d434d38381 100644 --- a/x/ibc/02-client/client/utils/utils.go +++ b/x/ibc/02-client/client/utils/utils.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" @@ -77,24 +76,17 @@ func QueryClientStateABCI( // If prove is true, it performs an ABCI store query in order to retrieve the merkle proof. Otherwise, // it uses the gRPC query client. func QueryConsensusState( - clientCtx client.Context, clientID string, heightI exported.Height, prove, latestHeight bool, + clientCtx client.Context, clientID string, height exported.Height, prove, latestHeight bool, ) (*types.QueryConsensusStateResponse, error) { if prove { - return QueryConsensusStateABCI(clientCtx, clientID, heightI) - } - height, ok := heightI.(types.Height) - if !ok { - return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidHeight, "invalid height type: %T, expected: %T", - heightI, types.Height{}, - ) + return QueryConsensusStateABCI(clientCtx, clientID, height) } queryClient := types.NewQueryClient(clientCtx) req := &types.QueryConsensusStateRequest{ ClientId: clientID, - EpochNumber: height.EpochNumber, - EpochHeight: height.EpochHeight, + EpochNumber: height.GetEpochNumber(), + EpochHeight: height.GetEpochHeight(), LatestHeight: latestHeight, } diff --git a/x/ibc/07-tendermint/types/misbehaviour_handle.go b/x/ibc/07-tendermint/types/misbehaviour_handle.go index 6718fabde5db..4890275c9229 100644 --- a/x/ibc/07-tendermint/types/misbehaviour_handle.go +++ b/x/ibc/07-tendermint/types/misbehaviour_handle.go @@ -52,10 +52,22 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState( } // calculate the age of the misbehaviour - infractionHeight := tmMisbehaviour.GetHeight().(clienttypes.Height).EpochHeight infractionTime := tmMisbehaviour.GetTime() ageDuration := ctx.BlockTime().Sub(infractionTime) - ageBlocks := int64(cs.LatestHeight.EpochHeight - infractionHeight) + + var ageBlocks int64 + if tmMisbehaviour.GetHeight().GetEpochNumber() == cs.LatestHeight.EpochNumber { + // if the misbehaviour is in the same epoch as the client then + // perform expiry check using block height in addition to time + infractionHeight := tmMisbehaviour.GetHeight().GetEpochHeight() + ageBlocks = int64(cs.LatestHeight.EpochHeight - infractionHeight) + } else { + // if the misbehaviour is from a previous epoch, then the epoch-height + // of misbehaviour has no correlation with the current epoch-height + // so we disable the block check by setting ageBlocks to 0 and only + // rely on the time expiry check with ageDuration + ageBlocks = 0 + } // TODO: Retrieve consensusparams from client state and not context // Issue #6516: https://github.com/cosmos/cosmos-sdk/issues/6516