Skip to content

Commit

Permalink
ci: setup handler to clean up old states (#647)
Browse files Browse the repository at this point in the history
* ci: setup handler to clean up old states

* Update app/setup_handlers.go

Co-authored-by: Amit Yadav <[email protected]>

---------

Co-authored-by: Amit Yadav <[email protected]>
  • Loading branch information
cosmic-vagabond and amityadav0 authored Jul 11, 2024
1 parent 89bfe0d commit 3cee1c2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package app
import (
"fmt"

wasmmodule "github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
m "github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -22,6 +24,37 @@ func setUpgradeHandler(app *ElysApp) {
func(ctx sdk.Context, plan upgradetypes.Plan, vm m.VersionMap) (m.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + version.Version)

if version.Version == "v0.38.0" || version.Version == "v999.999.999" {
// Retrieve the wasm module store key
storeKey := app.keys[wasmmodule.StoreKey]

// Retrieve the wasm module store
store := ctx.KVStore(storeKey)

// List of prefixes to clear
prefixes := [][]byte{
// Account History contract
wasmtypes.GetContractStorePrefix(sdk.MustAccAddressFromBech32("elys1s37xz7tzrru2cpl96juu9lfqrsd4jh73j9slyv440q5vttx2uyesetjpne")),
}

// Add old code keys to the list of prefixes to clear
for i := uint64(1); i < 671; i++ {
codeKey := wasmtypes.GetCodeKey(i)
// append the code key to the prefixes
prefixes = append(prefixes, codeKey)
}

// Clear all keys in the store
for _, prefix := range prefixes {
iter := sdk.KVStorePrefixIterator(store, prefix)
defer iter.Close()

for ; iter.Valid(); iter.Next() {
store.Delete(iter.Key())
}
}
}

return app.mm.RunMigrations(ctx, app.configurator, vm)
},
)
Expand Down

0 comments on commit 3cee1c2

Please sign in to comment.