Skip to content

Commit

Permalink
merge Remove ics #171 and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Sep 24, 2024
1 parent fa742bf commit 34857ac
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 79 deletions.
12 changes: 4 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
// "context"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -46,7 +45,6 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
// authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
"github.com/cosmos/cosmos-sdk/x/crisis"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand All @@ -55,7 +53,6 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
"github.com/spf13/cast"

"github.com/onomyprotocol/onomy/app/keepers"
Expand Down Expand Up @@ -376,9 +373,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 @@ -465,7 +459,7 @@ func (app *OnomyApp) SimulationManager() *module.SimulationManager {

func (app *OnomyApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(v1_1_6.Name, v1_1_6.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v2_0_0.Name, v2_0_0.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v2_0_0.Name, v2_0_0.CreateUpgradeHandler(app.mm, app.configurator, &app.AppKeepers))

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
Expand All @@ -485,7 +479,9 @@ func (app *OnomyApp) setupUpgradeHandlers() {
Deleted: []string{"provider"},
}
case v2_0_0.Name:
// no store upgrades.
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{"consensus", "crisis", "dao"},
}
default:
// no store upgrades.
}
Expand Down
46 changes: 2 additions & 44 deletions app/keepers/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ import (
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
icsprovider "github.com/cosmos/interchain-security/v5/x/ccv/provider"
icsproviderkeeper "github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

"github.com/onomyprotocol/onomy/x/dao"
daokeeper "github.com/onomyprotocol/onomy/x/dao/keeper"
Expand Down Expand Up @@ -87,7 +85,6 @@ type AppKeepers struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
ProviderKeeper icsproviderkeeper.Keeper

// make scoped keepers public for test purposes.
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -96,7 +93,6 @@ type AppKeepers struct {

// Modules.
TransferModule transfer.AppModule
ProviderModule icsprovider.AppModule

DaoKeeper daokeeper.Keeper
}
Expand Down Expand Up @@ -155,7 +151,6 @@ func NewAppKeeper(

appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedICSproviderkeeper = appKeepers.CapabilityKeeper.ScopeToModule(providertypes.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 @@ -238,7 +233,6 @@ func NewAppKeeper(
stakingtypes.NewMultiStakingHooks(
appKeepers.DistrKeeper.Hooks(),
appKeepers.SlashingKeeper.Hooks(),
appKeepers.ProviderKeeper.Hooks(),
),
)

Expand Down Expand Up @@ -269,27 +263,6 @@ func NewAppKeeper(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.ProviderKeeper = icsproviderkeeper.NewKeeper(
appCodec,
appKeepers.keys[providertypes.StoreKey],
appKeepers.GetSubspace(providertypes.ModuleName),
appKeepers.ScopedICSproviderkeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.IBCKeeper.PortKeeper,
appKeepers.IBCKeeper.ConnectionKeeper,
appKeepers.IBCKeeper.ClientKeeper,
appKeepers.StakingKeeper,
appKeepers.SlashingKeeper,
appKeepers.AccountKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
govkeeper.Keeper{},
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
authtypes.FeeCollectorName,
)

// gov depends on provider, so needs to be set after.
govConfig := govtypes.DefaultConfig()
// set the MaxMetadataLen for proposals to the same value as it was pre-sdk v0.47.x.
Expand Down Expand Up @@ -320,17 +293,9 @@ func NewAppKeeper(
)
ibcmodule := transfer.NewIBCModule(appKeepers.TransferKeeper)

// appKeepers.ProviderKeeper.SetGovKeeper(*appKeepers.GovKeeper).

appKeepers.ProviderModule = icsprovider.NewAppModule(
&appKeepers.ProviderKeeper,
appKeepers.GetSubspace(providertypes.ModuleName),
)

// Create static IBC router, add transfer route, then set and seal it.
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule)
ibcRouter.AddRoute(providertypes.ModuleName, appKeepers.ProviderModule)
appKeepers.IBCKeeper.SetRouter(ibcRouter)
// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
Expand All @@ -341,17 +306,11 @@ func NewAppKeeper(
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)).
AddRoute(daotypes.RouterKey, dao.NewProposalHandler(appKeepers.DaoKeeper)).
AddRoute(providertypes.RouterKey, icsprovider.NewProviderProposalHandler(appKeepers.ProviderKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper))

// Set legacy router for backwards compatibility with gov v1beta1.
appKeepers.GovKeeper.SetLegacyRouter(govRouter)

appKeepers.GovKeeper = appKeepers.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
appKeepers.ProviderKeeper.Hooks(),
),
)

evidenceKeeper := evidencekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[evidencetypes.StoreKey]),
Expand Down Expand Up @@ -420,7 +379,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) //nolint: staticcheck // SA1019
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(providertypes.ModuleName).WithKeyTable(providertypes.ParamKeyTable())
paramsKeeper.Subspace(daotypes.ModuleName)

return paramsKeeper
Expand Down
2 changes: 0 additions & 2 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

daotypes "github.com/onomyprotocol/onomy/x/dao/types"
)
Expand All @@ -44,7 +43,6 @@ func (appKeepers *AppKeepers) GenerateKeys() {
capabilitytypes.StoreKey,
feegrant.StoreKey,
authzkeeper.StoreKey,
providertypes.StoreKey,
daotypes.StoreKey,
consensusparamtypes.StoreKey,
)
Expand Down
30 changes: 11 additions & 19 deletions app/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

"github.com/onomyprotocol/onomy/x/dao"
daotypes "github.com/onomyprotocol/onomy/x/dao/types"
Expand All @@ -54,22 +53,20 @@ import (
var (
// 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.
allowedReceivingModAcc = map[string]bool{ //nolint:gochecknoglobals // cosmos-sdk application style
distrtypes.ModuleName: true,
daotypes.ModuleName: true,
// provider chain note: the fee-pool is allowed to receive tokens.
distrtypes.ModuleName: true,
daotypes.ModuleName: true,
authtypes.FeeCollectorName: true,
}
)
Expand All @@ -95,12 +92,12 @@ func appModules(
evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
ibctm.NewAppModule(),
sdkparams.NewAppModule(app.ParamsKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app, txConfig),
app.ProviderModule,
app.TransferModule,
// and.
}
Expand Down Expand Up @@ -144,7 +141,6 @@ func orderBeginBlockers() []string {
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
providertypes.ModuleName,
daotypes.ModuleName,
}
}
Expand All @@ -170,8 +166,6 @@ func orderEndBlockers() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
providertypes.ModuleName,
// and.
daotypes.ModuleName,
}
}
Expand All @@ -197,7 +191,6 @@ func orderInitBlockers() []string {
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
crisistypes.ModuleName,
providertypes.ModuleName,
daotypes.ModuleName,
}
}
Expand All @@ -222,7 +215,6 @@ func simulationModules(
evidence.NewAppModule(app.EvidenceKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
app.ProviderModule,
app.TransferModule,
}
}
66 changes: 64 additions & 2 deletions app/upgrades/v2.0.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,76 @@ package v1_1_4 //nolint:revive,stylecheck // app version
import (
"context"

"cosmossdk.io/math"
upgradetypes "cosmossdk.io/x/upgrade/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"

"github.com/onomyprotocol/onomy/app/keepers"
)

// Name is migration name.
const Name = "v2.0.0"

// UpgradeHandler is an x/upgrade handler.
func UpgradeHandler(_ context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {

return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

err = InitializeConsensusParamVersion(ctx, keepers.ConsensusParamsKeeper)
if err != nil {
// don't hard fail here, as this is not critical for the upgrade to succeed
ctx.Logger().Error("Error initializing ConsensusParam Version:", "message", err.Error())
}

err = collectionsInitializeMintParam(ctx, keepers.MintKeeper)
if err != nil {
// don't hard fail here, as this is not critical for the upgrade to succeed
ctx.Logger().Error("Error initializing mint params:", "message", err.Error())
}
return vm, nil
}
}

func InitializeConsensusParamVersion(ctx sdk.Context, consensusKeeper consensusparamkeeper.Keeper) error {
params, err := consensusKeeper.ParamsStore.Get(ctx)
if err != nil {
return err
}
params.Version = &cmtproto.VersionParams{}
return consensusKeeper.ParamsStore.Set(ctx, params)
}

// ######### Here are all the params mint from mainnet
// # blocks_per_year: "6311520"
// # goal_bonded: "0.670000000000000000"
// # inflation_max: "0.200000000000000000"
// # inflation_min: "0.070000000000000000"
// # inflation_rate_change: "0.130000000000000000"
// # mint_denom: anom
func collectionsInitializeMintParam(ctx sdk.Context, mintKeeper mintkeeper.Keeper) error {
params, err := mintKeeper.Params.Get(ctx)
if err != nil {
return err
}
params.BlocksPerYear = 6311520
params.GoalBonded = math.LegacyMustNewDecFromStr("0.670000000000000000")
params.InflationMax = math.LegacyMustNewDecFromStr("0.20000000000000000")
params.InflationMin = math.LegacyMustNewDecFromStr("0.070000000000000000")
params.InflationRateChange = math.LegacyMustNewDecFromStr("0.130000000000000000")
params.MintDenom = "anom"
return mintKeeper.Params.Set(ctx, params)
}
Loading

0 comments on commit 34857ac

Please sign in to comment.