From 1897d3547bc5f1c32306f283dd64591cd966bc30 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Tue, 14 May 2024 02:58:32 +0000 Subject: [PATCH 1/8] Added DistributionTransmissionChannel to Whitelist --- app/proposals_whitelisting.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/proposals_whitelisting.go b/app/proposals_whitelisting.go index d793fa6..1e74b1d 100644 --- a/app/proposals_whitelisting.go +++ b/app/proposals_whitelisting.go @@ -70,6 +70,7 @@ var WhitelistedParams = map[paramChangeKey]struct{}{ // ccv params (note: some CCV params should not be configurable or require special coordination with the provider chain) {Subspace: consumertypes.ModuleName, Key: "ProviderRewardDenoms"}: {}, {Subspace: consumertypes.ModuleName, Key: "RewardDenoms"}: {}, + {Subspace: consumertypes.ModuleName, Key: "DistributionTransmissionChannel"}: {}, {Subspace: consumertypes.ModuleName, Key: "ConsumerRedistributionFraction"}: {}, {Subspace: consumertypes.ModuleName, Key: "BlocksPerDistributionTransmission"}: {}, {Subspace: consumertypes.ModuleName, Key: "TransferTimeoutPeriod"}: {}, From d789ddc7e16764a5f08cdf09ddd3a29c9443b4d6 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Wed, 15 May 2024 19:15:18 +0000 Subject: [PATCH 2/8] Change upgrade version --- app/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index 357464a..bc067d7 100644 --- a/app/app.go +++ b/app/app.go @@ -124,7 +124,7 @@ import ( const ( AppName = "onex" - upgradeName = "v1.1.0" + upgradeName = "v1.1.2-testnet" AccountAddressPrefix = "onomy" ) From 8fe963d684bcb4594ec4e5ad6f0ee9541c0cdae1 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Thu, 16 May 2024 17:21:40 +0000 Subject: [PATCH 3/8] Add in upgrade handler --- app/app.go | 18 ++++++++---------- app/upgrades/v1.1.3/upgrade.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 app/upgrades/v1.1.3/upgrade.go diff --git a/app/app.go b/app/app.go index bc067d7..cc8dd3d 100644 --- a/app/app.go +++ b/app/app.go @@ -8,8 +8,6 @@ import ( "os" "path/filepath" - // v0 "github.com/onomyprotocol/onex/app/upgrades/" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -120,15 +118,17 @@ import ( marketclient "github.com/pendulum-labs/market/x/market/client" marketkeeper "github.com/pendulum-labs/market/x/market/keeper" markettypes "github.com/pendulum-labs/market/x/market/types" + + v1_1_3 "github.com/onomyprotocol/onex/app/upgrades/v1.1.3" ) const ( AppName = "onex" - upgradeName = "v1.1.2-testnet" AccountAddressPrefix = "onomy" ) var ( + // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -554,6 +554,7 @@ func New( consumertypes.ModuleName, ) app.MM.SetOrderEndBlockers( + upgradetypes.ModuleName, crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, @@ -567,7 +568,6 @@ func New( authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, - upgradetypes.ModuleName, vestingtypes.ModuleName, ibctransfertypes.ModuleName, ibchost.ModuleName, @@ -582,6 +582,7 @@ func New( // so that other modules that want to create or claim capabilities afterwards in InitChain // can do so safely. app.MM.SetOrderInitGenesis( + upgradetypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, @@ -595,7 +596,6 @@ func New( authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, - upgradetypes.ModuleName, vestingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, @@ -659,7 +659,7 @@ func New( app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) - app.setupUpgradeHandlers(app.configurator) + app.setupUpgradeHandlers() if loadLatest { if err := app.LoadLatestVersion(); err != nil { @@ -918,10 +918,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } -func (app *App) setupUpgradeHandlers(cfg module.Configurator) { - app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - return app.MM.RunMigrations(ctx, cfg, vm) - }) +func (app *App) setupUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler(v1_1_3.Name, v1_1_3.UpgradeHandler) upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { diff --git a/app/upgrades/v1.1.3/upgrade.go b/app/upgrades/v1.1.3/upgrade.go new file mode 100644 index 0000000..4a7c3e9 --- /dev/null +++ b/app/upgrades/v1.1.3/upgrade.go @@ -0,0 +1,16 @@ +// Package v1_1_3 is contains chain upgrade of the corresponding version. +package v1_1_3 //nolint:revive,stylecheck // app version + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +// Name is migration name. +const Name = "v1.1.3" + +// UpgradeHandler is an x/upgrade handler. +func UpgradeHandler(_ sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + return vm, nil +} From 113be772dc5fc1600c70cbc685542cca4132fb31 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 26 May 2024 14:19:16 -0500 Subject: [PATCH 4/8] Add in Market v1.1.3-dev dependency and pool reset --- app/app.go | 36 +++++++++++++--------- app/upgrades/types.go | 33 ++++++++++++++++++++ app/upgrades/v1.1.3/upgrade.go | 16 ---------- app/upgrades/v1.1.4/constants.go | 15 +++++++++ app/upgrades/v1.1.4/upgrade.go | 52 ++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 +-- 7 files changed, 125 insertions(+), 33 deletions(-) create mode 100644 app/upgrades/types.go delete mode 100644 app/upgrades/v1.1.3/upgrade.go create mode 100644 app/upgrades/v1.1.4/constants.go create mode 100644 app/upgrades/v1.1.4/upgrade.go diff --git a/app/app.go b/app/app.go index cc8dd3d..c3af161 100644 --- a/app/app.go +++ b/app/app.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" - storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" @@ -119,7 +118,8 @@ import ( marketkeeper "github.com/pendulum-labs/market/x/market/keeper" markettypes "github.com/pendulum-labs/market/x/market/types" - v1_1_3 "github.com/onomyprotocol/onex/app/upgrades/v1.1.3" + "github.com/onomyprotocol/onex/app/upgrades" + v1_1_4 "github.com/onomyprotocol/onex/app/upgrades/v1.1.4" ) const ( @@ -128,6 +128,7 @@ const ( ) var ( + Upgrades = []upgrades.Upgrade{v1_1_4.Upgrade} // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -918,27 +919,34 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } -func (app *App) setupUpgradeHandlers() { - app.UpgradeKeeper.SetUpgradeHandler(v1_1_3.Name, v1_1_3.UpgradeHandler) - +func (app *App) setupUpgradeStoreLoaders() { upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { - panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) + panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) } - // configure store loader that checks if version == upgradeHeight and applies store upgrades if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { return } - var storeUpgrades *storetypes.StoreUpgrades - - switch upgradeInfo.Name { - default: - // no store upgrades + for _, upgrade := range Upgrades { + if upgradeInfo.Name == upgrade.UpgradeName { + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) + } } +} - if storeUpgrades != nil { - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) +func (app *App) setupUpgradeHandlers() { + for _, upgrade := range Upgrades { + app.UpgradeKeeper.SetUpgradeHandler( + upgrade.UpgradeName, + upgrade.CreateUpgradeHandler( + app.MM, + app.configurator, + &upgrades.UpgradeKeepers{ + MarketKeeper: app.MarketKeeper, + }, + ), + ) } } diff --git a/app/upgrades/types.go b/app/upgrades/types.go new file mode 100644 index 0000000..6515d07 --- /dev/null +++ b/app/upgrades/types.go @@ -0,0 +1,33 @@ +package upgrades + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/types/module" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + marketkeeper "github.com/pendulum-labs/market/x/market/keeper" +) + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +// must have written, in order for the state migration to go smoothly. +// An upgrade must implement this struct, and then set it in the app.go. +// The app.go will then define the handler. +type Upgrade struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + + // CreateUpgradeHandler defines the function that creates an upgrade handler + CreateUpgradeHandler func(*module.Manager, module.Configurator, *UpgradeKeepers) upgradetypes.UpgradeHandler + + // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. + StoreUpgrades store.StoreUpgrades +} + +type UpgradeKeepers struct { + // keepers + SlashingKeeper slashingkeeper.Keeper + ParamsKeeper paramskeeper.Keeper + MarketKeeper marketkeeper.Keeper +} diff --git a/app/upgrades/v1.1.3/upgrade.go b/app/upgrades/v1.1.3/upgrade.go deleted file mode 100644 index 4a7c3e9..0000000 --- a/app/upgrades/v1.1.3/upgrade.go +++ /dev/null @@ -1,16 +0,0 @@ -// Package v1_1_3 is contains chain upgrade of the corresponding version. -package v1_1_3 //nolint:revive,stylecheck // app version - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -// Name is migration name. -const Name = "v1.1.3" - -// UpgradeHandler is an x/upgrade handler. -func UpgradeHandler(_ sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - return vm, nil -} diff --git a/app/upgrades/v1.1.4/constants.go b/app/upgrades/v1.1.4/constants.go new file mode 100644 index 0000000..7c8ec07 --- /dev/null +++ b/app/upgrades/v1.1.4/constants.go @@ -0,0 +1,15 @@ +package v1_1_4 + +import ( + "github.com/onomyprotocol/onex/app/upgrades" +) + +const ( + // UpgradeName defines the on-chain upgrades name. + UpgradeName = "v1.1.4" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, +} diff --git a/app/upgrades/v1.1.4/upgrade.go b/app/upgrades/v1.1.4/upgrade.go new file mode 100644 index 0000000..983d14d --- /dev/null +++ b/app/upgrades/v1.1.4/upgrade.go @@ -0,0 +1,52 @@ +// Package v1_1_4 is contains chain upgrade of the corresponding version. +package v1_1_4 //nolint:revive,stylecheck // app version + +import ( + "github.com/onomyprotocol/onex/app/upgrades" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + markettypes "github.com/pendulum-labs/market/x/market/types" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *upgrades.UpgradeKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Starting module migrations...") + + // Deactivate all drops + drops := keepers.MarketKeeper.GetAllDrop(ctx) + for _, drop := range drops { + drop.Active = false + keepers.MarketKeeper.SetDrop(ctx, drop) + } + + // Set pool drops to zero and wipe leaders + pools := keepers.MarketKeeper.GetAllPool(ctx) + for _, pool := range pools { + pool.Drops = sdk.ZeroInt() + pool.Leaders = []*markettypes.Leader{} + + keepers.MarketKeeper.SetPool(ctx, pool) + } + + // Set member balances to zero + members := keepers.MarketKeeper.GetAllMember(ctx) + for _, member := range members { + member.Balance = sdk.ZeroInt() + keepers.MarketKeeper.SetMember(ctx, member) + } + + vm, err := mm.RunMigrations(ctx, configurator, vm) + if err != nil { + return vm, err + } + + ctx.Logger().Info("Upgrade complete") + return vm, err + } +} diff --git a/go.mod b/go.mod index 10ea8a3..895e0e8 100644 --- a/go.mod +++ b/go.mod @@ -155,7 +155,7 @@ replace ( github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.45.16-ics github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 - github.com/pendulum-labs/market => github.com/onomyprotocol/market v1.1.2-dev + github.com/pendulum-labs/market => github.com/onomyprotocol/market v1.1.3-dev github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) diff --git a/go.sum b/go.sum index e5f844f..521c298 100644 --- a/go.sum +++ b/go.sum @@ -2204,8 +2204,8 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onomyprotocol/market v1.1.2-dev h1:uLCI2DMclMrKJ9YGi7RyOz5EmG8b7EvJoNwgqfwp5Ks= -github.com/onomyprotocol/market v1.1.2-dev/go.mod h1:OFWUMLq8cfNRQnc6WqReQYq+hNYRqoc2RmMvECSxdwk= +github.com/onomyprotocol/market v1.1.3-dev h1:t1auMPtqHiFumVjlpYibVMe4dI8LdgsCH0h5Ybo3YR8= +github.com/onomyprotocol/market v1.1.3-dev/go.mod h1:OFWUMLq8cfNRQnc6WqReQYq+hNYRqoc2RmMvECSxdwk= github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= From 74ef7c5cf4cb8610b517aa2d241c3fa69028da5c Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 26 May 2024 15:47:23 -0500 Subject: [PATCH 5/8] Add in reclaimation of pool funds --- app/app.go | 5 +++-- app/upgrades/types.go | 9 +++----- app/upgrades/{v1.1.4 => v1.1.5}/constants.go | 4 ++-- app/upgrades/{v1.1.4 => v1.1.5}/upgrade.go | 22 ++++++++++++++++++-- 4 files changed, 28 insertions(+), 12 deletions(-) rename app/upgrades/{v1.1.4 => v1.1.5}/constants.go (85%) rename app/upgrades/{v1.1.4 => v1.1.5}/upgrade.go (58%) diff --git a/app/app.go b/app/app.go index c3af161..8f3fd32 100644 --- a/app/app.go +++ b/app/app.go @@ -119,7 +119,7 @@ import ( markettypes "github.com/pendulum-labs/market/x/market/types" "github.com/onomyprotocol/onex/app/upgrades" - v1_1_4 "github.com/onomyprotocol/onex/app/upgrades/v1.1.4" + v1_1_5 "github.com/onomyprotocol/onex/app/upgrades/v1.1.5" ) const ( @@ -128,7 +128,7 @@ const ( ) var ( - Upgrades = []upgrades.Upgrade{v1_1_4.Upgrade} + Upgrades = []upgrades.Upgrade{v1_1_5.Upgrade} // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -944,6 +944,7 @@ func (app *App) setupUpgradeHandlers() { app.MM, app.configurator, &upgrades.UpgradeKeepers{ + BankKeeper: app.BankKeeper, MarketKeeper: app.MarketKeeper, }, ), diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 6515d07..d775913 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -3,10 +3,8 @@ package upgrades import ( store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/module" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" marketkeeper "github.com/pendulum-labs/market/x/market/keeper" ) @@ -27,7 +25,6 @@ type Upgrade struct { type UpgradeKeepers struct { // keepers - SlashingKeeper slashingkeeper.Keeper - ParamsKeeper paramskeeper.Keeper - MarketKeeper marketkeeper.Keeper + BankKeeper bankkeeper.Keeper + MarketKeeper marketkeeper.Keeper } diff --git a/app/upgrades/v1.1.4/constants.go b/app/upgrades/v1.1.5/constants.go similarity index 85% rename from app/upgrades/v1.1.4/constants.go rename to app/upgrades/v1.1.5/constants.go index 7c8ec07..1bdc280 100644 --- a/app/upgrades/v1.1.4/constants.go +++ b/app/upgrades/v1.1.5/constants.go @@ -1,4 +1,4 @@ -package v1_1_4 +package v1_1_5 import ( "github.com/onomyprotocol/onex/app/upgrades" @@ -6,7 +6,7 @@ import ( const ( // UpgradeName defines the on-chain upgrades name. - UpgradeName = "v1.1.4" + UpgradeName = "v1.1.5" ) var Upgrade = upgrades.Upgrade{ diff --git a/app/upgrades/v1.1.4/upgrade.go b/app/upgrades/v1.1.5/upgrade.go similarity index 58% rename from app/upgrades/v1.1.4/upgrade.go rename to app/upgrades/v1.1.5/upgrade.go index 983d14d..c22e8e2 100644 --- a/app/upgrades/v1.1.4/upgrade.go +++ b/app/upgrades/v1.1.5/upgrade.go @@ -1,5 +1,5 @@ -// Package v1_1_4 is contains chain upgrade of the corresponding version. -package v1_1_4 //nolint:revive,stylecheck // app version +// Package v1_1_5 is contains chain upgrade of the corresponding version. +package v1_1_5 //nolint:revive,stylecheck // app version import ( "github.com/onomyprotocol/onex/app/upgrades" @@ -41,6 +41,24 @@ func CreateUpgradeHandler( keepers.MarketKeeper.SetMember(ctx, member) } + onexAmount, _ := sdk.NewIntFromString("94784650277373001264452") + + ibc1Amount, _ := sdk.NewIntFromString("998915079") + + ibc2Amount, _ := sdk.NewIntFromString("28966246179579930912901") + + ibc3Amount, _ := sdk.NewIntFromString("2952795016") + + onexCoin := sdk.NewCoin("aonex", onexAmount) + ibc1 := sdk.NewCoin("ibc/30EDC220372A2C3D0FC1D987E19062E35375DECD1001A5EFA44EB92FF59D1867", ibc1Amount) + ibc2 := sdk.NewCoin("ibc/5BDD8875CC2AF7BC842BE44236ACD576EA4F53C36347F74903B852060D6BF29A", ibc2Amount) + ibc3 := sdk.NewCoin("ibc/CCCBD7307FEB70B0CF7ADF8503F711F6741F41623D25BAD8CB736E03BE384264", ibc3Amount) + + reclaimCoins := sdk.NewCoins(onexCoin, ibc1, ibc2, ibc3) + reclaimer, _ := sdk.AccAddressFromBech32("onomy1yc0lg97cy5e80jyajtkz0zke2rr4734anugf9g") + + keepers.BankKeeper.SendCoinsFromModuleToAccount(ctx, markettypes.ModuleName, reclaimer, reclaimCoins) + vm, err := mm.RunMigrations(ctx, configurator, vm) if err != nil { return vm, err From c26e1cdad178542baa5a3e590c169487d9c82fb6 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 26 May 2024 17:17:41 -0500 Subject: [PATCH 6/8] Add in fork logic --- app/app.go | 4 +- app/fork.go | 19 +++++++++ app/upgrades/types.go | 22 ++++++++++ app/upgrades/v1.1.5/constants.go | 10 +++-- app/upgrades/v1.1.5/fork.go | 59 +++++++++++++++++++++++++++ app/upgrades/v1.1.5/upgrade.go | 70 -------------------------------- 6 files changed, 109 insertions(+), 75 deletions(-) create mode 100644 app/fork.go create mode 100644 app/upgrades/v1.1.5/fork.go delete mode 100644 app/upgrades/v1.1.5/upgrade.go diff --git a/app/app.go b/app/app.go index 8f3fd32..fb5f6a9 100644 --- a/app/app.go +++ b/app/app.go @@ -128,7 +128,8 @@ const ( ) var ( - Upgrades = []upgrades.Upgrade{v1_1_5.Upgrade} + Upgrades = []upgrades.Upgrade{} + Forks = []upgrades.Fork{v1_1_5.Fork} // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -680,6 +681,7 @@ func (app *App) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + BeginBlockForks(ctx, app) return app.MM.BeginBlock(ctx, req) } diff --git a/app/fork.go b/app/fork.go new file mode 100644 index 0000000..9b36742 --- /dev/null +++ b/app/fork.go @@ -0,0 +1,19 @@ +package app + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/onomyprotocol/onex/app/upgrades" +) + +// BeginBlockForks is intended to be ran in a chain upgrade. +func BeginBlockForks(ctx sdk.Context, app *App) { + for _, fork := range Forks { + if ctx.BlockHeight() == fork.UpgradeHeight { + fork.BeginForkLogic(ctx, &upgrades.ForkKeepers{ + BankKeeper: app.BankKeeper, + MarketKeeper: app.MarketKeeper, + }) + return + } + } +} diff --git a/app/upgrades/types.go b/app/upgrades/types.go index d775913..8379495 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -2,6 +2,7 @@ package upgrades import ( store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -28,3 +29,24 @@ type UpgradeKeepers struct { BankKeeper bankkeeper.Keeper MarketKeeper marketkeeper.Keeper } + +// Fork defines a struct containing the requisite fields for a non-software upgrade proposal +// Hard Fork at a given height to implement. +// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`. +// Any other change in the code should be height-gated, if the goal is to have old and new binaries +// to be compatible prior to the upgrade height. +type Fork struct { + // Upgrade version name, for the upgrade handler, e.g. `v7` + UpgradeName string + // height the upgrade occurs at + UpgradeHeight int64 + + // Function that runs some custom state transition code at the beginning of a fork. + BeginForkLogic func(ctx sdk.Context, keepers *ForkKeepers) +} + +type ForkKeepers struct { + // keepers + BankKeeper bankkeeper.Keeper + MarketKeeper marketkeeper.Keeper +} diff --git a/app/upgrades/v1.1.5/constants.go b/app/upgrades/v1.1.5/constants.go index 1bdc280..9f36004 100644 --- a/app/upgrades/v1.1.5/constants.go +++ b/app/upgrades/v1.1.5/constants.go @@ -6,10 +6,12 @@ import ( const ( // UpgradeName defines the on-chain upgrades name. - UpgradeName = "v1.1.5" + UpgradeName = "v1_1_5" + UpgradeHeight = 389310 ) -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, +var Fork = upgrades.Fork{ + UpgradeName: UpgradeName, + UpgradeHeight: UpgradeHeight, + BeginForkLogic: RunForkLogic, } diff --git a/app/upgrades/v1.1.5/fork.go b/app/upgrades/v1.1.5/fork.go new file mode 100644 index 0000000..d8cae7e --- /dev/null +++ b/app/upgrades/v1.1.5/fork.go @@ -0,0 +1,59 @@ +// Package v1_1_5 is contains chain fork of the corresponding version. +package v1_1_5 //nolint:revive,stylecheck // app version + +import ( + "github.com/onomyprotocol/onex/app/upgrades" + + sdk "github.com/cosmos/cosmos-sdk/types" + markettypes "github.com/pendulum-labs/market/x/market/types" +) + +func RunForkLogic( + ctx sdk.Context, + keepers *upgrades.ForkKeepers, +) { + ctx.Logger().Info("Starting fork...") + + // Deactivate all drops + drops := keepers.MarketKeeper.GetAllDrop(ctx) + for _, drop := range drops { + drop.Active = false + keepers.MarketKeeper.SetDrop(ctx, drop) + } + + // Set pool drops to zero and wipe leaders + pools := keepers.MarketKeeper.GetAllPool(ctx) + for _, pool := range pools { + pool.Drops = sdk.ZeroInt() + pool.Leaders = []*markettypes.Leader{} + + keepers.MarketKeeper.SetPool(ctx, pool) + } + + // Set member balances to zero + members := keepers.MarketKeeper.GetAllMember(ctx) + for _, member := range members { + member.Balance = sdk.ZeroInt() + keepers.MarketKeeper.SetMember(ctx, member) + } + + onexAmount, _ := sdk.NewIntFromString("94784650277373001264452") + + ibc1Amount, _ := sdk.NewIntFromString("998915079") + + ibc2Amount, _ := sdk.NewIntFromString("28966246179579930912901") + + ibc3Amount, _ := sdk.NewIntFromString("2952795016") + + onexCoin := sdk.NewCoin("aonex", onexAmount) + ibc1 := sdk.NewCoin("ibc/30EDC220372A2C3D0FC1D987E19062E35375DECD1001A5EFA44EB92FF59D1867", ibc1Amount) + ibc2 := sdk.NewCoin("ibc/5BDD8875CC2AF7BC842BE44236ACD576EA4F53C36347F74903B852060D6BF29A", ibc2Amount) + ibc3 := sdk.NewCoin("ibc/CCCBD7307FEB70B0CF7ADF8503F711F6741F41623D25BAD8CB736E03BE384264", ibc3Amount) + + reclaimCoins := sdk.NewCoins(onexCoin, ibc1, ibc2, ibc3) + reclaimer, _ := sdk.AccAddressFromBech32("onomy1yc0lg97cy5e80jyajtkz0zke2rr4734anugf9g") + + keepers.BankKeeper.SendCoinsFromModuleToAccount(ctx, markettypes.ModuleName, reclaimer, reclaimCoins) + + ctx.Logger().Info("Fork complete") +} diff --git a/app/upgrades/v1.1.5/upgrade.go b/app/upgrades/v1.1.5/upgrade.go deleted file mode 100644 index c22e8e2..0000000 --- a/app/upgrades/v1.1.5/upgrade.go +++ /dev/null @@ -1,70 +0,0 @@ -// Package v1_1_5 is contains chain upgrade of the corresponding version. -package v1_1_5 //nolint:revive,stylecheck // app version - -import ( - "github.com/onomyprotocol/onex/app/upgrades" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - markettypes "github.com/pendulum-labs/market/x/market/types" -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - keepers *upgrades.UpgradeKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Starting module migrations...") - - // Deactivate all drops - drops := keepers.MarketKeeper.GetAllDrop(ctx) - for _, drop := range drops { - drop.Active = false - keepers.MarketKeeper.SetDrop(ctx, drop) - } - - // Set pool drops to zero and wipe leaders - pools := keepers.MarketKeeper.GetAllPool(ctx) - for _, pool := range pools { - pool.Drops = sdk.ZeroInt() - pool.Leaders = []*markettypes.Leader{} - - keepers.MarketKeeper.SetPool(ctx, pool) - } - - // Set member balances to zero - members := keepers.MarketKeeper.GetAllMember(ctx) - for _, member := range members { - member.Balance = sdk.ZeroInt() - keepers.MarketKeeper.SetMember(ctx, member) - } - - onexAmount, _ := sdk.NewIntFromString("94784650277373001264452") - - ibc1Amount, _ := sdk.NewIntFromString("998915079") - - ibc2Amount, _ := sdk.NewIntFromString("28966246179579930912901") - - ibc3Amount, _ := sdk.NewIntFromString("2952795016") - - onexCoin := sdk.NewCoin("aonex", onexAmount) - ibc1 := sdk.NewCoin("ibc/30EDC220372A2C3D0FC1D987E19062E35375DECD1001A5EFA44EB92FF59D1867", ibc1Amount) - ibc2 := sdk.NewCoin("ibc/5BDD8875CC2AF7BC842BE44236ACD576EA4F53C36347F74903B852060D6BF29A", ibc2Amount) - ibc3 := sdk.NewCoin("ibc/CCCBD7307FEB70B0CF7ADF8503F711F6741F41623D25BAD8CB736E03BE384264", ibc3Amount) - - reclaimCoins := sdk.NewCoins(onexCoin, ibc1, ibc2, ibc3) - reclaimer, _ := sdk.AccAddressFromBech32("onomy1yc0lg97cy5e80jyajtkz0zke2rr4734anugf9g") - - keepers.BankKeeper.SendCoinsFromModuleToAccount(ctx, markettypes.ModuleName, reclaimer, reclaimCoins) - - vm, err := mm.RunMigrations(ctx, configurator, vm) - if err != nil { - return vm, err - } - - ctx.Logger().Info("Upgrade complete") - return vm, err - } -} From c72245380d215b6337e12f7d7d6bc7b8de129905 Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 26 May 2024 17:29:40 -0500 Subject: [PATCH 7/8] Add store upgrade handler --- app/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/app.go b/app/app.go index fb5f6a9..c973a9c 100644 --- a/app/app.go +++ b/app/app.go @@ -661,6 +661,7 @@ func New( app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) + app.setupUpgradeStoreLoaders() app.setupUpgradeHandlers() if loadLatest { From 05d925ca4a6437cff0cb11b3133b73da5bc3323c Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Sun, 26 May 2024 18:01:14 -0500 Subject: [PATCH 8/8] Prepare for v1.1.6 and update Market Module --- app/app.go | 4 ++-- app/upgrades/{v1.1.5 => v1.1.6}/constants.go | 4 ++-- app/upgrades/{v1.1.5 => v1.1.6}/fork.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) rename app/upgrades/{v1.1.5 => v1.1.6}/constants.go (86%) rename app/upgrades/{v1.1.5 => v1.1.6}/fork.go (93%) diff --git a/app/app.go b/app/app.go index c973a9c..b2bb5d6 100644 --- a/app/app.go +++ b/app/app.go @@ -119,7 +119,7 @@ import ( markettypes "github.com/pendulum-labs/market/x/market/types" "github.com/onomyprotocol/onex/app/upgrades" - v1_1_5 "github.com/onomyprotocol/onex/app/upgrades/v1.1.5" + v1_1_6 "github.com/onomyprotocol/onex/app/upgrades/v1.1.6" ) const ( @@ -129,7 +129,7 @@ const ( var ( Upgrades = []upgrades.Upgrade{} - Forks = []upgrades.Fork{v1_1_5.Fork} + Forks = []upgrades.Fork{v1_1_6.Fork} // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string diff --git a/app/upgrades/v1.1.5/constants.go b/app/upgrades/v1.1.6/constants.go similarity index 86% rename from app/upgrades/v1.1.5/constants.go rename to app/upgrades/v1.1.6/constants.go index 9f36004..2f6208f 100644 --- a/app/upgrades/v1.1.5/constants.go +++ b/app/upgrades/v1.1.6/constants.go @@ -1,4 +1,4 @@ -package v1_1_5 +package v1_1_6 import ( "github.com/onomyprotocol/onex/app/upgrades" @@ -6,7 +6,7 @@ import ( const ( // UpgradeName defines the on-chain upgrades name. - UpgradeName = "v1_1_5" + UpgradeName = "v1_1_6" UpgradeHeight = 389310 ) diff --git a/app/upgrades/v1.1.5/fork.go b/app/upgrades/v1.1.6/fork.go similarity index 93% rename from app/upgrades/v1.1.5/fork.go rename to app/upgrades/v1.1.6/fork.go index d8cae7e..beff378 100644 --- a/app/upgrades/v1.1.5/fork.go +++ b/app/upgrades/v1.1.6/fork.go @@ -1,5 +1,5 @@ -// Package v1_1_5 is contains chain fork of the corresponding version. -package v1_1_5 //nolint:revive,stylecheck // app version +// Package v1_1_6 is contains chain fork of the corresponding version. +package v1_1_6 //nolint:revive,stylecheck // app version import ( "github.com/onomyprotocol/onex/app/upgrades" diff --git a/go.mod b/go.mod index 895e0e8..0a615a3 100644 --- a/go.mod +++ b/go.mod @@ -155,7 +155,7 @@ replace ( github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.45.16-ics github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 - github.com/pendulum-labs/market => github.com/onomyprotocol/market v1.1.3-dev + github.com/pendulum-labs/market => github.com/onomyprotocol/market v1.1.4-dev github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) diff --git a/go.sum b/go.sum index 521c298..bf36f74 100644 --- a/go.sum +++ b/go.sum @@ -2204,8 +2204,8 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onomyprotocol/market v1.1.3-dev h1:t1auMPtqHiFumVjlpYibVMe4dI8LdgsCH0h5Ybo3YR8= -github.com/onomyprotocol/market v1.1.3-dev/go.mod h1:OFWUMLq8cfNRQnc6WqReQYq+hNYRqoc2RmMvECSxdwk= +github.com/onomyprotocol/market v1.1.4-dev h1:fA1O3NAatEBx/YU2++2LcdBNRs+aX9N50rY/bWxmXfU= +github.com/onomyprotocol/market v1.1.4-dev/go.mod h1:OFWUMLq8cfNRQnc6WqReQYq+hNYRqoc2RmMvECSxdwk= github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=