Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: ibc callback is not used #1185

Merged
merged 26 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibccallbacks "github.com/cosmos/ibc-go/modules/apps/callbacks"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
Expand Down Expand Up @@ -551,7 +552,7 @@ func New(
[]vm.PrecompiledContract{
cronosprecompiles.NewBankContract(app.BankKeeper, appCodec),
cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec),
cronosprecompiles.NewIcaContract(&app.ICAAuthKeeper, appCodec),
cronosprecompiles.NewIcaContract(&app.ICAAuthKeeper, &app.CronosKeeper, appCodec),
},
allKeys,
)
Expand Down Expand Up @@ -655,8 +656,12 @@ func New(
icaAuthModule := icaauth.NewAppModule(appCodec, app.ICAAuthKeeper)
icaAuthIBCModule := icaauth.NewIBCModule(app.ICAAuthKeeper)

icaControllerIBCModule := icacontroller.NewIBCMiddleware(icaAuthIBCModule, app.ICAControllerKeeper)
icaControllerStack := ibcfee.NewIBCMiddleware(icaControllerIBCModule, app.IBCFeeKeeper)
var icaControllerStack porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(icaAuthIBCModule, app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
app.ICAControllerKeeper.WithICS4Wrapper(icaControllerStack.(porttypes.Middleware))
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, app.CronosKeeper, cronostypes.MaxCallbackGasDefaultValue)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
Expand Down
9 changes: 9 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ paths:
title: the admin address who can update token mapping
enable_auto_deployment:
type: boolean
max_callback_gas:
type: string
format: uint64
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -43648,6 +43651,9 @@ definitions:
title: the admin address who can update token mapping
enable_auto_deployment:
type: boolean
max_callback_gas:
type: string
format: uint64
description: Params defines the parameters for the cronos module.
cronos.QueryParamsResponse:
type: object
Expand All @@ -43666,6 +43672,9 @@ definitions:
title: the admin address who can update token mapping
enable_auto_deployment:
type: boolean
max_callback_gas:
type: string
format: uint64
description: QueryParamsResponse is the response type for the Query/Params RPC method.
cronos.QueryPermissionsResponse:
type: object
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/modules/apps/callbacks v0.1.1-0.20230831194909-17cf1260a9cd
github.com/cosmos/ibc-go/v7 v7.3.1-0.20230920070810-c3261472c815
github.com/crypto-org-chain/cronos/store v0.0.4
github.com/crypto-org-chain/cronos/versiondb v0.0.0-00010101000000-000000000000
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,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/modules/apps/callbacks v0.1.1-0.20230831194909-17cf1260a9cd h1:KVnAwC1d0b+LWrVi+U1rex0e9LlyGTZ17zYhU3S4il8=
github.com/cosmos/ibc-go/modules/apps/callbacks v0.1.1-0.20230831194909-17cf1260a9cd/go.mod h1:h+JtOsdOs/ikuntjZFXOAa8qnXUfgkTcRSHaTTcAM+M=
github.com/cosmos/ibc-go/v7 v7.3.1-0.20230920070810-c3261472c815 h1:raSo7w7B3IXCb7DZozHWz8ajG7HLWZw9foiyCbEgInI=
github.com/cosmos/ibc-go/v7 v7.3.1-0.20230920070810-c3261472c815/go.mod h1:wvx4pPBofe5ZdMNV3OFRxSI4auEP5Qfqf8JXLLNV04g=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down
3 changes: 3 additions & 0 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ schema = 3
[mod."github.com/cosmos/iavl"]
version = "v0.21.0-alpha.1.0.20230904092046-df3db2d96583"
hash = "sha256-3Va8Ljq63IXty0oHlRpqfsC6WsMut6TWZ2R+/nYtfTU="
[mod."github.com/cosmos/ibc-go/modules/apps/callbacks"]
version = "v0.1.1-0.20230831194909-17cf1260a9cd"
hash = "sha256-kVvGNQt3A1H6pQs3YtMvx1t9nNcL6ClKnIfsR24OTi8="
[mod."github.com/cosmos/ibc-go/v7"]
version = "v7.3.1-0.20230920070810-c3261472c815"
hash = "sha256-x/D64hmU+aOc5sm8RzXMB+8y+530+CCEik/Zpj3Rf9A="
Expand Down
18 changes: 18 additions & 0 deletions integration_tests/contracts/contracts/TestICA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ contract TestICA {
address constant icaContract = 0x0000000000000000000000000000000000000066;
IICAModule ica = IICAModule(icaContract);
address account;
// sha256('cronos-evm')[:20]
address constant module_address = 0x89A7EF2F08B1c018D5Cc88836249b84Dd5392905;
uint64 lastAckSeq;
bytes lastAck;
mapping (uint64 => bytes) public acknowledgement;
event OnPacketResult(uint64 seq, bytes ack);

function encodeRegister(string memory connectionID, string memory version) internal view returns (bytes memory) {
return abi.encodeWithSignature(
Expand Down Expand Up @@ -92,4 +97,17 @@ contract TestICA {
function getLastAckSeq() public view returns (uint256) {
return lastAckSeq;
}

function getLastAck() public view returns (bytes memory) {
return lastAck;
}

function onPacketResultCallback(uint64 seq, bytes calldata ack) external payable returns (bool) {
// require(msg.sender == module_address);
yihuang marked this conversation as resolved.
Show resolved Hide resolved
lastAckSeq = seq;
lastAck = ack;
acknowledgement[seq] = ack;
emit OnPacketResult(seq, ack);
return true;
}
}
24 changes: 10 additions & 14 deletions integration_tests/test_gov_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ def test_gov_update_params(cronos, tmp_path):
proposal = tmp_path / "proposal.json"
# governance module account as signer
signer = "crc10d07y265gmmuvt4z0w9aw880jnsr700jdufnyd"
params = {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": False,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01600000",
"ibc_timeout": "96400000000000",
"max_callback_gas": "400000",
}
proposal_src = {
"messages": [
{
"@type": "/cronos.MsgUpdateParams",
"authority": signer,
"params": {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": False,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01600000",
"ibc_timeout": "96400000000000",
},
"params": params,
}
],
"deposit": "1basetcro",
Expand All @@ -35,10 +37,4 @@ def test_gov_update_params(cronos, tmp_path):
print("check params have been updated now")
rsp = cli.query_params()
print("params", rsp)
assert rsp == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": False,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01600000",
"ibc_timeout": "96400000000000",
}
assert rsp == params
6 changes: 6 additions & 0 deletions integration_tests/test_ica_precompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def submit_msgs_ro(func, str):
submit_msgs_ro(tcontract.functions.staticSubmitMsgs, str)
assert tcontract.caller.getLastAckSeq() == seq
balance -= amt
ack = tcontract.caller.getLastAck()
assert ack == b"\x12&\n$/cosmos.bank.v1beta1.MsgSendResponse", ack
assert ack == tcontract.caller.acknowledgement(seq)
assert cli_host.balance(ica_address, denom=denom) == balance
seq = 2
str = submit_msgs(
Expand All @@ -206,3 +209,6 @@ def submit_msgs_ro(func, str):
balance -= amt
balance -= amt1
assert cli_host.balance(ica_address, denom=denom) == balance
ack = tcontract.caller.getLastAck()
expected = b"\x12&\n$/cosmos.bank.v1beta1.MsgSendResponse\x12-\n+/cosmos.staking.v1beta1.MsgDelegateResponse" # noqa: E501
assert ack == expected, ack
1 change: 1 addition & 0 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):

rsp = cli.query_params("icaauth")
assert rsp["params"]["min_timeout_duration"] == "3600s", rsp
assert cli.query_params()["max_callback_gas"] == "300000", rsp

# migrate to sdk v0.47
custom_cronos.supervisorctl("stop", "all")
Expand Down
1 change: 1 addition & 0 deletions proto/cronos/cronos.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message Params {
// the admin address who can update token mapping
string cronos_admin = 3;
bool enable_auto_deployment = 4;
uint64 max_callback_gas = 5;
}

// TokenMappingChangeProposal defines a proposal to change one token mapping.
Expand Down
2 changes: 2 additions & 0 deletions scripts/gen-bindings-contracts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ solc08 --abi --bin x/cronos/events/bindings/src/CosmosTypes.sol -o build --overw
solc08 --abi --bin x/cronos/events/bindings/src/Relayer.sol -o build --overwrite
solc08 --abi --bin x/cronos/events/bindings/src/Bank.sol -o build --overwrite
solc08 --abi --bin x/cronos/events/bindings/src/ICA.sol -o build --overwrite
solc08 --abi --bin x/cronos/events/bindings/src/ICACallback.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 bank --abi build/IBankModule.abi --bin build/IBankModule.bin --out x/cronos/events/bindings/cosmos/precompile/bank/i_bank_module.abigen.go --type BankModule
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
abigen --pkg icacallback --abi build/IICACallback.abi --bin build/IICACallback.bin --out x/cronos/events/bindings/cosmos/precompile/icacallback/i_ica_callback.abigen.go --type ICACallback

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading