Skip to content

Commit

Permalink
Problem: logs in callback contract are lost
Browse files Browse the repository at this point in the history
Closes: #1231

Solution:
- re-emit those logs
  • Loading branch information
yihuang committed Oct 31, 2023
1 parent dbd86c4 commit bad0847
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
2 changes: 2 additions & 0 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
14 changes: 12 additions & 2 deletions x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions x/cronos/keeper/precompiles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bad0847

Please sign in to comment.