Skip to content

Commit

Permalink
change frozen sequence to is frozen in solo machine
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed May 10, 2021
1 parent 5991e86 commit f3aeb1b
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 226 deletions.
2 changes: 1 addition & 1 deletion docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,7 @@ state and if the client is frozen.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sequence` | [uint64](#uint64) | | latest sequence of the client state |
| `frozen_sequence` | [uint64](#uint64) | | frozen sequence of the solo machine |
| `is_frozen` | [bool](#bool) | | frozen sequence of the solo machine |
| `consensus_state` | [ConsensusState](#ibc.lightclients.solomachine.v1.ConsensusState) | | |
| `allow_update_after_proposal` | [bool](#bool) | | when set to true, will allow governance to update a solo machine client. The client will be unfrozen if it is frozen. |

Expand Down
15 changes: 3 additions & 12 deletions modules/light-clients/06-solomachine/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ exported.ClientState = (*ClientState)(nil)
func NewClientState(latestSequence uint64, consensusState *ConsensusState, allowUpdateAfterProposal bool) *ClientState {
return &ClientState{
Sequence: latestSequence,
FrozenSequence: 0,
IsFrozen: false,
ConsensusState: consensusState,
AllowUpdateAfterProposal: allowUpdateAfterProposal,
}
Expand All @@ -45,23 +45,18 @@ func (cs ClientState) GetLatestHeight() exported.Height {
// - Active: if frozen sequence is 0
// - Frozen: otherwise solo machine is frozen
func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) exported.Status {
if cs.FrozenSequence != 0 {
if cs.IsFrozen {
return exported.Frozen
}

return exported.Active
}

// IsFrozen returns true if the client is frozen.
func (cs ClientState) IsFrozen() bool {
return cs.FrozenSequence != 0
}

// GetFrozenHeight returns the frozen sequence of the client.
// Return exported.Height to satisfy interface
// Revision number is always 0 for a solo-machine
func (cs ClientState) GetFrozenHeight() exported.Height {
return clienttypes.NewHeight(0, cs.FrozenSequence)
return clienttypes.NewHeight(0, 1)
}

// GetProofSpecs returns nil proof specs since client state verification uses signatures.
Expand Down Expand Up @@ -445,10 +440,6 @@ func produceVerificationArgs(
}
// sequence is encoded in the revision height of height struct
sequence := height.GetRevisionHeight()
if cs.IsFrozen() {
return nil, nil, 0, 0, clienttypes.ErrClientFrozen
}

if prefix == nil {
return nil, nil, 0, 0, sdkerrors.Wrap(commitmenttypes.ErrInvalidPrefix, "prefix cannot be empty")
}
Expand Down
98 changes: 1 addition & 97 deletions modules/light-clients/06-solomachine/types/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (suite *SoloMachineTestSuite) TestStatus() {
suite.Require().Equal(exported.Active, status)

// freeze solo machine
clientState.FrozenSequence = 1
clientState.IsFrozen = true
status = clientState.Status(suite.chainA.GetContext(), nil, nil)
suite.Require().Equal(exported.Frozen, status)
}
Expand Down Expand Up @@ -188,18 +188,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientState() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"consensus state in client state is nil",
types.NewClientState(1, nil, false),
Expand Down Expand Up @@ -321,18 +309,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientConsensusState() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"consensus state in client state is nil",
types.NewClientState(1, nil, false),
Expand Down Expand Up @@ -450,18 +426,6 @@ func (suite *SoloMachineTestSuite) TestVerifyConnectionState() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"proof is nil",
solomachine.ClientState(),
Expand Down Expand Up @@ -540,18 +504,6 @@ func (suite *SoloMachineTestSuite) TestVerifyChannelState() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"proof is nil",
solomachine.ClientState(),
Expand Down Expand Up @@ -629,18 +581,6 @@ func (suite *SoloMachineTestSuite) TestVerifyPacketCommitment() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"proof is nil",
solomachine.ClientState(),
Expand Down Expand Up @@ -716,18 +656,6 @@ func (suite *SoloMachineTestSuite) TestVerifyPacketAcknowledgement() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"proof is nil",
solomachine.ClientState(),
Expand Down Expand Up @@ -803,18 +731,6 @@ func (suite *SoloMachineTestSuite) TestVerifyPacketReceiptAbsence() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"proof is nil",
solomachine.ClientState(),
Expand Down Expand Up @@ -890,18 +806,6 @@ func (suite *SoloMachineTestSuite) TestVerifyNextSeqRecv() {
proof,
false,
},
{
"client is frozen",
&types.ClientState{
Sequence: 1,
FrozenSequence: 1,
ConsensusState: solomachine.ConsensusState(),
AllowUpdateAfterProposal: false,
},
prefix,
proof,
false,
},
{
"proof is nil",
solomachine.ClientState(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
)
}

if cs.IsFrozen() {
return nil, sdkerrors.Wrapf(clienttypes.ErrClientFrozen, "client is already frozen")
}

// NOTE: a check that the misbehaviour message data are not equal is done by
// misbehaviour.ValidateBasic which is called by the 02-client keeper.

Expand All @@ -46,7 +42,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
return nil, sdkerrors.Wrap(err, "failed to verify signature two")
}

cs.FrozenSequence = soloMisbehaviour.Sequence
cs.IsFrozen = true
return &cs, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ func (suite *SoloMachineTestSuite) TestCheckMisbehaviourAndUpdateState() {
misbehaviour = solomachine.CreateMisbehaviour()
}, true,
},
{
"client is frozen",
func() {
cs := solomachine.ClientState()
cs.FrozenSequence = 1
clientState = cs
misbehaviour = solomachine.CreateMisbehaviour()
},
false,
},
{
"wrong client state type",
func() {
Expand Down Expand Up @@ -264,7 +254,7 @@ func (suite *SoloMachineTestSuite) TestCheckMisbehaviourAndUpdateState() {

if tc.expPass {
suite.Require().NoError(err)
suite.Require().True(clientState.(*types.ClientState).FrozenSequence != 0, "client not frozen")
suite.Require().True(clientState.(*types.ClientState).IsFrozen, "client not frozen")
} else {
suite.Require().Error(err)
suite.Require().Nil(clientState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState(
// update to substitute parameters
clientState.Sequence = substituteClientState.Sequence
clientState.ConsensusState = substituteClientState.ConsensusState
clientState.FrozenSequence = 0
clientState.IsFrozen = false

return clientState, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (suite *SoloMachineTestSuite) TestCheckSubstituteAndUpdateState() {

suite.Require().Equal(substituteClientState.(*types.ClientState).ConsensusState, updatedClient.(*types.ClientState).ConsensusState)
suite.Require().Equal(substituteClientState.(*types.ClientState).Sequence, updatedClient.(*types.ClientState).Sequence)
suite.Require().Equal(uint64(0), updatedClient.(*types.ClientState).FrozenSequence)
suite.Require().Equal(false, updatedClient.(*types.ClientState).IsFrozen)
} else {
suite.Require().Error(err)
suite.Require().Nil(updatedClient)
Expand Down
Loading

0 comments on commit f3aeb1b

Please sign in to comment.