Skip to content

Commit

Permalink
prepare v0.6.2 release (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Nov 21, 2024
1 parent 8a3d125 commit a58daf9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 88 deletions.
83 changes: 1 addition & 82 deletions app/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,100 +1,19 @@
package app

import (
"bytes"
"context"
"errors"
"fmt"

"cosmossdk.io/collections"
sdkerrors "cosmossdk.io/errors"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"

movetypes "github.com/initia-labs/initia/x/move/types"
vmprecompile "github.com/initia-labs/movevm/precompile"
vmtypes "github.com/initia-labs/movevm/types"
)

const upgradeName = "0.6.0"
const upgradeName = "0.6.2"

// RegisterUpgradeHandlers returns upgrade handlers
func (app *InitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {

// 1. publish new code module first
codeModuleBz, err := vmprecompile.ReadStdlib("code.mv")
if err != nil {
return nil, err
}
err = app.MoveKeeper.SetModule(ctx, vmtypes.StdAddress, movetypes.MoveModuleNameCode, codeModuleBz[0])
if err != nil {
return nil, err
}

// 2. update vm data with new separator and add checksums of each module

// Previous:
// ModuleSeparator = byte(0)
// ResourceSeparator = byte(1)
// TableEntrySeparator = byte(2)
// TableInfoSeparator = byte(3)

// Current:
// ModuleSeparator = byte(0)
// ChecksumSeparator = byte(1)
// ResourceSeparator = byte(2)
// TableEntrySeparator = byte(3)
// TableInfoSeparator = byte(4)

err = app.MoveKeeper.VMStore.Walk(ctx, new(collections.Range[[]byte]).Descending(), func(key, value []byte) (stop bool, err error) {
key = bytes.Clone(key)

cursor := movetypes.AddressBytesLength
if len(key) <= cursor {
return true, fmt.Errorf("invalid key length: %d", len(key))
}

separator := key[cursor]
if separator == movetypes.ModuleSeparator {
checksum := movetypes.ModuleBzToChecksum(value)
value = checksum[:]
} else if separator >= movetypes.TableInfoSeparator {
return true, errors.New("unknown prefix")
} else if err = app.MoveKeeper.VMStore.Remove(ctx, key); err != nil {
return true, err
}

key[cursor] = key[cursor] + 1
err = app.MoveKeeper.VMStore.Set(ctx, key, value)
if err != nil {
return true, err
}

return false, nil
})
if err != nil {
return nil, err
}

// 3. update new modules

codesBz, err := vmprecompile.ReadStdlib("object_code_deployment.mv", "coin.mv", "cosmos.mv", "dex.mv", "json.mv", "bech32.mv", "hash.mv", "collection.mv")
if err != nil {
return nil, err
}
modules := make([]vmtypes.Module, len(codesBz))
for i, codeBz := range codesBz {
modules[i] = vmtypes.NewModule(codeBz)
}

err = app.MoveKeeper.PublishModuleBundle(ctx, vmtypes.StdAddress, vmtypes.NewModuleBundle(modules...), movetypes.UpgradePolicy_COMPATIBLE)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to publish module bundle")
}

return vm, nil
},
)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/go-metrics v0.5.3
github.com/initia-labs/OPinit v0.5.6
github.com/initia-labs/OPinit v0.6.0
// we also need to update `LIBMOVEVM_VERSION` of Dockerfile#9
github.com/initia-labs/movevm v0.6.1
github.com/noble-assets/forwarding/v2 v2.0.0-20240521090705-86712c4c9e43
Expand Down Expand Up @@ -151,7 +151,7 @@ require (
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/initia-labs/OPinit/api v0.5.1 // indirect
github.com/initia-labs/OPinit/api v0.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,10 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/initia-labs/OPinit v0.5.6 h1:m+RHWD64rWcvEfe4ZEi9IHxBrMmKUq4VQA7KTZpMMSk=
github.com/initia-labs/OPinit v0.5.6/go.mod h1:lx1amLMszculwPu8ln+btJno38UV28fd2nP7XC88ZeE=
github.com/initia-labs/OPinit/api v0.5.1 h1:zwyJf7HtKJCKvLJ1R9PjVfJO1L+d/jKoeFyT7WTLHFI=
github.com/initia-labs/OPinit/api v0.5.1/go.mod h1:gHK6DEWb3/DqQD5LjKirUx9jilAh2UioXanoQdgqVfU=
github.com/initia-labs/OPinit v0.6.0 h1:V9jQf8+PjNctLX31FHMGUsk6fpnygVJO1WYzCmBMzkU=
github.com/initia-labs/OPinit v0.6.0/go.mod h1:gDpCh4Zx94mihwgzP/PLav8eVHLroZBu3dFyzCy8iIs=
github.com/initia-labs/OPinit/api v0.6.0 h1:Q3hDHpTd9EqlDfY/OryCKIwuXYWJxGJdGfJicV1RjL4=
github.com/initia-labs/OPinit/api v0.6.0/go.mod h1:gHK6DEWb3/DqQD5LjKirUx9jilAh2UioXanoQdgqVfU=
github.com/initia-labs/cometbft v0.0.0-20241106155049-4698d4a37fe1 h1:Hqxf4a6PfCatz5vCBCovjhn4FwYaooCXIvyv4MM4Wjs=
github.com/initia-labs/cometbft v0.0.0-20241106155049-4698d4a37fe1/go.mod h1:+wh6ap6xctVG+JOHwbl8pPKZ0GeqdPYqISu7F4b43cQ=
github.com/initia-labs/movevm v0.6.1 h1:g+nUX289tou8HaHkwvZIE7KzhVAi+fykpGORItw8j0E=
Expand Down

0 comments on commit a58daf9

Please sign in to comment.