From 57b190e5c2982417447dd2d22dd0a669a46cec36 Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 6 May 2024 21:32:54 +0800 Subject: [PATCH] Problem: contract migration in upgrade (#1428) * Problem: contract migration in upgrade * cleanup * cleanup * padding * cleanup --- app/upgrades.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/upgrades.go b/app/upgrades.go index 2211ea414c..bdfa657135 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -2,6 +2,7 @@ package app import ( "fmt" + "math/big" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -9,10 +10,28 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper" + "github.com/ethereum/go-ethereum/common" e2eetypes "github.com/crypto-org-chain/cronos/v2/x/e2ee/types" ) +type contractMigration struct { + Contract common.Address + Slot common.Hash + Value common.Hash +} + +// ContractMigrations records the list of contract migrations, chain-id -> migrations +var ContractMigrations = map[string][]contractMigration{ + "cronostestnet_338-3": { + { + Contract: common.HexToAddress("0x6265bf2371ccf45767184c8bd77b5c52e752c2bb"), + Slot: common.BigToHash(big.NewInt(0)), + Value: common.HexToHash("0x000000000000000000000000730CbB94480d50788481373B43d83133e171367e"), + }, + }, +} + func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) { planName := "v1.3" app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { @@ -20,6 +39,12 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clie if err != nil { return m, err } + + // migrate contract states + for _, migration := range ContractMigrations[ctx.ChainID()] { + app.EvmKeeper.SetState(ctx, migration.Contract, migration.Slot, migration.Value.Bytes()) + } + return m, nil })