Skip to content

Commit

Permalink
Fix upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
liorbond committed Sep 23, 2023
1 parent c738b00 commit 0330f65
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package v1_11_testnet_shade_hardcoded_admins_fix

Check failure on line 1 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/scrtlabs/SecretNetwork/app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix

import (
"fmt"

store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/scrtlabs/SecretNetwork/app/keepers"
"github.com/scrtlabs/SecretNetwork/app/upgrades"
)

const upgradeName = "v1.11-testnet-shade-hardcoded-admins-fix"

var Upgrade = upgrades.Upgrade{
UpgradeName: upgradeName,
CreateUpgradeHandler: createUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

func setHardCodedAdmins(ctx sdk.Context) error {
iter := prefix.NewStore(ctx.KVStore(m.keeper.storeKey), types.ContractKeyPrefix).Iterator(nil, nil)

Check failure on line 23 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: prefix

Check failure on line 23 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: m

Check failure on line 23 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: types
for ; iter.Valid(); iter.Next() {
var contractAddress sdk.AccAddress = iter.Key()

var contractInfo types.ContractInfo

Check failure on line 27 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: types
m.keeper.cdc.MustUnmarshal(iter.Value(), &contractInfo)

Check failure on line 28 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: m

if hardcodedContractAdmins[contractAddress.String()] != "" {

Check failure on line 30 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: hardcodedContractAdmins
contractInfo.Admin = hardcodedContractAdmins[contractAddress.String()]

Check failure on line 31 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: hardcodedContractAdmins
// When the contract has a hardcoded admin via gov, adminProof is ignored inside the enclave.
// Otherwise and if valid, adminProof is a 32 bytes array (output of sha256).
// For future proofing and avoiding passing null pointers to the enclave, we'll set it to a 32 bytes array of 0.
contractInfo.AdminProof = make([]byte, 32)
}

// get v1 contract key
v1ContractKey := v1GetContractKey(ctx, m.keeper, contractAddress)

Check failure on line 39 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: v1GetContractKey

Check failure on line 39 in app/upgrades/v1.11-testnet-shade-hardcoded-admins_fix/upgrade.go

View workflow job for this annotation

GitHub Actions / lint

undefined: m

// convert v1 contract key to v2 contract key
v2ContractKey := types.ContractKey{
OgContractKey: v1ContractKey,
CurrentContractKey: v1ContractKey,
CurrentContractKeyProof: nil,
}

// overide v1 contract key with v2 contract key in the store
m.keeper.SetContractKey(ctx, contractAddress, &v2ContractKey)
}

return nil
}

func createUpgradeHandler(mm *module.Manager, _ *keepers.SecretAppKeepers, configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info(` _ _ _____ _____ _____ _____ ______ `)
ctx.Logger().Info(`| | | | __ \ / ____| __ \ /\ | __ \| ____|`)
ctx.Logger().Info(`| | | | |__) | | __| |__) | / \ | | | | |__ `)
ctx.Logger().Info(`| | | | ___/| | |_ | _ / / /\ \ | | | | __| `)
ctx.Logger().Info(`| |__| | | | |__| | | \ \ / ____ \| |__| | |____ `)
ctx.Logger().Info(` \____/|_| \_____|_| \_\/_/ \_\_____/|______|`)

setHardCodedAdmins(ctx)

ctx.Logger().Info(fmt.Sprintf("Running module migrations for %s...", upgradeName))
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit 0330f65

Please sign in to comment.