Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change FrozenSequence to boolean in solo machine #169

Merged
merged 7 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking

* (06-solomachine) [\#169](https://github.com/cosmos/ibc-go/pull/169) Change FrozenSequence to boolean in solomachine ClientState.
* (modules) [\#162](https://github.com/cosmos/ibc-go/pull/162) Remove deprecated Handler types in core IBC and the ICS 20 transfer module.
* (modules/core) [\#161](https://github.com/cosmos/ibc-go/pull/161) Remove Type(), Route(), GetSignBytes() from 02-client, 03-connection, and 04-channel messages.
* (modules) [\#140](https://github.com/cosmos/ibc-go/pull/140) IsFrozen() client state interface changed to Status(). gRPC `ClientStatus` route added.
Expand Down
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been deleted in the Status pr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you removed it from localhost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I think this one got added back during a merge of main when I fixed the solo machine bug

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be removed by #165

}

// 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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have been removed by Status pr, this is checked in 02-client

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
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