From 706dfc4505aabfca87062c799ac3cd8e5dbc05f2 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Sun, 4 Aug 2024 06:47:33 +0700 Subject: [PATCH 01/24] add upgrade handler --- app/upgrades/v1.1.5-fix/upgrade.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/upgrades/v1.1.5-fix/upgrade.go diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go new file mode 100644 index 00000000..eeda3265 --- /dev/null +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -0,0 +1,27 @@ +// Package v1_1_5 is contains chain upgrade of the corresponding version. +package v1_1_5_fix //nolint:revive,stylecheck // app version + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" +) + +// Name is migration name. +const Name = "v1.1.5-fix" + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + ak *authkeeper.AccountKeeper, + sk *stakingkeeper.Keeper, + pk *ibcproviderkeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + + return mm.RunMigrations(ctx, configurator, vm) + } +} From be46cf0d73277e4c52f76a973f9f5704f4cb2957 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Sun, 4 Aug 2024 07:08:48 +0700 Subject: [PATCH 02/24] update --- app/upgrades/v1.1.5-fix/upgrade.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index eeda3265..3976245d 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -2,12 +2,14 @@ package v1_1_5_fix //nolint:revive,stylecheck // app version import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" + "github.com/cosmos/interchain-security/x/ccv/provider/types" ) // Name is migration name. @@ -18,10 +20,18 @@ func CreateUpgradeHandler( configurator module.Configurator, ak *authkeeper.AccountKeeper, sk *stakingkeeper.Keeper, + providerStoreKey storetypes.StoreKey, pk *ibcproviderkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - + ids := pk.GetMaturedUnbondingOps(ctx) + for _, id := range ids { + _, found := sk.GetUnbondingType(ctx, id) + if !found { + store := ctx.KVStore(providerStoreKey) + store.Delete(types.MaturedUnbondingOpsKey()) + } + } return mm.RunMigrations(ctx, configurator, vm) } } From 41321a1114d32b0334859db567fb3c9e545b3941 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Sun, 4 Aug 2024 07:10:26 +0700 Subject: [PATCH 03/24] update --- app/upgrades/v1.1.5-fix/upgrade.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index eeda3265..90d60a6d 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -2,12 +2,16 @@ package v1_1_5_fix //nolint:revive,stylecheck // app version import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" + ibcprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" + ccv "github.com/cosmos/interchain-security/x/ccv/types" ) // Name is migration name. @@ -19,8 +23,32 @@ func CreateUpgradeHandler( ak *authkeeper.AccountKeeper, sk *stakingkeeper.Keeper, pk *ibcproviderkeeper.Keeper, + providerStoreKey sdk.StoreKey, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ids := []uint64{} + for _, id := range pk.GetMaturedUnbondingOps(ctx) { + // Attempt to complete unbonding in staking module + _, found := sk.GetUnbondingType(ctx, id) + if !found { + continue + } + ids = append(ids, id) + } + + maturedOps := ccv.MaturedUnbondingOps{ + Ids: ids, + } + bz, err := maturedOps.Marshal() + if err != nil { + // An error here would indicate something is very wrong, + // maturedOps is instantiated in this method and should be able to be marshaled. + panic(fmt.Sprintf("failed to marshal matured unbonding operations: %s", err)) + } + + // update mature ubd ids + store := ctx.KVStore(providerStoreKey) + store.Set(ibcprovidertypes.MaturedUnbondingOpsKey(), bz) return mm.RunMigrations(ctx, configurator, vm) } From 8a2ae6a373583f891c5d703bb8202dce8fd63ebd Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Sun, 4 Aug 2024 07:52:14 +0700 Subject: [PATCH 04/24] add more check --- app/upgrades/v1.1.5-fix/upgrade.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 90d60a6d..6d2ed03e 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -28,11 +28,18 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { - // Attempt to complete unbonding in staking module _, found := sk.GetUnbondingType(ctx, id) if !found { continue } + ubd, found := sk.GetUnbondingDelegationByUnbondingID(ctx, id) + if !found { + continue + } + if len(ubd.Entries) == 0 { + continue + } + ids = append(ids, id) } From 20d310a9703aa0fc14f1c57fe819eead58e0dec5 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Sun, 4 Aug 2024 20:10:05 +0700 Subject: [PATCH 05/24] filter all invalid ids --- app/upgrades/v1.1.5-fix/upgrade.go | 54 +++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 6d2ed03e..ec9cda61 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -12,11 +12,14 @@ import ( ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" ibcprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" + "golang.org/x/exp/slices" ) // Name is migration name. const Name = "v1.1.5-fix" +var targetIds = []uint64{uint64(3372), uint64(3374), uint64(3373)} + func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, @@ -26,17 +29,50 @@ func CreateUpgradeHandler( providerStoreKey sdk.StoreKey, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - ids := []uint64{} - for _, id := range pk.GetMaturedUnbondingOps(ctx) { - _, found := sk.GetUnbondingType(ctx, id) - if !found { - continue + for _, id := range targetIds { + var consumerChainIDS []string + + for _, chain := range pk.GetAllConsumerChains(ctx) { + consumerChainIDS = append(consumerChainIDS, chain.ChainId) } - ubd, found := sk.GetUnbondingDelegationByUnbondingID(ctx, id) - if !found { - continue + + if len(consumerChainIDS) == 0 { + break } - if len(ubd.Entries) == 0 { + valsetUpdateID := pk.GetValidatorSetUpdateId(ctx) + + // Add to indexes + for _, consumerChainID := range consumerChainIDS { + ubdIds, ok := pk.GetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID) + if !ok { + continue + } + + newIds := []uint64{} + + for _, ubdId := range ubdIds { + if ubdId == id { + continue + } + + newIds = append(newIds, ubdId) + } + + // filter out invalid ID + pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) + } + + // remove ubd entries + _, found := pk.GetUnbondingOp(ctx, id) + if found { + pk.DeleteUnbondingOp(ctx, id) + } + } + + // clear invalid mature ubd entries + ids := []uint64{} + for _, id := range pk.GetMaturedUnbondingOps(ctx) { + if slices.Contains(targetIds, id) { continue } From c3cd2a0e78e5c3a54265f49ed1f612a9f11475f6 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Sun, 4 Aug 2024 23:29:55 +0700 Subject: [PATCH 06/24] update upgrade func --- app/upgrades/v1.1.5-fix/upgrade.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index ec9cda61..ec38c88a 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -12,14 +12,11 @@ import ( ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" ibcprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" - "golang.org/x/exp/slices" ) // Name is migration name. const Name = "v1.1.5-fix" -var targetIds = []uint64{uint64(3372), uint64(3374), uint64(3373)} - func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, @@ -29,12 +26,23 @@ func CreateUpgradeHandler( providerStoreKey sdk.StoreKey, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - for _, id := range targetIds { - var consumerChainIDS []string + toBeRemovedUbdIDs := map[uint64]bool{} + var consumerChainIDS []string + for _, chain := range pk.GetAllConsumerChains(ctx) { + consumerChainIDS = append(consumerChainIDS, chain.ChainId) + } - for _, chain := range pk.GetAllConsumerChains(ctx) { - consumerChainIDS = append(consumerChainIDS, chain.ChainId) + for _, chainID := range consumerChainIDS { + for _, ubdOpIndex := range pk.GetAllUnbondingOpIndexes(ctx, chainID) { + for _, id := range ubdOpIndex.UnbondingOpIds { + if _, found := sk.GetUnbondingType(ctx, id); found { + toBeRemovedUbdIDs[id] = true + } + } } + } + + for id := range toBeRemovedUbdIDs { if len(consumerChainIDS) == 0 { break @@ -72,7 +80,7 @@ func CreateUpgradeHandler( // clear invalid mature ubd entries ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { - if slices.Contains(targetIds, id) { + if toBeRemovedUbdIDs[id] { continue } From 3d4feaabf0ebe3571624f4bac28784f6c1c7e61e Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Sun, 4 Aug 2024 23:34:04 +0700 Subject: [PATCH 07/24] update --- app/upgrades/v1.1.5-fix/upgrade.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index ec38c88a..1afa87b3 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -65,9 +65,12 @@ func CreateUpgradeHandler( newIds = append(newIds, ubdId) } - - // filter out invalid ID - pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) + if len(newIds) == 0 { + pk.DeleteUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID) + } else { + // filter out invalid ID + pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) + } } // remove ubd entries From b3f13341d38c0eb3cc0d0dfd10a57038029ad191 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 5 Aug 2024 01:05:17 +0700 Subject: [PATCH 08/24] update --- app/app.go | 14 ++++++++++++++ app/upgrades/types.go | 20 ++++++++++++++++++++ app/upgrades/v1.1.5-fix/constant.go | 10 ++++++++++ app/upgrades/v1.1.5-fix/upgrade.go | 23 +++++++++-------------- 4 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 app/upgrades/types.go create mode 100644 app/upgrades/v1.1.5-fix/constant.go diff --git a/app/app.go b/app/app.go index a79c187a..6cd7ff5a 100644 --- a/app/app.go +++ b/app/app.go @@ -100,6 +100,7 @@ import ( ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" + "github.com/onomyprotocol/onomy/app/upgrades" v1_0_1 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.1" v1_0_3 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.3" v1_0_3_4 "github.com/onomyprotocol/onomy/app/upgrades/v1.0.3.4" @@ -108,6 +109,7 @@ import ( v1_1_2 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.2" v1_1_4 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.4" v1_1_5 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.5" + v1_1_5_fix "github.com/onomyprotocol/onomy/app/upgrades/v1.1.5-fix" "github.com/onomyprotocol/onomy/docs" "github.com/onomyprotocol/onomy/x/dao" daoclient "github.com/onomyprotocol/onomy/x/dao/client" @@ -192,6 +194,8 @@ var ( // provider chain note: the fee-pool is allowed to receive tokens authtypes.FeeCollectorName: true, } + + Forks = []upgrades.Fork{} ) var ( @@ -619,6 +623,7 @@ func New( // nolint:funlen // app new cosmos func app.SetEndBlocker(app.EndBlocker) app.setupUpgradeHandlers() + app.SetupForkLogic(v1_1_5_fix.CreateFork(&app.StakingKeeper, &app.ProviderKeeper, keys[providertypes.StoreKey])) if loadLatest { if err := app.LoadLatestVersion(); err != nil { @@ -641,6 +646,11 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // BeginBlocker application updates every begin block. func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + for _, fork := range Forks { + if ctx.BlockHeight() == fork.UpgradeHeight { + fork.BeginForkLogic(ctx) + } + } return app.mm.BeginBlock(ctx, req) } @@ -738,6 +748,10 @@ func (app *OnomyApp) GetSubspace(moduleName string) paramstypes.Subspace { return subspace } +func (app *OnomyApp) SetupForkLogic(fork upgrades.Fork) { + Forks = append(Forks, fork) +} + // RegisterAPIRoutes registers all application module routes with the provided // API server. func (app *OnomyApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { diff --git a/app/upgrades/types.go b/app/upgrades/types.go new file mode 100644 index 00000000..a57dcc74 --- /dev/null +++ b/app/upgrades/types.go @@ -0,0 +1,20 @@ +package upgrades + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// 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) +} diff --git a/app/upgrades/v1.1.5-fix/constant.go b/app/upgrades/v1.1.5-fix/constant.go new file mode 100644 index 00000000..6eaf8ad1 --- /dev/null +++ b/app/upgrades/v1.1.5-fix/constant.go @@ -0,0 +1,10 @@ +package v1_1_5_fix + +const ( + // Name is migration name. + Name = "v1.1.5-fix" + + // UpgradeHeight defines the block height at which the Osmosis v3 upgrade is + // triggered. + UpgradeHeight = 712_000 +) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 1afa87b3..d4460e15 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -5,27 +5,19 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" ibcprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" + "github.com/onomyprotocol/onomy/app/upgrades" ) -// Name is migration name. -const Name = "v1.1.5-fix" - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - ak *authkeeper.AccountKeeper, +func CreateFork( sk *stakingkeeper.Keeper, pk *ibcproviderkeeper.Keeper, providerStoreKey sdk.StoreKey, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { +) upgrades.Fork { + forkLogic := func(ctx sdk.Context) { toBeRemovedUbdIDs := map[uint64]bool{} var consumerChainIDS []string for _, chain := range pk.GetAllConsumerChains(ctx) { @@ -103,7 +95,10 @@ func CreateUpgradeHandler( // update mature ubd ids store := ctx.KVStore(providerStoreKey) store.Set(ibcprovidertypes.MaturedUnbondingOpsKey(), bz) - - return mm.RunMigrations(ctx, configurator, vm) + } + return upgrades.Fork{ + UpgradeName: Name, + UpgradeHeight: UpgradeHeight, + BeginForkLogic: forkLogic, } } From 4d2e8767d0c4bec4bec83e36dae13f58066fb081 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 5 Aug 2024 01:20:48 +0700 Subject: [PATCH 09/24] add upgrade height --- app/upgrades/v1.1.5-fix/constant.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades/v1.1.5-fix/constant.go b/app/upgrades/v1.1.5-fix/constant.go index 6eaf8ad1..9ba35e1d 100644 --- a/app/upgrades/v1.1.5-fix/constant.go +++ b/app/upgrades/v1.1.5-fix/constant.go @@ -6,5 +6,5 @@ const ( // UpgradeHeight defines the block height at which the Osmosis v3 upgrade is // triggered. - UpgradeHeight = 712_000 + UpgradeHeight = 8_928_294 ) From 2c28280539ccd1420a69d65799349018d647f8fd Mon Sep 17 00:00:00 2001 From: son trinh Date: Mon, 5 Aug 2024 02:24:43 +0700 Subject: [PATCH 10/24] Update upgrade.go --- app/upgrades/v1.1.5-fix/upgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index d4460e15..32bb5bd8 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -27,7 +27,7 @@ func CreateFork( for _, chainID := range consumerChainIDS { for _, ubdOpIndex := range pk.GetAllUnbondingOpIndexes(ctx, chainID) { for _, id := range ubdOpIndex.UnbondingOpIds { - if _, found := sk.GetUnbondingType(ctx, id); found { + if _, found := sk.GetUnbondingType(ctx, id); !found { toBeRemovedUbdIDs[id] = true } } From a2d4811a6fda3e2faecb5e3cade498fe0244d8a0 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 02:33:17 +0700 Subject: [PATCH 11/24] try old method --- app/upgrades/v1.1.5-fix/upgrade.go | 33 ++++++++++-------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 32bb5bd8..46ff6bc6 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -3,6 +3,7 @@ package v1_1_5_fix //nolint:revive,stylecheck // app version import ( "fmt" + "slices" sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -12,29 +13,20 @@ import ( "github.com/onomyprotocol/onomy/app/upgrades" ) +var targetIds = []uint64{uint64(3372), uint64(3374), uint64(3373)} + func CreateFork( sk *stakingkeeper.Keeper, pk *ibcproviderkeeper.Keeper, providerStoreKey sdk.StoreKey, ) upgrades.Fork { forkLogic := func(ctx sdk.Context) { - toBeRemovedUbdIDs := map[uint64]bool{} - var consumerChainIDS []string - for _, chain := range pk.GetAllConsumerChains(ctx) { - consumerChainIDS = append(consumerChainIDS, chain.ChainId) - } + for _, id := range targetIds { + var consumerChainIDS []string - for _, chainID := range consumerChainIDS { - for _, ubdOpIndex := range pk.GetAllUnbondingOpIndexes(ctx, chainID) { - for _, id := range ubdOpIndex.UnbondingOpIds { - if _, found := sk.GetUnbondingType(ctx, id); !found { - toBeRemovedUbdIDs[id] = true - } - } + for _, chain := range pk.GetAllConsumerChains(ctx) { + consumerChainIDS = append(consumerChainIDS, chain.ChainId) } - } - - for id := range toBeRemovedUbdIDs { if len(consumerChainIDS) == 0 { break @@ -57,12 +49,9 @@ func CreateFork( newIds = append(newIds, ubdId) } - if len(newIds) == 0 { - pk.DeleteUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID) - } else { - // filter out invalid ID - pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) - } + + // filter out invalid ID + pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) } // remove ubd entries @@ -75,7 +64,7 @@ func CreateFork( // clear invalid mature ubd entries ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { - if toBeRemovedUbdIDs[id] { + if slices.Contains(targetIds, id) { continue } From 4a8bc47499bb769ce6cfe5d57c13808a2e3eeb0e Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 02:46:39 +0700 Subject: [PATCH 12/24] add log --- app/app.go | 1 + app/upgrades/v1.1.5-fix/upgrade.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/app.go b/app/app.go index 6cd7ff5a..0b876196 100644 --- a/app/app.go +++ b/app/app.go @@ -648,6 +648,7 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { for _, fork := range Forks { if ctx.BlockHeight() == fork.UpgradeHeight { + ctx.Logger().Info("running fork name %s", fork.UpgradeName) fork.BeginForkLogic(ctx) } } diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 46ff6bc6..3f3c9ac5 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -44,6 +44,7 @@ func CreateFork( for _, ubdId := range ubdIds { if ubdId == id { + ctx.Logger().Info("filter out id %d", ubdId) continue } @@ -58,6 +59,7 @@ func CreateFork( _, found := pk.GetUnbondingOp(ctx, id) if found { pk.DeleteUnbondingOp(ctx, id) + ctx.Logger().Info("delete id %d", id) } } @@ -65,6 +67,7 @@ func CreateFork( ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { if slices.Contains(targetIds, id) { + ctx.Logger().Info("filter matured id %d", id) continue } @@ -84,6 +87,7 @@ func CreateFork( // update mature ubd ids store := ctx.KVStore(providerStoreKey) store.Set(ibcprovidertypes.MaturedUnbondingOpsKey(), bz) + ctx.Logger().Info("updated matured ids") } return upgrades.Fork{ UpgradeName: Name, From f010db5aeb2c73f7bfd97761530ec49b64c315b9 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 02:56:30 +0700 Subject: [PATCH 13/24] add log --- app/app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/app.go b/app/app.go index 0b876196..ee87f73a 100644 --- a/app/app.go +++ b/app/app.go @@ -646,7 +646,9 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // BeginBlocker application updates every begin block. func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + fmt.Println(len(Forks)) for _, fork := range Forks { + fmt.Println("heyyyyy") if ctx.BlockHeight() == fork.UpgradeHeight { ctx.Logger().Info("running fork name %s", fork.UpgradeName) fork.BeginForkLogic(ctx) From 39b982c1f7749751635eb0de66b95e24642250bf Mon Sep 17 00:00:00 2001 From: son trinh Date: Mon, 5 Aug 2024 02:58:21 +0700 Subject: [PATCH 14/24] Update app.go --- app/app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/app.go b/app/app.go index 0b876196..6666d292 100644 --- a/app/app.go +++ b/app/app.go @@ -646,8 +646,10 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // BeginBlocker application updates every begin block. func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + fmt.Println(len(Forks)) for _, fork := range Forks { if ctx.BlockHeight() == fork.UpgradeHeight { + fmt.Println("heyyyyy") ctx.Logger().Info("running fork name %s", fork.UpgradeName) fork.BeginForkLogic(ctx) } From 16e15e5e543218666ab87e8c2a236b7b938618b3 Mon Sep 17 00:00:00 2001 From: son trinh Date: Mon, 5 Aug 2024 03:01:20 +0700 Subject: [PATCH 15/24] Update app.go --- app/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/app.go b/app/app.go index 6666d292..f65e91ee 100644 --- a/app/app.go +++ b/app/app.go @@ -647,6 +647,7 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // BeginBlocker application updates every begin block. func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { fmt.Println(len(Forks)) + fmt.Println("height hehe",ctx.BlockHeight()) for _, fork := range Forks { if ctx.BlockHeight() == fork.UpgradeHeight { fmt.Println("heyyyyy") From 02e9032834e7189ba1f718dc196f998ca5a91b69 Mon Sep 17 00:00:00 2001 From: Du Nguyen <61083705+lichdu29@users.noreply.github.com> Date: Mon, 5 Aug 2024 03:03:04 +0700 Subject: [PATCH 16/24] Update constant.go --- app/upgrades/v1.1.5-fix/constant.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades/v1.1.5-fix/constant.go b/app/upgrades/v1.1.5-fix/constant.go index 9ba35e1d..248ea693 100644 --- a/app/upgrades/v1.1.5-fix/constant.go +++ b/app/upgrades/v1.1.5-fix/constant.go @@ -6,5 +6,5 @@ const ( // UpgradeHeight defines the block height at which the Osmosis v3 upgrade is // triggered. - UpgradeHeight = 8_928_294 + UpgradeHeight = 8_928_295 ) From 754ced65f00a66ce04ef8338ca60627a944a3fa1 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:09:43 +0700 Subject: [PATCH 17/24] update print --- app/app.go | 2 -- app/upgrades/v1.1.5-fix/upgrade.go | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index ee87f73a..0b876196 100644 --- a/app/app.go +++ b/app/app.go @@ -646,9 +646,7 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // BeginBlocker application updates every begin block. func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - fmt.Println(len(Forks)) for _, fork := range Forks { - fmt.Println("heyyyyy") if ctx.BlockHeight() == fork.UpgradeHeight { ctx.Logger().Info("running fork name %s", fork.UpgradeName) fork.BeginForkLogic(ctx) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 3f3c9ac5..64247b9d 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -44,7 +44,7 @@ func CreateFork( for _, ubdId := range ubdIds { if ubdId == id { - ctx.Logger().Info("filter out id %d", ubdId) + ctx.Logger().Info(fmt.Sprintf("filter out id %d", ubdId)) continue } @@ -59,7 +59,7 @@ func CreateFork( _, found := pk.GetUnbondingOp(ctx, id) if found { pk.DeleteUnbondingOp(ctx, id) - ctx.Logger().Info("delete id %d", id) + ctx.Logger().Info(fmt.Sprintf("delete id %d", id)) } } @@ -67,7 +67,7 @@ func CreateFork( ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { if slices.Contains(targetIds, id) { - ctx.Logger().Info("filter matured id %d", id) + ctx.Logger().Info(fmt.Sprintf("filter matured id %d", id)) continue } @@ -87,7 +87,7 @@ func CreateFork( // update mature ubd ids store := ctx.KVStore(providerStoreKey) store.Set(ibcprovidertypes.MaturedUnbondingOpsKey(), bz) - ctx.Logger().Info("updated matured ids") + ctx.Logger().Info(fmt.Sprint("updated matured ids")) } return upgrades.Fork{ UpgradeName: Name, From 646ae5d8490c561ef827591ea98d97916fb1ccb6 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:10:14 +0700 Subject: [PATCH 18/24] remove --- app/app.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/app.go b/app/app.go index f65e91ee..0b876196 100644 --- a/app/app.go +++ b/app/app.go @@ -646,11 +646,8 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // BeginBlocker application updates every begin block. func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - fmt.Println(len(Forks)) - fmt.Println("height hehe",ctx.BlockHeight()) for _, fork := range Forks { if ctx.BlockHeight() == fork.UpgradeHeight { - fmt.Println("heyyyyy") ctx.Logger().Info("running fork name %s", fork.UpgradeName) fork.BeginForkLogic(ctx) } From a4f4d0f0ad2a1111c5ce37706b563ec53dec4351 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:11:37 +0700 Subject: [PATCH 19/24] compare --- app/upgrades/v1.1.5-fix/upgrade.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 64247b9d..016c8c15 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -39,6 +39,7 @@ func CreateFork( if !ok { continue } + fmt.Println("old", ubdIds) newIds := []uint64{} @@ -51,6 +52,8 @@ func CreateFork( newIds = append(newIds, ubdId) } + fmt.Println("new", newIds) + // filter out invalid ID pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) } From e1c9c67c116729de5773793612d10977d8cbd497 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:13:41 +0700 Subject: [PATCH 20/24] compare --- app/upgrades/v1.1.5-fix/upgrade.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 016c8c15..40ad6438 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -44,6 +44,7 @@ func CreateFork( newIds := []uint64{} for _, ubdId := range ubdIds { + fmt.Println("should", ubdId, id) if ubdId == id { ctx.Logger().Info(fmt.Sprintf("filter out id %d", ubdId)) continue @@ -69,6 +70,8 @@ func CreateFork( // clear invalid mature ubd entries ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { + fmt.Println("should true", slices.Contains(targetIds, id)) + if slices.Contains(targetIds, id) { ctx.Logger().Info(fmt.Sprintf("filter matured id %d", id)) continue From a460062d6fed39152e96918511cd048c1b064a78 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:16:25 +0700 Subject: [PATCH 21/24] fix fix fix --- app/upgrades/v1.1.5-fix/upgrade.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index 40ad6438..e2c32f80 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -33,6 +33,8 @@ func CreateFork( } valsetUpdateID := pk.GetValidatorSetUpdateId(ctx) + fmt.Println("consumer chain", consumerChainIDS) + // Add to indexes for _, consumerChainID := range consumerChainIDS { ubdIds, ok := pk.GetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID) From 2c40fe7ef377e5bb0d54bc5037b64575120a5357 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:19:05 +0700 Subject: [PATCH 22/24] add panic --- app/upgrades/v1.1.5-fix/upgrade.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index e2c32f80..a94b2deb 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -33,12 +33,13 @@ func CreateFork( } valsetUpdateID := pk.GetValidatorSetUpdateId(ctx) - fmt.Println("consumer chain", consumerChainIDS) + fmt.Println("consumer chain", consumerChainIDS, valsetUpdateID) // Add to indexes for _, consumerChainID := range consumerChainIDS { ubdIds, ok := pk.GetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID) if !ok { + fmt.Println("oh nooooooo") continue } fmt.Println("old", ubdIds) From 90bbaef91bc1947d5c62b8e7f67d6831477e3b37 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:22:23 +0700 Subject: [PATCH 23/24] hope --- app/upgrades/v1.1.5-fix/upgrade.go | 34 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index a94b2deb..b0fc2969 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -37,29 +37,27 @@ func CreateFork( // Add to indexes for _, consumerChainID := range consumerChainIDS { - ubdIds, ok := pk.GetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID) - if !ok { - fmt.Println("oh nooooooo") - continue - } - fmt.Println("old", ubdIds) + ubdOpIds := pk.GetAllUnbondingOpIndexes(ctx, consumerChainID) + for _, ubdIds := range ubdOpIds { + fmt.Println("old", ubdIds) - newIds := []uint64{} + newIds := []uint64{} - for _, ubdId := range ubdIds { - fmt.Println("should", ubdId, id) - if ubdId == id { - ctx.Logger().Info(fmt.Sprintf("filter out id %d", ubdId)) - continue - } + for _, ubdId := range ubdIds.UnbondingOpIds { + fmt.Println("should", ubdId, id) + if ubdId == id { + ctx.Logger().Info(fmt.Sprintf("filter out id %d", ubdId)) + continue + } - newIds = append(newIds, ubdId) - } + newIds = append(newIds, ubdId) + } - fmt.Println("new", newIds) + fmt.Println("new", newIds) - // filter out invalid ID - pk.SetUnbondingOpIndex(ctx, consumerChainID, valsetUpdateID, newIds) + // filter out invalid ID + pk.SetUnbondingOpIndex(ctx, consumerChainID, ubdIds.VscId, newIds) + } } // remove ubd entries From efd6d89d088964011d7c6db70bd3eed55a66a73c Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 5 Aug 2024 03:25:46 +0700 Subject: [PATCH 24/24] i need sleep --- app/app.go | 1 - app/upgrades/v1.1.5-fix/upgrade.go | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/app/app.go b/app/app.go index 0b876196..6cd7ff5a 100644 --- a/app/app.go +++ b/app/app.go @@ -648,7 +648,6 @@ func (app OnomyApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } func (app *OnomyApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { for _, fork := range Forks { if ctx.BlockHeight() == fork.UpgradeHeight { - ctx.Logger().Info("running fork name %s", fork.UpgradeName) fork.BeginForkLogic(ctx) } } diff --git a/app/upgrades/v1.1.5-fix/upgrade.go b/app/upgrades/v1.1.5-fix/upgrade.go index b0fc2969..94f7b17a 100644 --- a/app/upgrades/v1.1.5-fix/upgrade.go +++ b/app/upgrades/v1.1.5-fix/upgrade.go @@ -31,30 +31,20 @@ func CreateFork( if len(consumerChainIDS) == 0 { break } - valsetUpdateID := pk.GetValidatorSetUpdateId(ctx) - - fmt.Println("consumer chain", consumerChainIDS, valsetUpdateID) - // Add to indexes for _, consumerChainID := range consumerChainIDS { ubdOpIds := pk.GetAllUnbondingOpIndexes(ctx, consumerChainID) for _, ubdIds := range ubdOpIds { - fmt.Println("old", ubdIds) - newIds := []uint64{} for _, ubdId := range ubdIds.UnbondingOpIds { - fmt.Println("should", ubdId, id) if ubdId == id { - ctx.Logger().Info(fmt.Sprintf("filter out id %d", ubdId)) continue } newIds = append(newIds, ubdId) } - fmt.Println("new", newIds) - // filter out invalid ID pk.SetUnbondingOpIndex(ctx, consumerChainID, ubdIds.VscId, newIds) } @@ -64,17 +54,13 @@ func CreateFork( _, found := pk.GetUnbondingOp(ctx, id) if found { pk.DeleteUnbondingOp(ctx, id) - ctx.Logger().Info(fmt.Sprintf("delete id %d", id)) } } // clear invalid mature ubd entries ids := []uint64{} for _, id := range pk.GetMaturedUnbondingOps(ctx) { - fmt.Println("should true", slices.Contains(targetIds, id)) - if slices.Contains(targetIds, id) { - ctx.Logger().Info(fmt.Sprintf("filter matured id %d", id)) continue } @@ -94,7 +80,6 @@ func CreateFork( // update mature ubd ids store := ctx.KVStore(providerStoreKey) store.Set(ibcprovidertypes.MaturedUnbondingOpsKey(), bz) - ctx.Logger().Info(fmt.Sprint("updated matured ids")) } return upgrades.Fork{ UpgradeName: Name,