Skip to content

Commit 6deb5bc

Browse files
committed
add channel to SubmitMsgsResult
1 parent a3096a8 commit 6deb5bc

File tree

8 files changed

+101
-34
lines changed

8 files changed

+101
-34
lines changed

app/app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func New(
637637
}
638638
app.StakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(hooks...))
639639

640-
app.ICAAuthKeeper = *icaauthkeeper.NewKeeper(appCodec, keys[icaauthtypes.StoreKey], keys[icaauthtypes.MemStoreKey], app.ICAControllerKeeper, scopedICAAuthKeeper)
640+
app.ICAAuthKeeper = *icaauthkeeper.NewKeeper(appCodec, keys[icaauthtypes.StoreKey], keys[icaauthtypes.MemStoreKey], app.ICAControllerKeeper, scopedICAAuthKeeper, scopedICAControllerKeeper)
641641
icaAuthModule := icaauth.NewAppModule(appCodec, app.ICAAuthKeeper)
642642
icaAuthIBCModule := icaauth.NewIBCModule(app.ICAAuthKeeper)
643643

@@ -646,6 +646,7 @@ func New(
646646
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
647647
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
648648
app.ICAControllerKeeper.WithICS4Wrapper(icaControllerStack.(porttypes.Middleware))
649+
app.ICAAuthKeeper.WithICS4Wrapper(icaControllerStack.(porttypes.Middleware))
649650
// we don't limit gas usage here, because the cronos keeper will use network parameter to control it.
650651
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, app.CronosKeeper, math.MaxUint64)
651652

integration_tests/test_ica_precompile.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def submit_msgs(
8080
amount=amt,
8181
need_wait=True,
8282
msg_num=2,
83+
channel_id="",
8384
):
8485
cli_host = ibc.chainmain.cosmos_cli()
8586
cli_controller = ibc.cronos.cosmos_cli()
@@ -119,7 +120,12 @@ def submit_msgs(
119120
else:
120121
logs = event.getLogs()
121122
assert len(logs) > 0
122-
assert logs[0].args == AttributeDict({"seq": expected_seq})
123+
assert logs[0].args == AttributeDict(
124+
{
125+
"packetSrcChannel": keccak(text=channel_id),
126+
"seq": expected_seq,
127+
}
128+
)
123129
if need_wait:
124130
wait_for_check_tx(cli_host, ica_address, num_txs)
125131
return str, diff_amt
@@ -134,14 +140,15 @@ def test_call(ibc):
134140
contract_info = json.loads(CONTRACT_ABIS["IICAModule"].read_text())
135141
contract = w3.eth.contract(address=CONTRACT, abi=contract_info)
136142
data = {"from": ADDRS[name]}
143+
channel_id = get_next_channel(cli_controller, connid)
137144
ica_address = register_acc(
138145
cli_controller,
139146
w3,
140147
contract.functions.registerAccount,
141148
contract.functions.queryAccount,
142149
data,
143150
addr,
144-
get_next_channel(cli_controller, connid),
151+
channel_id,
145152
)
146153
balance = funds_ica(cli_host, ica_address)
147154
expected_seq = 1
@@ -153,6 +160,7 @@ def test_call(ibc):
153160
False,
154161
expected_seq,
155162
contract.events.SubmitMsgsResult,
163+
channel_id=channel_id,
156164
)
157165
balance -= diff
158166
assert cli_host.balance(ica_address, denom=denom) == balance
@@ -165,6 +173,7 @@ def test_call(ibc):
165173
True,
166174
expected_seq,
167175
contract.events.SubmitMsgsResult,
176+
channel_id=channel_id,
168177
)
169178
balance -= diff
170179
assert cli_host.balance(ica_address, denom=denom) == balance
@@ -259,6 +268,7 @@ def submit_msgs_ro(func, str):
259268
False,
260269
expected_seq,
261270
contract.events.SubmitMsgsResult,
271+
channel_id=channel_id,
262272
)
263273
submit_msgs_ro(tcontract.functions.delegateSubmitMsgs, str)
264274
submit_msgs_ro(tcontract.functions.staticSubmitMsgs, str)
@@ -280,6 +290,7 @@ def submit_msgs_ro(func, str):
280290
True,
281291
expected_seq,
282292
contract.events.SubmitMsgsResult,
293+
channel_id=channel_id,
283294
)
284295
submit_msgs_ro(tcontract.functions.delegateSubmitMsgs, str)
285296
submit_msgs_ro(tcontract.functions.staticSubmitMsgs, str)
@@ -304,6 +315,7 @@ def submit_msgs_ro(func, str):
304315
contract.events.SubmitMsgsResult,
305316
amount=100000001,
306317
need_wait=False,
318+
channel_id=channel_id,
307319
)
308320
last_seq = tcontract.caller.getLastSeq()
309321
wait_for_status_change(tcontract, channel_id, last_seq)
@@ -327,6 +339,7 @@ def submit_msgs_ro(func, str):
327339
contract.events.SubmitMsgsResult,
328340
timeout,
329341
msg_num=100,
342+
channel_id=channel_id,
330343
)
331344
last_seq = tcontract.caller.getLastSeq()
332345
wait_for_status_change(tcontract, channel_id, last_seq)
@@ -358,6 +371,7 @@ def submit_msgs_ro(func, str):
358371
False,
359372
expected_seq,
360373
contract.events.SubmitMsgsResult,
374+
channel_id=channel_id2,
361375
)
362376
last_seq = tcontract.caller.getLastSeq()
363377
wait_for_status_change(tcontract, channel_id2, last_seq)

x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go

Lines changed: 24 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/cronos/events/bindings/src/ICA.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.4;
33

44
interface IICAModule {
5-
event SubmitMsgsResult(uint64 seq);
5+
event SubmitMsgsResult(string indexed packetSrcChannel, uint64 seq);
66
function registerAccount(string calldata connectionID, string calldata version) external payable returns (bool);
77
function queryAccount(string calldata connectionID, address addr) external view returns (string memory);
88
function submitMsgs(string calldata connectionID, bytes calldata data, uint256 timeout) external payable returns (uint64);

x/cronos/events/events.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ var (
3535
transfertypes.AttributeKeyDenom: ReturnStringAsIs,
3636
}
3737
IcaValueDecoders = ValueDecoders{
38-
cronoseventstypes.AttributeKeySeq: ConvertUint64,
38+
cronoseventstypes.AttributeKeySeq: ConvertUint64,
39+
channeltypes.AttributeKeySrcChannel: ReturnStringAsIs,
3940
}
4041
)
4142

x/cronos/keeper/precompiles/ica.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/cosmos/cosmos-sdk/codec"
1212
sdk "github.com/cosmos/cosmos-sdk/types"
1313
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
14+
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1415
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
1516
"github.com/crypto-org-chain/cronos/v2/x/cronos/events/bindings/cosmos/precompile/ica"
1617
"github.com/crypto-org-chain/cronos/v2/x/cronos/events/bindings/cosmos/precompile/icacallback"
@@ -181,7 +182,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
181182
timeoutDuration := time.Duration(timeout.Uint64())
182183
seq := uint64(0)
183184
execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
184-
response, err := ic.icaauthKeeper.SubmitTxWithArgs(
185+
activeChannelID, response, err := ic.icaauthKeeper.SubmitTxWithArgs(
185186
ctx,
186187
owner,
187188
connectionID,
@@ -193,6 +194,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
193194
ctx.EventManager().EmitEvents(sdk.Events{
194195
sdk.NewEvent(
195196
cronoseventstypes.EventTypeSubmitMsgsResult,
197+
sdk.NewAttribute(channeltypes.AttributeKeySrcChannel, activeChannelID),
196198
sdk.NewAttribute(cronoseventstypes.AttributeKeySeq, fmt.Sprintf("%d", response.Sequence)),
197199
),
198200
})

x/cronos/types/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type EvmKeeper interface {
8787
type Icaauthkeeper interface {
8888
RegisterAccount(goCtx context.Context, msg *icaauthtypes.MsgRegisterAccount) (*icaauthtypes.MsgRegisterAccountResponse, error)
8989
InterchainAccountAddress(goCtx context.Context, req *icaauthtypes.QueryInterchainAccountAddressRequest) (*icaauthtypes.QueryInterchainAccountAddressResponse, error)
90-
SubmitTxWithArgs(goCtx context.Context, owner, connectionId string, timeoutDuration time.Duration, packetData icatypes.InterchainAccountPacketData) (*icaauthtypes.MsgSubmitTxResponse, error)
90+
SubmitTxWithArgs(goCtx context.Context, owner, connectionId string, timeoutDuration time.Duration, packetData icatypes.InterchainAccountPacketData) (string, *icaauthtypes.MsgSubmitTxResponse, error)
9191
}
9292

9393
// CronosKeeper defines the interface for cronos keeper

x/icaauth/keeper/keeper.go

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"time"
77

8+
errorsmod "cosmossdk.io/errors"
89
"github.com/cometbft/cometbft/libs/log"
910
"github.com/cosmos/cosmos-sdk/codec"
1011
storetypes "github.com/cosmos/cosmos-sdk/store/types"
@@ -13,6 +14,9 @@ import (
1314
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
1415
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
1516
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
17+
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
18+
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
19+
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
1620
"github.com/crypto-org-chain/cronos/v2/x/icaauth/types"
1721
"google.golang.org/grpc/codes"
1822
"google.golang.org/grpc/status"
@@ -24,8 +28,10 @@ type (
2428
storeKey storetypes.StoreKey
2529
memKey storetypes.StoreKey
2630

27-
icaControllerKeeper icacontrollerkeeper.Keeper
28-
scopedKeeper capabilitykeeper.ScopedKeeper
31+
icaControllerKeeper icacontrollerkeeper.Keeper
32+
ics4Wrapper porttypes.ICS4Wrapper
33+
scopedKeeper capabilitykeeper.ScopedKeeper
34+
controllerScopedKeeper capabilitykeeper.ScopedKeeper
2935
}
3036
)
3137

@@ -35,17 +41,22 @@ func NewKeeper(
3541
memKey storetypes.StoreKey,
3642
icaControllerKeeper icacontrollerkeeper.Keeper,
3743
scopedKeeper capabilitykeeper.ScopedKeeper,
44+
controllerScopedKeeper capabilitykeeper.ScopedKeeper,
3845
) *Keeper {
3946
return &Keeper{
40-
cdc: cdc,
41-
storeKey: storeKey,
42-
memKey: memKey,
43-
44-
icaControllerKeeper: icaControllerKeeper,
45-
scopedKeeper: scopedKeeper,
47+
cdc: cdc,
48+
storeKey: storeKey,
49+
memKey: memKey,
50+
icaControllerKeeper: icaControllerKeeper,
51+
scopedKeeper: scopedKeeper,
52+
controllerScopedKeeper: controllerScopedKeeper,
4653
}
4754
}
4855

56+
func (k *Keeper) WithICS4Wrapper(ics4Wrapper porttypes.ICS4Wrapper) {
57+
k.ics4Wrapper = ics4Wrapper
58+
}
59+
4960
// SubmitTx submits a transaction to the host chain on behalf of interchain account
5061
func (k *Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) {
5162
msgs, err := msg.GetMessages()
@@ -62,26 +73,53 @@ func (k *Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types
6273
Type: icatypes.EXECUTE_TX,
6374
Data: data,
6475
}
65-
return k.SubmitTxWithArgs(goCtx, msg.Owner, msg.ConnectionId, *msg.TimeoutDuration, packetData)
76+
_, rsp, err := k.SubmitTxWithArgs(goCtx, msg.Owner, msg.ConnectionId, *msg.TimeoutDuration, packetData)
77+
return rsp, err
6678
}
6779

68-
func (k *Keeper) SubmitTxWithArgs(goCtx context.Context, owner, connectionId string, timeoutDuration time.Duration, packetData icatypes.InterchainAccountPacketData) (*types.MsgSubmitTxResponse, error) {
80+
func (k *Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (string, uint64, error) {
81+
activeChannelID, found := k.icaControllerKeeper.GetOpenActiveChannel(ctx, connectionID, portID)
82+
if !found {
83+
return "", 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID)
84+
}
85+
86+
chanCap, found := k.controllerScopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, activeChannelID))
87+
if !found {
88+
return "", 0, errorsmod.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", host.ChannelCapabilityPath(portID, activeChannelID))
89+
}
90+
91+
if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp {
92+
return "", 0, icatypes.ErrInvalidTimeoutTimestamp
93+
}
94+
95+
if err := icaPacketData.ValidateBasic(); err != nil {
96+
return "", 0, errorsmod.Wrap(err, "invalid interchain account packet data")
97+
}
98+
99+
sequence, err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes())
100+
if err != nil {
101+
return "", 0, err
102+
}
103+
return activeChannelID, sequence, nil
104+
}
105+
106+
func (k *Keeper) SubmitTxWithArgs(goCtx context.Context, owner, connectionId string, timeoutDuration time.Duration, packetData icatypes.InterchainAccountPacketData) (string, *types.MsgSubmitTxResponse, error) {
69107
ctx := sdk.UnwrapSDKContext(goCtx)
70108
portID, err := icatypes.NewControllerPortID(owner)
71109
if err != nil {
72-
return nil, err
110+
return "", nil, err
73111
}
74112
minTimeoutDuration := k.MinTimeoutDuration(ctx)
75113
// timeoutDuration should be constraited by MinTimeoutDuration parameter.
76114
timeoutTimestamp := ctx.BlockTime().Add(
77115
types.MsgSubmitTx{
78116
TimeoutDuration: &timeoutDuration,
79117
}.CalculateTimeoutDuration(minTimeoutDuration)).UnixNano()
80-
res, err := k.icaControllerKeeper.SendTx(ctx, nil, connectionId, portID, packetData, uint64(timeoutTimestamp)) //nolint:staticcheck
118+
activeChannelID, res, err := k.sendTx(ctx, connectionId, portID, packetData, uint64(timeoutTimestamp))
81119
if err != nil {
82-
return nil, err
120+
return "", nil, err
83121
}
84-
return &types.MsgSubmitTxResponse{
122+
return activeChannelID, &types.MsgSubmitTxResponse{
85123
Sequence: res,
86124
}, nil
87125
}

0 commit comments

Comments
 (0)