Skip to content

Commit

Permalink
Merge pull request #18 from rarimo/chains/mainnet-beta-v1.1.1-rc2
Browse files Browse the repository at this point in the history
Chains/mainnet beta v1.1.1 rc2
  • Loading branch information
olegfomenko authored Apr 30, 2024
2 parents bc58121 + 73b61ba commit 5ab0e1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
34 changes: 20 additions & 14 deletions x/cscalist/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

0 comments on commit 5ab0e1c

Please sign in to comment.