Skip to content

Commit

Permalink
Problem: ibc 8.3 not used
Browse files Browse the repository at this point in the history
Solution:
- upgrade ibc-go
- remove icaauth, use builtin
  • Loading branch information
yihuang committed Jul 22, 2024
1 parent 7f581a6 commit 976c0c7
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [#1394](https://github.com/crypto-org-chain/cronos/pull/1394) Add icahost wirings but disable in parameters.
* [#1414](https://github.com/crypto-org-chain/cronos/pull/1414) Integrate new evm tx format.
* [#1458](https://github.com/crypto-org-chain/cronos/pull/1458) Adjust require gas for recvPacket when ReceiverChainIsSource.
* [#]() Upgrade ibc-go to 8.3 and remove icaauth module.

### Improvements

Expand Down
24 changes: 3 additions & 21 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ import (
cronosprecompiles "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/precompiles"
"github.com/crypto-org-chain/cronos/v2/x/cronos/middleware"
cronostypes "github.com/crypto-org-chain/cronos/v2/x/cronos/types"
icaauth "github.com/crypto-org-chain/cronos/v2/x/icaauth"
icaauthkeeper "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper"
icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"

e2ee "github.com/crypto-org-chain/cronos/v2/x/e2ee"
e2eekeeper "github.com/crypto-org-chain/cronos/v2/x/e2ee/keeper"
Expand Down Expand Up @@ -252,7 +249,6 @@ func StoreKeys() (
ibcfeetypes.StoreKey,
// ica keys
icacontrollertypes.StoreKey,
icaauthtypes.StoreKey,
icahosttypes.StoreKey,
// ethermint keys
evmtypes.StoreKey, feemarkettypes.StoreKey,
Expand Down Expand Up @@ -314,7 +310,6 @@ type App struct {
IBCFeeKeeper ibcfeekeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
ICAAuthKeeper icaauthkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
Expand All @@ -324,7 +319,6 @@ type App struct {
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAAuthKeeper capabilitykeeper.ScopedKeeper

// Ethermint keepers
EvmKeeper *evmkeeper.Keeper
Expand Down Expand Up @@ -452,7 +446,6 @@ func New(
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
Expand Down Expand Up @@ -585,6 +578,7 @@ func New(
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter())
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)

// Create Transfer Keepers
Expand Down Expand Up @@ -622,7 +616,7 @@ func New(
return cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec, rules, app.Logger())
},
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewIcaContract(ctx, &app.ICAAuthKeeper, &app.CronosKeeper, appCodec, gasConfig)
return cronosprecompiles.NewIcaContract(ctx, app.ICAControllerKeeper, &app.CronosKeeper, appCodec, gasConfig)
},
},
)
Expand Down Expand Up @@ -685,17 +679,12 @@ func New(
evmhandlers.NewSendToIbcV2Handler(app.BankKeeper, app.CronosKeeper),
))

app.ICAAuthKeeper = *icaauthkeeper.NewKeeper(appCodec, keys[icaauthtypes.StoreKey], keys[icaauthtypes.MemStoreKey], app.ICAControllerKeeper, scopedICAAuthKeeper, scopedICAControllerKeeper)
icaAuthIBCModule := icaauth.NewIBCModule(app.ICAAuthKeeper)

var icaControllerStack porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(icaAuthIBCModule, app.ICAControllerKeeper)
icaControllerStack = icacontroller.NewIBCMiddleware(nil, 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
ics4Wrapper := icaControllerStack.(porttypes.Middleware)
app.ICAControllerKeeper.WithICS4Wrapper(ics4Wrapper)
app.ICAAuthKeeper.WithICS4Wrapper(ics4Wrapper)
icaAuthModule := icaauth.NewAppModule(appCodec, app.ICAAuthKeeper, ics4Wrapper)
// we don't limit gas usage here, because the cronos keeper will use network parameter to control it.
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, app.CronosKeeper, math.MaxUint64)

Expand All @@ -707,7 +696,6 @@ func New(
ibcRouter := porttypes.NewRouter()
// Add controller & ica auth modules to IBC router
ibcRouter.
AddRoute(icaauthtypes.ModuleName, icaControllerStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, transferStack)
Expand Down Expand Up @@ -772,7 +760,6 @@ func New(
ibctm.AppModule{},
transferModule,
icaModule,
icaAuthModule,
feeModule,

// Ethermint app modules
Expand Down Expand Up @@ -815,7 +802,6 @@ func New(
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
icaauthtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
Expand All @@ -837,7 +823,6 @@ func New(
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
icaauthtypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand Down Expand Up @@ -880,7 +865,6 @@ func New(
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
icaauthtypes.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
Expand Down Expand Up @@ -1013,7 +997,6 @@ func New(
app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedICAAuthKeeper = scopedICAAuthKeeper
// this line is used by starport scaffolding # stargate/app/beforeInitReturn

return app
Expand Down Expand Up @@ -1345,7 +1328,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icaauthtypes.ModuleName)
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(v0evmtypes.ParamKeyTable()) //nolint: staticcheck
paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())
// this line is used by starport scaffolding # stargate/app/paramSubspace
Expand Down
4 changes: 4 additions & 0 deletions app/icahost.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ var _ icatypes.ParamSubspace = ICAHostMockSubspace{}
func (ICAHostMockSubspace) GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) {
*(ps.(*icahosttypes.Params)) = icahosttypes.DefaultParams()
}

func (ICAHostMockSubspace) GetParamSetIfExists(ctx sdk.Context, ps paramtypes.ParamSet) {
return
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ require (
github.com/cometbft/cometbft v0.38.10-0.20240709120009-0792c8bdda44
github.com/cosmos/cosmos-db v1.0.3-0.20240408151834-e75f6e4b28d8
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cosmos/cosmos-sdk v0.50.7
github.com/cosmos/gogoproto v1.4.12
github.com/cosmos/ibc-go/modules/apps/callbacks v0.0.0-20240410121711-d89cb0895b1e
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.2.1
github.com/cosmos/ibc-go/v8 v8.3.2
github.com/cosmos/rosetta v0.50.3-1
github.com/crypto-org-chain/cronos/store v0.0.4
github.com/crypto-org-chain/cronos/versiondb v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ github.com/cosmos/ibc-go/modules/apps/callbacks v0.0.0-20240410121711-d89cb0895b
github.com/cosmos/ibc-go/modules/apps/callbacks v0.0.0-20240410121711-d89cb0895b1e/go.mod h1:ssYtyFK+55wraj3hcNNkI1XVJ7eP4XyBcYdUe32IKNU=
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/v8 v8.2.1 h1:MTsnZZjxvGD4Fv5pYyx5UkELafSX0rlPt6IfsE2BpTQ=
github.com/cosmos/ibc-go/v8 v8.2.1/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/cosmos/ibc-go/v8 v8.3.2 h1:8X1oHHKt2Bh9hcExWS89rntLaCKZp2EjFTUSxKlPhGI=
github.com/cosmos/ibc-go/v8 v8.3.2/go.mod h1:WVVIsG39jGrF9Cjggjci6LzySyWGloz194sjTxiGNIE=
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
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ schema = 3
version = "v1.0.0"
hash = "sha256-xOeHJWUj6fTc2EUGiE4dgfY2WkvrqTg/FWewoUvQcvg="
[mod."github.com/cosmos/ibc-go/v8"]
version = "v8.2.1"
hash = "sha256-FYMkZG3dYTXkqoSSyJSSe5NDd9K+3KlMWKfQKahXz3s="
version = "v8.3.2"
hash = "sha256-uqt1GlZ1sQ7k5b3vGiRxawGp53yeAv0RjOotOIY7Z0E="
[mod."github.com/cosmos/ics23/go"]
version = "v0.10.0"
hash = "sha256-KYEv727BO/ht63JO02xiKFGFAddg41Ve9l2vSSZZBq0="
Expand Down
69 changes: 44 additions & 25 deletions x/cronos/keeper/precompiles/ica.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"errors"
"fmt"
"math/big"
"time"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
Expand All @@ -18,7 +19,6 @@ import (
cronoseventstypes "github.com/crypto-org-chain/cronos/v2/x/cronos/events/types"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"

icaauthtypes "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 @@ -70,21 +70,27 @@ func OnPacketResultCallback(args ...interface{}) ([]byte, error) {
type IcaContract struct {
BaseContract

ctx sdk.Context
cdc codec.Codec
icaauthKeeper types.Icaauthkeeper
cronosKeeper types.CronosKeeper
kvGasConfig storetypes.GasConfig
ctx sdk.Context
cdc codec.Codec
controllerKeeper icacontrollerkeeper.Keeper
cronosKeeper types.CronosKeeper
kvGasConfig storetypes.GasConfig
}

func NewIcaContract(ctx sdk.Context, icaauthKeeper types.Icaauthkeeper, cronosKeeper types.CronosKeeper, cdc codec.Codec, kvGasConfig storetypes.GasConfig) vm.PrecompiledContract {
func NewIcaContract(
ctx sdk.Context,
controllerKeeper icacontrollerkeeper.Keeper,
cronosKeeper types.CronosKeeper,
cdc codec.Codec,
kvGasConfig storetypes.GasConfig,
) vm.PrecompiledContract {
return &IcaContract{
BaseContract: NewBaseContract(icaContractAddress),
ctx: ctx,
cdc: cdc,
icaauthKeeper: icaauthKeeper,
cronosKeeper: cronosKeeper,
kvGasConfig: kvGasConfig,
BaseContract: NewBaseContract(icaContractAddress),
ctx: ctx,
cdc: cdc,
controllerKeeper: controllerKeeper,
cronosKeeper: cronosKeeper,
kvGasConfig: kvGasConfig,
}
}

Expand Down Expand Up @@ -133,7 +139,8 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
connectionID := args[0].(string)
version := args[1].(string)
execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
_, err := ic.icaauthKeeper.RegisterAccount(ctx, &icaauthtypes.MsgRegisterAccount{
msgServer := icacontrollerkeeper.NewMsgServerImpl(&ic.controllerKeeper)
_, err := msgServer.RegisterInterchainAccount(ctx, &icacontrollertypes.MsgRegisterInterchainAccount{
Owner: owner,
ConnectionId: connectionID,
Version: version,
Expand All @@ -153,17 +160,17 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
account := args[1].(common.Address)
owner := sdk.AccAddress(account.Bytes()).String()
icaAddress := ""
response, err := ic.icaauthKeeper.InterchainAccountAddress(
response, err := ic.controllerKeeper.InterchainAccount(
stateDB.Context(),
&icaauthtypes.QueryInterchainAccountAddressRequest{
&icacontrollertypes.QueryInterchainAccountRequest{
Owner: owner,
ConnectionId: connectionID,
})
if err != nil {
return nil, err
}
if response != nil {
icaAddress = response.InterchainAccountAddress
icaAddress = response.Address
}
return method.Outputs.Pack(icaAddress)
case SubmitMsgsMethodName:
Expand All @@ -182,18 +189,30 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([
Data: data,
Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, caller.String()),
}
timeoutDuration := time.Duration(timeout.Uint64())
seq := uint64(0)
execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error {
activeChannelID, response, err := ic.icaauthKeeper.SubmitTxWithArgs(
ctx,
owner,
connectionID,
timeoutDuration,
icaMsgData,
msgServer := icacontrollerkeeper.NewMsgServerImpl(&ic.controllerKeeper)
response, err := msgServer.SendTx(
ctx, &icacontrollertypes.MsgSendTx{
Owner: owner,
ConnectionId: connectionID,
RelativeTimeout: timeout.Uint64(),
PacketData: icaMsgData,
},
)
if err == nil && response != nil {
seq = response.Sequence

// fetch src channel id for event
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
return err
}
activeChannelID, found := ic.controllerKeeper.GetActiveChannelID(ctx, connectionID, portID)
if !found {
return errors.New("failed to retrieve active channel")
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
cronoseventstypes.EventTypeSubmitMsgsResult,
Expand Down
10 changes: 0 additions & 10 deletions x/cronos/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package types
import (
context "context"
"math/big"
time "time"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

tmbytes "github.com/cometbft/cometbft/libs/bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -72,13 +69,6 @@ type EvmKeeper interface {
ChainID() *big.Int
}

// Icaauthkeeper defines the interface for icaauth keeper
type Icaauthkeeper interface {
RegisterAccount(goCtx context.Context, msg *icaauthtypes.MsgRegisterAccount) (*icaauthtypes.MsgRegisterAccountResponse, error)
InterchainAccountAddress(goCtx context.Context, req *icaauthtypes.QueryInterchainAccountAddressRequest) (*icaauthtypes.QueryInterchainAccountAddressResponse, error)
SubmitTxWithArgs(goCtx context.Context, owner, connectionId string, timeoutDuration time.Duration, packetData icatypes.InterchainAccountPacketData) (string, *icaauthtypes.MsgSubmitTxResponse, error)
}

// CronosKeeper defines the interface for cronos keeper
type CronosKeeper interface {
GetParams(ctx sdk.Context) (params Params)
Expand Down

0 comments on commit 976c0c7

Please sign in to comment.