From bad0847025ffd6ba395cbda4a7aba4d79432eb1e Mon Sep 17 00:00:00 2001 From: HuangYi Date: Tue, 31 Oct 2023 15:13:16 +0800 Subject: [PATCH] Problem: logs in callback contract are lost Closes: #1231 Solution: - re-emit those logs --- CHANGELOG.md | 1 + integration_tests/test_ica_precompile.py | 2 ++ x/cronos/keeper/keeper.go | 14 ++++++++++++-- x/cronos/keeper/precompiles/utils.go | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 664257e030..d7fe420fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [#1217](https://github.com/crypto-org-chain/cronos/pull/1217) Use the default chain-id behavour in sdk. - [#1216](https://github.com/crypto-org-chain/cronos/pull/1216) Update ethermint to fix of avoid redundant parse chainID from gensis when start server. - [#1230](https://github.com/crypto-org-chain/cronos/pull/1230) Fix mem store in versiondb multistore. +- [#]() Re-emit logs in callback contract. *October 17, 2023* diff --git a/integration_tests/test_ica_precompile.py b/integration_tests/test_ica_precompile.py index 52c39e14c7..09311a1823 100644 --- a/integration_tests/test_ica_precompile.py +++ b/integration_tests/test_ica_precompile.py @@ -302,3 +302,5 @@ def submit_msgs_ro(func, str): assert expected_seq == last_seq assert status == Status.FAIL assert cli_host.balance(ica_address, denom=denom) == balance + + print(tcontract.events.OnPacketResult().get_logs()) diff --git a/x/cronos/keeper/keeper.go b/x/cronos/keeper/keeper.go index 8a013756a4..9bfb1acedd 100644 --- a/x/cronos/keeper/keeper.go +++ b/x/cronos/keeper/keeper.go @@ -23,6 +23,7 @@ import ( cronosprecompiles "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/precompiles" "github.com/crypto-org-chain/cronos/v2/x/cronos/types" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" // this line is used by starport scaffolding # ibc/keeper/import ) @@ -298,8 +299,17 @@ func (k Keeper) onPacketResult( return err } gasLimit := k.GetParams(ctx).MaxCallbackGas - _, _, err = k.CallEVM(ctx, &contractAddr, data, big.NewInt(0), gasLimit) - return err + _, rsp, err := k.CallEVM(ctx, &contractAddr, data, big.NewInt(0), gasLimit) + if err != nil { + return err + } + + if stateDB, ok := ctx.Value("statedb").(vm.StateDB); ok { + for _, l := range rsp.Logs { + stateDB.AddLog(l.ToEthereum()) + } + } + return nil } func (k Keeper) IBCOnAcknowledgementPacketCallback( diff --git a/x/cronos/keeper/precompiles/utils.go b/x/cronos/keeper/precompiles/utils.go index 34c70ceb0d..4b5a477116 100644 --- a/x/cronos/keeper/precompiles/utils.go +++ b/x/cronos/keeper/precompiles/utils.go @@ -45,6 +45,7 @@ func exec[Req any, PReq interface { var res Resp if err := stateDB.ExecuteNativeAction(contract, converter, func(ctx sdk.Context) error { var err error + ctx = ctx.WithValue("statedb", stateDB) res, err = action(ctx, msg) return err }); err != nil {