7211 followup (#7235)
* address chris comment and cleanup * Update x/ibc/07-tendermint/types/misbehaviour_handle.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
5df7dbc182
commit
12d95de096
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue