From 9307dc0ca0bcc49670c969d0d6b3b9e97b99f94d Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:31:18 +0900 Subject: [PATCH] feat: bump movevm and point (#248) * wip * bump movevm and opinit * bump versiong --- Dockerfile | 2 +- cmd/move/move.go | 16 +++++++++++ go.mod | 6 ++-- go.sum | 8 +++--- x/ibc-hooks/move-hooks/ack_test.go | 12 ++++---- x/ibc-hooks/move-hooks/receive_test.go | 12 +++++--- x/ibc-hooks/move-hooks/timeout_test.go | 8 +++--- x/ibc/nft-transfer/keeper/relay_test.go | 2 +- x/move/config/config.go | 24 ---------------- x/move/keeper/api_test.go | 6 ++-- x/move/keeper/bank_test.go | 2 +- x/move/keeper/handler.go | 38 +++++++++++++------------ x/move/keeper/keeper.go | 29 +++++-------------- x/move/keeper/querier.go | 18 ++++-------- x/move/keeper/vesting.go | 4 +-- x/move/types/keys.go | 23 ++------------- x/move/types/vm_engine.go | 6 ++-- 17 files changed, 88 insertions(+), 128 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0222c821..5225b15a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG TARGETARCH ARG GOARCH # See https://github.com/initia-labs/movevm/releases -ENV LIBMOVEVM_VERSION=v0.3.4 +ENV LIBMOVEVM_VERSION=v0.4.1 # Install necessary packages RUN set -eux; apk add --no-cache ca-certificates build-base git cmake diff --git a/cmd/move/move.go b/cmd/move/move.go index 13f4d145..f8f0e50b 100644 --- a/cmd/move/move.go +++ b/cmd/move/move.go @@ -49,6 +49,8 @@ const ( flagFetchDepsOnly = "fetch-deps-only" flagSkipFetchLatestGitDeps = "skip-fetch-latest-git-deps" flagBytecodeVersion = "bytecode-version" + flagCompilerVersion = "compiler-version" + flagLanguageVersion = "language-version" /* test options */ flagGasLimit = "gas-limit" flagGasLimitShorthand = "g" @@ -613,6 +615,8 @@ the 'tests' directory`) cmd.Flags().Bool(flagVerbose, false, "Print additional diagnostics if available") cmd.Flags().Bool(flagSkipFetchLatestGitDeps, false, "Skip fetching latest git dependencies") cmd.Flags().Uint32(flagBytecodeVersion, 0, "Specify the version of the bytecode the compiler is going to emit") + cmd.Flags().Uint32(flagCompilerVersion, 1, "Specify the version of the compiler to use") + cmd.Flags().Uint32(flagLanguageVersion, 1, "Specify the version of the language to use") } func addMoveTestFlags(cmd *cobra.Command) { @@ -720,6 +724,18 @@ func getBuildConfig(cmd *cobra.Command) (*buildtypes.BuildConfig, error) { } options = append(options, buildtypes.WithBytecodeVersion(bytecodeVersion)) + compilerVersion, err := cmd.Flags().GetUint32(flagCompilerVersion) + if err != nil { + return nil, err + } + options = append(options, buildtypes.WithCompilerVersion(compilerVersion)) + + languageVersion, err := cmd.Flags().GetUint32(flagLanguageVersion) + if err != nil { + return nil, err + } + options = append(options, buildtypes.WithLanguageVersion(languageVersion)) + bc := buildtypes.NewBuildConfig(options...) return &bc, nil diff --git a/go.mod b/go.mod index a75e0e5b..7ba91c08 100644 --- a/go.mod +++ b/go.mod @@ -38,9 +38,9 @@ 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.4.1 - // we also need to update `LIBMOVEVM_VERSION` of Dockerfile#5 - github.com/initia-labs/movevm v0.3.4 + github.com/initia-labs/OPinit v0.4.2 + // we also need to update `LIBMOVEVM_VERSION` of Dockerfile#9 + github.com/initia-labs/movevm v0.4.1 github.com/noble-assets/forwarding/v2 v2.0.0-20240521090705-86712c4c9e43 github.com/pelletier/go-toml v1.9.5 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 1306db71..c8af7aba 100644 --- a/go.sum +++ b/go.sum @@ -727,14 +727,14 @@ 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.4.1 h1:g6IVEAOe2X31pgjk/q0zg4R1GfNj2QP3q5s3HMcWm8w= -github.com/initia-labs/OPinit v0.4.1/go.mod h1:n0eqwOnVGE1vuTnW+3jzyEXfE4ndTM0vCRGmPu9VvUc= +github.com/initia-labs/OPinit v0.4.2 h1:cfE6LXb3EquDK1/UTDT62o9c2HOQL0E9pWTr5BWAf8g= +github.com/initia-labs/OPinit v0.4.2/go.mod h1:bM+tav+ER4uC6U84PB5vgnRUNyjc/phNgHGYQX9ALhg= github.com/initia-labs/OPinit/api v0.4.1 h1:Q8etW92LiwekKZxzDYVFdiHF3uOpEA4nyajy8zpcxB0= github.com/initia-labs/OPinit/api v0.4.1/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0= github.com/initia-labs/cometbft v0.0.0-20240802022359-e0a5ce0336b6 h1:ObKvj9nGiKE+MWZ/LnH3rPcXsnBVVn4c30/iw+fMsd4= github.com/initia-labs/cometbft v0.0.0-20240802022359-e0a5ce0336b6/go.mod h1:jHPx9vQpWzPHEAiYI/7EDKaB1NXhK6o3SArrrY8ExKc= -github.com/initia-labs/movevm v0.3.4 h1:kzqs6uzTq0f5peZJNzLq/1qgnmAFfC+I9eCyPBducxM= -github.com/initia-labs/movevm v0.3.4/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30= +github.com/initia-labs/movevm v0.4.1 h1:eC+wCG8Fp6bwFSC6mi0UFlenNc/NJ7pCxXcsgCbWg/A= +github.com/initia-labs/movevm v0.4.1/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30= github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls= github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= diff --git a/x/ibc-hooks/move-hooks/ack_test.go b/x/ibc-hooks/move-hooks/ack_test.go index acb4a874..507a2ea9 100644 --- a/x/ibc-hooks/move-hooks/ack_test.go +++ b/x/ibc-hooks/move-hooks/ack_test.go @@ -73,7 +73,7 @@ func Test_onAckPacket_memo(t *testing.T) { require.NoError(t, err) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -94,7 +94,7 @@ func Test_onAckPacket_memo(t *testing.T) { require.NoError(t, err) // check the contract state; increased by 99 if ack is success - queryRes, err = input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err = input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -111,7 +111,7 @@ func Test_onAckPacket_memo(t *testing.T) { }, failedAckBz, addr) require.NoError(t, err) - queryRes, err = input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err = input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -189,7 +189,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) { require.NoError(t, err) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -210,7 +210,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) { require.NoError(t, err) // check the contract state; increased by 99 if ack is success - queryRes, err = input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err = input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -227,7 +227,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) { }, failedAckBz, addr) require.NoError(t, err) - queryRes, err = input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err = input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", diff --git a/x/ibc-hooks/move-hooks/receive_test.go b/x/ibc-hooks/move-hooks/receive_test.go index 41909ad0..06c4da76 100644 --- a/x/ibc-hooks/move-hooks/receive_test.go +++ b/x/ibc-hooks/move-hooks/receive_test.go @@ -24,7 +24,11 @@ func Test_OnReceivePacketWithoutMemo(t *testing.T) { Amount: "10000", Sender: addr.String(), Receiver: addr2.String(), - Memo: "", + Memo: `{ + "move": { + "message": null + } + }`, } dataBz, err := json.Marshal(&data) @@ -76,7 +80,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) { require.True(t, ack.Success()) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -158,7 +162,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) { require.True(t, ack.Success()) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -215,7 +219,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) { require.True(t, ack.Success()) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", diff --git a/x/ibc-hooks/move-hooks/timeout_test.go b/x/ibc-hooks/move-hooks/timeout_test.go index 59eef1f0..f9b07ee4 100644 --- a/x/ibc-hooks/move-hooks/timeout_test.go +++ b/x/ibc-hooks/move-hooks/timeout_test.go @@ -66,7 +66,7 @@ func Test_onTimeoutPacket_memo(t *testing.T) { require.NoError(t, err) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -87,7 +87,7 @@ func Test_onTimeoutPacket_memo(t *testing.T) { require.NoError(t, err) // check the contract state; increased by 99 - queryRes, err = input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err = input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -159,7 +159,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) { require.NoError(t, err) // check the contract state - queryRes, err := input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", @@ -180,7 +180,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) { require.NoError(t, err) // check the contract state; increased by 99 if ack is success - queryRes, err = input.MoveKeeper.ExecuteViewFunction( + queryRes, _, err = input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "Counter", diff --git a/x/ibc/nft-transfer/keeper/relay_test.go b/x/ibc/nft-transfer/keeper/relay_test.go index a5d8d27c..9788b8d2 100644 --- a/x/ibc/nft-transfer/keeper/relay_test.go +++ b/x/ibc/nft-transfer/keeper/relay_test.go @@ -33,7 +33,7 @@ func (suite *KeeperTestSuite) GetNFTOwner(ctx context.Context, k *keeper.Keeper, ta, err := tokenAddr.BcsSerialize() suite.Require().NoError(err) - res, err := moveKeeper.ExecuteViewFunction(ctx, moduleAddr, "object", "owner", typeTags, [][]byte{ta}) + res, _, err := moveKeeper.ExecuteViewFunction(ctx, moduleAddr, "object", "owner", typeTags, [][]byte{ta}) suite.Require().NoError(err) strAddr := strings.Trim(res.Ret, "\"") diff --git a/x/move/config/config.go b/x/move/config/config.go index 09d99f9c..55678941 100644 --- a/x/move/config/config.go +++ b/x/move/config/config.go @@ -7,33 +7,21 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" ) -// DefaultModuleCacheCapacity the number of modules can be stay in module cache -const DefaultModuleCacheCapacity = uint64(500) - -// DefaultScriptCacheCapacity the number of modules can be stay in module cache -const DefaultScriptCacheCapacity = uint64(100) - // DefaultContractSimulationGasLimit - default max simulation gas const DefaultContractSimulationGasLimit = uint64(3_000_000) const ( - flagModuleCacheCapacity = "move.module-cache-capacity" - flagScriptCacheCapacity = "move.script-cache-capacity" flagContractSimulationGasLimit = "move.contract-simulation-gas-limit" ) // MoveConfig is the extra config required for move type MoveConfig struct { - ModuleCacheCapacity uint64 `mapstructure:"module-cache-capacity"` - ScriptCacheCapacity uint64 `mapstructure:"script-cache-capacity"` ContractSimulationGasLimit uint64 `mapstructure:"contract-simulation-gas-limit"` } // DefaultMoveConfig returns the default settings for MoveConfig func DefaultMoveConfig() MoveConfig { return MoveConfig{ - ModuleCacheCapacity: DefaultModuleCacheCapacity, - ScriptCacheCapacity: DefaultScriptCacheCapacity, ContractSimulationGasLimit: DefaultContractSimulationGasLimit, } } @@ -41,16 +29,12 @@ func DefaultMoveConfig() MoveConfig { // GetConfig load config values from the app options func GetConfig(appOpts servertypes.AppOptions) MoveConfig { return MoveConfig{ - ModuleCacheCapacity: cast.ToUint64(appOpts.Get(flagModuleCacheCapacity)), - ScriptCacheCapacity: cast.ToUint64(appOpts.Get(flagScriptCacheCapacity)), ContractSimulationGasLimit: cast.ToUint64(appOpts.Get(flagContractSimulationGasLimit)), } } // AddConfigFlags implements servertypes.MoveConfigFlags interface. func AddConfigFlags(startCmd *cobra.Command) { - startCmd.Flags().Uint64(flagModuleCacheCapacity, DefaultModuleCacheCapacity, "Set the number of modules which can stay in the cache") - startCmd.Flags().Uint64(flagScriptCacheCapacity, DefaultScriptCacheCapacity, "Set the number of scripts which can stay in the cache") startCmd.Flags().Uint64(flagContractSimulationGasLimit, DefaultContractSimulationGasLimit, "Set the max simulation gas for move contract execution") } @@ -61,14 +45,6 @@ const DefaultConfigTemplate = ` ############################################################################### [move] -# in-memory cache for Move modules. -# The value is in MiB not bytes. -module-cache-capacity = "{{ .MoveConfig.ModuleCacheCapacity }}" - -# in-memory cache for Move scripts. -# The value is in MiB not bytes. -script-cache-capacity = "{{ .MoveConfig.ScriptCacheCapacity }}" - # The maximum gas amount can be used in a tx simulation call. contract-simulation-gas-limit = "{{ .MoveConfig.ContractSimulationGasLimit }}" ` diff --git a/x/move/keeper/api_test.go b/x/move/keeper/api_test.go index 4c683135..35418f43 100644 --- a/x/move/keeper/api_test.go +++ b/x/move/keeper/api_test.go @@ -219,7 +219,7 @@ func Test_GetPrice(t *testing.T) { pairIdArg, err := vmtypes.SerializeString(pairId) require.NoError(t, err) - res, err := input.MoveKeeper.ExecuteViewFunction( + res, _, err := input.MoveKeeper.ExecuteViewFunction( ctx, vmtypes.StdAddress, "oracle", @@ -287,14 +287,14 @@ func Test_API_CustomQuery(t *testing.T) { require.NoError(t, err) // to sdk - res, err := input.MoveKeeper.ExecuteViewFunction(ctx, vmtypes.TestAddress, "TestAddress", "to_sdk", []vmtypes.TypeTag{}, [][]byte{vmAddr.Bytes()}) + res, _, err := input.MoveKeeper.ExecuteViewFunction(ctx, vmtypes.TestAddress, "TestAddress", "to_sdk", []vmtypes.TypeTag{}, [][]byte{vmAddr.Bytes()}) require.NoError(t, err) require.Equal(t, fmt.Sprintf("\"%s\"", addrs[0].String()), res.Ret) // from sdk inputBz, err := vmtypes.SerializeString(addrs[0].String()) require.NoError(t, err) - res, err = input.MoveKeeper.ExecuteViewFunction(ctx, vmtypes.TestAddress, "TestAddress", "from_sdk", []vmtypes.TypeTag{}, [][]byte{inputBz}) + res, _, err = input.MoveKeeper.ExecuteViewFunction(ctx, vmtypes.TestAddress, "TestAddress", "from_sdk", []vmtypes.TypeTag{}, [][]byte{inputBz}) require.NoError(t, err) require.Equal(t, fmt.Sprintf("\"%s\"", vmAddr.String()), res.Ret) } diff --git a/x/move/keeper/bank_test.go b/x/move/keeper/bank_test.go index b6847ed6..492b773a 100644 --- a/x/move/keeper/bank_test.go +++ b/x/move/keeper/bank_test.go @@ -213,7 +213,7 @@ func Test_BurnCoins(t *testing.T) { vmtypes.TestAddress, vmtypes.StdAddress, "managed_coin", - "mint", + "mint_to", []vmtypes.TypeTag{}, []string{fmt.Sprintf("\"%s\"", vmtypes.TestAddress.String()), fmt.Sprintf("\"%s\"", barMetadata.String()), `"1000000"`}, ) diff --git a/x/move/keeper/handler.go b/x/move/keeper/handler.go index 92776524..fe9fa9f2 100644 --- a/x/move/keeper/handler.go +++ b/x/move/keeper/handler.go @@ -199,17 +199,19 @@ func (k Keeper) executeEntryFunction( sdkCtx = sdkCtx.WithGasMeter(storetypes.NewInfiniteGasMeter()) // run vm + gasBalance := gasForRuntime execRes, err := k.moveVM.ExecuteEntryFunction( + &gasBalance, types.NewVMStore(sdkCtx, k.VMStore), NewApi(k, sdkCtx), types.NewEnv(sdkCtx, ac, ec), - gasForRuntime, senders, payload, ) // consume gas first and check error - gasMeter.ConsumeGas(execRes.GasUsed, "move runtime") + gasUsed := gasForRuntime - gasBalance + gasMeter.ConsumeGas(gasUsed, "move runtime") if err != nil { return err } @@ -312,17 +314,19 @@ func (k Keeper) executeScript( sdkCtx = sdkCtx.WithGasMeter(storetypes.NewInfiniteGasMeter()) // run vm + gasBalance := gasForRuntime execRes, err := k.moveVM.ExecuteScript( + &gasBalance, types.NewVMStore(sdkCtx, k.VMStore), NewApi(k, sdkCtx), types.NewEnv(sdkCtx, ac, ec), - gasForRuntime, senders, payload, ) // consume gas first and check error - gasMeter.ConsumeGas(execRes.GasUsed, "move runtime") + gasUsed := gasForRuntime - gasBalance + gasMeter.ConsumeGas(gasUsed, "move runtime") if err != nil { return err } @@ -346,11 +350,7 @@ func (k Keeper) handleExecuteResponse( ) error { // Emit contract events for _, event := range execRes.Events { - typeTag, err := vmapi.StringifyTypeTag(event.TypeTag) - if err != nil { - return err - } - + typeTag := event.TypeTag ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeMove, sdk.NewAttribute(types.AttributeKeyTypeTag, typeTag), sdk.NewAttribute(types.AttributeKeyData, event.EventData), @@ -511,7 +511,7 @@ func (k Keeper) ExecuteViewFunction( functionName string, typeArgs []vmtypes.TypeTag, args [][]byte, -) (vmtypes.ViewOutput, error) { +) (vmtypes.ViewOutput, uint64, error) { return k.executeViewFunction( ctx, moduleAddr, @@ -530,7 +530,7 @@ func (k Keeper) ExecuteViewFunctionJSON( functionName string, typeArgs []vmtypes.TypeTag, jsonArgs []string, -) (vmtypes.ViewOutput, error) { +) (vmtypes.ViewOutput, uint64, error) { args := make([][]byte, len(jsonArgs)) for i, jsonArg := range jsonArgs { // use unsafe method for fast conversion @@ -556,7 +556,7 @@ func (k Keeper) executeViewFunction( typeArgs []vmtypes.TypeTag, args [][]byte, isJSON bool, -) (vmtypes.ViewOutput, error) { +) (vmtypes.ViewOutput, uint64, error) { payload, err := types.BuildExecuteViewFunctionPayload( moduleAddr, moduleName, @@ -566,12 +566,12 @@ func (k Keeper) executeViewFunction( isJSON, ) if err != nil { - return vmtypes.ViewOutput{}, err + return vmtypes.ViewOutput{}, 0, err } executionCounter, err := k.ExecutionCounter.Next(ctx) if err != nil { - return vmtypes.ViewOutput{}, err + return vmtypes.ViewOutput{}, 0, err } api := NewApi(k, ctx) @@ -585,19 +585,21 @@ func (k Keeper) executeViewFunction( gasMeter := sdkCtx.GasMeter() gasForRuntime := gasMeter.Limit() - gasMeter.GasConsumedToLimit() + gasBalance := gasForRuntime viewRes, err := k.moveVM.ExecuteViewFunction( + &gasBalance, types.NewVMStore(ctx, k.VMStore), api, env, - gasForRuntime, payload, ) if err != nil { - return vmtypes.ViewOutput{}, err + return vmtypes.ViewOutput{}, 0, err } // consume gas first and check error - gasMeter.ConsumeGas(viewRes.GasUsed, "view; move runtime") + gasUsed := gasForRuntime - gasBalance + gasMeter.ConsumeGas(gasUsed, "view; move runtime") - return viewRes, nil + return viewRes, gasUsed, nil } diff --git a/x/move/keeper/keeper.go b/x/move/keeper/keeper.go index 932e05bf..3cf5ba3f 100644 --- a/x/move/keeper/keeper.go +++ b/x/move/keeper/keeper.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "golang.org/x/crypto/sha3" moveconfig "github.com/initia-labs/initia/x/move/config" "github.com/initia-labs/initia/x/move/types" @@ -82,22 +81,17 @@ func NewKeeper( panic("authority is not a valid acc address") } - if moveConfig.ModuleCacheCapacity == 0 { - moveConfig.ModuleCacheCapacity = moveconfig.DefaultModuleCacheCapacity - } - - if moveConfig.ScriptCacheCapacity == 0 { - moveConfig.ScriptCacheCapacity = moveconfig.DefaultScriptCacheCapacity - } - if moveConfig.ContractSimulationGasLimit == 0 { moveConfig.ContractSimulationGasLimit = moveconfig.DefaultContractSimulationGasLimit } - moveVM := vm.NewVM( - moveConfig.ModuleCacheCapacity*1024*1024, // convert MiB to bytes - moveConfig.ScriptCacheCapacity*1024*1024, // convert MiB to bytes - ) + moveVM, err := vm.NewVM(vmtypes.InitiaVMConfig{ + // TODO: check this before mainnet + AllowUnstable: true, + }) + if err != nil { + panic(err) + } sb := collections.NewSchemaBuilder(storeService) k := &Keeper{ @@ -180,13 +174,6 @@ func (k Keeper) SetModule( return err } - checksum := sha3.Sum256(moduleBytes) - if checksumKey, err := types.GetChecksumKey(addr, moduleName); err != nil { - return err - } else if err := k.VMStore.Set(ctx, checksumKey, checksum[:]); err != nil { - return err - } - return nil } @@ -554,8 +541,6 @@ func (k Keeper) IterateVMStore(ctx context.Context, cb func(*types.Module, *type KeyBytes: key[cursor:], ValueBytes: value, }) - } else if separator == types.ChecksumSeparator { - // ignore checksum } else { return true, errors.New("unknown prefix") } diff --git a/x/move/keeper/querier.go b/x/move/keeper/querier.go index 8d36d8aa..4f804f4a 100644 --- a/x/move/keeper/querier.go +++ b/x/move/keeper/querier.go @@ -288,7 +288,7 @@ func (q Querier) View(ctx context.Context, req *types.QueryViewRequest) (res *ty return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "empty function name") } - output, err := q.ExecuteViewFunction( + output, gasUsed, err := q.ExecuteViewFunction( ctx, moduleAddr, req.ModuleName, @@ -303,16 +303,13 @@ func (q Querier) View(ctx context.Context, req *types.QueryViewRequest) (res *ty events := make([]types.VMEvent, len(output.Events)) for i, event := range output.Events { events[i].Data = event.EventData - events[i].TypeTag, err = vmapi.StringifyTypeTag(event.TypeTag) - if err != nil { - return - } + events[i].TypeTag = event.TypeTag } res = &types.QueryViewResponse{ Data: output.Ret, Events: events, - GasUsed: output.GasUsed, + GasUsed: gasUsed, } return @@ -359,7 +356,7 @@ func (q Querier) ViewJSON(ctx context.Context, req *types.QueryViewJSONRequest) return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "empty function name") } - output, err := q.ExecuteViewFunctionJSON( + output, gasUsed, err := q.ExecuteViewFunctionJSON( ctx, moduleAddr, req.ModuleName, @@ -374,16 +371,13 @@ func (q Querier) ViewJSON(ctx context.Context, req *types.QueryViewJSONRequest) events := make([]types.VMEvent, len(output.Events)) for i, event := range output.Events { events[i].Data = event.EventData - events[i].TypeTag, err = vmapi.StringifyTypeTag(event.TypeTag) - if err != nil { - return - } + events[i].TypeTag = event.TypeTag } res = &types.QueryViewJSONResponse{ Data: output.Ret, Events: events, - GasUsed: output.GasUsed, + GasUsed: gasUsed, } return diff --git a/x/move/keeper/vesting.go b/x/move/keeper/vesting.go index ad7c8e5b..9349aa06 100644 --- a/x/move/keeper/vesting.go +++ b/x/move/keeper/vesting.go @@ -64,7 +64,7 @@ func (vk VestingKeeper) getVestingTokenDenom(ctx context.Context, moduleAccAddr return "", err } - output, err := vk.executeViewFunction( + output, _, err := vk.executeViewFunction( ctx, moduleAddr, moduleName, @@ -104,7 +104,7 @@ func (vk VestingKeeper) getVestingTableHandler(ctx context.Context, moduleAccAdd return nil, err } - output, err := vk.executeViewFunction( + output, _, err := vk.executeViewFunction( ctx, moduleAddr, moduleName, diff --git a/x/move/types/keys.go b/x/move/types/keys.go index b9435db3..71c0ba17 100644 --- a/x/move/types/keys.go +++ b/x/move/types/keys.go @@ -65,10 +65,9 @@ var ( ParamsKey = []byte{0x31} // prefix for parameters for module x/move ModuleSeparator = byte(0) - ChecksumSeparator = byte(1) - ResourceSeparator = byte(2) - TableEntrySeparator = byte(3) - TableInfoSeparator = byte(4) + ResourceSeparator = byte(1) + TableEntrySeparator = byte(2) + TableInfoSeparator = byte(3) ) // GetModulePrefix returns the prefix key of an account module store @@ -87,22 +86,6 @@ func GetModuleKey(addr vmtypes.AccountAddress, moduleName string) ([]byte, error return append(append(addr.Bytes(), ModuleSeparator), bz...), nil } -// GetChecksumPrefix returns the prefix key of an account module checksum store -func GetChecksumPrefix(addr vmtypes.AccountAddress) []byte { - return append(addr.Bytes(), ChecksumSeparator) -} - -// GetChecksumKey returns the key of the published move module checksum -func GetChecksumKey(addr vmtypes.AccountAddress, moduleName string) ([]byte, error) { - identifier := vmtypes.Identifier(moduleName) - bz, err := identifier.BcsSerialize() - if err != nil { - return nil, err - } - - return append(append(addr.Bytes(), ChecksumSeparator), bz...), nil -} - // GetResourcePrefix returns the prefix key of an account resource store func GetResourcePrefix(addr vmtypes.AccountAddress) []byte { return append(addr.Bytes(), ResourceSeparator) diff --git a/x/move/types/vm_engine.go b/x/move/types/vm_engine.go index f935b227..80683443 100644 --- a/x/move/types/vm_engine.go +++ b/x/move/types/vm_engine.go @@ -16,25 +16,25 @@ type VMEngine interface { ) (vmtypes.ExecutionResult, error) Destroy() ExecuteViewFunction( + gasBalance *uint64, kvStore api.KVStore, goApi api.GoAPI, env vmtypes.Env, - gasLimit uint64, payload vmtypes.ViewFunction, ) (vmtypes.ViewOutput, error) ExecuteEntryFunction( + gasBalance *uint64, kvStore api.KVStore, goApi api.GoAPI, env vmtypes.Env, - gasLimit uint64, senders []vmtypes.AccountAddress, payload vmtypes.EntryFunction, ) (vmtypes.ExecutionResult, error) ExecuteScript( + gasBalance *uint64, kvStore api.KVStore, goApi api.GoAPI, env vmtypes.Env, - gasLimit uint64, senders []vmtypes.AccountAddress, payload vmtypes.Script, ) (vmtypes.ExecutionResult, error)