Skip to content

Commit

Permalink
7211 followup (cosmos#7235)
Browse files Browse the repository at this point in the history
* address chris comment and cleanup

* Update x/ibc/07-tendermint/types/misbehaviour_handle.go

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 4, 2020
1 parent 5df7dbc commit 12d95de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 4 additions & 12 deletions x/ibc/02-client/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}

Expand Down
16 changes: 14 additions & 2 deletions x/ibc/07-tendermint/types/misbehaviour_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12d95de

Please sign in to comment.