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

Problem: no packet info for indexed field in ibc relayer event #1662

Merged
merged 3 commits into from
Oct 23, 2024
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 @@ -18,6 +18,7 @@
* (testground)[#1650](https://github.com/crypto-org-chain/cronos/pull/1650) Benchmark support batch mode.
* [#1658](https://github.com/crypto-org-chain/cronos/pull/1658) Optimize when block-list is empty.
* (testground)[#1659](https://github.com/crypto-org-chain/cronos/pull/1659) Support skip check-tx in benchmark.
* [#1662](https://github.com/crypto-org-chain/cronos/pull/1662) Emit more packet info for ibc relayer event.

*Oct 14, 2024*

Expand Down
22 changes: 14 additions & 8 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def coin_spent(spender, amt, denom):
def distribute_fee(receiver, fee):
return {
"receiver": receiver,
"fee": keccak(text=fee),
"fee": fee,
}


def fungible(dst, src, amt, denom):
return {
"receiver": dst,
"sender": src,
"denom": keccak(text=denom),
"denom": denom,
"amount": amt,
}

Expand All @@ -123,9 +123,11 @@ def burn(burner, amt, denom):

def recv_packet(seq, src, dst, amt, denom):
return {
"packetSequence": keccak(text=f"{seq}"),
"packetSequence": seq,
"packetSrcPort": keccak(text="transfer"),
"packetSrcChannel": keccak(text=channel),
"packetSrcPortInfo": "transfer",
"packetSrcChannelInfo": channel,
"packetDstPort": "transfer",
"packetDstChannel": channel,
"connectionId": "connection-0",
Expand All @@ -141,9 +143,11 @@ def recv_packet(seq, src, dst, amt, denom):

def acknowledge_packet(seq):
return {
"packetSequence": keccak(text=f"{seq}"),
"packetSequence": seq,
"packetSrcPort": keccak(text="transfer"),
"packetSrcChannel": keccak(text=channel),
"packetSrcPortInfo": "transfer",
"packetSrcChannelInfo": channel,
"packetDstPort": "transfer",
"packetDstChannel": channel,
"connectionId": "connection-0",
Expand All @@ -152,15 +156,17 @@ def acknowledge_packet(seq):

def denom_trace(denom):
return {
"denom": keccak(text=denom),
"denom": denom,
}


def write_ack(seq, src, dst, amt, denom):
return {
"packetSequence": keccak(text=f"{seq}"),
"packetSequence": seq,
"packetSrcPort": keccak(text="transfer"),
"packetSrcChannel": keccak(text=channel),
"packetSrcPortInfo": "transfer",
"packetSrcChannelInfo": channel,
"packetDstPort": "transfer",
"packetDstChannel": channel,
"connectionId": "connection-0",
Expand Down Expand Up @@ -209,7 +215,7 @@ def get_send_packet_seq(
events = parse_events_rpc(res["events"])
target = events.get("send_packet")
if target and target["packet_sequence"]:
return target["packet_sequence"]
return int(target["packet_sequence"])
return None


Expand All @@ -220,7 +226,7 @@ def filter_logs_since(w3, start, name, seq):
{
"fromBlock": start,
"address": [CONTRACT],
"topics": [topic, "0x" + keccak(text=f"{seq}").hex()],
"topics": [topic, "0x{:064x}".format(seq)],
}
)

Expand Down

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

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions x/cronos/events/bindings/src/Relayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,71 @@ interface IRelayerModule {
Cosmos.Coin[] amount;
}
event RecvPacket(
string indexed packetSequence,
uint256 indexed packetSequence,
string indexed packetSrcPort,
string indexed packetSrcChannel,
string packetSrcPortInfo,
string packetSrcChannelInfo,
string packetDstPort,
string packetDstChannel,
string connectionId,
PacketData packetDataHex
);
event WriteAcknowledgement(
string indexed packetSequence,
uint256 indexed packetSequence,
string indexed packetSrcPort,
string indexed packetSrcChannel,
string packetSrcPortInfo,
string packetSrcChannelInfo,
string packetDstPort,
string packetDstChannel,
string connectionId,
PacketData packetDataHex
);
event AcknowledgePacket(
string indexed packetSequence,
uint256 indexed packetSequence,
string indexed packetSrcPort,
string indexed packetSrcChannel,
string packetSrcPortInfo,
string packetSrcChannelInfo,
string packetDstPort,
string packetDstChannel,
string connectionId
);
event TimeoutPacket(
string indexed packetSequence,
uint256 indexed packetSequence,
string indexed packetSrcPort,
string indexed packetSrcChannel,
string packetSrcPortInfo,
string packetSrcChannelInfo,
string packetDstPort,
string packetDstChannel,
string connectionId
);
// IBC transfer
event Timeout(
address indexed refundReceiver,
string indexed refundDenom,
string refundDenom,
uint256 amount
);
event FungibleTokenPacket(
address indexed receiver,
address indexed sender,
string indexed denom,
string denom,
uint256 amount
);
event IbcTransfer(
address indexed sender,
address indexed receiver,
string indexed denom,
string denom,
uint256 amount
);
event ChannelClosed();
event DenominationTrace(string indexed denom);
event DenominationTrace(string denom);
// 29-fee
event DistributeFee(
address indexed receiver,
string indexed fee
string fee
);
// Bank
event Transfer(
Expand Down
5 changes: 4 additions & 1 deletion x/cronos/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@
func (desc *EventDescriptor) ConvertEvent(
event []abci.EventAttribute,
valueDecoders ValueDecoders,
replaceAttrs map[string]string,
) (*ethtypes.Log, error) {
attrs := make(map[string]string, len(event))
for _, attr := range event {
attrs[toUnderScore(attr.Key)] = attr.Value
}

for k, v := range replaceAttrs {
attrs[k] = attrs[v]
}

Check warning on line 73 in x/cronos/events/event.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/events/event.go#L71-L73

Added lines #L71 - L73 were not covered by tests
Comment on lines +71 to +73

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
filterQuery, err := makeFilter(valueDecoders, attrs, desc.indexed, true)
if err != nil {
return nil, err
Expand Down
42 changes: 24 additions & 18 deletions x/cronos/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@
RelayerEvents map[string]*EventDescriptor
IcaEvents map[string]*EventDescriptor
RelayerValueDecoders = ValueDecoders{
channeltypes.AttributeKeyDataHex: ConvertPacketData,
transfertypes.AttributeKeyAmount: ConvertAmount,
banktypes.AttributeKeyRecipient: ConvertAccAddressFromBech32,
banktypes.AttributeKeySpender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyReceiver: ConvertAccAddressFromBech32,
banktypes.AttributeKeySender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyMinter: ConvertAccAddressFromBech32,
banktypes.AttributeKeyBurner: ConvertAccAddressFromBech32,
channeltypes.AttributeKeySequence: ReturnStringAsIs,
channeltypes.AttributeKeySrcPort: ReturnStringAsIs,
channeltypes.AttributeKeySrcChannel: ReturnStringAsIs,
channeltypes.AttributeKeyDstPort: ReturnStringAsIs,
channeltypes.AttributeKeyDstChannel: ReturnStringAsIs,
channeltypes.AttributeKeyConnectionID: ReturnStringAsIs,
ibcfeetypes.AttributeKeyFee: ReturnStringAsIs,
transfertypes.AttributeKeyDenom: ReturnStringAsIs,
channeltypes.AttributeKeyDataHex: ConvertPacketData,
transfertypes.AttributeKeyAmount: ConvertAmount,
banktypes.AttributeKeyRecipient: ConvertAccAddressFromBech32,
banktypes.AttributeKeySpender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyReceiver: ConvertAccAddressFromBech32,
banktypes.AttributeKeySender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyMinter: ConvertAccAddressFromBech32,
banktypes.AttributeKeyBurner: ConvertAccAddressFromBech32,
channeltypes.AttributeKeySequence: ConvertUint64,
channeltypes.AttributeKeySrcPort: ReturnStringAsIs,
cronoseventstypes.AttributeKeySrcPortInfo: ReturnStringAsIs,
channeltypes.AttributeKeySrcChannel: ReturnStringAsIs,
cronoseventstypes.AttributeKeySrcChannelInfo: ReturnStringAsIs,
channeltypes.AttributeKeyDstPort: ReturnStringAsIs,
channeltypes.AttributeKeyDstChannel: ReturnStringAsIs,
channeltypes.AttributeKeyConnectionID: ReturnStringAsIs,
ibcfeetypes.AttributeKeyFee: ReturnStringAsIs,
transfertypes.AttributeKeyDenom: ReturnStringAsIs,
}
IcaValueDecoders = ValueDecoders{
cronoseventstypes.AttributeKeySeq: ConvertUint64,
Expand All @@ -59,13 +61,17 @@
if !ok {
return nil, nil
}
return desc.ConvertEvent(event.Attributes, RelayerValueDecoders)
replaceAttrs := map[string]string{
cronoseventstypes.AttributeKeySrcPortInfo: channeltypes.AttributeKeySrcPort,
cronoseventstypes.AttributeKeySrcChannelInfo: channeltypes.AttributeKeySrcChannel,
}
return desc.ConvertEvent(event.Attributes, RelayerValueDecoders, replaceAttrs)

Check warning on line 68 in x/cronos/events/events.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/events/events.go#L64-L68

Added lines #L64 - L68 were not covered by tests
Comment on lines +64 to +68
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add test coverage for the new attribute replacement logic.

The new attribute replacement logic is not covered by tests. Please add test cases to verify the correct mapping of AttributeKeySrcPortInfo and AttributeKeySrcChannelInfo.

Would you like me to help generate test cases? Here's a suggested test structure:

func TestRelayerConvertEvent_AttributeReplacement(t *testing.T) {
    testCases := []struct {
        name     string
        event    sdk.Event
        expected *ethtypes.Log
    }{
        {
            name: "should replace port info attributes",
            event: sdk.Event{
                Type: "ibc_transfer",
                Attributes: []sdk.Attribute{
                    {Key: cronoseventstypes.AttributeKeySrcPortInfo, Value: "transfer"},
                    {Key: cronoseventstypes.AttributeKeySrcChannelInfo, Value: "channel-0"},
                },
            },
            // Add expected values
        },
        // Add more test cases
    }
    // Implement test logic
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 64-68: x/cronos/events/events.go#L64-L68
Added lines #L64 - L68 were not covered by tests

}

func IcaConvertEvent(event sdk.Event) (*ethtypes.Log, error) {
desc, ok := IcaEvents[event.Type]
if !ok {
return nil, nil
}
return desc.ConvertEvent(event.Attributes, IcaValueDecoders)
return desc.ConvertEvent(event.Attributes, IcaValueDecoders, map[string]string{})

Check warning on line 76 in x/cronos/events/events.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/events/events.go#L76

Added line #L76 was not covered by tests
}
6 changes: 4 additions & 2 deletions x/cronos/events/types/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

const (
EventTypeSubmitMsgsResult = "submit_msgs_result"
AttributeKeySeq = "seq"
EventTypeSubmitMsgsResult = "submit_msgs_result"
AttributeKeySeq = "seq"
AttributeKeySrcPortInfo = "packet_src_port_info"
AttributeKeySrcChannelInfo = "packet_src_channel_info"
)
Loading