Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/irisnet/irishub into upda…
Browse files Browse the repository at this point in the history
…te-changelog
  • Loading branch information
Dreamer committed Mar 25, 2024
2 parents dbc0b1f + 9b4c8d7 commit fbb82d1
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 1,292 deletions.
93 changes: 36 additions & 57 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tokentypes "github.com/irisnet/irismod/modules/token/types"
"github.com/stretchr/testify/require"

"github.com/irisnet/irishub/v3/app/params"
iristypes "github.com/irisnet/irishub/v3/types"

dbm "github.com/cometbft/cometbft-db"
Expand Down Expand Up @@ -98,15 +99,7 @@ func TestFullAppSimulation(t *testing.T) {

encfg := RegisterEncodingConfig()

app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
app := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", app.Name())

// run randomized simulation
Expand Down Expand Up @@ -136,6 +129,8 @@ func TestAppImportExport(t *testing.T) {
config := simcli.NewConfigFromFlags()
config.ChainID = AppChainID

sdk.DefaultBondDenom = iristypes.NativeToken.Symbol

db, dir, logger, skip, err := simtestutil.SetupSimulation(
config,
"goleveldb-app-sim",
Expand All @@ -155,15 +150,7 @@ func TestAppImportExport(t *testing.T) {
}()

encfg := RegisterEncodingConfig()
app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
app := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -209,15 +196,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewIrisApp(
log.NewNopLogger(),
newDB,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
newApp := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", newApp.Name())

var genesisState iristypes.GenesisState
Expand All @@ -244,11 +223,13 @@ func TestAppImportExport(t *testing.T) {

storeKeysPrefixes := []StoreKeysPrefixes{
{app.AppKeepers.KvStoreKeys()[authtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[authtypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey],
{
app.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey],
[][]byte{
stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey,
stakingtypes.HistoricalInfoKey,
}}, // ordering may change but it doesn't matter
},
}, // ordering may change but it doesn't matter
{app.AppKeepers.KvStoreKeys()[slashingtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[slashingtypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[minttypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[minttypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[distrtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[distrtypes.StoreKey], [][]byte{}},
Expand All @@ -267,7 +248,7 @@ func TestAppImportExport(t *testing.T) {
// check irismod module
{app.AppKeepers.KvStoreKeys()[tokentypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[tokentypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[oracletypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[oracletypes.StoreKey], [][]byte{}},
//mt.Supply is InitSupply, can be not equal to TotalSupply
// mt.Supply is InitSupply, can be not equal to TotalSupply
{app.AppKeepers.KvStoreKeys()[mttypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[mttypes.StoreKey], [][]byte{mttypes.PrefixMT}},
{app.AppKeepers.KvStoreKeys()[nfttypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[nfttypes.StoreKey], [][]byte{{0x05}}},
{
Expand Down Expand Up @@ -334,15 +315,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
app := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -393,15 +366,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewIrisApp(
log.NewNopLogger(),
newDB,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
newApp := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand All @@ -428,6 +393,7 @@ func TestAppStateDeterminism(t *testing.T) {
if !simcli.FlagEnabledValue {
t.Skip("skipping application simulation")
}
sdk.DefaultBondDenom = iristypes.NativeToken.Symbol

config := simcli.NewConfigFromFlags()
config.InitialBlockHeight = 1
Expand All @@ -453,15 +419,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
interBlockCacheOpt(),
)
app := createApp(logger, db, encfg, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down Expand Up @@ -516,3 +474,24 @@ type EmptyAppOptions struct{}
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}

func createApp(
logger log.Logger,
db dbm.DB,
encodingConfig params.EncodingConfig,
baseAppOptions ...func(*baseapp.BaseApp),
) *IrisApp {
if baseAppOptions == nil {
baseAppOptions = []func(*baseapp.BaseApp){}
}
baseAppOptions = append(baseAppOptions, baseapp.SetChainID(AppChainID))
return NewIrisApp(
logger,
db,
nil,
true,
encodingConfig,
EmptyAppOptions{},
baseAppOptions...,
)
}
41 changes: 1 addition & 40 deletions app/upgrades/v300/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,5 @@ var (
// the portion of a chain's total stake can be liquid
GlobalLiquidStakingCap = sdk.MustNewDecFromStr("0.25") // 25%

allowMessages = []string{
"/cosmos.authz.v1beta1.MsgExec",
"/cosmos.authz.v1beta1.MsgGrant",
"/cosmos.authz.v1beta1.MsgRevoke",
"/cosmos.bank.v1beta1.MsgSend",
"/cosmos.bank.v1beta1.MsgMultiSend",
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
"/cosmos.feegrant.v1beta1.MsgGrantAllowance",
"/cosmos.feegrant.v1beta1.MsgRevokeAllowance",
"/cosmos.gov.v1beta1.MsgVoteWeighted",
"/cosmos.gov.v1beta1.MsgSubmitProposal",
"/cosmos.gov.v1beta1.MsgDeposit",
"/cosmos.gov.v1beta1.MsgVote",
"/cosmos.gov.v1.MsgVoteWeighted",
"/cosmos.gov.v1.MsgSubmitProposal",
"/cosmos.gov.v1.MsgDeposit",
"/cosmos.gov.v1.MsgVote",
"/cosmos.staking.v1beta1.MsgEditValidator",
"/cosmos.staking.v1beta1.MsgDelegate",
"/cosmos.staking.v1beta1.MsgUndelegate",
"/cosmos.staking.v1beta1.MsgBeginRedelegate",
"/cosmos.staking.v1beta1.MsgCreateValidator",
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount",
"/ibc.applications.transfer.v1.MsgTransfer",
"/irismod.nft.MsgIssueDenom",
"/irismod.nft.MsgTransferDenom",
"/irismod.nft.MsgMintNFT",
"/irismod.nft.MsgEditNFT",
"/irismod.nft.MsgTransferNFT",
"/irismod.nft.MsgBurnNFT",
"/irismod.mt.MsgIssueDenom",
"/irismod.mt.MsgTransferDenom",
"/irismod.mt.MsgMintMT",
"/irismod.mt.MsgEditMT",
"/irismod.mt.MsgTransferMT",
"/irismod.mt.MsgBurnMT",
}
allowMessages = []string{"*"}
)
30 changes: 16 additions & 14 deletions app/upgrades/v300/lsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ type keeper interface {
SetParams(ctx sdk.Context, params types.Params) error
}

// MigrateParamsStore migrates the params store to the latest version.
// migrateParamsStore migrates the params store to the latest version.
//
// ctx - sdk context
// k - keeper
func MigrateParamsStore(ctx sdk.Context, k keeper) {
func migrateParamsStore(ctx sdk.Context, k keeper) error {
params := k.GetParams(ctx)
params.ValidatorBondFactor = ValidatorBondFactor
params.ValidatorLiquidStakingCap = ValidatorLiquidStakingCap
params.GlobalLiquidStakingCap = GlobalLiquidStakingCap
k.SetParams(ctx, params)
return k.SetParams(ctx, params)
}

// MigrateValidators Set each validator's ValidatorBondShares and LiquidShares to 0
func MigrateValidators(ctx sdk.Context, k keeper) {
// migrateValidators Set each validator's ValidatorBondShares and LiquidShares to 0
func migrateValidators(ctx sdk.Context, k keeper) {
for _, validator := range k.GetAllValidators(ctx) {
validator.ValidatorBondShares = sdk.ZeroDec()
validator.LiquidShares = sdk.ZeroDec()
k.SetValidator(ctx, validator)
}
}

// MigrateDelegations Set each delegation's ValidatorBond field to false
func MigrateDelegations(ctx sdk.Context, k keeper) {
// migrateDelegations Set each delegation's ValidatorBond field to false
func migrateDelegations(ctx sdk.Context, k keeper) {
for _, delegation := range k.GetAllDelegations(ctx) {
delegation.ValidatorBond = false
k.SetDelegation(ctx, delegation)
Expand All @@ -52,7 +52,7 @@ func MigrateDelegations(ctx sdk.Context, k keeper) {

// MigrateUBDEntries will remove the ubdEntries with same creation_height
// and create a new ubdEntry with updated balance and initial_balance
func MigrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
func migrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
iterator := sdk.KVStorePrefixIterator(store, types.UnbondingDelegationKey)
defer iterator.Close()

Expand Down Expand Up @@ -108,25 +108,27 @@ func setUBDToStore(_ sdk.Context, store storetypes.KVStore, cdc codec.BinaryCode
store.Set(key, bz)
}

// MigrateStore performs the in-place store migration for adding LSM support to v0.45.16-ics, including:
// migrateStore performs the in-place store migration for adding LSM support to v0.45.16-ics, including:
// - Adding params ValidatorBondFactor, GlobalLiquidStakingCap, ValidatorLiquidStakingCap
// - Setting each validator's ValidatorBondShares and LiquidShares to 0
// - Setting each delegation's ValidatorBond field to false
// - Calculating the total liquid staked by summing the delegations from ICA accounts
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, k keeper) error {
func migrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, k keeper) error {
store := ctx.KVStore(storeKey)

ctx.Logger().Info("Staking LSM Migration: Migrating param store")
MigrateParamsStore(ctx, k)
if err := migrateParamsStore(ctx, k); err != nil {
return err
}

ctx.Logger().Info("Staking LSM Migration: Migrating validators")
MigrateValidators(ctx, k)
migrateValidators(ctx, k)

ctx.Logger().Info("Staking LSM Migration: Migrating delegations")
MigrateDelegations(ctx, k)
migrateDelegations(ctx, k)

ctx.Logger().Info("Staking LSM Migration: Migrating UBD entries")
if err := MigrateUBDEntries(ctx, store, cdc); err != nil {
if err := migrateUBDEntries(ctx, store, cdc); err != nil {
return err
}

Expand Down
10 changes: 6 additions & 4 deletions app/upgrades/v300/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
var Upgrade = upgrades.Upgrade{
UpgradeName: "v3.0",
UpgradeName: "v3",
UpgradeHandlerConstructor: upgradeHandlerConstructor,
StoreUpgrades: &storetypes.StoreUpgrades{
Added: []string{icahosttypes.StoreKey},
Expand All @@ -34,7 +34,9 @@ func upgradeHandlerConstructor(
initICAModule(ctx, m, fromVM)

// merge liquid staking module
mergeLSModule(ctx, box)
if err := mergeLSModule(ctx, box); err != nil {
return nil, err
}
return box.ModuleManager.RunMigrations(ctx, c, fromVM)
}
}
Expand All @@ -52,9 +54,9 @@ func initICAModule(ctx sdk.Context, m *module.Manager, fromVM module.VersionMap)
icaModule.InitModule(ctx, controllerParams, hostParams)
}

func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) {
func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) error {
ctx.Logger().Info("start to run lsm module migrations...")

storeKey := box.GetKey(stakingtypes.StoreKey)
MigrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper)
return migrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
)

require (
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d
github.com/gogo/protobuf v1.3.2
github.com/olebedev/config v0.0.0-20190528211619-364964f3a8e4
github.com/pkg/errors v0.9.1
Expand All @@ -52,6 +51,7 @@ require (
require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
Expand Down
6 changes: 3 additions & 3 deletions modules/guardian/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
guardiancli "github.com/irisnet/irishub/v3/modules/guardian/client/cli"
guardiantestutil "github.com/irisnet/irishub/v3/modules/guardian/client/testutil"
guardiantypes "github.com/irisnet/irishub/v3/modules/guardian/types"
"github.com/irisnet/irishub/v3/simapp"
apptestutil "github.com/irisnet/irishub/v3/testutil"
)

var privKey cryptotypes.PrivKey
Expand All @@ -35,7 +35,7 @@ type IntegrationTestSuite struct {
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

cfg := simapp.NewConfig()
cfg := apptestutil.NewConfig()
cfg.NumValidators = 1

privKey, pubKey, addr = testdata.KeyTestPubAddr()
Expand Down Expand Up @@ -90,7 +90,7 @@ func (s *IntegrationTestSuite) TestGuardian() {
),
}

result := simapp.ExecTxCmdWithResult(s.T(), s.network, clientCtx, bankcli.NewSendTxCmd(), args)
result := apptestutil.ExecCommand(s.T(), s.network, clientCtx, bankcli.NewSendTxCmd(), args)
s.Require().Equal(uint32(0), result.TxResult.Code, result.TxResult.Log)

//------test GetCmdQuerySupers()-------------
Expand Down
Loading

0 comments on commit fbb82d1

Please sign in to comment.