From 55796fb3e73c222eb97c1308d4eee26144e8189f Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Wed, 10 Jun 2020 11:34:18 +0200 Subject: [PATCH] x/ibc: client consensus_height event (#6381) --- x/ibc/02-client/handler.go | 10 +++++++++- x/ibc/02-client/keeper/client.go | 9 +++++++-- x/ibc/02-client/types/events.go | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/x/ibc/02-client/handler.go b/x/ibc/02-client/handler.go index a15c8efa79..70441e56e6 100644 --- a/x/ibc/02-client/handler.go +++ b/x/ibc/02-client/handler.go @@ -1,6 +1,8 @@ package client import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/evidence" @@ -15,7 +17,10 @@ import ( func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg exported.MsgCreateClient) (*sdk.Result, error) { clientType := exported.ClientTypeFromString(msg.GetClientType()) - var clientState exported.ClientState + var ( + clientState exported.ClientState + consensusHeight uint64 + ) switch clientType { case exported.Tendermint: @@ -29,9 +34,11 @@ func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg exported.MsgCreateClie if err != nil { return nil, err } + consensusHeight = msg.GetConsensusState().GetHeight() case exported.Localhost: // msg client id is always "localhost" clientState = localhosttypes.NewClientState(ctx.ChainID(), ctx.BlockHeight()) + consensusHeight = uint64(ctx.BlockHeight()) default: return nil, sdkerrors.Wrap(ErrInvalidClientType, msg.GetClientType()) } @@ -48,6 +55,7 @@ func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg exported.MsgCreateClie EventTypeCreateClient, sdk.NewAttribute(AttributeKeyClientID, msg.GetClientID()), sdk.NewAttribute(AttributeKeyClientType, msg.GetClientType()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, fmt.Sprintf("%d", consensusHeight)), ), sdk.NewEvent( sdk.EventTypeMessage, diff --git a/x/ibc/02-client/keeper/client.go b/x/ibc/02-client/keeper/client.go index 058ce64424..481659a770 100644 --- a/x/ibc/02-client/keeper/client.go +++ b/x/ibc/02-client/keeper/client.go @@ -65,8 +65,9 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H } var ( - consensusState exported.ConsensusState - err error + consensusState exported.ConsensusState + consensusHeight uint64 + err error ) switch clientType { @@ -80,6 +81,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H ctx.ChainID(), // use the chain ID from context since the client is from the running chain (i.e self). ctx.BlockHeight(), ) + consensusHeight = uint64(ctx.BlockHeight()) default: err = types.ErrInvalidClientType } @@ -93,6 +95,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H // we don't set consensus state for localhost client if header != nil && clientType != exported.Localhost { k.SetClientConsensusState(ctx, clientID, header.GetHeight(), consensusState) + consensusHeight = consensusState.GetHeight() } k.Logger(ctx).Info(fmt.Sprintf("client %s updated to height %d", clientID, clientState.GetLatestHeight())) @@ -103,6 +106,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H types.EventTypeUpdateClient, sdk.NewAttribute(types.AttributeKeyClientID, clientID), sdk.NewAttribute(types.AttributeKeyClientType, clientType.String()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, fmt.Sprintf("%d", consensusHeight)), ), ) @@ -155,6 +159,7 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex types.EventTypeSubmitMisbehaviour, sdk.NewAttribute(types.AttributeKeyClientID, misbehaviour.GetClientID()), sdk.NewAttribute(types.AttributeKeyClientType, misbehaviour.ClientType().String()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, fmt.Sprintf("%d", consensusState.GetHeight())), ), ) diff --git a/x/ibc/02-client/types/events.go b/x/ibc/02-client/types/events.go index c2d75b71ff..08e83a4976 100644 --- a/x/ibc/02-client/types/events.go +++ b/x/ibc/02-client/types/events.go @@ -8,8 +8,9 @@ import ( // IBC client events const ( - AttributeKeyClientID = "client_id" - AttributeKeyClientType = "client_type" + AttributeKeyClientID = "client_id" + AttributeKeyClientType = "client_type" + AttributeKeyConsensusHeight = "consensus_height" ) // IBC client events vars