Skip to content

Commit 57b190e

Browse files
authored
Problem: contract migration in upgrade (crypto-org-chain#1428)
* Problem: contract migration in upgrade * cleanup * cleanup * padding * cleanup
1 parent 17123a5 commit 57b190e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/upgrades.go

+25
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,49 @@ package app
22

33
import (
44
"fmt"
5+
"math/big"
56

67
"github.com/cosmos/cosmos-sdk/codec"
78
storetypes "github.com/cosmos/cosmos-sdk/store/types"
89
sdk "github.com/cosmos/cosmos-sdk/types"
910
"github.com/cosmos/cosmos-sdk/types/module"
1011
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
1112
clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper"
13+
"github.com/ethereum/go-ethereum/common"
1214

1315
e2eetypes "github.com/crypto-org-chain/cronos/v2/x/e2ee/types"
1416
)
1517

18+
type contractMigration struct {
19+
Contract common.Address
20+
Slot common.Hash
21+
Value common.Hash
22+
}
23+
24+
// ContractMigrations records the list of contract migrations, chain-id -> migrations
25+
var ContractMigrations = map[string][]contractMigration{
26+
"cronostestnet_338-3": {
27+
{
28+
Contract: common.HexToAddress("0x6265bf2371ccf45767184c8bd77b5c52e752c2bb"),
29+
Slot: common.BigToHash(big.NewInt(0)),
30+
Value: common.HexToHash("0x000000000000000000000000730CbB94480d50788481373B43d83133e171367e"),
31+
},
32+
},
33+
}
34+
1635
func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) {
1736
planName := "v1.3"
1837
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
1938
m, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
2039
if err != nil {
2140
return m, err
2241
}
42+
43+
// migrate contract states
44+
for _, migration := range ContractMigrations[ctx.ChainID()] {
45+
app.EvmKeeper.SetState(ctx, migration.Contract, migration.Slot, migration.Value.Bytes())
46+
}
47+
2348
return m, nil
2449
})
2550

0 commit comments

Comments
 (0)