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

ICA controller #57

Merged
merged 8 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,34 @@ proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protocgen.sh; fi

init-hermes: kill-dev install
@echo "Initializing both blockchains..."
./network/init.sh
./network/start.sh
@echo "Initializing relayer..."
./network/hermes/restore-keys.sh
./network/hermes/create-conn.sh

init-golang-rly: kill-dev install
@echo "Initializing both blockchains..."
./network/init.sh
./network/start.sh
@echo "Initializing relayer..."
./network/relayer/interchain-acc-config/rly.sh

start:
@echo "Starting up test network"
./network/start.sh

start-hermes:
./network/hermes/start.sh

start-rly:
./network/hermes/start.sh

kill-dev:
@echo "Killing icad and removing previous data"
-@rm -rf ./data
-@killall icad 2>/dev/null
-@killall teritorid 2>/dev/null
138 changes: 95 additions & 43 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"path/filepath"
"strings"

"github.com/TERITORI/teritori-chain/app/keepers"
"github.com/TERITORI/teritori-chain/app/upgrades"
v130 "github.com/TERITORI/teritori-chain/app/upgrades/v130"
v140 "github.com/TERITORI/teritori-chain/app/upgrades/v140"
airdrop "github.com/TERITORI/teritori-chain/x/airdrop"
airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper"
airdroptypes "github.com/TERITORI/teritori-chain/x/airdrop/types"
Expand Down Expand Up @@ -83,6 +85,9 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
Expand All @@ -106,6 +111,10 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

intertx "github.com/TERITORI/teritori-chain/x/intertx"
intertxkeeper "github.com/TERITORI/teritori-chain/x/intertx/keeper"
intertxtypes "github.com/TERITORI/teritori-chain/x/intertx/types"

teritoriappparams "github.com/TERITORI/teritori-chain/app/params"
"github.com/strangelove-ventures/packet-forward-middleware/v2/router"
routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v2/router/keeper"
Expand Down Expand Up @@ -180,7 +189,7 @@ var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

Upgrades = []upgrades.Upgrade{v130.Upgrade}
Upgrades = []upgrades.Upgrade{v130.Upgrade, v140.Upgrade}

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
Expand Down Expand Up @@ -215,6 +224,7 @@ var (
router.AppModuleBasic{},
wasm.AppModuleBasic{},
ica.AppModuleBasic{},
intertx.AppModule{},
)

// module account permissions
Expand All @@ -241,6 +251,8 @@ var (
// capabilities aren't needed for testing.
type TeritoriApp struct { // nolint: golint
*baseapp.BaseApp
keepers.AppKeepers

legacyAmino *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
Expand All @@ -252,35 +264,6 @@ type TeritoriApp struct { // nolint: golint
tkeys map[string]*sdk.TransientStoreKey
memKeys map[string]*sdk.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ICAHostKeeper icahostkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
RouterKeeper routerkeeper.Keeper
AirdropKeeper airdropkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

WasmKeeper wasm.Keeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper

// the module manager
mm *module.Manager

Expand Down Expand Up @@ -326,9 +309,11 @@ func NewTeritoriApp(
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey,
capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, routertypes.StoreKey,
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,
airdroptypes.StoreKey,
wasm.StoreKey,
intertxtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -360,9 +345,11 @@ func NewTeritoriApp(
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedInterTxKeeper := app.CapabilityKeeper.ScopeToModule(intertxtypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)

scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -475,16 +462,24 @@ func NewTeritoriApp(
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, app.MsgServiceRouter(),
)
app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
)
icaModule := ica.NewAppModule(nil, &app.ICAHostKeeper)
icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)

app.InterTxKeeper = intertxkeeper.NewKeeper(appCodec, keys[intertxtypes.StoreKey], app.ICAControllerKeeper, scopedInterTxKeeper)
interTxModule := intertx.NewAppModule(appCodec, app.InterTxKeeper)
interTxIBCModule := intertx.NewIBCModule(app.InterTxKeeper)

icaControllerIBCModule := icacontroller.NewIBCModule(app.ICAControllerKeeper, interTxIBCModule)
icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper)

app.RouterKeeper = routerkeeper.NewKeeper(appCodec, keys[routertypes.StoreKey], app.GetSubspace(routertypes.ModuleName), app.TransferKeeper, app.DistrKeeper)
Expand All @@ -508,6 +503,8 @@ func NewTeritoriApp(
panic("error while reading wasm config: " + err.Error())
}

app.setupUpgradeStoreLoaders()

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate"
Expand Down Expand Up @@ -538,10 +535,13 @@ func NewTeritoriApp(
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
}

// create static IBC router, add transfer route, then set and seal it
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
ibcRouter.AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(intertxtypes.ModuleName, icaControllerIBCModule)

ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper))
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -587,6 +587,7 @@ func NewTeritoriApp(
icaModule,
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
routerModule,
interTxModule,
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -616,6 +617,7 @@ func NewTeritoriApp(
routertypes.ModuleName,
airdroptypes.ModuleName,
wasm.ModuleName,
intertxtypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
distrtypes.ModuleName,
Expand All @@ -640,6 +642,7 @@ func NewTeritoriApp(
authz.ModuleName,
airdroptypes.ModuleName,
wasm.ModuleName,
intertxtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -670,6 +673,7 @@ func NewTeritoriApp(
routertypes.ModuleName,
airdroptypes.ModuleName,
wasm.ModuleName,
intertxtypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -764,7 +768,10 @@ func NewTeritoriApp(

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.scopedWasmKeeper = scopedWasmKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedInterTxKeeper = scopedInterTxKeeper
app.ScopedWasmKeeper = scopedWasmKeeper

return app
}
Expand Down Expand Up @@ -896,6 +903,31 @@ func (app *TeritoriApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// GetBaseApp implements the BaseApp
func (app *TeritoriApp) GetBaseApp() *baseapp.BaseApp {
return app.BaseApp
}

// GetBaseApp implements the StakingKeeper
func (app *TeritoriApp) GetStakingKeeper() stakingkeeper.Keeper {
return app.StakingKeeper
}

// GetBaseApp implements the StakingKeeper
func (app *TeritoriApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetBaseApp implements the StakingKeeper
func (app *TeritoriApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.ScopedIBCKeeper
}

// GetBaseApp implements the StakingKeeper
func (app *TeritoriApp) GetTxConfig() client.TxConfig {
return MakeEncodingConfig().TxConfig
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down Expand Up @@ -933,18 +965,38 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(routertypes.ModuleName).WithKeyTable(routertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(airdroptypes.ModuleName)

return paramsKeeper
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
func (app *TeritoriApp) setupUpgradeStoreLoaders() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
}
}

func (app *TeritoriApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
app.configurator,
app.AppKeepers,
),
)
}
Expand Down
67 changes: 67 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package keepers

import (
airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper"
mintkeeper "github.com/TERITORI/teritori-chain/x/mint/keeper"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
icacontrollerkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

intertxkeeper "github.com/TERITORI/teritori-chain/x/intertx/keeper"

routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v2/router/keeper"

"github.com/CosmWasm/wasmd/x/wasm"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)

type AppKeepers struct {
// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ICAHostKeeper icahostkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
RouterKeeper routerkeeper.Keeper
AirdropKeeper airdropkeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
InterTxKeeper intertxkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedInterTxKeeper capabilitykeeper.ScopedKeeper

WasmKeeper wasm.Keeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
}
Loading