From 2fc0287138f78970d05ee35ab7439fcaadf3d7e2 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 18 Jun 2024 09:42:04 +0800 Subject: [PATCH] Problem: packed batch is not supported --- integration_tests/configs/ibc.jsonnet | 1 + .../contracts/contracts/TestRelayer.sol | 9 +- integration_tests/poetry.lock | 9 +- integration_tests/pyproject.toml | 2 +- integration_tests/test_ibc_rly.py | 5 +- integration_tests/test_ibc_rly_gas.py | 8 +- nix/sources.json | 6 +- .../relayer/i_relayer_functions.abigen.go | 275 +----------------- .../events/bindings/src/RelayerFunctions.sol | 13 - x/cronos/keeper/precompiles/relayer.go | 223 ++++++++------ 10 files changed, 156 insertions(+), 395 deletions(-) diff --git a/integration_tests/configs/ibc.jsonnet b/integration_tests/configs/ibc.jsonnet index 385defbf2a..0d1d6cb768 100644 --- a/integration_tests/configs/ibc.jsonnet +++ b/integration_tests/configs/ibc.jsonnet @@ -151,6 +151,7 @@ config { id: 'cronos_777-1', max_gas: 2500000, gas_multiplier: 1.1, + max_msg_num: 5, address_type: { derivation: 'ethermint', proto_type: { diff --git a/integration_tests/contracts/contracts/TestRelayer.sol b/integration_tests/contracts/contracts/TestRelayer.sol index 663b02e65f..2d697ea53c 100644 --- a/integration_tests/contracts/contracts/TestRelayer.sol +++ b/integration_tests/contracts/contracts/TestRelayer.sol @@ -4,10 +4,11 @@ pragma solidity ^0.8.4; contract TestRelayer { address constant relayer = 0x0000000000000000000000000000000000000065; - function batchCall(bytes[] memory payloads) public { - for (uint256 i = 0; i < payloads.length; i++) { - (bool success,) = relayer.call(payloads[i]); - require(success); + function batchCall(bytes[][] memory batches) public { + for (uint256 i = 0; i < batches.length; i++) { + bytes memory payload = abi.encode(batches[i]); + (bool success, ) = relayer.call(payload); + require(success, "Relayer call failed"); } } } diff --git a/integration_tests/poetry.lock b/integration_tests/poetry.lock index c5ca3dee2a..48d155972b 100644 --- a/integration_tests/poetry.lock +++ b/integration_tests/poetry.lock @@ -1514,15 +1514,14 @@ python-dateutil = "^2.8" python-dotenv = "^1.0" pyyaml = "^6.0" pyyaml-include = "^1.3" -rpds-py = "^0.17.0" supervisor = "^4.2" tomlkit = "^0" [package.source] type = "git" -url = "https://github.com/crypto-com/pystarport.git" -reference = "main" -resolved_reference = "4704c4a27b159eaa4d434ef44b9bf1046e81da1b" +url = "https://github.com/mmsqe/pystarport.git" +reference = "packed_batch" +resolved_reference = "b61a1c8a42d1bc09d42574f0d3a9f9e4fb03df20" [[package]] name = "pytest" @@ -2318,4 +2317,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "f4a81d2f69d093b02c4861288d41ab79aa75959de1e69043566ef4cdbb6bd3de" +content-hash = "967cdab01630c35c1f904a71ac456594ebcc430e28d06806c9e1ca811e8933c8" diff --git a/integration_tests/pyproject.toml b/integration_tests/pyproject.toml index 1d2fed78fa..a1e6a03db8 100644 --- a/integration_tests/pyproject.toml +++ b/integration_tests/pyproject.toml @@ -17,7 +17,7 @@ protobuf = "^4.25" python-dateutil = "^2.8" web3 = "^6.15" python-dotenv = "^1.0" -pystarport = { git = "https://github.com/crypto-com/pystarport.git", branch = "main" } +pystarport = { git = "https://github.com/mmsqe/pystarport.git", branch = "packed_batch" } websockets = "^12.0" toml = "^0" jsonnet = "^0" diff --git a/integration_tests/test_ibc_rly.py b/integration_tests/test_ibc_rly.py index 22f69a7f2f..e8a6877caa 100644 --- a/integration_tests/test_ibc_rly.py +++ b/integration_tests/test_ibc_rly.py @@ -16,6 +16,7 @@ ibc_multi_transfer, ibc_transfer, prepare_network, + rly_transfer, ) from .utils import ( ADDRS, @@ -52,7 +53,7 @@ def ibc(request, tmp_path_factory): yield from prepare_network( path, name, - relayer=cluster.Relayer.HERMES.value, + relayer=cluster.Relayer.RLY.value, ) @@ -230,7 +231,7 @@ def test_ibc(ibc): w3 = ibc.cronos.w3 wait_for_new_blocks(ibc.cronos.cosmos_cli(), 1) start = w3.eth.get_block_number() - ibc_transfer(ibc) + ibc_transfer(ibc, transfer_fn=rly_transfer) denom = ibc_denom(channel, src_denom) logs = get_logs_since(w3, CONTRACT, start) chainmain_cli = ibc.chainmain.cosmos_cli() diff --git a/integration_tests/test_ibc_rly_gas.py b/integration_tests/test_ibc_rly_gas.py index ce1f206895..a931d8fb3d 100644 --- a/integration_tests/test_ibc_rly_gas.py +++ b/integration_tests/test_ibc_rly_gas.py @@ -7,6 +7,7 @@ ibc_transfer, log_gas_records, prepare_network, + rly_transfer, ) from .utils import wait_for_new_blocks @@ -18,7 +19,7 @@ def ibc(request, tmp_path_factory): "prepare-network" name = request.param path = tmp_path_factory.mktemp(name) - yield from prepare_network(path, name, relayer=cluster.Relayer.HERMES.value) + yield from prepare_network(path, name, relayer=cluster.Relayer.RLY.value) records = [] @@ -28,13 +29,16 @@ def test_ibc(ibc): # chainmain-1 relayer -> cronos_777-1 signer2 cli = ibc.cronos.cosmos_cli() wait_for_new_blocks(cli, 1) - ibc_transfer(ibc) + ibc_transfer(ibc, transfer_fn=rly_transfer) + # ibc_transfer(ibc) ibc_incentivized_transfer(ibc) ibc_multi_transfer(ibc) diff = 0.1 record = log_gas_records(cli) if record: + print("mm-record", record) records.append(record) if len(records) == 2: res = float(sum(records[0]) / sum(records[1])) + print("mm-res", res) assert 1 - diff <= res <= 1 + diff, res diff --git a/nix/sources.json b/nix/sources.json index eae66bb9ad..01910130f3 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -126,10 +126,10 @@ "homepage": "https://github.com/crypto-org-chain/relayer", "owner": "crypto-org-chain", "repo": "relayer", - "rev": "fe5722292a9961e80818e3ef5c987330b538bc05", - "sha256": "0jv4pkrqhckbabxxxbr0bcil0fakbnc7sf22k2wa5q6v6921ci0y", + "rev": "9993381407ea57ea75ffb3ebd9e07a9d1ebed2f2", + "sha256": "0kjs1s2ap90rrn4qvbibhad0c4hv4qp9m2nx1mnabadw9yhj5i0b", "type": "tarball", - "url": "https://github.com/crypto-org-chain/relayer/archive/fe5722292a9961e80818e3ef5c987330b538bc05.tar.gz", + "url": "https://github.com/mmsqe/relayer/archive/9993381407ea57ea75ffb3ebd9e07a9d1ebed2f2.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go b/x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go index eb1cd85583..bed262a3e6 100644 --- a/x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go +++ b/x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go @@ -31,7 +31,7 @@ var ( // RelayerFunctionsMetaData contains all meta data concerning the RelayerFunctions contract. var RelayerFunctionsMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"acknowledgement\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelCloseConfirm\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelCloseInit\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenAck\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenConfirm\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenInit\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenTry\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenAck\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenConfirm\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenInit\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenTry\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"createClient\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"recvPacket\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"submitMisbehaviour\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"timeout\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"timeoutOnClose\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"updateClient\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndAcknowledgement\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndChannelCloseConfirm\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndChannelCloseInit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndChannelOpenAck\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndChannelOpenConfirm\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndChannelOpenInit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndChannelOpenTry\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndConnectionOpenAck\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndConnectionOpenConfirm\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndConnectionOpenInit\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndConnectionOpenTry\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndRecvPacket\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data1\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"data2\",\"type\":\"bytes\"}],\"name\":\"updateClientAndTimeout\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"upgradeClient\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"}]", + ABI: "[{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"acknowledgement\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelCloseConfirm\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelCloseInit\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenAck\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenConfirm\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenInit\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"channelOpenTry\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenAck\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenConfirm\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenInit\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"connectionOpenTry\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"createClient\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"recvPacket\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"submitMisbehaviour\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"timeout\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"timeoutOnClose\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"updateClient\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"upgradeClient\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"payable\",\"type\":\"function\"}]", } // RelayerFunctionsABI is the input ABI used to generate the binding from. @@ -537,279 +537,6 @@ func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClient(data [] return _RelayerFunctions.Contract.UpdateClient(&_RelayerFunctions.TransactOpts, data) } -// UpdateClientAndAcknowledgement is a paid mutator transaction binding the contract method 0x65a939c6. -// -// Solidity: function updateClientAndAcknowledgement(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndAcknowledgement(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndAcknowledgement", data1, data2) -} - -// UpdateClientAndAcknowledgement is a paid mutator transaction binding the contract method 0x65a939c6. -// -// Solidity: function updateClientAndAcknowledgement(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndAcknowledgement(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndAcknowledgement(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndAcknowledgement is a paid mutator transaction binding the contract method 0x65a939c6. -// -// Solidity: function updateClientAndAcknowledgement(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndAcknowledgement(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndAcknowledgement(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelCloseConfirm is a paid mutator transaction binding the contract method 0x9bbcbfd2. -// -// Solidity: function updateClientAndChannelCloseConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndChannelCloseConfirm(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndChannelCloseConfirm", data1, data2) -} - -// UpdateClientAndChannelCloseConfirm is a paid mutator transaction binding the contract method 0x9bbcbfd2. -// -// Solidity: function updateClientAndChannelCloseConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndChannelCloseConfirm(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelCloseConfirm(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelCloseConfirm is a paid mutator transaction binding the contract method 0x9bbcbfd2. -// -// Solidity: function updateClientAndChannelCloseConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndChannelCloseConfirm(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelCloseConfirm(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelCloseInit is a paid mutator transaction binding the contract method 0x5447448d. -// -// Solidity: function updateClientAndChannelCloseInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndChannelCloseInit(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndChannelCloseInit", data1, data2) -} - -// UpdateClientAndChannelCloseInit is a paid mutator transaction binding the contract method 0x5447448d. -// -// Solidity: function updateClientAndChannelCloseInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndChannelCloseInit(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelCloseInit(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelCloseInit is a paid mutator transaction binding the contract method 0x5447448d. -// -// Solidity: function updateClientAndChannelCloseInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndChannelCloseInit(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelCloseInit(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenAck is a paid mutator transaction binding the contract method 0xc518ffc8. -// -// Solidity: function updateClientAndChannelOpenAck(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndChannelOpenAck(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndChannelOpenAck", data1, data2) -} - -// UpdateClientAndChannelOpenAck is a paid mutator transaction binding the contract method 0xc518ffc8. -// -// Solidity: function updateClientAndChannelOpenAck(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndChannelOpenAck(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenAck(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenAck is a paid mutator transaction binding the contract method 0xc518ffc8. -// -// Solidity: function updateClientAndChannelOpenAck(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndChannelOpenAck(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenAck(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenConfirm is a paid mutator transaction binding the contract method 0x0982b806. -// -// Solidity: function updateClientAndChannelOpenConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndChannelOpenConfirm(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndChannelOpenConfirm", data1, data2) -} - -// UpdateClientAndChannelOpenConfirm is a paid mutator transaction binding the contract method 0x0982b806. -// -// Solidity: function updateClientAndChannelOpenConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndChannelOpenConfirm(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenConfirm(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenConfirm is a paid mutator transaction binding the contract method 0x0982b806. -// -// Solidity: function updateClientAndChannelOpenConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndChannelOpenConfirm(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenConfirm(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenInit is a paid mutator transaction binding the contract method 0x66365fc4. -// -// Solidity: function updateClientAndChannelOpenInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndChannelOpenInit(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndChannelOpenInit", data1, data2) -} - -// UpdateClientAndChannelOpenInit is a paid mutator transaction binding the contract method 0x66365fc4. -// -// Solidity: function updateClientAndChannelOpenInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndChannelOpenInit(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenInit(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenInit is a paid mutator transaction binding the contract method 0x66365fc4. -// -// Solidity: function updateClientAndChannelOpenInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndChannelOpenInit(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenInit(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenTry is a paid mutator transaction binding the contract method 0x33978088. -// -// Solidity: function updateClientAndChannelOpenTry(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndChannelOpenTry(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndChannelOpenTry", data1, data2) -} - -// UpdateClientAndChannelOpenTry is a paid mutator transaction binding the contract method 0x33978088. -// -// Solidity: function updateClientAndChannelOpenTry(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndChannelOpenTry(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenTry(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndChannelOpenTry is a paid mutator transaction binding the contract method 0x33978088. -// -// Solidity: function updateClientAndChannelOpenTry(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndChannelOpenTry(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndChannelOpenTry(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenAck is a paid mutator transaction binding the contract method 0xfedb9353. -// -// Solidity: function updateClientAndConnectionOpenAck(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndConnectionOpenAck(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndConnectionOpenAck", data1, data2) -} - -// UpdateClientAndConnectionOpenAck is a paid mutator transaction binding the contract method 0xfedb9353. -// -// Solidity: function updateClientAndConnectionOpenAck(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndConnectionOpenAck(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenAck(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenAck is a paid mutator transaction binding the contract method 0xfedb9353. -// -// Solidity: function updateClientAndConnectionOpenAck(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndConnectionOpenAck(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenAck(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenConfirm is a paid mutator transaction binding the contract method 0x70009dfc. -// -// Solidity: function updateClientAndConnectionOpenConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndConnectionOpenConfirm(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndConnectionOpenConfirm", data1, data2) -} - -// UpdateClientAndConnectionOpenConfirm is a paid mutator transaction binding the contract method 0x70009dfc. -// -// Solidity: function updateClientAndConnectionOpenConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndConnectionOpenConfirm(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenConfirm(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenConfirm is a paid mutator transaction binding the contract method 0x70009dfc. -// -// Solidity: function updateClientAndConnectionOpenConfirm(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndConnectionOpenConfirm(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenConfirm(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenInit is a paid mutator transaction binding the contract method 0x491e69c7. -// -// Solidity: function updateClientAndConnectionOpenInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndConnectionOpenInit(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndConnectionOpenInit", data1, data2) -} - -// UpdateClientAndConnectionOpenInit is a paid mutator transaction binding the contract method 0x491e69c7. -// -// Solidity: function updateClientAndConnectionOpenInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndConnectionOpenInit(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenInit(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenInit is a paid mutator transaction binding the contract method 0x491e69c7. -// -// Solidity: function updateClientAndConnectionOpenInit(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndConnectionOpenInit(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenInit(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenTry is a paid mutator transaction binding the contract method 0x5f3a7169. -// -// Solidity: function updateClientAndConnectionOpenTry(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndConnectionOpenTry(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndConnectionOpenTry", data1, data2) -} - -// UpdateClientAndConnectionOpenTry is a paid mutator transaction binding the contract method 0x5f3a7169. -// -// Solidity: function updateClientAndConnectionOpenTry(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndConnectionOpenTry(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenTry(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndConnectionOpenTry is a paid mutator transaction binding the contract method 0x5f3a7169. -// -// Solidity: function updateClientAndConnectionOpenTry(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndConnectionOpenTry(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndConnectionOpenTry(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndRecvPacket is a paid mutator transaction binding the contract method 0xd3cffc28. -// -// Solidity: function updateClientAndRecvPacket(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndRecvPacket(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndRecvPacket", data1, data2) -} - -// UpdateClientAndRecvPacket is a paid mutator transaction binding the contract method 0xd3cffc28. -// -// Solidity: function updateClientAndRecvPacket(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndRecvPacket(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndRecvPacket(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndRecvPacket is a paid mutator transaction binding the contract method 0xd3cffc28. -// -// Solidity: function updateClientAndRecvPacket(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndRecvPacket(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndRecvPacket(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndTimeout is a paid mutator transaction binding the contract method 0xca4c72a0. -// -// Solidity: function updateClientAndTimeout(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactor) UpdateClientAndTimeout(opts *bind.TransactOpts, data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.contract.Transact(opts, "updateClientAndTimeout", data1, data2) -} - -// UpdateClientAndTimeout is a paid mutator transaction binding the contract method 0xca4c72a0. -// -// Solidity: function updateClientAndTimeout(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsSession) UpdateClientAndTimeout(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndTimeout(&_RelayerFunctions.TransactOpts, data1, data2) -} - -// UpdateClientAndTimeout is a paid mutator transaction binding the contract method 0xca4c72a0. -// -// Solidity: function updateClientAndTimeout(bytes data1, bytes data2) payable returns(bool) -func (_RelayerFunctions *RelayerFunctionsTransactorSession) UpdateClientAndTimeout(data1 []byte, data2 []byte) (*types.Transaction, error) { - return _RelayerFunctions.Contract.UpdateClientAndTimeout(&_RelayerFunctions.TransactOpts, data1, data2) -} - // UpgradeClient is a paid mutator transaction binding the contract method 0x8a8e4c5d. // // Solidity: function upgradeClient(bytes data) payable returns(bytes) diff --git a/x/cronos/events/bindings/src/RelayerFunctions.sol b/x/cronos/events/bindings/src/RelayerFunctions.sol index f580fe5ccb..096bc7f0b7 100644 --- a/x/cronos/events/bindings/src/RelayerFunctions.sol +++ b/x/cronos/events/bindings/src/RelayerFunctions.sol @@ -20,17 +20,4 @@ interface IRelayerFunctions { function acknowledgement(bytes calldata data) external payable returns (bytes calldata); function timeout(bytes calldata data) external payable returns (bytes calldata); function timeoutOnClose(bytes calldata data) external payable returns (bytes calldata); - function updateClientAndConnectionOpenInit(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndConnectionOpenTry(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndConnectionOpenAck(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndConnectionOpenConfirm(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndChannelOpenInit(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndChannelOpenTry(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndChannelOpenAck(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndChannelOpenConfirm(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndRecvPacket(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndAcknowledgement(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndTimeout(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndChannelCloseInit(bytes calldata data1, bytes calldata data2) external payable returns (bool); - function updateClientAndChannelCloseConfirm(bytes calldata data1, bytes calldata data2) external payable returns (bool); } diff --git a/x/cronos/keeper/precompiles/relayer.go b/x/cronos/keeper/precompiles/relayer.go index 8bbcad970c..f347eb2c57 100644 --- a/x/cronos/keeper/precompiles/relayer.go +++ b/x/cronos/keeper/precompiles/relayer.go @@ -123,120 +123,161 @@ func (bc *RelayerContract) Address() common.Address { return relayerContractAddress } +func unpackInput(input []byte) ([][]byte, abi.Type, error) { + t, err := abi.NewType("bytes[]", "", nil) + if err != nil { + return nil, t, err + } + var inputs [][]byte + args, err := abi.Arguments{{ + Type: t, + }}.Unpack(input) + if err != nil { + inputs = [][]byte{input} + } else { + inputs = append(inputs, args[0].([][]byte)...) + } + return inputs, t, nil +} + // RequiredGas calculates the contract gas use // `max(0, len(input) * DefaultTxSizeCostPerByte + requiredGasTable[methodPrefix] - intrinsicGas)` -func (bc *RelayerContract) RequiredGas(input []byte) (gas uint64) { - // base cost to prevent large input size - inputLen := len(input) - baseCost := uint64(inputLen) * authtypes.DefaultTxSizeCostPerByte - var methodID [4]byte - copy(methodID[:], input[:4]) - requiredGas, ok := relayerGasRequiredByMethod[methodID] - method, err := irelayerABI.MethodById(methodID[:]) +func (bc *RelayerContract) RequiredGas(input []byte) (finalGas uint64) { + inputs, _, err := unpackInput(input) if err != nil { panic(err) } - if method.Name == RecvPacket { - args, err := method.Inputs.Unpack(input[4:]) + + for _, input := range inputs { + // base cost to prevent large input size + inputLen := len(input) + baseCost := uint64(inputLen) * authtypes.DefaultTxSizeCostPerByte + var methodID [4]byte + copy(methodID[:], input[:4]) + requiredGas, ok := relayerGasRequiredByMethod[methodID] + method, err := irelayerABI.MethodById(methodID[:]) if err != nil { panic(err) } - i := args[0].([]byte) - var msg channeltypes.MsgRecvPacket - if err = bc.cdc.Unmarshal(i, &msg); err != nil { - panic(err) + if method.Name == RecvPacket { + args, err := method.Inputs.Unpack(input[4:]) + if err != nil { + panic(err) + } + i := args[0].([]byte) + var msg channeltypes.MsgRecvPacket + if err = bc.cdc.Unmarshal(i, &msg); err != nil { + panic(err) + } + var data ibctransfertypes.FungibleTokenPacketData + if err = ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.Packet.GetData(), &data); err != nil { + panic(err) + } + if ibctransfertypes.ReceiverChainIsSource(msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), data.Denom) { + requiredGas = GasWhenReceiverChainIsSource + } } - var data ibctransfertypes.FungibleTokenPacketData - if err = ibctransfertypes.ModuleCdc.UnmarshalJSON(msg.Packet.GetData(), &data); err != nil { - panic(err) + intrinsicGas, _ := core.IntrinsicGas(input, nil, false, bc.isHomestead, bc.isIstanbul, bc.isShanghai) + if !ok { + requiredGas = 0 } - if ibctransfertypes.ReceiverChainIsSource(msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), data.Denom) { - requiredGas = GasWhenReceiverChainIsSource + gas := requiredGas + baseCost + if gas < intrinsicGas { + gas = 0 + } else { + gas -= intrinsicGas + finalGas += gas } - } - intrinsicGas, _ := core.IntrinsicGas(input, nil, false, bc.isHomestead, bc.isIstanbul, bc.isShanghai) - defer func() { + methodName := relayerMethodNamedByMethod[methodID] + fmt.Println("mm-required", "gas", gas, "method", methodName, "len", inputLen, "intrinsic", intrinsicGas) bc.logger.Debug("required", "gas", gas, "method", methodName, "len", inputLen, "intrinsic", intrinsicGas) - }() - if !ok { - requiredGas = 0 - } - total := requiredGas + baseCost - if total < intrinsicGas { - return 0 } - return total - intrinsicGas + return finalGas } func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { if readonly { return nil, errors.New("the method is not readonly") } - if len(contract.Input) < 4 { - return nil, errors.New("input too short") - } - // parse input - methodID := contract.Input[:4] - method, err := irelayerABI.MethodById(methodID) + inputs, t, err := unpackInput(contract.Input) if err != nil { return nil, err } - stateDB := evm.StateDB.(ExtStateDB) - var res []byte - precompileAddr := bc.Address() - args, err := method.Inputs.Unpack(contract.Input[4:]) - if err != nil { - return nil, errors.New("fail to unpack input arguments") - } - input := args[0].([]byte) - converter := cronosevents.RelayerConvertEvent - e := &Executor{ - cdc: bc.cdc, - stateDB: stateDB, - caller: contract.CallerAddress, - contract: precompileAddr, - input: input, - converter: converter, - } - switch method.Name { - case CreateClient: - res, err = exec(e, bc.ibcKeeper.CreateClient) - case UpdateClient: - res, err = exec(e, bc.ibcKeeper.UpdateClient) - case UpgradeClient: - res, err = exec(e, bc.ibcKeeper.UpgradeClient) - case ConnectionOpenInit: - res, err = exec(e, bc.ibcKeeper.ConnectionOpenInit) - case ConnectionOpenTry: - res, err = exec(e, bc.ibcKeeper.ConnectionOpenTry) - case ConnectionOpenAck: - res, err = exec(e, bc.ibcKeeper.ConnectionOpenAck) - case ConnectionOpenConfirm: - res, err = exec(e, bc.ibcKeeper.ConnectionOpenConfirm) - case ChannelOpenInit: - res, err = exec(e, bc.ibcKeeper.ChannelOpenInit) - case ChannelOpenTry: - res, err = exec(e, bc.ibcKeeper.ChannelOpenTry) - case ChannelOpenAck: - res, err = exec(e, bc.ibcKeeper.ChannelOpenAck) - case ChannelOpenConfirm: - res, err = exec(e, bc.ibcKeeper.ChannelOpenConfirm) - case ChannelCloseInit: - res, err = exec(e, bc.ibcKeeper.ChannelCloseInit) - case ChannelCloseConfirm: - res, err = exec(e, bc.ibcKeeper.ChannelCloseConfirm) - case RecvPacket: - res, err = exec(e, bc.ibcKeeper.RecvPacket) - case Acknowledgement: - res, err = exec(e, bc.ibcKeeper.Acknowledgement) - case Timeout: - res, err = exec(e, bc.ibcKeeper.Timeout) - case TimeoutOnClose: - res, err = exec(e, bc.ibcKeeper.TimeoutOnClose) - default: - return nil, fmt.Errorf("unknown method: %s", method.Name) + var responses [][]byte + for _, input := range inputs { + if len(input) < 4 { + return nil, errors.New("input too short") + } + // parse input + methodID := input[:4] + method, err := irelayerABI.MethodById(methodID) + if err != nil { + return nil, err + } + stateDB := evm.StateDB.(ExtStateDB) + + var res []byte + precompileAddr := bc.Address() + args, err := method.Inputs.Unpack(input[4:]) + if err != nil { + return nil, errors.New("fail to unpack input arguments") + } + input := args[0].([]byte) + converter := cronosevents.RelayerConvertEvent + e := &Executor{ + cdc: bc.cdc, + stateDB: stateDB, + caller: contract.CallerAddress, + contract: precompileAddr, + input: input, + converter: converter, + } + switch method.Name { + case CreateClient: + res, err = exec(e, bc.ibcKeeper.CreateClient) + case UpdateClient: + res, err = exec(e, bc.ibcKeeper.UpdateClient) + case UpgradeClient: + res, err = exec(e, bc.ibcKeeper.UpgradeClient) + case ConnectionOpenInit: + res, err = exec(e, bc.ibcKeeper.ConnectionOpenInit) + case ConnectionOpenTry: + res, err = exec(e, bc.ibcKeeper.ConnectionOpenTry) + case ConnectionOpenAck: + res, err = exec(e, bc.ibcKeeper.ConnectionOpenAck) + case ConnectionOpenConfirm: + res, err = exec(e, bc.ibcKeeper.ConnectionOpenConfirm) + case ChannelOpenInit: + res, err = exec(e, bc.ibcKeeper.ChannelOpenInit) + case ChannelOpenTry: + res, err = exec(e, bc.ibcKeeper.ChannelOpenTry) + case ChannelOpenAck: + res, err = exec(e, bc.ibcKeeper.ChannelOpenAck) + case ChannelOpenConfirm: + res, err = exec(e, bc.ibcKeeper.ChannelOpenConfirm) + case ChannelCloseInit: + res, err = exec(e, bc.ibcKeeper.ChannelCloseInit) + case ChannelCloseConfirm: + res, err = exec(e, bc.ibcKeeper.ChannelCloseConfirm) + case RecvPacket: + res, err = exec(e, bc.ibcKeeper.RecvPacket) + case Acknowledgement: + res, err = exec(e, bc.ibcKeeper.Acknowledgement) + case Timeout: + res, err = exec(e, bc.ibcKeeper.Timeout) + case TimeoutOnClose: + res, err = exec(e, bc.ibcKeeper.TimeoutOnClose) + default: + return nil, fmt.Errorf("unknown method: %s", method.Name) + } + if err != nil { + return nil, err + } + responses = append(responses, res) } - return res, err + return abi.Arguments{{ + Type: t, + }}.Pack(responses) }