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

chore: Remove GetClientID() From Misbehaviour Interface #897

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -289,6 +289,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Client Breaking Changes

* (02-client/cli) [\#196](https://github.com/cosmos/ibc-go/pull/196) Rename `node-state` cli command to `self-consensus-state`.
* (02-client/cli) [\#897](https://github.com/cosmos/ibc-go/pull/897) Remove `GetClientID()` from `Misbehaviour` interface. Submit client misbehaviour cli command requires an explicit client id now.

## IBC in the Cosmos SDK Repository

Expand Down
11 changes: 6 additions & 5 deletions modules/core/02-client/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func NewUpdateClientCmd() *cobra.Command {
// future updates.
func NewSubmitMisbehaviourCmd() *cobra.Command {
return &cobra.Command{
Use: "misbehaviour [path/to/misbehaviour.json]",
Use: "misbehaviour [clientID] [path/to/misbehaviour.json]",
Short: "submit a client misbehaviour",
Long: "submit a client misbehaviour to prevent future updates",
Example: fmt.Sprintf("%s tx ibc %s misbehaviour [path/to/misbehaviour.json] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Args: cobra.ExactArgs(1),
Example: fmt.Sprintf("%s tx ibc %s misbehaviour [clientID] [path/to/misbehaviour.json] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -142,7 +142,8 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)

var misbehaviour exported.Misbehaviour
misbehaviourContentOrFileName := args[0]
clientID := args[0]
misbehaviourContentOrFileName := args[1]
if err := cdc.UnmarshalInterfaceJSON([]byte(misbehaviourContentOrFileName), &misbehaviour); err != nil {

// check for file path if JSON input is not provided
Expand All @@ -156,7 +157,7 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
}
}

msg, err := types.NewMsgSubmitMisbehaviour(misbehaviour.GetClientID(), misbehaviour, clientCtx.GetFromAddress().String())
msg, err := types.NewMsgSubmitMisbehaviour(clientID, misbehaviour, clientCtx.GetFromAddress().String())
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e

// CheckMisbehaviourAndUpdateState checks for client misbehaviour and freezes the
// client if so.
func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour exported.Misbehaviour) error {
clientState, found := k.GetClientState(ctx, misbehaviour.GetClientID())
func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, clientID string, misbehaviour exported.Misbehaviour) error {
clientState, found := k.GetClientState(ctx, clientID)
if !found {
return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot check misbehaviour for client with ID %s", misbehaviour.GetClientID())
return sdkerrors.Wrapf(types.ErrClientNotFound, "cannot check misbehaviour for client with ID %s", clientID)
}

clientStore := k.ClientStore(ctx, misbehaviour.GetClientID())
clientStore := k.ClientStore(ctx, clientID)

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)
return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot process misbehaviour for client (%s) with status %s", clientID, status)
}

if err := misbehaviour.ValidateBasic(); err != nil {
Expand All @@ -209,21 +209,21 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex
return err
}

k.SetClientState(ctx, misbehaviour.GetClientID(), clientState)
k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", misbehaviour.GetClientID())
k.SetClientState(ctx, clientID, clientState)
k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", clientID)

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "client", "misbehaviour"},
1,
[]metrics.Label{
telemetry.NewLabel(types.LabelClientType, misbehaviour.ClientType()),
telemetry.NewLabel(types.LabelClientID, misbehaviour.GetClientID()),
telemetry.NewLabel(types.LabelClientID, clientID),
},
)
}()

EmitSubmitMisbehaviourEvent(ctx, misbehaviour.GetClientID(), clientState)
EmitSubmitMisbehaviourEvent(ctx, clientID, clientState)

return nil
}
2 changes: 1 addition & 1 deletion modules/core/02-client/keeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {

tc.misbehaviour.ClientId = clientID

err = suite.keeper.CheckMisbehaviourAndUpdateState(suite.ctx, tc.misbehaviour)
err = suite.keeper.CheckMisbehaviourAndUpdateState(suite.ctx, clientID, tc.misbehaviour)

if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.name)
Expand Down
7 changes: 0 additions & 7 deletions modules/core/02-client/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,6 @@ func (msg MsgSubmitMisbehaviour) ValidateBasic() error {
if err := misbehaviour.ValidateBasic(); err != nil {
return err
}
if misbehaviour.GetClientID() != msg.ClientId {
return sdkerrors.Wrapf(
ErrInvalidMisbehaviour,
"misbehaviour client-id doesn't match client-id from message (%s ≠ %s)",
misbehaviour.GetClientID(), msg.ClientId,
)
}

return host.ClientIdentifierValidator(msg.ClientId)
}
Expand Down
1 change: 0 additions & 1 deletion modules/core/exported/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ type Misbehaviour interface {
proto.Message

ClientType() string
GetClientID() string
ValidateBasic() error
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (k Keeper) SubmitMisbehaviour(goCtx context.Context, msg *clienttypes.MsgSu
return nil, err
}

if err := k.ClientKeeper.CheckMisbehaviourAndUpdateState(ctx, misbehaviour); err != nil {
if err := k.ClientKeeper.CheckMisbehaviourAndUpdateState(ctx, msg.ClientId, misbehaviour); err != nil {
return nil, sdkerrors.Wrap(err, "failed to process misbehaviour for IBC client")
}

Expand Down