Skip to content

Commit

Permalink
chore(app): finalise upgrade v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Ixo committed Oct 17, 2024
1 parent da66855 commit 652d86e
Show file tree
Hide file tree
Showing 41 changed files with 6,834 additions and 1,814 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_STORE
# docker-compose volume mapping for chain config and data
.data
.data2
.data3

# Created by https://www.toptal.com/developers/gitignore/api/intellij,vscode,macos,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,vscode,macos,windows
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/ixofoundation/ixo-blockchain/v3/app/upgrades"
v2 "github.com/ixofoundation/ixo-blockchain/v3/app/upgrades/v2"
v3 "github.com/ixofoundation/ixo-blockchain/v3/app/upgrades/v3"
v4 "github.com/ixofoundation/ixo-blockchain/v3/app/upgrades/v4"
"github.com/ixofoundation/ixo-blockchain/v3/docs"
"github.com/ixofoundation/ixo-blockchain/v3/lib/ixo"
"github.com/spf13/cast"
Expand All @@ -66,7 +67,7 @@ var (
maccPerms = moduleAccountPermissions

// scheduled upgrades and forks
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade}
Forks = []upgrades.Fork{}

// EmptyWasmOpts defines a type alias for a list of wasm options.
Expand Down Expand Up @@ -544,7 +545,7 @@ func (app *IxoApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(app.ModuleManager, app.configurator),
upgrade.CreateUpgradeHandler(app.ModuleManager, app.configurator, app.AppKeepers),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func appModules(
bonds.NewAppModule(app.BondsKeeper),
entitymodule.NewAppModule(app.EntityKeeper),
tokenmodule.NewAppModule(app.TokenKeeper),
claimsmodule.NewAppModule(app.ClaimsKeeper),
claimsmodule.NewAppModule(app.ClaimsKeeper, app.GetSubspace(claimsmoduletypes.ModuleName)),
smartaccount.NewAppModule(*app.SmartAccountKeeper),
epochs.NewAppModule(*app.EpochsKeeper),
}
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/ixofoundation/ixo-blockchain/v3/app/keepers"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
Expand All @@ -16,7 +17,7 @@ type Upgrade struct {
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator) upgradetypes.UpgradeHandler
CreateUpgradeHandler func(*module.Manager, module.Configurator, keepers.AppKeepers) upgradetypes.UpgradeHandler

// used for any new modules introduced, new modules deleted, or store names renamed
StoreUpgrades store.StoreUpgrades
Expand Down
25 changes: 2 additions & 23 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/ixofoundation/ixo-blockchain/v3/app/keepers"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(context context.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(context)
Expand Down Expand Up @@ -50,29 +52,6 @@ func CreateUpgradeHandler(

// Run migrations before applying any other state changes.
migrations, err := mm.RunMigrations(ctx, configurator, fromVM)

// ctx.Logger().Info("set ICQKeeper params")
// setICQParams(ctx, keepers.ICQKeeper)

// ctx.Logger().Info("update ICAHostKeeper params to allow all messages")
// setICAHostParams(ctx, &keepers.ICAHostKeeper)

return migrations, err
}
}

// TODO pass keepers through with cosmos sdk upgrade and implement this, not needed for now
// func setICQParams(ctx sdk.Context, icqKeeper *icqkeeper.Keeper) {
// icqparams := icqtypes.DefaultParams()
// icqparams.AllowQueries = wasmbinding.GetStargateWhitelistedPaths()
// // Adding SmartContractState query to allowlist
// icqparams.AllowQueries = append(icqparams.AllowQueries, "/cosmwasm.wasm.v1.Query/SmartContractState")
// icqKeeper.SetParams(ctx, icqparams)
// }

// func setICAHostParams(ctx sdk.Context, icahostkeeper *icahostkeeper.Keeper) {
// icahostkeeper.SetParams(ctx, icahosttypes.Params{
// HostEnabled: true,
// AllowMessages: []string{"*"},
// })
// }
2 changes: 2 additions & 0 deletions app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/ixofoundation/ixo-blockchain/v3/app/keepers"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(context context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(context)
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# v4

v4 release changes is available [here](https://github.com/ixofoundation/ixo-blockchain/releases/tag/v4.0.0).
56 changes: 56 additions & 0 deletions app/upgrades/v4/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package v4

import (
store "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
cosmosminttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types"
"github.com/ixofoundation/ixo-blockchain/v3/app/upgrades"
epochstypes "github.com/ixofoundation/ixo-blockchain/v3/x/epochs/types"
minttypes "github.com/ixofoundation/ixo-blockchain/v3/x/mint/types"
smartaccounttypes "github.com/ixofoundation/ixo-blockchain/v3/x/smart-account/types"
)

// UpgradeName defines the on-chain upgrade name for the Ixo v4 upgrade.
const (
UpgradeName = "v4"

// BlockMaxBytes is the max bytes for a block, 10mb (current 22020096)
BlockMaxBytes = int64(10000000)
// BlockMaxGas is the max gas allowed in a block (current 200000000)
BlockMaxGas = int64(300000000)

// Normal proposal deposit is 10k ixo, make expedited proposal deposit 3x
ExpeditedProposalDeposit = 30000000000
MinInitialDepositRatio = "0.100000000000000000"

// MaximumUnauthenticatedGas for smart account transactions to verify the fee payer
MaximumUnauthenticatedGas = uint64(250_000)
// IsSmartAccountActive is used for the smart account circuit breaker, smartaccounts are activated for v4
IsSmartAccountActive = false
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
smartaccounttypes.StoreKey,
minttypes.StoreKey,
epochstypes.StoreKey,
ibchooks.StoreKey,
// Add circuittypes as per 0.47 to 0.50 upgrade handler
// https://github.com/cosmos/cosmos-sdk/blob/b7d9d4c8a9b6b8b61716d2023982d29bdc9839a6/simapp/upgrades.go#L21
circuittypes.ModuleName,
// v47 modules
crisistypes.ModuleName,
consensustypes.ModuleName,
},
Deleted: []string{
cosmosminttypes.StoreKey,
"intertx", // uninstalled module
},
},
}
214 changes: 214 additions & 0 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
package v4

import (
"context"

wasmv2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v8/types"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"

// Local
"github.com/ixofoundation/ixo-blockchain/v3/app/keepers"
"github.com/ixofoundation/ixo-blockchain/v3/lib/ixo"
"github.com/ixofoundation/ixo-blockchain/v3/wasmbinding"
bondstypes "github.com/ixofoundation/ixo-blockchain/v3/x/bonds/types"
claimsmoduletypes "github.com/ixofoundation/ixo-blockchain/v3/x/claims/types"
entitytypes "github.com/ixofoundation/ixo-blockchain/v3/x/entity/types"
smartaccounttypes "github.com/ixofoundation/ixo-blockchain/v3/x/smart-account/types"
tokentypes "github.com/ixofoundation/ixo-blockchain/v3/x/token/types"

// SDK v47 modules
"cosmossdk.io/math"
upgradetypes "cosmossdk.io/x/upgrade/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(context context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(context)
ctx.Logger().Info("🚀 executing Ixo " + UpgradeName + "upgrade 🚀")

// -------------------------------------------------
// Migrate Params
// -------------------------------------------------
ctx.Logger().Info("Migrate params")
baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
// https://github.com/cosmos/cosmos-sdk/pull/12363/files
// Set param key table for params module migration
for _, subspace := range keepers.ParamsKeeper.GetSubspaces() {
subspace := subspace

var keyTable paramstypes.KeyTable
switch subspace.Name() {
// sdk
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
case slashingtypes.ModuleName:
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
case govtypes.ModuleName:
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck

// ibc types
case ibcexported.ModuleName:
keyTable = ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck
case icacontrollertypes.SubModuleName:
keyTable = icacontrollertypes.ParamKeyTable() //nolint:staticcheck
case icqtypes.ModuleName:
keyTable = icqtypes.ParamKeyTable() //nolint:staticcheck
case packetforwardtypes.ModuleName:
keyTable = packetforwardtypes.ParamKeyTable() //nolint:staticcheck
// case ibchookstypes.ModuleName:
// keyTable = ibchookstypes.ParamKeyTable() //nolint:staticcheck

// wasm
case wasmtypes.ModuleName:
keyTable = wasmv2.ParamKeyTable() //nolint:staticcheck

// ixo modules
case bondstypes.ModuleName:
keyTable = bondstypes.ParamKeyTable() //nolint:staticcheck
case claimsmoduletypes.ModuleName:
keyTable = claimsmoduletypes.ParamKeyTable() //nolint:staticcheck
case entitytypes.ModuleName:
keyTable = entitytypes.ParamKeyTable() //nolint:staticcheck
// epochs doesn't have params
// iidtypes doesn't have params
case tokentypes.ModuleName:
keyTable = tokentypes.ParamKeyTable() //nolint:staticcheck
case smartaccounttypes.ModuleName:
keyTable = smartaccounttypes.ParamKeyTable() //nolint:staticcheck

default:
continue
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}

// Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module.
// The old params module is required to still be imported in your app.go in order to handle this migration.
err := baseapp.MigrateParams(ctx, baseAppLegacySS, keepers.ConsensusParamsKeeper.ParamsStore)
if err != nil {
return nil, err
}

// Remove "mint" from fromVM since have custom mint module and want to run init genesis for it
delete(fromVM, minttypes.ModuleName)

// -------------------------------------------------
// Run migrations before applying any other state changes.
// NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations().
// -------------------------------------------------
ctx.Logger().Info("Run migrations")
migrations, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}

// -------------------------------------------------
// Set proposal param:
// -------------------------------------------------
ctx.Logger().Info("Set expedited proposal params")
govParams, err := keepers.GovKeeper.Params.Get(ctx)
if err != nil {
return nil, err
}
// normal proposal deposit is 10k ixo, make expedited proposal deposit 3x
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewCoin(ixo.IxoNativeToken, math.NewInt(ExpeditedProposalDeposit)))
govParams.MinInitialDepositRatio = MinInitialDepositRatio
err = keepers.GovKeeper.Params.Set(ctx, govParams)
if err != nil {
return nil, err
}

// -------------------------------------------------
// Set consensus params:
// -------------------------------------------------
ctx.Logger().Info("Set consensus params")
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
defaultConsensusParams.Block.MaxBytes = BlockMaxBytes // previously 5000000
defaultConsensusParams.Block.MaxGas = BlockMaxGas // unchanged
err = keepers.ConsensusParamsKeeper.ParamsStore.Set(ctx, defaultConsensusParams)
if err != nil {
return nil, err
}

// -------------------------------------------------
// Set the authenticator params in the store
// -------------------------------------------------
ctx.Logger().Info("Set authenticator params")
authenticatorParams := keepers.SmartAccountKeeper.GetParams(ctx)
authenticatorParams.MaximumUnauthenticatedGas = MaximumUnauthenticatedGas
authenticatorParams.IsSmartAccountActive = IsSmartAccountActive
keepers.SmartAccountKeeper.SetParams(ctx, authenticatorParams)

// -------------------------------------------------
// Set the ICQ params in the store
// -------------------------------------------------
ctx.Logger().Info("Set ICQKeeper params")
icqparams := icqtypes.DefaultParams()
icqparams.AllowQueries = wasmbinding.GetStargateWhitelistedPaths()
// Adding SmartContractState query to allowlist
icqparams.AllowQueries = append(icqparams.AllowQueries, "/cosmwasm.wasm.v1.Query/SmartContractState")
err = keepers.ICQKeeper.SetParams(ctx, icqparams)
if err != nil {
return nil, err
}

// -------------------------------------------------
// Set the ICA Host params in the store
// -------------------------------------------------
ctx.Logger().Info("Set ICAHostKeeper params")
// Allow all messages
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{"*"},
}
keepers.ICAHostKeeper.SetParams(ctx, hostParams)

return migrations, nil
}
}
Loading

0 comments on commit 652d86e

Please sign in to comment.