From 061e6ce170338b9ca6535131ed311d9b90bbe87e Mon Sep 17 00:00:00 2001 From: vuong Date: Wed, 3 Aug 2022 01:24:11 +0700 Subject: [PATCH 1/4] new param migrate --- x/pylons/keeper/migrate.go | 2 +- x/pylons/migrations/v046/store.go | 19 ++++++--- x/pylons/types/genesis.go | 67 +++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/x/pylons/keeper/migrate.go b/x/pylons/keeper/migrate.go index aa0cce0fda..24ef866267 100644 --- a/x/pylons/keeper/migrate.go +++ b/x/pylons/keeper/migrate.go @@ -17,5 +17,5 @@ func NewMigrator(keeper Keeper) Migrator { // Migrate2to3 migrates from version 2 to 3. func (m Migrator) Migrate2to3(ctx sdk.Context) error { - return v046.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) + return v046.MigrateStore(ctx, m.keeper.storeKey, m.keeper.paramSpace, m.keeper.cdc) } diff --git a/x/pylons/migrations/v046/store.go b/x/pylons/migrations/v046/store.go index 1ff881ff06..6a0bd61bfa 100644 --- a/x/pylons/migrations/v046/store.go +++ b/x/pylons/migrations/v046/store.go @@ -1,13 +1,13 @@ package v046 import ( + "github.com/Pylons-tech/pylons/x/pylons/types" + v1 "github.com/Pylons-tech/pylons/x/pylons/types/v1" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/Pylons-tech/pylons/x/pylons/types" - v1 "github.com/Pylons-tech/pylons/x/pylons/types/v1" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // migrateProposals migrates all legacy proposals into MsgExecLegacyContent @@ -38,12 +38,21 @@ func migrateAppleInAppPurchaseOrder(store sdk.KVStore, cdc codec.BinaryCodec) er return nil } +func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { + if paramstore.HasKeyTable() { + paramstore.Set(ctx, types.ParamStoreKeyMaxTxsInBlock, types.DefaultMaxTxsInBlock) + } else { + paramstore.WithKeyTable(types.ParamKeyTable()) + paramstore.Set(ctx, types.ParamStoreKeyMaxTxsInBlock, types.DefaultMaxTxsInBlock) + } +} + // MigrateStore performs in-place store migrations from v0.43 to v0.46. The // migration includes: // // - Migrate proposals to be Msg-based. -func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, paramstore paramtypes.Subspace, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) - + migrateParamsStore(ctx, paramstore) return migrateAppleInAppPurchaseOrder(store, cdc) } diff --git a/x/pylons/types/genesis.go b/x/pylons/types/genesis.go index 7324087453..8a95dec1b0 100644 --- a/x/pylons/types/genesis.go +++ b/x/pylons/types/genesis.go @@ -2,6 +2,8 @@ package types import ( "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultIndex is the default capability global index @@ -10,17 +12,68 @@ const DefaultIndex uint64 = 1 // DefaultGenesis returns the default Pylons genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - RedeemInfoList: []RedeemInfo{}, - PaymentInfoList: []PaymentInfo{}, - AccountList: []UserMap{}, + // this line is used by starport scaffolding # ibc/genesistype/default + // this line is used by starport scaffolding # genesis/types/default + RedeemInfoList: []RedeemInfo{}, + PaymentInfoList: []PaymentInfo{}, + AccountList: []UserMap{ + { + AccountAddr: "pylo1gna56yt36rznvm90zcxa7payfcn6490zagswtn", + Username: "test", + }, + }, TradeList: []Trade{}, GoogleInAppPurchaseOrderList: []GoogleInAppPurchaseOrder{}, PendingExecutionList: []Execution{}, ExecutionList: []Execution{}, - ItemList: []Item{}, - RecipeList: []Recipe{}, - CookbookList: []Cookbook{}, - Params: DefaultParams(), + ItemList: []Item{ + { + Owner: "pylo1gna56yt36rznvm90zcxa7payfcn6490zagswtn", + CookbookId: "1", + Id: "1", + NodeVersion: 1, + Doubles: []DoubleKeyValue{}, + Longs: []LongKeyValue{}, + Strings: []StringKeyValue{}, + MutableStrings: []StringKeyValue{}, + Tradeable: true, + LastUpdate: 1, + TransferFee: sdk.Coins{}, + TradePercentage: sdk.NewDec(0), + }, + }, + RecipeList: []Recipe{ + { + CookbookId: "1", + Id: "1", + NodeVersion: 1, + Name: "test", + Description: "test", + Version: "0.0.1", + CoinInputs: []CoinInput{}, + ItemInputs: []ItemInput{}, + Entries: EntriesList{}, + Outputs: []WeightedOutputs{}, + BlockInterval: 0, + CostPerBlock: sdk.Coin{}, + Enabled: true, + ExtraInfo: "", + }, + }, + CookbookList: []Cookbook{ + { + Creator: "test", + Id: "1", + NodeVersion: 1, + Name: "test", + Description: "des", + Developer: "test", + Version: "0.0.1", + SupportEmail: "hieuvubk@gmail.com", + Enabled: true, + }, + }, + Params: DefaultParams(), } } From 8a8bac653dd8b9455ba3835fb155099724211da1 Mon Sep 17 00:00:00 2001 From: vuong <56973102+vuong177@users.noreply.github.com> Date: Wed, 3 Aug 2022 02:47:49 +0700 Subject: [PATCH 2/4] Update genesis.go --- x/pylons/types/genesis.go | 65 +++++---------------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/x/pylons/types/genesis.go b/x/pylons/types/genesis.go index 8a95dec1b0..0524aa439d 100644 --- a/x/pylons/types/genesis.go +++ b/x/pylons/types/genesis.go @@ -12,68 +12,17 @@ const DefaultIndex uint64 = 1 // DefaultGenesis returns the default Pylons genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - // this line is used by starport scaffolding # ibc/genesistype/default - // this line is used by starport scaffolding # genesis/types/default - RedeemInfoList: []RedeemInfo{}, - PaymentInfoList: []PaymentInfo{}, - AccountList: []UserMap{ - { - AccountAddr: "pylo1gna56yt36rznvm90zcxa7payfcn6490zagswtn", - Username: "test", - }, - }, + RedeemInfoList: []RedeemInfo{}, + PaymentInfoList: []PaymentInfo{}, + AccountList: []UserMap{}, TradeList: []Trade{}, GoogleInAppPurchaseOrderList: []GoogleInAppPurchaseOrder{}, PendingExecutionList: []Execution{}, ExecutionList: []Execution{}, - ItemList: []Item{ - { - Owner: "pylo1gna56yt36rznvm90zcxa7payfcn6490zagswtn", - CookbookId: "1", - Id: "1", - NodeVersion: 1, - Doubles: []DoubleKeyValue{}, - Longs: []LongKeyValue{}, - Strings: []StringKeyValue{}, - MutableStrings: []StringKeyValue{}, - Tradeable: true, - LastUpdate: 1, - TransferFee: sdk.Coins{}, - TradePercentage: sdk.NewDec(0), - }, - }, - RecipeList: []Recipe{ - { - CookbookId: "1", - Id: "1", - NodeVersion: 1, - Name: "test", - Description: "test", - Version: "0.0.1", - CoinInputs: []CoinInput{}, - ItemInputs: []ItemInput{}, - Entries: EntriesList{}, - Outputs: []WeightedOutputs{}, - BlockInterval: 0, - CostPerBlock: sdk.Coin{}, - Enabled: true, - ExtraInfo: "", - }, - }, - CookbookList: []Cookbook{ - { - Creator: "test", - Id: "1", - NodeVersion: 1, - Name: "test", - Description: "des", - Developer: "test", - Version: "0.0.1", - SupportEmail: "hieuvubk@gmail.com", - Enabled: true, - }, - }, - Params: DefaultParams(), + ItemList: []Item{}, + RecipeList: []Recipe{}, + CookbookList: []Cookbook{}, + Params: DefaultParams(), } } From 0ed7745c1422131b739ae44b494d76ca90169446 Mon Sep 17 00:00:00 2001 From: vuong Date: Wed, 3 Aug 2022 02:55:29 +0700 Subject: [PATCH 3/4] revert param migrate --- x/pylons/keeper/migrate.go | 3 ++- x/pylons/migrations/v046/store.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 x/pylons/migrations/v046/store.go diff --git a/x/pylons/keeper/migrate.go b/x/pylons/keeper/migrate.go index 4fa7aacb09..1c6e0a3a59 100644 --- a/x/pylons/keeper/migrate.go +++ b/x/pylons/keeper/migrate.go @@ -1,6 +1,7 @@ package keeper import ( + v046 "github.com/Pylons-tech/pylons/x/pylons/migrations/v046" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -16,5 +17,5 @@ func NewMigrator(keeper Keeper) Migrator { // Migrate2to3 migrates from version 2 to 3. func (m Migrator) Migrate2to3(ctx sdk.Context) error { - return nil + return v046.MigrateStore(ctx, m.keeper.paramSpace) } diff --git a/x/pylons/migrations/v046/store.go b/x/pylons/migrations/v046/store.go new file mode 100644 index 0000000000..e8eac64dba --- /dev/null +++ b/x/pylons/migrations/v046/store.go @@ -0,0 +1,25 @@ +package v046 + +import ( + "github.com/Pylons-tech/pylons/x/pylons/types" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { + if paramstore.HasKeyTable() { + paramstore.Set(ctx, types.ParamStoreKeyMaxTxsInBlock, types.DefaultMaxTxsInBlock) + } else { + paramstore.WithKeyTable(types.ParamKeyTable()) + paramstore.Set(ctx, types.ParamStoreKeyMaxTxsInBlock, types.DefaultMaxTxsInBlock) + } +} + +// MigrateStore performs in-place store migrations from v0.43 to v0.46. The +// migration includes: +// +// - Migrate proposals to be Msg-based. +func MigrateStore(ctx sdk.Context, paramstore paramtypes.Subspace) error { + migrateParamsStore(ctx, paramstore) + return nil +} From 174acd45b8984f3a8cec3514390c517645e37756 Mon Sep 17 00:00:00 2001 From: vuong Date: Wed, 3 Aug 2022 02:58:34 +0700 Subject: [PATCH 4/4] minor remove --- x/pylons/types/genesis.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/pylons/types/genesis.go b/x/pylons/types/genesis.go index 0524aa439d..7324087453 100644 --- a/x/pylons/types/genesis.go +++ b/x/pylons/types/genesis.go @@ -2,8 +2,6 @@ package types import ( "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultIndex is the default capability global index