From 42320db47e97757d2246948d45168728a40f4834 Mon Sep 17 00:00:00 2001 From: Ran Mishael <106548467+ranlavanet@users.noreply.github.com> Date: Sun, 16 Apr 2023 17:12:23 +0200 Subject: [PATCH] upgrade version v0.9.8 (#426) --- app/app.go | 2 ++ app/upgrades/v0_9_8/constants.go | 14 +++++++++ app/upgrades/v0_9_8/upgrades.go | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 app/upgrades/v0_9_8/constants.go create mode 100644 app/upgrades/v0_9_8/upgrades.go diff --git a/app/app.go b/app/app.go index 0ffe35c7f5..c3ed200c21 100644 --- a/app/app.go +++ b/app/app.go @@ -92,6 +92,7 @@ import ( "github.com/lavanet/lava/app/upgrades/v0_9_1" "github.com/lavanet/lava/app/upgrades/v0_9_6" "github.com/lavanet/lava/app/upgrades/v0_9_7" + "github.com/lavanet/lava/app/upgrades/v0_9_8" "github.com/lavanet/lava/docs" conflictmodule "github.com/lavanet/lava/x/conflict" conflictmodulekeeper "github.com/lavanet/lava/x/conflict/keeper" @@ -152,6 +153,7 @@ var Upgrades = []upgrades.Upgrade{ upgrades.Upgrade_0_9_5, v0_9_6.Upgrade, v0_9_7.Upgrade, + v0_9_8.Upgrade, } // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals diff --git a/app/upgrades/v0_9_8/constants.go b/app/upgrades/v0_9_8/constants.go new file mode 100644 index 0000000000..b1bcb4ef15 --- /dev/null +++ b/app/upgrades/v0_9_8/constants.go @@ -0,0 +1,14 @@ +package v0_9_8 + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/lavanet/lava/app/upgrades" +) + +const UpgradeName = "v0.9.8" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, // upgrade name defined few lines above + CreateUpgradeHandler: CreateUpgradeHandler, // create CreateUpgradeHandler in upgrades.go below + StoreUpgrades: store.StoreUpgrades{}, // StoreUpgrades has 3 fields: Added/Renamed/Deleted any module that fits these description should be added in the way below +} diff --git a/app/upgrades/v0_9_8/upgrades.go b/app/upgrades/v0_9_8/upgrades.go new file mode 100644 index 0000000000..2489dfef4d --- /dev/null +++ b/app/upgrades/v0_9_8/upgrades.go @@ -0,0 +1,49 @@ +package v0_9_8 + +import ( + "log" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/lavanet/lava/app/keepers" + "github.com/lavanet/lava/app/upgrades" + epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types" +) + +const ( + // ClientPaymentStorageKeyPrefix is the prefix to retrieve all ClientPaymentStorage + ClientPaymentStorageKeyPrefix = "ClientPaymentStorage/value/" + // UniquePaymentStorageClientProviderKeyPrefix is the prefix to retrieve all UniquePaymentStorageClientProvider + UniquePaymentStorageClientProviderKeyPrefix = "UniquePaymentStorageClientProvider/value/" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + bpm upgrades.BaseAppParamManager, + keepers *keepers.LavaKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + log.Println("########################") + log.Println("# STARTING UPGRADE #") + log.Println("########################") + + chainIDs := keepers.SpecKeeper.GetAllChainIDs(ctx) + for _, chainID := range chainIDs { + storage, found := keepers.EpochstorageKeeper.GetStakeStorageCurrent(ctx, epochstoragetypes.ProviderKey, chainID) + if !found { + continue + } + + for _, entry := range storage.StakeEntries { + err := keepers.PairingKeeper.FreezeProvider(ctx, entry.Address, []string{chainID}, "") + if err != nil { + continue + } + } + } + + return mm.RunMigrations(ctx, configurator, vm) + } +}