Skip to content

Commit

Permalink
Merge pull request onomyprotocol#171 from decentrio/remove_ics
Browse files Browse the repository at this point in the history
refactor: Remove ics
  • Loading branch information
vuong177 authored Sep 9, 2024
2 parents 66de4c1 + 213eb92 commit 4139929
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 90 deletions.
103 changes: 13 additions & 90 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,8 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

ibcprovider "github.com/cosmos/interchain-security/x/ccv/provider"
ibcproviderclient "github.com/cosmos/interchain-security/x/ccv/provider/client"
ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"

"github.com/onomyprotocol/onomy/app/upgrades"
v1_0_1 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.1"
v1_0_3 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.3"
v1_0_3_4 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.3.4"
v1_0_3_5 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.3.5"
v1_1_1 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.1"
v1_1_2 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.2"
v1_1_4 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.4"
v1_1_5 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.5"
v1_1_5_fix "github.com/onomyprotocol/onomy/app/upgrades/v1.1.5-fix"
v1_1_6 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.6"
"github.com/onomyprotocol/onomy/docs"
"github.com/onomyprotocol/onomy/x/dao"
daoclient "github.com/onomyprotocol/onomy/x/dao/client"
Expand All @@ -136,9 +123,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
ibcclientclient.UpgradeProposalHandler,
daoclient.FundTreasuryProposalHandler,
daoclient.ExchangeWithTreasuryProposalProposalHandler,
ibcproviderclient.ConsumerAdditionProposalHandler,
ibcproviderclient.ConsumerRemovalProposalHandler,
ibcproviderclient.EquivocationProposalHandler,
)

return govProposalHandlers
Expand Down Expand Up @@ -171,20 +155,18 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
dao.AppModuleBasic{},
ibcprovider.AppModuleBasic{},
)

// module account permissions.
maccPerms = map[string][]string{ // nolint:gochecknoglobals // cosmos-sdk application style
authtypes.FeeCollectorName: nil,
daotypes.ModuleName: {authtypes.Minter},
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
providertypes.ConsumerRewardsPool: nil,
authtypes.FeeCollectorName: nil,
daotypes.ModuleName: {authtypes.Minter},
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

// module accounts that are allowed to receive tokens.
Expand Down Expand Up @@ -252,7 +234,6 @@ type OnomyApp struct {
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ProviderKeeper ibcproviderkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -296,7 +277,6 @@ func New( // nolint:funlen // app new cosmos func
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey,
providertypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand All @@ -323,7 +303,6 @@ func New( // nolint:funlen // app new cosmos func
// grant capabilities for the ibc and ibc-transfer modules
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedIBCProviderKeeper := app.CapabilityKeeper.ScopeToModule(providertypes.ModuleName)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -406,7 +385,6 @@ func New( // nolint:funlen // app new cosmos func
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.ProviderKeeper.Hooks(),
),
)

Expand All @@ -417,29 +395,9 @@ func New( // nolint:funlen // app new cosmos func
}
})

app.ProviderKeeper = ibcproviderkeeper.NewKeeper(
appCodec,
keys[providertypes.StoreKey],
app.GetSubspace(providertypes.ModuleName),
scopedIBCProviderKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ClientKeeper,
app.StakingKeeper,
app.SlashingKeeper,
app.AccountKeeper,
app.EvidenceKeeper,
app.DistrKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
)
providerModule := ibcprovider.NewAppModule(&app.ProviderKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule)
ibcRouter.AddRoute(providertypes.ModuleName, providerModule)
app.IBCKeeper.SetRouter(ibcRouter)

// register the proposal types
Expand All @@ -449,8 +407,7 @@ func New( // nolint:funlen // app new cosmos func
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(daotypes.RouterKey, dao.NewProposalHandler(app.DaoKeeper)).
AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(app.ProviderKeeper))
AddRoute(daotypes.RouterKey, dao.NewProposalHandler(app.DaoKeeper))

app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand Down Expand Up @@ -489,7 +446,6 @@ func New( // nolint:funlen // app new cosmos func
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
transferModule,
dao.NewAppModule(appCodec, app.DaoKeeper),
providerModule,
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -516,7 +472,6 @@ func New( // nolint:funlen // app new cosmos func
vestingtypes.ModuleName,
feegrant.ModuleName,
daotypes.ModuleName,
providertypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
upgradetypes.ModuleName,
Expand All @@ -538,7 +493,6 @@ func New( // nolint:funlen // app new cosmos func
vestingtypes.ModuleName,
feegrant.ModuleName,
daotypes.ModuleName,
providertypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -566,7 +520,6 @@ func New( // nolint:funlen // app new cosmos func
vestingtypes.ModuleName,
feegrant.ModuleName,
daotypes.ModuleName,
providertypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -623,7 +576,6 @@ func New( // nolint:funlen // app new cosmos func
app.SetEndBlocker(app.EndBlocker)

app.setupUpgradeHandlers()
app.SetupForkLogic(v1_1_5_fix.CreateFork(&app.StakingKeeper, &app.ProviderKeeper, keys[providertypes.StoreKey]))

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand All @@ -633,7 +585,6 @@ func New( // nolint:funlen // app new cosmos func

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedIBCProviderKeeper = scopedIBCProviderKeeper

return app
}
Expand Down Expand Up @@ -692,9 +643,6 @@ func (app *OnomyApp) BlockedAddrs() map[string]bool {
blockedAddrs[authtypes.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
}

// For ICS multiden fix
delete(blockedAddrs, authtypes.NewModuleAddress(providertypes.ConsumerRewardsPool).String())

return blockedAddrs
}

Expand Down Expand Up @@ -803,7 +751,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(daotypes.ModuleName)
paramsKeeper.Subspace(providertypes.ModuleName)

return paramsKeeper
}
Expand All @@ -814,27 +761,7 @@ func (app *OnomyApp) SimulationManager() *module.SimulationManager {
}

func (app *OnomyApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(v1_0_1.Name, v1_0_1.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v1_0_3.Name, v1_0_3.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v1_0_3_4.Name, v1_0_3_4.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v1_0_3_5.Name, v1_0_3_5.UpgradeHandler)
// we need to have the reference to `app` which is why we need this `func` here
app.UpgradeKeeper.SetUpgradeHandler(
v1_1_1.Name,
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
for moduleName, eachModule := range app.mm.Modules {
fromVM[moduleName] = eachModule.ConsensusVersion()
}

// This is critical for the chain upgrade to work
app.ProviderKeeper.InitGenesis(ctx, providertypes.DefaultGenesisState())

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
app.UpgradeKeeper.SetUpgradeHandler(v1_1_2.Name, v1_1_2.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v1_1_4.Name, v1_1_4.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v1_1_5.Name, v1_1_5.CreateUpgradeHandler(app.mm, app.configurator, &app.AccountKeeper, &app.BankKeeper, &app.StakingKeeper))
app.UpgradeKeeper.SetUpgradeHandler(v1_1_6.Name, v1_1_6.UpgradeHandler)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
Expand All @@ -849,13 +776,9 @@ func (app *OnomyApp) setupUpgradeHandlers() {
var storeUpgrades *storetypes.StoreUpgrades

switch upgradeInfo.Name {
case v1_1_1.Name:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{providertypes.ModuleName, providertypes.StoreKey},
}
case v1_1_4.Name:
case v1_1_6.Name:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{authz.ModuleName, authzkeeper.StoreKey},
Deleted: []string{"provider"},
}
default:
// no store upgrades
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v1.1.6/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package v1_1_6 //nolint:revive,stylecheck // app version

const Name = "v1.1.6"
12 changes: 12 additions & 0 deletions app/upgrades/v1.1.6/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v1_1_6 //nolint:revive,stylecheck // app version

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// UpgradeHandler is an x/upgrade handler.
func UpgradeHandler(_ sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
}

0 comments on commit 4139929

Please sign in to comment.