diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e00b39638d..be8a44f14d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,6 +78,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)" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1810c66592..bea8652214 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -40,6 +40,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)" diff --git a/CHANGELOG.md b/CHANGELOG.md index f8153a8774..8e047f5d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - [#1058](https://github.com/crypto-org-chain/cronos/pull/1058) Fix decode log for multi topics in websocket subscribe ([ethermint commit](https://github.com/crypto-org-chain/ethermint/commit/2136ad029860c819942ad1836dd3f42585002233)). - [#1062](https://github.com/crypto-org-chain/cronos/pull/1062) Update cometbft `v0.34.29` with several minor bug fixes and low-severity security-fixes. +- [#1102](https://github.com/crypto-org-chain/cronos/pull/1102) avoid duplicate cache events emitted from ibc and gravity hook. *Jun 9, 2023* diff --git a/go.mod b/go.mod index 5f15abcb42..95c84ed885 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/tendermint/tendermint v0.34.28 github.com/tendermint/tm-db v0.6.7 golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 - golang.org/x/sys v0.8.0 google.golang.org/genproto v0.0.0-20230323212658-478b75c54725 google.golang.org/grpc v1.54.0 google.golang.org/protobuf v1.30.0 @@ -208,6 +207,7 @@ require ( golang.org/x/net v0.10.0 // indirect golang.org/x/oauth2 v0.6.0 // indirect golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.8.0 // indirect golang.org/x/term v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/integration_tests/test_gravity.py b/integration_tests/test_gravity.py index 9b3c04c28e..a504eac900 100644 --- a/integration_tests/test_gravity.py +++ b/integration_tests/test_gravity.py @@ -1,6 +1,7 @@ import json import pytest +import requests import sha3 import toml from dateutil.parser import isoparse @@ -382,6 +383,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}" + @pytest.mark.skip(reason="gravity-bridge not supported in v1.0.x") def test_direct_token_mapping(gravity): diff --git a/integration_tests/test_ibc.py b/integration_tests/test_ibc.py index 0862aa8639..1affeb98af 100644 --- a/integration_tests/test_ibc.py +++ b/integration_tests/test_ibc.py @@ -34,6 +34,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 @@ -65,6 +80,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: diff --git a/x/cronos/keeper/gravity_hooks.go b/x/cronos/keeper/gravity_hooks.go index fc2771568c..2bbeb8dfd6 100644 --- a/x/cronos/keeper/gravity_hooks.go +++ b/x/cronos/keeper/gravity_hooks.go @@ -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) } diff --git a/x/cronos/keeper/keeper.go b/x/cronos/keeper/keeper.go index b601463b36..46a14ab026 100644 --- a/x/cronos/keeper/keeper.go +++ b/x/cronos/keeper/keeper.go @@ -197,7 +197,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",