Skip to content

Commit

Permalink
IsFrozen() changed to Status() (#140)
Browse files Browse the repository at this point in the history
* initial work, pause for feedback

* IsFrozen() -> Status()

* fix bug

* fix tests

* remove typo

* add verify tests

* error message and code cleanup

* self review fixes

* Update modules/core/02-client/keeper/client.go

* add gRPC route to proto

* add gRPC route and tests

* update changelog

* apply review suggestions

* Update modules/light-clients/06-solomachine/types/client_state_test.go

* code ordering

* add set consensus state helper function

* use typed string for status
  • Loading branch information
colin-axner authored May 4, 2021
1 parent 094fa31 commit 2c880a2
Show file tree
Hide file tree
Showing 51 changed files with 1,831 additions and 1,055 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking

* (modules) [\#140](https://github.com/cosmos/ibc-go/pull/140) IsFrozen() client state interface changed to Status(). gRPC `ClientStatus` route added.
* (modules/core) [\#109](https://github.com/cosmos/ibc-go/pull/109) Remove connection and channel handshake CLI commands.
* (modules) [\#107](https://github.com/cosmos/ibc-go/pull/107) Modify OnRecvPacket callback to return an acknowledgement which indicates if it is successful or not. Callback state changes are discarded for unsuccessful acknowledgements only.
* (modules) [\#108](https://github.com/cosmos/ibc-go/pull/108) All message constructors take the signer as a string to prevent upstream bugs. The `String()` function for an SDK Acc Address relies on external context.
Expand Down
73 changes: 73 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@
<a href="#ibc.core.client.v1.QueryClientStatesResponse"><span class="badge">M</span>QueryClientStatesResponse</a>
</li>
<li>
<a href="#ibc.core.client.v1.QueryClientStatusRequest"><span class="badge">M</span>QueryClientStatusRequest</a>
</li>
<li>
<a href="#ibc.core.client.v1.QueryClientStatusResponse"><span class="badge">M</span>QueryClientStatusResponse</a>
</li>
<li>
<a href="#ibc.core.client.v1.QueryConsensusStateRequest"><span class="badge">M</span>QueryConsensusStateRequest</a>
</li>
Expand Down Expand Up @@ -4547,6 +4555,54 @@ MsgChannelCloseConfirm.</p></td>

<h3 id="ibc.core.client.v1.QueryClientStatusRequest">QueryClientStatusRequest</h3>
<p>QueryClientStatusRequest is the request type for the Query/ClientStatus RPC</p><p>method</p>

<table class="field-table">
<thead>
<tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td>client_id</td>
<td><a href="#string">string</a></td>
<td></td>
<td><p>client unique identifier </p></td>
</tr>
</tbody>
</table>


<h3 id="ibc.core.client.v1.QueryClientStatusResponse">QueryClientStatusResponse</h3>
<p>QueryClientStatusResponse is the response type for the Query/ClientStatus RPC</p><p>method. It returns the current status of the IBC client.</p>

<table class="field-table">
<thead>
<tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
</thead>
<tbody>
<tr>
<td>status</td>
<td><a href="#string">string</a></td>
<td></td>
<td><p> </p></td>
</tr>
</tbody>
</table>


<h3 id="ibc.core.client.v1.QueryConsensusStateRequest">QueryConsensusStateRequest</h3>
<p>QueryConsensusStateRequest is the request type for the Query/ConsensusState</p><p>RPC method. Besides the consensus state, it includes a proof and the height</p><p>from which the proof was retrieved.</p>

Expand Down Expand Up @@ -4799,6 +4855,13 @@ a given height.</p></td>
client.</p></td>
</tr>

<tr>
<td>ClientStatus</td>
<td><a href="#ibc.core.client.v1.QueryClientStatusRequest">QueryClientStatusRequest</a></td>
<td><a href="#ibc.core.client.v1.QueryClientStatusResponse">QueryClientStatusResponse</a></td>
<td><p>Status queries the status of an IBC client.</p></td>
</tr>

<tr>
<td>ClientParams</td>
<td><a href="#ibc.core.client.v1.QueryClientParamsRequest">QueryClientParamsRequest</a></td>
Expand Down Expand Up @@ -4880,6 +4943,16 @@ client.</p></td>
<tr>
<td>ClientStatus</td>
<td>GET</td>
<td>/ibc/core/client/v1/client_status/{client_id}</td>
<td></td>
</tr>
<tr>
<td>ClientParams</td>
<td>GET</td>
Expand Down
26 changes: 15 additions & 11 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID)
}

// prevent update if the client is frozen before or at header height
if clientState.IsFrozen() && clientState.GetFrozenHeight().LTE(header.GetHeight()) {
return sdkerrors.Wrapf(types.ErrClientFrozen, "cannot update client with ID %s", clientID)
clientStore := k.ClientStore(ctx, clientID)

if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active {
return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status)
}

clientState, consensusState, err := clientState.CheckHeaderAndUpdateState(ctx, k.cdc, k.ClientStore(ctx, clientID), header)
clientState, consensusState, err := clientState.CheckHeaderAndUpdateState(ctx, k.cdc, clientStore, header)
if err != nil {
return sdkerrors.Wrapf(err, "cannot update client with ID %s", clientID)
}
Expand Down Expand Up @@ -130,12 +131,13 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e
return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot update client with ID %s", clientID)
}

// prevent upgrade if current client is frozen
if clientState.IsFrozen() {
return sdkerrors.Wrapf(types.ErrClientFrozen, "cannot update client with ID %s", clientID)
clientStore := k.ClientStore(ctx, clientID)

if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active {
return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot upgrade client (%s) with status %s", clientID, status)
}

updatedClientState, updatedConsState, err := clientState.VerifyUpgradeAndUpdateState(ctx, k.cdc, k.ClientStore(ctx, clientID),
updatedClientState, updatedConsState, err := clientState.VerifyUpgradeAndUpdateState(ctx, k.cdc, clientStore,
upgradedClient, upgradedConsState, proofUpgradeClient, proofUpgradeConsState)
if err != nil {
return sdkerrors.Wrapf(err, "cannot upgrade client with ID %s", clientID)
Expand Down Expand Up @@ -178,11 +180,13 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex
return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot check misbehaviour for client with ID %s", misbehaviour.GetClientID())
}

if clientState.IsFrozen() && clientState.GetFrozenHeight().LTE(misbehaviour.GetHeight()) {
return sdkerrors.Wrapf(types.ErrInvalidMisbehaviour, "client is already frozen at height ≤ misbehaviour height (%s ≤ %s)", clientState.GetFrozenHeight(), misbehaviour.GetHeight())
clientStore := k.ClientStore(ctx, misbehaviour.GetClientID())

if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active {
return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot process misbehaviour for client (%s) with status %s", misbehaviour.GetClientID(), status)
}

clientState, err := clientState.CheckMisbehaviourAndUpdateState(ctx, k.cdc, k.ClientStore(ctx, misbehaviour.GetClientID()), misbehaviour)
clientState, err := clientState.CheckMisbehaviourAndUpdateState(ctx, k.cdc, clientStore, misbehaviour)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 2c880a2

Please sign in to comment.