Add same attributes for all connection/ channel/ packet IBC events (#6482)

* Emmit events with same attributes in connection handlers

* Emmit events with same attributes in channel handlers

* Add paket_data attribute to EventTypeAcknowledgePacket

* Revert proto changes

* Query channel and connection to emit events with same  attributes

* Simplify code

* Update x/ibc/04-channel/keeper/packet.go

* Update x/ibc/04-channel/handler.go

* Apply suggestions from code review

Co-authored-by: Aditya <adityasripal@gmail.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
dauTT 2020-07-03 17:48:48 +02:00 committed by GitHub
parent a76ba6f02c
commit 4f3efaded4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 3 deletions

View File

@ -20,6 +20,7 @@ func HandleMsgConnectionOpenInit(ctx sdk.Context, k keeper.Keeper, msg *types.Ms
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.ConnectionID),
sdk.NewAttribute(types.AttributeKeyClientID, msg.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, msg.Counterparty.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyConnetionID, msg.Counterparty.ConnectionID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
@ -48,6 +49,7 @@ func HandleMsgConnectionOpenTry(ctx sdk.Context, k keeper.Keeper, msg *types.Msg
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.ConnectionID),
sdk.NewAttribute(types.AttributeKeyClientID, msg.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, msg.Counterparty.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyConnetionID, msg.Counterparty.ConnectionID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
@ -69,10 +71,15 @@ func HandleMsgConnectionOpenAck(ctx sdk.Context, k keeper.Keeper, msg *types.Msg
return nil, err
}
connectionEnd, _ := k.GetConnection(ctx, msg.ConnectionID)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeConnectionOpenAck,
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.ConnectionID),
sdk.NewAttribute(types.AttributeKeyClientID, connectionEnd.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, connectionEnd.Counterparty.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyConnetionID, connectionEnd.Counterparty.ConnectionID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
@ -93,10 +100,15 @@ func HandleMsgConnectionOpenConfirm(ctx sdk.Context, k keeper.Keeper, msg *types
return nil, err
}
connectionEnd, _ := k.GetConnection(ctx, msg.ConnectionID)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeConnectionOpenConfirm,
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.ConnectionID),
sdk.NewAttribute(types.AttributeKeyClientID, connectionEnd.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, connectionEnd.Counterparty.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyConnetionID, connectionEnd.Counterparty.ConnectionID),
),
sdk.NewEvent(
sdk.EventTypeMessage,

View File

@ -8,9 +8,10 @@ import (
// IBC connection events
const (
AttributeKeyConnectionID = "connection_id"
AttributeKeyClientID = "client_id"
AttributeKeyCounterpartyClientID = "counterparty_client_id"
AttributeKeyConnectionID = "connection_id"
AttributeKeyClientID = "client_id"
AttributeKeyCounterpartyClientID = "counterparty_client_id"
AttributeKeyCounterpartyConnetionID = "counterparty_connection_id"
)
// IBC connection events vars

View File

@ -1,6 +1,8 @@
package channel
import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/keeper"
@ -75,11 +77,16 @@ func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capab
return nil, err
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenAck,
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
sdk.NewAttribute(types.AttributeKeyConnectionID, strings.Join(channel.ConnectionHops, ", ")),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
@ -99,11 +106,16 @@ func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *c
return nil, err
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenConfirm,
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
sdk.NewAttribute(types.AttributeKeyConnectionID, strings.Join(channel.ConnectionHops, ", ")),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
@ -123,11 +135,16 @@ func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *cap
return nil, err
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelCloseInit,
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
sdk.NewAttribute(types.AttributeKeyConnectionID, strings.Join(channel.ConnectionHops, ", ")),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelID),
),
sdk.NewEvent(
sdk.EventTypeMessage,
@ -147,11 +164,16 @@ func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *
return nil, err
}
channel, _ := k.GetChannel(ctx, msg.PortID, msg.ChannelID)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelCloseConfirm,
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
sdk.NewAttribute(types.AttributeKeyConnectionID, strings.Join(channel.ConnectionHops, ", ")),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelID),
),
sdk.NewEvent(
sdk.EventTypeMessage,