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

feat: add upgrade handler #2

Closed
wants to merge 18 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.vscode
init-root.sh
build
_build
62 changes: 62 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package app

import (
"github.com/CudoVentures/cudos-node/app/decorators"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
type HandlerOptions struct {
ante.HandlerOptions

BankViewKeeper bankkeeper.ViewKeeper
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

if options.BankViewKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank view keeper is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
decorators.NewMinSelfDelegationDecorator(),
decorators.NewOnlyAdminVerifyInvariantDecorator(options.BankViewKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
}
31 changes: 13 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"

// vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/bank"
custombank "github.com/CudoVentures/cudos-node/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -67,9 +67,6 @@ import (

"github.com/CudoVentures/cudos-node/x/cudoMint"
cudominttypes "github.com/CudoVentures/cudos-node/x/cudoMint/types"

"github.com/cosmos/cosmos-sdk/x/group"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
)

const Name = "cudos-node"
Expand All @@ -86,7 +83,7 @@ var (
func init() {
cudosHome, present := os.LookupEnv("CUDOS_HOME")
if !present {
userHomeDir, err := os.Getwd()
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -133,7 +130,6 @@ func New(
wasm.StoreKey,
gravitytypes.StoreKey,
feegrant.StoreKey,
group.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -174,7 +170,7 @@ func New(
genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, encodingConfig.TxConfig),
auth.NewAppModule(appCodec, app.AccountKeeper, nil),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
custombank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper, cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
Expand All @@ -192,7 +188,6 @@ func New(
gravity.NewAppModule(app.GravityKeeper, app.BankKeeper),
feegrantmod.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.feegrantKeeper, app.interfaceRegistry),
// this line is used by starport scaffolding # stargate/app/appModule
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -220,7 +215,6 @@ func New(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
wasmtypes.ModuleName,
group.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -244,7 +238,6 @@ func New(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
wasmtypes.ModuleName,
group.ModuleName,
)
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand Down Expand Up @@ -277,20 +270,22 @@ func New(
feegrant.ModuleName,
upgradetypes.ModuleName,
paramstypes.ModuleName,
group.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterServices(app.configurator)

anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.feegrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.feegrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
BankViewKeeper: app.BankKeeper,
},
)
if err != nil {
Expand Down
11 changes: 2 additions & 9 deletions app/app_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/group"
abci "github.com/tendermint/tendermint/abci/types"

// Authz - Authorization for accounts to perform actions on behalf of other accounts.
Expand All @@ -36,7 +35,7 @@ import (

// vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
custombankkeeper "github.com/CudoVentures/cudos-node/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
Expand Down Expand Up @@ -85,9 +84,6 @@ import (
"github.com/althea-net/cosmos-gravity-bridge/module/x/gravity"
gravitykeeper "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/keeper"
gravitytypes "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/types"

groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
)

// We pull these out so we can set them with LDFLAGS in the Makefile
Expand Down Expand Up @@ -149,7 +145,6 @@ var (
gravity.AppModuleBasic{},
feegrantmod.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
groupmodule.AppModuleBasic{},
)

maccPerms = map[string][]string{
Expand Down Expand Up @@ -191,7 +186,7 @@ type App struct {
// keepers
AccountKeeper authkeeper.AccountKeeper
AuthzKeeper authzkeeper.Keeper
BankKeeper bankkeeper.Keeper
BankKeeper custombankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
Expand All @@ -213,7 +208,6 @@ type App struct {
feegrantKeeper feegrantkeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

GroupKeeper groupkeeper.Keeper
// the module manager
mm *module.Manager
configurator module.Configurator
Expand Down Expand Up @@ -369,7 +363,6 @@ func InitParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(gravitytypes.ModuleName)
paramsKeeper.Subspace(authz.ModuleName)
paramsKeeper.Subspace(feegrant.ModuleName)
paramsKeeper.Subspace(group.ModuleName)

return paramsKeeper
}
15 changes: 2 additions & 13 deletions app/app_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"

bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
custombankkeeper "github.com/CudoVentures/cudos-node/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -55,9 +55,6 @@ import (

gravitykeeper "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/keeper"
gravitytypes "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/types"

"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
)

func (app *App) AddKeepers(skipUpgradeHeights map[int64]bool, homePath string, appOpts servertypes.AppOptions) {
Expand Down Expand Up @@ -86,7 +83,7 @@ func (app *App) AddKeepers(skipUpgradeHeights map[int64]bool, homePath string, a

app.AuthzKeeper = authzkeeper.NewKeeper(app.keys[authzkeeper.StoreKey], app.appCodec, app.BaseApp.MsgServiceRouter())

bankKeeper := bankkeeper.NewBaseKeeper(
bankKeeper := custombankkeeper.NewCustomKeeper(
app.appCodec, app.keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
)
stakingKeeper := stakingkeeper.NewKeeper(
Expand Down Expand Up @@ -203,12 +200,4 @@ func (app *App) AddKeepers(skipUpgradeHeights map[int64]bool, homePath string, a
app.appCodec, app.keys[gravitytypes.StoreKey], app.GetSubspace(gravitytypes.ModuleName), stakingKeeper, app.BankKeeper, app.SlashingKeeper, app.AccountKeeper,
)

groupConfig := group.DefaultConfig()
app.GroupKeeper = groupkeeper.NewKeeper(
app.keys[group.StoreKey],
app.appCodec,
app.MsgServiceRouter(),
app.AccountKeeper,
groupConfig,
)
}
34 changes: 31 additions & 3 deletions app/app_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/group"

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

const AddressBookModuleName = "addressbook"
const NftModuleName = "nft"
const MarketplaceModuleName = "marketplace"
const GroupModuleName = "group"

func (app *App) SetUpgradeHandlers() {
setHandlerForVersion_1_0(app)
setHandlerForVersion_1_1(app)
setHandlerForVersion_1_2(app)
}

func setHandlerForVersion_1_0(app *App) {
Expand Down Expand Up @@ -47,7 +48,7 @@ func setHandlerForVersion_1_1(app *App) {
if len(fromVM) == 0 {
fromVM = app.mm.GetVersionMap()
delete(fromVM, authz.ModuleName)
delete(fromVM, group.ModuleName)
delete(fromVM, GroupModuleName)
delete(fromVM, AddressBookModuleName)
delete(fromVM, MarketplaceModuleName)

Expand All @@ -70,7 +71,34 @@ func setHandlerForVersion_1_1(app *App) {

if upgradeInfo.Name == upgradeVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{authz.ModuleName, group.ModuleName, AddressBookModuleName, MarketplaceModuleName},
Added: []string{authz.ModuleName, GroupModuleName, AddressBookModuleName, MarketplaceModuleName},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

func setHandlerForVersion_1_2(app *App) {
const upgradeVersion string = "v1.2"

app.UpgradeKeeper.SetUpgradeHandler(upgradeVersion, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == upgradeVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{},
Deleted: []string{
AddressBookModuleName,
MarketplaceModuleName,
NftModuleName,
GroupModuleName,
},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Expand Down
Loading