From 3d30858df94e0c0c5d511182d8ab1b76b9849b3f Mon Sep 17 00:00:00 2001 From: violog <51th.apprent1ce.f0rce@gmail.com> Date: Mon, 29 Apr 2024 18:47:11 +0300 Subject: [PATCH 1/2] Must update params on Merkle root change instead of treap root --- x/cscalist/keeper/proposal.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/x/cscalist/keeper/proposal.go b/x/cscalist/keeper/proposal.go index f0e244d8..c89f2b25 100644 --- a/x/cscalist/keeper/proposal.go +++ b/x/cscalist/keeper/proposal.go @@ -8,8 +8,11 @@ import ( ) func (k Keeper) EditCSCAListProposal(ctx sdk.Context, proposal *types.EditCSCAListProposal) error { - tree := Treap{k} - root := k.GetRootKey(ctx) + var ( + tree = Treap{k} + oldRootKey = k.GetRootKey(ctx) + oldRoot, _ = k.GetNode(ctx, oldRootKey) + ) for _, leaf := range proposal.ToRemove { tree.Remove(ctx, leaf) @@ -22,31 +25,34 @@ func (k Keeper) EditCSCAListProposal(ctx sdk.Context, proposal *types.EditCSCALi tree.Insert(ctx, leaf) } - if root != k.GetRootKey(ctx) { - params := k.GetParams(ctx) - params.RootUpdated = true - params.UpdatedAtBlock = uint64(ctx.BlockHeight()) - k.SetParams(ctx, params) - } - + k.updateParamsOnNeed(ctx, oldRoot) return nil } func (k Keeper) ReplaceCSCAListProposal(ctx sdk.Context, proposal *types.ReplaceCSCAListProposal) error { - tree := Treap{k} - root := k.GetRootKey(ctx) + var ( + tree = Treap{k} + oldRootKey = k.GetRootKey(ctx) + oldRoot, _ = k.GetNode(ctx, oldRootKey) + ) k.RemoveTree(ctx) // safe while no errors are expected, otherwise think about a backup for _, leaf := range proposal.Leaves { tree.Insert(ctx, leaf) } - if root != k.GetRootKey(ctx) { + k.updateParamsOnNeed(ctx, oldRoot) + return nil +} + +func (k Keeper) updateParamsOnNeed(ctx sdk.Context, oldRoot types.Node) { + newRootKey := k.GetRootKey(ctx) + newRoot, _ := k.GetNode(ctx, newRootKey) + + if oldRoot.Hash != newRoot.Hash { params := k.GetParams(ctx) params.RootUpdated = true params.UpdatedAtBlock = uint64(ctx.BlockHeight()) k.SetParams(ctx, params) } - - return nil } From 73b61ba6d7f067f723bc09819f2198fee2ee1c6c Mon Sep 17 00:00:00 2001 From: olegfomenko Date: Tue, 30 Apr 2024 14:48:03 +0300 Subject: [PATCH 2/2] adding upgrade handler for v1.1.1-rc2 --- app/app.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/app.go b/app/app.go index 78de9822..9777031b 100644 --- a/app/app.go +++ b/app/app.go @@ -1036,6 +1036,13 @@ func New( }, ) + app.UpgradeKeeper.SetUpgradeHandler( + "v1.1.1-rc2", + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error())