From 758a5ed55422aa8d983d4fa3599893e357942f17 Mon Sep 17 00:00:00 2001
From: mmsqe <mavis@crypto.com>
Date: Tue, 24 Oct 2023 09:45:22 +0800
Subject: [PATCH] Problem: ibc keeper interface is not used in relayer
 precompile

---
 integration_tests/configs/ibc_rly.jsonnet |  2 +-
 integration_tests/ibc_utils.py            | 17 +++-------------
 x/cronos/keeper/precompiles/relayer.go    |  6 +++---
 x/cronos/types/interfaces.go              | 24 +++++++++++++++++++++++
 4 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/integration_tests/configs/ibc_rly.jsonnet b/integration_tests/configs/ibc_rly.jsonnet
index 18db224674..50dfd73524 100644
--- a/integration_tests/configs/ibc_rly.jsonnet
+++ b/integration_tests/configs/ibc_rly.jsonnet
@@ -3,7 +3,7 @@ local ibc = import 'ibc.jsonnet';
 ibc {
   relayer+: {
     chains: [super.chains[0] {
-      'precompiled_contract_address': '0x0000000000000000000000000000000000000065',
+      precompiled_contract_address: '0x0000000000000000000000000000000000000065',
     }] + super.chains[1:],
   },
 }
diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py
index a00b3c2986..5c67f734df 100644
--- a/integration_tests/ibc_utils.py
+++ b/integration_tests/ibc_utils.py
@@ -1,6 +1,5 @@
 import hashlib
 import json
-import os
 import subprocess
 from contextlib import contextmanager
 from pathlib import Path
@@ -83,12 +82,12 @@ def call_hermes_cmd(
         )
 
 
-def call_rly_cmd(path, connection_only, version):
+def call_rly_cmd(path, connection_only, version, hostchain="chainmain-1"):
     cmd = [
         "rly",
         "pth",
         "new",
-        "chainmain-1",
+        hostchain,
         "cronos_777-1",
         "chainmain-cronos",
         "--home",
@@ -179,20 +178,10 @@ def prepare_network(
 
         port = None
         if is_relay:
+            cronos.supervisorctl("start", "relayer-demo")
             if is_hermes:
-                cronos.supervisorctl("start", "relayer-demo")
                 port = hermes.port
             else:
-                subprocess.Popen(
-                    [
-                        "rly",
-                        "start",
-                        "chainmain-cronos",
-                        "--home",
-                        str(path),
-                    ],
-                    preexec_fn=os.setsid,
-                )
                 port = 5183
         yield IBCNetwork(cronos, chainmain, hermes, incentivized)
         if port:
diff --git a/x/cronos/keeper/precompiles/relayer.go b/x/cronos/keeper/precompiles/relayer.go
index 8154e271ae..f03fc4f314 100644
--- a/x/cronos/keeper/precompiles/relayer.go
+++ b/x/cronos/keeper/precompiles/relayer.go
@@ -10,8 +10,8 @@ import (
 	"github.com/ethereum/go-ethereum/common"
 	"github.com/ethereum/go-ethereum/core/vm"
 
-	ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
 	cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
+	"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
 )
 
 var (
@@ -42,11 +42,11 @@ type RelayerContract struct {
 	BaseContract
 
 	cdc         codec.Codec
-	ibcKeeper   *ibckeeper.Keeper
+	ibcKeeper   types.IbcKeeper
 	kvGasConfig storetypes.GasConfig
 }
 
-func NewRelayerContract(ibcKeeper *ibckeeper.Keeper, cdc codec.Codec, kvGasConfig storetypes.GasConfig) vm.PrecompiledContract {
+func NewRelayerContract(ibcKeeper types.IbcKeeper, cdc codec.Codec, kvGasConfig storetypes.GasConfig) vm.PrecompiledContract {
 	return &RelayerContract{
 		BaseContract: NewBaseContract(relayerContractAddress),
 		ibcKeeper:    ibcKeeper,
diff --git a/x/cronos/types/interfaces.go b/x/cronos/types/interfaces.go
index 37beaf900d..89ce4b312f 100644
--- a/x/cronos/types/interfaces.go
+++ b/x/cronos/types/interfaces.go
@@ -20,6 +20,10 @@ import (
 	"github.com/ethereum/go-ethereum/params"
 	evmtypes "github.com/evmos/ethermint/x/evm/types"
 	gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types"
+
+	clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
+	connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
+	channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
 )
 
 // BankKeeper defines the expected interface needed to retrieve account balances.
@@ -90,3 +94,23 @@ type Icaauthkeeper interface {
 type CronosKeeper interface {
 	CallEVM(ctx sdk.Context, to *common.Address, data []byte, value *big.Int, gasLimit uint64) (*ethtypes.Message, *evmtypes.MsgEthereumTxResponse, error)
 }
+
+// IbcKeeper defines the interface for ibc keeper
+type IbcKeeper interface {
+	CreateClient(goCtx context.Context, msg *clienttypes.MsgCreateClient) (*clienttypes.MsgCreateClientResponse, error)
+	UpdateClient(goCtx context.Context, msg *clienttypes.MsgUpdateClient) (*clienttypes.MsgUpdateClientResponse, error)
+	UpgradeClient(goCtx context.Context, msg *clienttypes.MsgUpgradeClient) (*clienttypes.MsgUpgradeClientResponse, error)
+	SubmitMisbehaviour(goCtx context.Context, msg *clienttypes.MsgSubmitMisbehaviour) (*clienttypes.MsgSubmitMisbehaviourResponse, error)
+	ConnectionOpenInit(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenInit) (*connectiontypes.MsgConnectionOpenInitResponse, error)
+	ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenTry) (*connectiontypes.MsgConnectionOpenTryResponse, error)
+	ConnectionOpenAck(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenAck) (*connectiontypes.MsgConnectionOpenAckResponse, error)
+	ConnectionOpenConfirm(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenConfirm) (*connectiontypes.MsgConnectionOpenConfirmResponse, error)
+	ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChannelOpenInit) (*channeltypes.MsgChannelOpenInitResponse, error)
+	ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChannelOpenTry) (*channeltypes.MsgChannelOpenTryResponse, error)
+	ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChannelOpenAck) (*channeltypes.MsgChannelOpenAckResponse, error)
+	ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgChannelOpenConfirm) (*channeltypes.MsgChannelOpenConfirmResponse, error)
+	RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacket) (*channeltypes.MsgRecvPacketResponse, error)
+	Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAcknowledgement) (*channeltypes.MsgAcknowledgementResponse, error)
+	Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*channeltypes.MsgTimeoutResponse, error)
+	TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeoutOnClose) (*channeltypes.MsgTimeoutOnCloseResponse, error)
+}