Skip to content

Commit

Permalink
avoid fork ibc-go
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
mmsqe committed Sep 19, 2023
1 parent 03b060c commit 2a3c887
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 226 deletions.
6 changes: 1 addition & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,7 @@ func New(
[]vm.PrecompiledContract{
cronosprecompiles.NewBankContract(app.BankKeeper, appCodec),
cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec),
cronosprecompiles.NewIcaContract(
appCodec,
&app.IBCKeeper.ChannelKeeper,
&app.ICAControllerKeeper,
),
cronosprecompiles.NewIcaContract(&app.ICAAuthKeeper, appCodec),
},
allKeys,
)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ replace (
github.com/cometbft/cometbft => github.com/cometbft/cometbft v0.37.2-0.20230905115601-790d57e1748f
github.com/cometbft/cometbft-db => github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b
github.com/cosmos/ibc-go/v7 => github.com/mmsqe/ibc-go/v7 v7.0.0-20230912011206-c6947c7bc623
github.com/crypto-org-chain/cronos/memiavl => ./memiavl
github.com/crypto-org-chain/cronos/store => ./store
github.com/crypto-org-chain/cronos/versiondb => ./versiondb
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK
github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek=
github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583 h1:3Matt7/LjZiZkIBPalYazOZcw2B05Ch14dU5TJyqJEc=
github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cosmos/ibc-go/v7 v7.2.0 h1:dx0DLUl7rxdyZ8NiT6UsrbzKOJx/w7s+BOaewFRH6cg=
github.com/cosmos/ibc-go/v7 v7.2.0/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
Expand Down Expand Up @@ -1192,8 +1194,6 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mmsqe/ibc-go/v7 v7.0.0-20230912011206-c6947c7bc623 h1:JjCrbTMp2OKUx6AXSNNLgIERDpgfdfbJk1aElv1NtaA=
github.com/mmsqe/ibc-go/v7 v7.0.0-20230912011206-c6947c7bc623/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc=
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
Expand Down
5 changes: 2 additions & 3 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ schema = 3
version = "v0.21.0-alpha.1.0.20230904092046-df3db2d96583"
hash = "sha256-3Va8Ljq63IXty0oHlRpqfsC6WsMut6TWZ2R+/nYtfTU="
[mod."github.com/cosmos/ibc-go/v7"]
version = "v7.0.0-20230912011206-c6947c7bc623"
hash = "sha256-zaoFkKhNBOQmIU8wKMCeq9Y+4GtAMHx8wZ6Q1JFEdkc="
replaced = "github.com/mmsqe/ibc-go/v7"
version = "v7.2.0"
hash = "sha256-fg+0AykvEMzqRGI5CmqwjQtSIwTyT6RuSDpp12wzReM="
[mod."github.com/cosmos/ics23/go"]
version = "v0.10.0"
hash = "sha256-KYEv727BO/ht63JO02xiKFGFAddg41Ve9l2vSSZZBq0="
Expand Down
1 change: 1 addition & 0 deletions integration_tests/contracts/contracts/TestICA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.6.6;

contract TestICA {
address constant icaContract = 0x0000000000000000000000000000000000000066;
event SubmitMsgsResult(string seq);

function nativeRegister(string memory connectionID) public {
(bool result,) = icaContract.call(abi.encodeWithSignature(
Expand Down
13 changes: 0 additions & 13 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,3 @@ def funds_ica(cli, adr):

# check if the funds are received in interchain account
assert cli.balance(adr, denom="basecro") == 100000000


def generate_ica_packet(cli, ica_address, to):
# generate a transaction to send to host chain
generated_tx_msg = {
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": ica_address,
"to_address": to,
"amount": [{"denom": "basecro", "amount": "50000000"}],
}
str = json.dumps(generated_tx_msg)
generated_packet = cli.ica_generate_packet_data(str)
return json.dumps(generated_packet)
34 changes: 19 additions & 15 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

from .ibc_utils import (
funds_ica,
generate_ica_packet,
prepare_network,
wait_for_check_channel_ready,
wait_for_check_tx,
)
from .utils import (
ADDRS,
CONTRACT_ABIS,
CONTRACTS,
KEYS,
deploy_contract,
Expand All @@ -24,10 +22,6 @@
send_transaction,
)

CONTRACT = "0x0000000000000000000000000000000000000066"
contract_info = json.loads(CONTRACT_ABIS["IICAModule"].read_text())
method_map = get_method_map(contract_info)


@pytest.fixture(scope="module")
def ibc(request, tmp_path_factory):
Expand All @@ -38,6 +32,19 @@ def ibc(request, tmp_path_factory):
yield from network


def generate_ica_packet(cli, ica_address, to):
# generate a transaction to send to host chain
generated_tx_msg = {
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": ica_address,
"to_address": to,
"amount": [{"denom": "basecro", "amount": "50000000"}],
}
str = json.dumps(generated_tx_msg)
generated_packet = cli.ica_generate_packet_data(str)
return json.dumps(generated_packet)


def test_call(ibc):
connid = "connection-0"
cli_host = ibc.chainmain.cosmos_cli()
Expand All @@ -47,23 +54,18 @@ def test_call(ibc):
addr = ADDRS["signer2"]
keys = KEYS["signer2"]
jsonfile = CONTRACTS["TestICA"]
contract_info = json.loads(jsonfile.read_text())
method_map = get_method_map(contract_info["abi"])

contract = deploy_contract(w3, jsonfile, (), keys)
data = {"from": addr, "gas": 200000}

print("register ica account from", contract.address)
start = w3.eth.get_block_number()
tx = contract.functions.nativeRegister(connid).build_transaction(data)
receipt = send_transaction(w3, tx, keys)
assert receipt.status == 1
logs = get_logs_since(w3, CONTRACT, start)
owner = eth_to_bech32(addr)
channel_id = "channel-0"
port_id = f"icacontroller-{owner}"
expected = [{"channelId": channel_id, "portId": port_id}]
for i, log in enumerate(logs):
method_name, args = get_topic_data(w3, method_map, contract_info, log)
assert args == AttributeDict(expected[i]), [i, method_name]

wait_for_check_channel_ready(cli_controller, connid, channel_id)
res = cli_controller.ica_query_account(connid, owner)
ica_address = res["interchain_account_address"]
Expand All @@ -80,7 +82,9 @@ def test_call(ibc):
tx = contract.functions.nativeSubmitMsgs(connid, str).build_transaction(data)
receipt = send_transaction(w3, tx, keys)
assert receipt.status == 1
logs = get_logs_since(w3, CONTRACT, start)

precompile_addr = "0x0000000000000000000000000000000000000066"
logs = get_logs_since(w3, precompile_addr, start)
expected = [{"seq": "1"}]
for i, log in enumerate(logs):
method_name, args = get_topic_data(w3, method_map, contract_info, log)
Expand Down
1 change: 0 additions & 1 deletion integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def contract_path(name, filename):

CONTRACT_ABIS = {
"IRelayerModule": Path(__file__).parent.parent / "build/IRelayerModule.abi",
"IICAModule": Path(__file__).parent.parent / "build/IICAModule.abi",
}


Expand Down
2 changes: 1 addition & 1 deletion proto/icaauth/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ message MsgSubmitTx {
}

// MsgSubmitTxResponse defines the response message for MsgSubmitTx
message MsgSubmitTxResponse {}
message MsgSubmitTxResponse { uint64 sequence = 1; }
2 changes: 0 additions & 2 deletions scripts/gen-bindings-contracts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

solc08 --abi --bin x/cronos/events/bindings/src/CosmosTypes.sol -o build --overwrite
solc08 --abi --bin x/cronos/events/bindings/src/Relayer.sol -o build --overwrite
solc06 --abi --bin x/cronos/events/bindings/src/ICA.sol -o build --overwrite


abigen --pkg lib --abi build/CosmosTypes.abi --bin build/CosmosTypes.bin --out x/cronos/events/bindings/cosmos/lib/cosmos_types.abigen.go --type CosmosTypes
abigen --pkg relayer --abi build/IRelayerModule.abi --bin build/IRelayerModule.bin --out x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go --type RelayerModule
abigen --pkg ica --abi build/IICAModule.abi --bin build/IICAModule.bin --out x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go --type ICAModule
2 changes: 1 addition & 1 deletion scripts/run-integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cd ../integration_tests/contracts
HUSKY_SKIP_INSTALL=1 npm install
npm run typechain
cd ..
nix-shell --run "pytest -v -s test_ica_precompile.py"
nix-shell --run "pytest -vv -s"
7 changes: 0 additions & 7 deletions x/cronos/events/bindings/src/ICA.sol

This file was deleted.

5 changes: 2 additions & 3 deletions x/cronos/events/types/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

const (
EventTypeRegisterAccountResult = "register_account_result"
EventTypeSubmitMsgsResult = "submit_msgs_result"
AttributeKeySeq = "seq"
EventTypeSubmitMsgsResult = "submit_msgs_result"
AttributeKeySeq = "seq"
)
71 changes: 31 additions & 40 deletions x/cronos/keeper/precompiles/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"errors"
"fmt"
"math/big"
"time"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcchannelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
cronoseventstypes "github.com/crypto-org-chain/cronos/v2/x/cronos/events/types"
icaauthkeeper "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper"
"github.com/crypto-org-chain/cronos/v2/x/icaauth/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -86,20 +85,17 @@ func init() {
}

type IcaContract struct {
cdc codec.Codec
channelKeeper *ibcchannelkeeper.Keeper
icaControllerKeeper *icacontrollerkeeper.Keeper
BaseContract

cdc codec.Codec
icaauthKeeper *icaauthkeeper.Keeper
}

func NewIcaContract(
cdc codec.Codec,
channelKeeper *ibcchannelkeeper.Keeper,
icaControllerKeeper *icacontrollerkeeper.Keeper,
) vm.PrecompiledContract {
func NewIcaContract(icaauthKeeper *icaauthkeeper.Keeper, cdc codec.Codec) vm.PrecompiledContract {
return &IcaContract{
cdc,
channelKeeper,
icaControllerKeeper,
BaseContract: NewBaseContract(IcaContractAddress),
cdc: cdc,
icaauthKeeper: icaauthKeeper,
}
}

Expand All @@ -122,7 +118,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
stateDB := evm.StateDB.(ExtStateDB)
precompileAddr := ic.Address()
converter := cronosevents.IcaConvertEvent
var err error
var execErr error
var res codec.ProtoMarshaler
switch string(methodID) {
case string(RegisterAccountMethod.ID):
Expand All @@ -141,22 +137,13 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
return nil, errors.New("unauthorized account registration")
}
owner := sdk.AccAddress(account.Bytes()).String()
err = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
response, err := ic.icaControllerKeeper.RegisterInterchainAccount(ctx, &icacontrollertypes.MsgRegisterInterchainAccount{
execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
response, err := ic.icaauthKeeper.RegisterAccount(ctx, &types.MsgRegisterAccount{
Owner: owner,
ConnectionId: connectionID,
Version: version,
})
res = response
if err == nil && response != nil {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
cronoseventstypes.EventTypeRegisterAccountResult,
sdk.NewAttribute(channeltypes.AttributeKeyChannelID, response.ChannelId),
sdk.NewAttribute(channeltypes.AttributeKeyPortID, response.PortId),
),
})
}
return err
})
case string(QueryAccountMethod.ID):
Expand All @@ -166,11 +153,13 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
}
connectionID := args[0].(string)
account := args[1].(common.Address)
err = stateDB.ExecuteNativeAction(precompileAddr, nil, func(ctx sdk.Context) error {
res, err = ic.icaControllerKeeper.InterchainAccount(ctx, &icacontrollertypes.QueryInterchainAccountRequest{
Owner: sdk.AccAddress(account.Bytes()).String(),
owner := sdk.AccAddress(account.Bytes()).String()
execErr = stateDB.ExecuteNativeAction(precompileAddr, nil, func(ctx sdk.Context) error {
response, err := ic.icaauthKeeper.InterchainAccountAddress(ctx, &types.QueryInterchainAccountAddressRequest{
Owner: owner,
ConnectionId: connectionID,
})
res = response
return err
})
case string(SubmitMsgsMethod.ID):
Expand All @@ -192,16 +181,18 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
var icaMsgData icatypes.InterchainAccountPacketData
err = ic.cdc.UnmarshalJSON([]byte(data), &icaMsgData)
if err != nil {
panic(err)
return nil, errors.New("fail to unmarshal packet data")
}
owner := sdk.AccAddress(account.Bytes()).String()
err = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
response, err := ic.icaControllerKeeper.SendTx(ctx, &icacontrollertypes.MsgSendTx{ //nolint:staticcheck
Owner: owner,
ConnectionId: connectionID,
PacketData: icaMsgData,
RelativeTimeout: timeout.Uint64(),
})
timeoutDuration := time.Duration(timeout.Uint64())
execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
response, err := ic.icaauthKeeper.SubmitTxWithArgs(
ctx,
owner,
connectionID,
timeoutDuration,
icaMsgData,
)
res = response
if err == nil && response != nil {
ctx.EventManager().EmitEvents(sdk.Events{
Expand All @@ -216,8 +207,8 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
default:
return nil, errors.New("unknown method")
}
if err != nil {
return nil, err
if execErr != nil {
return nil, execErr
}
return ic.cdc.Marshal(res)
}
Expand Down
27 changes: 0 additions & 27 deletions x/icaauth/keeper/grpc_query_interchain_account_address.go

This file was deleted.

Loading

0 comments on commit 2a3c887

Please sign in to comment.