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

x/ibc: implement ADR 032 typed events #7762

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5b539e7
Add EmitTypedEvent in events
akhilkumarpilli Oct 3, 2020
ed85dd7
Add parseTypedEvent method
akhilkumarpilli Oct 5, 2020
7d9919b
Use jsonpb
anilcse Oct 6, 2020
deb1e3c
Modify unmarshal proto in events
akhilkumarpilli Oct 6, 2020
5e11d14
Merge branch 'events-adr' of github.com:akhilkumarpilli/cosmos-sdk in…
akhilkumarpilli Oct 6, 2020
171f362
Add a test for typed events
anilcse Oct 6, 2020
f158344
Fix reflect issue in parseTypedEvent
akhilkumarpilli Oct 7, 2020
faeab07
Modify event tests and add comments
akhilkumarpilli Oct 15, 2020
fe5f8ca
Merge remote-tracking branch 'upstream/master' into events-adr
akhilkumarpilli Oct 15, 2020
50f3f1f
Add EmitTypedEvents and refactor other methods
akhilkumarpilli Oct 15, 2020
45f32f8
Merge remote-tracking branch 'upstream/master' into events-adr
akhilkumarpilli Oct 15, 2020
fa6a618
Fix golangci-lint issues
akhilkumarpilli Oct 15, 2020
625501d
Merge remote-tracking branch 'upstream/master' into events-adr
akhilkumarpilli Oct 15, 2020
526d942
Update ProtoMarshalJSON params
akhilkumarpilli Oct 16, 2020
6719759
Merge remote-tracking branch 'upstream/master' into events-adr
akhilkumarpilli Oct 16, 2020
d8b6883
Merge branch 'master' into events-adr
jackzampolin Oct 23, 2020
5f472bf
Address PR comments
akhilkumarpilli Oct 27, 2020
a79c878
Merge remote-tracking branch 'upstream/master' into events-adr
akhilkumarpilli Oct 27, 2020
ebb07e3
Add typed events in ibc transfer
akhilkumarpilli Oct 27, 2020
b16fcd0
Merge branch 'master' into events-adr
jackzampolin Oct 27, 2020
700f504
x/ibc: migrate EmitEvent to EmitTypedEvents
akhilkumarpilli Oct 28, 2020
62be11a
Merge branch 'events-adr' into ibc-typed-events
akhilkumarpilli Oct 28, 2020
7f98f3f
Merge remote-tracking branch 'upstream/master' into ibc-typed-events
akhilkumarpilli Oct 29, 2020
3324f28
Merge branch 'master' into ibc-typed-events
jackzampolin Oct 29, 2020
2a7b622
Merge branch 'master' into ibc-typed-events
akhilkumarpilli Oct 30, 2020
8d7747e
Add TestPackHeight
akhilkumarpilli Oct 30, 2020
123f0c2
Merge branch 'master' into ibc-typed-events
jackzampolin Oct 30, 2020
d998bd9
Use *Height instead of Height
akhilkumarpilli Nov 3, 2020
5efe687
Merge branch 'master' into akhil/7563-ibc-typed-events
akhilkumarpilli Nov 3, 2020
d8c41cf
Merge branch 'master' into akhil/7563-ibc-typed-events
akhilkumarpilli Nov 3, 2020
f0212b1
Merge branch 'master' into akhil/7563-ibc-typed-events
jackzampolin Nov 6, 2020
a4d9034
Fix tendermint abci query txs issue
akhilkumarpilli Nov 11, 2020
5a4d5dc
Merge branch 'master' into akhil/7563-ibc-typed-events
akhilkumarpilli Nov 11, 2020
f609c7e
Add ResultEventToABCIEvent
akhilkumarpilli Nov 11, 2020
6d92028
Fix golangci lint issues
akhilkumarpilli Nov 11, 2020
344614b
Update attribute value encoding
akhilkumarpilli Nov 18, 2020
dfe947b
Merge branch 'master' into akhil/7563-ibc-typed-events
akhilkumarpilli Nov 19, 2020
3e9169c
Revert EventTypeMessage events
akhilkumarpilli Nov 19, 2020
f9eb795
Revert Height changes
akhilkumarpilli Nov 30, 2020
f3fa0c7
Address PR comments
akhilkumarpilli Nov 30, 2020
d0192c8
Merge branch 'master' into akhil/7563-ibc-typed-events
akhilkumarpilli Nov 30, 2020
c00f98d
Fix error
akhilkumarpilli Nov 30, 2020
7e85d4e
Address few PR comments
akhilkumarpilli Dec 1, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ message EventTransfer {
string receiver = 2;
}

// EventAcknowledgementSuccess is a typed event emitted on packet acknowledgement success
message EventAcknowledgementSuccess {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these can go in channel. We have a acknowledgement success/error type defined in channel so other applications may want to use this event. It's usage would make it easier on relayers as well

bytes success = 1;
}

// EventAcknowledgementError is a typed event emitted on packet acknowledgement error
message EventAcknowledgementError {
string error = 1;
}

// EventDenominationTrace is a typed event for denomination trace
message EventDenominationTrace {
bytes trace_hash = 1 [
(gogoproto.casttype) = "github.com/tendermint/tendermint/libs/bytes.HexBytes",
(gogoproto.moretags) = "yaml:\"trace_hash\""
];
string trace_hash = 1 [(gogoproto.moretags) = "yaml:\"trace_hash\""];

string denom = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ message EventChannelOpenInit {

string counterparty_port_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_port_id\""];

string counterparty_channel_id = 4 [(gogoproto.moretags) = "yaml:\"counterparty_channel_id\""];

string connection_id = 5 [(gogoproto.moretags) = "yaml:\"connection_id\""];
}

Expand Down Expand Up @@ -46,8 +44,8 @@ message EventChannelOpenAck {
string connection_id = 5 [(gogoproto.moretags) = "yaml:\"connection_id\""];
}

// EventChannelCloseInit is a typed event emitted on channel close init
message EventChannelCloseInit {
// EventChannelOpenConfirm is a typed event emitted on channel open confirm
message EventChannelOpenConfirm {
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];

string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
Expand All @@ -59,8 +57,8 @@ message EventChannelCloseInit {
string connection_id = 5 [(gogoproto.moretags) = "yaml:\"connection_id\""];
}

// EventChannelOpenConfirm is a typed event emitted on channel open confirm
message EventChannelOpenConfirm {
// EventChannelCloseInit is a typed event emitted on channel close init
message EventChannelCloseInit {
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];

string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
Expand Down Expand Up @@ -127,8 +125,6 @@ message EventChannelRecvPacket {
string dst_channel = 8 [(gogoproto.moretags) = "yaml:\"dst_channel\""];

Order channel_ordering = 9 [(gogoproto.moretags) = "yaml:\"channel_ordering\""];

bool success = 10;
}

// EventChannelWriteAck is a typed event emitted on write acknowledgement
Expand Down Expand Up @@ -198,13 +194,3 @@ message EventChannelTimeoutPacket {

Order channel_ordering = 9 [(gogoproto.moretags) = "yaml:\"channel_ordering\""];
}

// EventAcknowledgementSuccess is a typed event emitted on packet acknowledgement success
message EventAcknowledgementSuccess {
bytes success = 1;
}

// EventAcknowledgementError is a typed event emitted on packet acknowledgement error
message EventAcknowledgementError {
string error = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ message EventConnectionOpenInit {

string client_id = 2 [(gogoproto.moretags) = "yaml:\"client_id\""];

string counterparty_connection_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_connection_id\""];

string counterparty_client_id = 4 [(gogoproto.moretags) = "yaml:\"counterparty_client_id\""];
}

Expand Down
2 changes: 1 addition & 1 deletion types/query/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions x/ibc/applications/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,3 @@ func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Cap
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}

// GetChannel returns a channel with a particular identifier binded to a specific port
func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool) {
return k.channelKeeper.GetChannel(ctx, portID, channelID)
}
7 changes: 0 additions & 7 deletions x/ibc/applications/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,5 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
return nil, err
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
),
)

return &types.MsgTransferResponse{}, nil
}
2 changes: 1 addition & 1 deletion x/ibc/applications/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
voucherDenom := denomTrace.IBCDenom()
if err := ctx.EventManager().EmitTypedEvent(
&types.EventDenominationTrace{
TraceHash: traceHash,
TraceHash: traceHash.String(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should emit the amount and receiver here as well

Denom: voucherDenom,
},
); err != nil {
Expand Down
63 changes: 2 additions & 61 deletions x/ibc/applications/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/simulation"
"github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
Expand Down Expand Up @@ -335,27 +334,6 @@ func (am AppModule) OnRecvPacket(
acknowledgement = channeltypes.NewErrorAcknowledgement(err.Error())
}

channel, _ := am.keeper.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())

err = ctx.EventManager().EmitTypedEvent(
&channeltypes.EventChannelRecvPacket{
Data: packet.GetData(),
TimeoutHeight: packet.GetTimeoutHeight().(clienttypes.Height),
TimeoutTimestamp: packet.GetTimeoutTimestamp(),
Sequence: packet.GetSequence(),
SrcPort: packet.GetSourcePort(),
SrcChannel: packet.GetSourceChannel(),
DstPort: packet.GetDestPort(),
DstChannel: packet.GetDestChannel(),
ChannelOrdering: channel.Ordering,
Success: err != nil,
},
)

if err != nil {
acknowledgement = channeltypes.NewErrorAcknowledgement(err.Error())
}

// NOTE: acknowledgement will be written synchronously during IBC handler execution.
return &sdk.Result{
Events: ctx.EventManager().Events().ToABCIEvents(),
Expand All @@ -381,37 +359,18 @@ func (am AppModule) OnAcknowledgementPacket(
return nil, err
}

channel, _ := am.keeper.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())

if err := ctx.EventManager().EmitTypedEvent(
&channeltypes.EventChannelAckPacket{
Data: packet.GetData(),
TimeoutHeight: packet.GetTimeoutHeight().(clienttypes.Height),
TimeoutTimestamp: packet.GetTimeoutTimestamp(),
Sequence: packet.GetSequence(),
SrcPort: packet.GetSourcePort(),
SrcChannel: packet.GetSourceChannel(),
DstPort: packet.GetDestPort(),
DstChannel: packet.GetDestChannel(),
ChannelOrdering: channel.Ordering,
Acknowledgement: acknowledgement,
},
); err != nil {
return nil, err
}

switch resp := ack.Response.(type) {
case *channeltypes.Acknowledgement_Result:
if err := ctx.EventManager().EmitTypedEvent(
&channeltypes.EventAcknowledgementSuccess{
&types.EventAcknowledgementSuccess{
Success: resp.Result,
},
); err != nil {
return nil, err
}
case *channeltypes.Acknowledgement_Error:
if err := ctx.EventManager().EmitTypedEvent(
&channeltypes.EventAcknowledgementError{
&types.EventAcknowledgementError{
Error: resp.Error,
},
); err != nil {
Expand All @@ -438,24 +397,6 @@ func (am AppModule) OnTimeoutPacket(
return nil, err
}

channel, _ := am.keeper.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())

if err := ctx.EventManager().EmitTypedEvent(
&channeltypes.EventChannelTimeoutPacket{
Data: packet.GetData(),
TimeoutHeight: packet.GetTimeoutHeight().(clienttypes.Height),
TimeoutTimestamp: packet.GetTimeoutTimestamp(),
Sequence: packet.GetSequence(),
SrcPort: packet.GetSourcePort(),
SrcChannel: packet.GetSourceChannel(),
DstPort: packet.GetDestPort(),
DstChannel: packet.GetDestChannel(),
ChannelOrdering: channel.Ordering,
},
); err != nil {
return nil, err
}

return &sdk.Result{
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
Expand Down
44 changes: 13 additions & 31 deletions x/ibc/applications/transfer/spec/05_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,21 @@ order: 5

## MsgTransfer

| Type | Attribute Key | Attribute Value |
|--------------|---------------|-----------------|
| ibc_transfer | sender | {sender} |
| ibc_transfer | receiver | {receiver} |
| message | action | transfer |
| message | module | transfer |
| Type | Attribute Key | Attribute Value |
|--------------------------------------------|---------------|-----------------|
| ibc-applications-transfer-v1-EventTransfer | sender | {sender} |
| ibc-applications-transfer-v1-EventTransfer | receiver | {receiver} |
| message | action | transfer |

## OnRecvPacket callback

| Type | Attribute Key | Attribute Value |
|-----------------------|---------------|-----------------|
| fungible_token_packet | module | transfer |
| fungible_token_packet | receiver | {receiver} |
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| fungible_token_packet | success | {ackSuccess} |
| denomination_trace | trace_hash | {hex_hash} |
| Type | Attribute Key | Attribute Value |
|-----------------------------------------------------|---------------|-----------------|
| ibc-applications-transfer-v1-EventDenominationTrace | trace_hash | {hex_hash} |

## OnAcknowledgePacket callback
## OnAcknowledgePacket callback (emitted any one of the below events)

| Type | Attribute Key | Attribute Value |
|-----------------------|-----------------|-------------------|
| fungible_token_packet | module | transfer |
| fungible_token_packet | receiver | {receiver} |
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| fungible_token_packet | success | error | {ack.Response} |

## OnTimeoutPacket callback

| Type | Attribute Key | Attribute Value |
|-----------------------|-----------------|-----------------|
| fungible_token_packet | module | transfer |
| fungible_token_packet | refund_receiver | {receiver} |
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| Type | Attribute Key | Attribute Value |
|----------------------------------------------------------|---------------|-------------------|
| ibc-applications-transfer-v1-EventAcknowledgementSuccess | success | {ack.Response} |
| ibc-applications-transfer-v1-EventAcknowledgementError | error | {ack.Response} |
Loading