* use cleaner helper function * fix error strings * lint * typos Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> 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
81ec5668cc
commit
8f51c150de
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue