Skip to content

Commit

Permalink
DRY FrozenHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed May 3, 2021
1 parent c7f8bd2 commit 76e932a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/light-clients/07-tendermint/types/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (

var _ exported.Misbehaviour = &Misbehaviour{}

// Use the same FrozenHeight for all misbehaviour
var FrozenHeight = clienttypes.NewHeight(0, 1)

// NewMisbehaviour creates a new Misbehaviour instance.
func NewMisbehaviour(clientID string, header1, header2 *Header) *Misbehaviour {
return &Misbehaviour{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
return nil, sdkerrors.Wrap(err, "verifying Header2 in Misbehaviour failed")
}

cs.FrozenHeight = clienttypes.NewHeight(0, 1)
cs.FrozenHeight = FrozenHeight

return &cs, nil
}
Expand Down
6 changes: 3 additions & 3 deletions modules/light-clients/07-tendermint/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (cs ClientState) CheckHeaderAndUpdateState(
consState := tmHeader.ConsensusState()
// Header is different from existing consensus state and also valid, so freeze the client and return
if conflictingHeader {
cs.FrozenHeight = clienttypes.NewHeight(0, 1)
cs.FrozenHeight = FrozenHeight
return &cs, consState, nil
}
// Check that consensus state timestamps are monotonic
Expand All @@ -100,13 +100,13 @@ func (cs ClientState) CheckHeaderAndUpdateState(
// if previous consensus state exists, check consensus state time is greater than previous consensus state time
// if previous consensus state is not before current consensus state, freeze the client and return.
if prevOk && !prevCons.Timestamp.Before(consState.Timestamp) {
cs.FrozenHeight = clienttypes.NewHeight(0, 1)
cs.FrozenHeight = FrozenHeight
return &cs, consState, nil
}
// if next consensus state exists, check consensus state time is less than next consensus state time
// if next consensus state is not after current consensus state, freeze the client and return.
if nextOk && !nextCons.Timestamp.After(consState.Timestamp) {
cs.FrozenHeight = clienttypes.NewHeight(0, 1)
cs.FrozenHeight = FrozenHeight
return &cs, consState, nil
}

Expand Down

0 comments on commit 76e932a

Please sign in to comment.