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: duplicate cache events are emitted #1102

Merged
merged 8 commits into from
Jul 17, 2023
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
make test

# run versiondb tests
nix registry add nixpkgs github:NixOS/nixpkgs/23.05
nix profile install nixpkgs#rocksdb
export PKG_CONFIG_PATH=$HOME/.nix-profile/lib/pkgconfig
export CGO_CFLAGS="$(pkg-config --cflags rocksdb)" CGO_LDFLAGS="$(pkg-config --libs rocksdb)"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
*.sum
- name: run golangci-lint
run: |
nix registry add nixpkgs github:NixOS/nixpkgs/23.05
nix profile install nixpkgs#rocksdb nixpkgs#golangci-lint
export PKG_CONFIG_PATH=$HOME/.nix-profile/lib/pkgconfig
export CGO_CFLAGS="$(pkg-config --cflags rocksdb)" CGO_LDFLAGS="$(pkg-config --libs rocksdb)"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [#1073](https://github.com/crypto-org-chain/cronos/pull/1073) memiavl automatically truncate corrupted wal tail.
- [#1087](https://github.com/crypto-org-chain/cronos/pull/1087) memiavl fix LastCommitID when memiavl db not loaded.
- [#1088](https://github.com/crypto-org-chain/cronos/pull/1088) memiavl fix empty value in write-ahead-log replaying.
- [#1102](https://github.com/crypto-org-chain/cronos/pull/1102) avoid duplicate cache events emitted from ibc and gravity hook.

### Features

Expand Down
13 changes: 13 additions & 0 deletions integration_tests/test_gravity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json

import pytest
import requests
from eth_account.account import Account
from eth_utils import abi
from hexbytes import HexBytes
from pystarport import ports
from web3.exceptions import BadFunctionCallOutput

from .gravity_utils import prepare_gravity, setup_cosmos_erc20_contract
Expand Down Expand Up @@ -295,6 +297,17 @@ def check():

wait_for_fn("check balance on cronos", check)

# check duplicate end_block_events
height = cli.block_height()
port = ports.rpc_port(gravity.cronos.base_port(0))
url = f"http://127.0.0.1:{port}/block_results?height={height}"
res = requests.get(url).json().get("result")
if res:
events = res["end_block_events"]
target = "ethereum_send_to_cosmos_handled"
count = sum(1 for evt in events if evt["type"] == target)
assert count <= 2, f"duplicate {target}"
yihuang marked this conversation as resolved.
Show resolved Hide resolved


def test_direct_token_mapping(gravity):
"""
Expand Down
23 changes: 23 additions & 0 deletions integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ def get_balances(chain, addr):
return chain.cosmos_cli().balances(addr)


def find_duplicate(attributes):
res = set()
key = attributes[0]["key"]
for attribute in attributes:
if attribute["key"] == key:
value0 = attribute["value"]
elif attribute["key"] == "amount":
amount = attribute["value"]
value_pair = f"{value0}:{amount}"
if value_pair in res:
return value_pair
res.add(value_pair)
return None


def test_ibc_transfer_with_hermes(ibc):
"""
test ibc transfer tokens with hermes cli
Expand Down Expand Up @@ -68,6 +83,14 @@ def check_balance_change():
# rather than the normal gas price
assert fee == gas * 1000000

# check duplicate OnRecvPacket events
criteria = "message.action=/ibc.core.channel.v1.MsgRecvPacket"
tx = cli.tx_search(criteria)["txs"][0]
events = tx["logs"][1]["events"]
for event in events:
dup = find_duplicate(event["attributes"])
assert not dup, f"duplicate {dup} in {event['type']}"


def test_ibc_incentivized_transfer(ibc):
if not ibc.incentivized:
Expand Down
1 change: 0 additions & 1 deletion x/cronos/keeper/gravity_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (k Keeper) AfterSendToCosmosEvent(ctx sdk.Context, event gravitytypes.SendT
err := k.doAfterSendToCosmosEvent(cacheCtx, event)
if err == nil {
commit()
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
} else {
k.Logger(ctx).Error("AfterSendToCosmosEvent hook failed", "error", err)
}
Expand Down
1 change: 0 additions & 1 deletion x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func (k Keeper) OnRecvVouchers(
err := k.ConvertVouchersToEvmCoins(cacheCtx, receiver, tokens)
if err == nil {
commit()
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
} else {
k.Logger(ctx).Error(
fmt.Sprintf("Failed to convert vouchers to evm tokens for receiver %s, coins %s. Receive error %s",
Expand Down
Loading