diff --git a/modules/core/02-client/keeper/client.go b/modules/core/02-client/keeper/client.go index 8e0a0639316..d8085ac719f 100644 --- a/modules/core/02-client/keeper/client.go +++ b/modules/core/02-client/keeper/client.go @@ -51,6 +51,8 @@ func (k Keeper) CreateClient( ) }() + EmitCreateClientEvent(ctx, clientID, clientState) + return clientID, nil } @@ -67,8 +69,6 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H return sdkerrors.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status) } - eventType := types.EventTypeUpdateClient - // Any writes made in CheckHeaderAndUpdateState are persisted on both valid updates and misbehaviour updates. // Light client implementations are responsible for writing the correct metadata (if any) in either case. newClientState, newConsensusState, err := clientState.CheckHeaderAndUpdateState(ctx, k.cdc, clientStore, header) @@ -118,9 +118,10 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H }, ) }() + + // emitting events in the keeper emits for both begin block and handler client updates + EmitUpdateClientEvent(ctx, clientID, newClientState, consensusHeight, headerStr) } else { - // set eventType to SubmitMisbehaviour - eventType = types.EventTypeSubmitMisbehaviour k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", clientID) @@ -135,18 +136,10 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H }, ) }() + + EmitSubmitMisbehaviourEventOnUpdate(ctx, clientID, newClientState, consensusHeight, headerStr) } - // emitting events in the keeper emits for both begin block and handler client updates - ctx.EventManager().EmitEvent( - sdk.NewEvent( - eventType, - sdk.NewAttribute(types.AttributeKeyClientID, clientID), - sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), - sdk.NewAttribute(types.AttributeKeyConsensusHeight, consensusHeight.String()), - sdk.NewAttribute(types.AttributeKeyHeader, headerStr), - ), - ) return nil } @@ -188,14 +181,7 @@ func (k Keeper) UpgradeClient(ctx sdk.Context, clientID string, upgradedClient e }() // emitting events in the keeper emits for client upgrades - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeUpgradeClient, - sdk.NewAttribute(types.AttributeKeyClientID, clientID), - sdk.NewAttribute(types.AttributeKeyClientType, updatedClientState.ClientType()), - sdk.NewAttribute(types.AttributeKeyConsensusHeight, updatedClientState.GetLatestHeight().String()), - ), - ) + EmitUpgradeClientEvent(ctx, clientID, updatedClientState) return nil } @@ -237,5 +223,7 @@ func (k Keeper) CheckMisbehaviourAndUpdateState(ctx sdk.Context, misbehaviour ex ) }() + EmitSubmitMisbehaviourEvent(ctx, misbehaviour.GetClientID(), clientState) + return nil } diff --git a/modules/core/02-client/keeper/events.go b/modules/core/02-client/keeper/events.go new file mode 100644 index 00000000000..ff8ae1c3acd --- /dev/null +++ b/modules/core/02-client/keeper/events.go @@ -0,0 +1,93 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v3/modules/core/exported" +) + +// EmitCreateClientEvent emits a create client event +func EmitCreateClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeCreateClient, + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, clientState.GetLatestHeight().String()), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitUpdateClientEvent emits an update client event +func EmitUpdateClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState, consensusHeight exported.Height, headerStr string) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeUpdateClient, + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, consensusHeight.String()), + sdk.NewAttribute(types.AttributeKeyHeader, headerStr), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitUpdateClientEvent emits an upgrade client event +func EmitUpgradeClientEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeUpgradeClient, + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, clientState.GetLatestHeight().String()), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitUpdateClientProposalEvent emits an update client proposal event +func EmitUpdateClientProposalEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeUpdateClientProposal, + sdk.NewAttribute(types.AttributeKeySubjectClientID, clientID), + sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, clientState.GetLatestHeight().String()), + ), + ) +} + +// EmitSubmitMisbehaviourEvent emits a client misbehaviour event +func EmitSubmitMisbehaviourEvent(ctx sdk.Context, clientID string, clientState exported.ClientState) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeSubmitMisbehaviour, + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), + ), + ) +} + +// EmitSubmitMisbehaviourEventOnUpdate emits a client misbehaviour event on a client update event +func EmitSubmitMisbehaviourEventOnUpdate(ctx sdk.Context, clientID string, clientState exported.ClientState, consensusHeight exported.Height, headerStr string) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeSubmitMisbehaviour, + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), + sdk.NewAttribute(types.AttributeKeyConsensusHeight, consensusHeight.String()), + sdk.NewAttribute(types.AttributeKeyHeader, headerStr), + ), + ) +} diff --git a/modules/core/02-client/keeper/proposal.go b/modules/core/02-client/keeper/proposal.go index bc210df85ce..ef0bf043e50 100644 --- a/modules/core/02-client/keeper/proposal.go +++ b/modules/core/02-client/keeper/proposal.go @@ -70,14 +70,7 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo }() // emitting events in the keeper for proposal updates to clients - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeUpdateClientProposal, - sdk.NewAttribute(types.AttributeKeySubjectClientID, p.SubjectClientId), - sdk.NewAttribute(types.AttributeKeyClientType, clientState.ClientType()), - sdk.NewAttribute(types.AttributeKeyConsensusHeight, clientState.GetLatestHeight().String()), - ), - ) + EmitUpdateClientProposalEvent(ctx, p.SubjectClientId, clientState) return nil } diff --git a/modules/core/03-connection/keeper/events.go b/modules/core/03-connection/keeper/events.go new file mode 100644 index 00000000000..6b1636ea71e --- /dev/null +++ b/modules/core/03-connection/keeper/events.go @@ -0,0 +1,75 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types" +) + +// EmitConnectionOpenInitEvent emits a connection open init event +func EmitConnectionOpenInitEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeConnectionOpenInit, + sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, counterparty.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyConnectionID, counterparty.ConnectionId), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitConnectionOpenTryEvent emits a connection open try event +func EmitConnectionOpenTryEvent(ctx sdk.Context, connectionID string, clientID string, counterparty types.Counterparty) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeConnectionOpenTry, + sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, counterparty.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyConnectionID, counterparty.ConnectionId), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitConnectionOpenAckEvent emits a connection open acknowledge event +func EmitConnectionOpenAckEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeConnectionOpenAck, + sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), + sdk.NewAttribute(types.AttributeKeyClientID, connectionEnd.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, connectionEnd.Counterparty.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyConnectionID, connectionEnd.Counterparty.ConnectionId), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitConnectionOpenConfirmEvent emits a connection open confirm event +func EmitConnectionOpenConfirmEvent(ctx sdk.Context, connectionID string, connectionEnd types.ConnectionEnd) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeConnectionOpenConfirm, + sdk.NewAttribute(types.AttributeKeyConnectionID, connectionID), + sdk.NewAttribute(types.AttributeKeyClientID, connectionEnd.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, connectionEnd.Counterparty.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyConnectionID, connectionEnd.Counterparty.ConnectionId), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index ed209c26cf2..177324e3e17 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -50,6 +50,8 @@ func (k Keeper) ConnOpenInit( telemetry.IncrCounter(1, "ibc", "connection", "open-init") }() + EmitConnectionOpenInitEvent(ctx, connectionID, clientID, counterparty) + return connectionID, nil } @@ -185,6 +187,8 @@ func (k Keeper) ConnOpenTry( telemetry.IncrCounter(1, "ibc", "connection", "open-try") }() + EmitConnectionOpenTryEvent(ctx, connectionID, clientID, counterparty) + return connectionID, nil } @@ -290,6 +294,9 @@ func (k Keeper) ConnOpenAck( connection.Versions = []*types.Version{version} connection.Counterparty.ConnectionId = counterpartyConnectionID k.SetConnection(ctx, connectionID, connection) + + EmitConnectionOpenAckEvent(ctx, connectionID, connection) + return nil } @@ -338,5 +345,7 @@ func (k Keeper) ConnOpenConfirm( telemetry.IncrCounter(1, "ibc", "connection", "open-confirm") }() + EmitConnectionOpenConfirmEvent(ctx, connectionID, connection) + return nil } diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index 1a5b44dbb1c..d299d6afeda 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -10,6 +10,119 @@ import ( "github.com/cosmos/ibc-go/v3/modules/core/exported" ) +// EmitChannelOpenInitEvent emits a channel open init event +func EmitChannelOpenInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenInit, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitChannelOpenTryEvent emits a channel open try event +func EmitChannelOpenTryEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenTry, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitChannelOpenAckEvent emits a channel open acknowledge event +func EmitChannelOpenAckEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenAck, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitChannelOpenConfirmEvent emits a channel open confirm event +func EmitChannelOpenConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenConfirm, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitChannelCloseInitEvent emits a channel close init event +func EmitChannelCloseInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelCloseInit, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// EmitChannelCloseConfirmEvent emits a channel close confirm event +func EmitChannelCloseConfirmEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelCloseConfirm, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + // EmitSendPacketEvent emits an event with packet data along with other packet information for relayer // to pick up and relay to other chain func EmitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, timeoutHeight exported.Height) { diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index a9c5046c099..1d650bb4d7b 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -89,23 +89,7 @@ func (k Keeper) WriteOpenInitChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-init") }() - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenInit, - sdk.NewAttribute(types.AttributeKeyPortID, portID), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, connectionHops[0]), - ), - }) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) + EmitChannelOpenInitEvent(ctx, portID, channelID, channel) } // ChanOpenTry is called by a module to accept the first step of a channel opening @@ -263,22 +247,7 @@ func (k Keeper) WriteOpenTryChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-try") }() - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenTry, - sdk.NewAttribute(types.AttributeKeyPortID, portID), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - }) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) + EmitChannelOpenTryEvent(ctx, portID, channelID, channel) } // ChanOpenAck is called by the handshake-originating module to acknowledge the @@ -366,23 +335,7 @@ func (k Keeper) WriteOpenAckChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-ack") }() - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenAck, - sdk.NewAttribute(types.AttributeKeyPortID, portID), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - }) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - + EmitChannelOpenAckEvent(ctx, portID, channelID, channel) } // ChanOpenConfirm is called by the counterparty module to close their end of the @@ -462,22 +415,7 @@ func (k Keeper) WriteOpenConfirmChannel( telemetry.IncrCounter(1, "ibc", "channel", "open-confirm") }() - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenConfirm, - sdk.NewAttribute(types.AttributeKeyPortID, portID), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - }) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) + EmitChannelOpenConfirmEvent(ctx, portID, channelID, channel) } // Closing Handshake @@ -527,16 +465,7 @@ func (k Keeper) ChanCloseInit( channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelCloseInit, - sdk.NewAttribute(types.AttributeKeyPortID, portID), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - }) + EmitChannelCloseInitEvent(ctx, portID, channelID, channel) return nil } @@ -601,16 +530,7 @@ func (k Keeper) ChanCloseConfirm( channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelCloseConfirm, - sdk.NewAttribute(types.AttributeKeyPortID, portID), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - }) + EmitChannelCloseConfirmEvent(ctx, portID, channelID, channel) return nil } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 8ad5cad5938..2e6800c25f5 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -33,24 +33,10 @@ func (k Keeper) CreateClient(goCtx context.Context, msg *clienttypes.MsgCreateCl return nil, err } - clientID, err := k.ClientKeeper.CreateClient(ctx, clientState, consensusState) - if err != nil { + if _, err = k.ClientKeeper.CreateClient(ctx, clientState, consensusState); err != nil { return nil, err } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - clienttypes.EventTypeCreateClient, - sdk.NewAttribute(clienttypes.AttributeKeyClientID, clientID), - sdk.NewAttribute(clienttypes.AttributeKeyClientType, clientState.ClientType()), - sdk.NewAttribute(clienttypes.AttributeKeyConsensusHeight, clientState.GetLatestHeight().String()), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, clienttypes.AttributeValueCategory), - ), - }) - return &clienttypes.MsgCreateClientResponse{}, nil } @@ -67,13 +53,6 @@ func (k Keeper) UpdateClient(goCtx context.Context, msg *clienttypes.MsgUpdateCl return nil, err } - ctx.EventManager().EmitEvent( - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, clienttypes.AttributeValueCategory), - ), - ) - return &clienttypes.MsgUpdateClientResponse{}, nil } @@ -95,13 +74,6 @@ func (k Keeper) UpgradeClient(goCtx context.Context, msg *clienttypes.MsgUpgrade return nil, err } - ctx.EventManager().EmitEvent( - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, clienttypes.AttributeValueCategory), - ), - ) - return &clienttypes.MsgUpgradeClientResponse{}, nil } @@ -118,14 +90,6 @@ func (k Keeper) SubmitMisbehaviour(goCtx context.Context, msg *clienttypes.MsgSu return nil, sdkerrors.Wrap(err, "failed to process misbehaviour for IBC client") } - ctx.EventManager().EmitEvent( - sdk.NewEvent( - clienttypes.EventTypeSubmitMisbehaviour, - sdk.NewAttribute(clienttypes.AttributeKeyClientID, msg.ClientId), - sdk.NewAttribute(clienttypes.AttributeKeyClientType, misbehaviour.ClientType()), - ), - ) - return &clienttypes.MsgSubmitMisbehaviourResponse{}, nil } @@ -133,25 +97,10 @@ func (k Keeper) SubmitMisbehaviour(goCtx context.Context, msg *clienttypes.MsgSu func (k Keeper) ConnectionOpenInit(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenInit) (*connectiontypes.MsgConnectionOpenInitResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - connectionID, err := k.ConnectionKeeper.ConnOpenInit(ctx, msg.ClientId, msg.Counterparty, msg.Version, msg.DelayPeriod) - if err != nil { + if _, err := k.ConnectionKeeper.ConnOpenInit(ctx, msg.ClientId, msg.Counterparty, msg.Version, msg.DelayPeriod); err != nil { return nil, sdkerrors.Wrap(err, "connection handshake open init failed") } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - connectiontypes.EventTypeConnectionOpenInit, - sdk.NewAttribute(connectiontypes.AttributeKeyConnectionID, connectionID), - sdk.NewAttribute(connectiontypes.AttributeKeyClientID, msg.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyClientID, msg.Counterparty.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyConnectionID, msg.Counterparty.ConnectionId), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, connectiontypes.AttributeValueCategory), - ), - }) - return &connectiontypes.MsgConnectionOpenInitResponse{}, nil } @@ -164,29 +113,14 @@ func (k Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.Ms return nil, err } - connectionID, err := k.ConnectionKeeper.ConnOpenTry( + if _, err := k.ConnectionKeeper.ConnOpenTry( ctx, msg.PreviousConnectionId, msg.Counterparty, msg.DelayPeriod, msg.ClientId, targetClient, connectiontypes.ProtoVersionsToExported(msg.CounterpartyVersions), msg.ProofInit, msg.ProofClient, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, - ) - if err != nil { + ); err != nil { return nil, sdkerrors.Wrap(err, "connection handshake open try failed") } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - connectiontypes.EventTypeConnectionOpenTry, - sdk.NewAttribute(connectiontypes.AttributeKeyConnectionID, connectionID), - sdk.NewAttribute(connectiontypes.AttributeKeyClientID, msg.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyClientID, msg.Counterparty.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyConnectionID, msg.Counterparty.ConnectionId), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, connectiontypes.AttributeValueCategory), - ), - }) - return &connectiontypes.MsgConnectionOpenTryResponse{}, nil } @@ -206,22 +140,6 @@ func (k Keeper) ConnectionOpenAck(goCtx context.Context, msg *connectiontypes.Ms return nil, sdkerrors.Wrap(err, "connection handshake open ack failed") } - connectionEnd, _ := k.ConnectionKeeper.GetConnection(ctx, msg.ConnectionId) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - connectiontypes.EventTypeConnectionOpenAck, - sdk.NewAttribute(connectiontypes.AttributeKeyConnectionID, msg.ConnectionId), - sdk.NewAttribute(connectiontypes.AttributeKeyClientID, connectionEnd.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyClientID, connectionEnd.Counterparty.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyConnectionID, connectionEnd.Counterparty.ConnectionId), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, connectiontypes.AttributeValueCategory), - ), - }) - return &connectiontypes.MsgConnectionOpenAckResponse{}, nil } @@ -235,28 +153,12 @@ func (k Keeper) ConnectionOpenConfirm(goCtx context.Context, msg *connectiontype return nil, sdkerrors.Wrap(err, "connection handshake open confirm failed") } - connectionEnd, _ := k.ConnectionKeeper.GetConnection(ctx, msg.ConnectionId) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - connectiontypes.EventTypeConnectionOpenConfirm, - sdk.NewAttribute(connectiontypes.AttributeKeyConnectionID, msg.ConnectionId), - sdk.NewAttribute(connectiontypes.AttributeKeyClientID, connectionEnd.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyClientID, connectionEnd.Counterparty.ClientId), - sdk.NewAttribute(connectiontypes.AttributeKeyCounterpartyConnectionID, connectionEnd.Counterparty.ConnectionId), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, connectiontypes.AttributeValueCategory), - ), - }) - return &connectiontypes.MsgConnectionOpenConfirmResponse{}, nil } // ChannelOpenInit defines a rpc handler method for MsgChannelOpenInit. // ChannelOpenInit will perform 04-channel checks, route to the application -// callback, and write an OpenInit channel into state upon successful exection. +// callback, and write an OpenInit channel into state upon successful execution. func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChannelOpenInit) (*channeltypes.MsgChannelOpenInitResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -294,7 +196,7 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan // ChannelOpenTry defines a rpc handler method for MsgChannelOpenTry. // ChannelOpenTry will perform 04-channel checks, route to the application -// callback, and write an OpenTry channel into state upon successful exection. +// callback, and write an OpenTry channel into state upon successful execution. func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChannelOpenTry) (*channeltypes.MsgChannelOpenTryResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -332,7 +234,7 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann // ChannelOpenAck defines a rpc handler method for MsgChannelOpenAck. // ChannelOpenAck will perform 04-channel checks, route to the application -// callback, and write an OpenAck channel into state upon successful exection. +// callback, and write an OpenAck channel into state upon successful execution. func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChannelOpenAck) (*channeltypes.MsgChannelOpenAckResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -368,7 +270,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann // ChannelOpenConfirm defines a rpc handler method for MsgChannelOpenConfirm. // ChannelOpenConfirm will perform 04-channel checks, route to the application -// callback, and write an OpenConfirm channel into state upon successful exection. +// callback, and write an OpenConfirm channel into state upon successful execution. func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgChannelOpenConfirm) (*channeltypes.MsgChannelOpenConfirmResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -424,13 +326,6 @@ func (k Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgCha return nil, sdkerrors.Wrap(err, "channel handshake close init failed") } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), - ), - }) - return &channeltypes.MsgChannelCloseInitResponse{}, nil } @@ -459,13 +354,6 @@ func (k Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Msg return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed") } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory), - ), - }) - return &channeltypes.MsgChannelCloseConfirmResponse{}, nil }