From af6fca1c91a11685f43846d7fe729ea8ba79ad49 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:23:16 +0900 Subject: [PATCH 1/3] wip --- cmd/move/move.go | 16 +++++++++++++ go.mod | 2 ++ go.sum | 2 -- 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/handler.go | 32 +++++++++++++++---------- x/move/keeper/keeper.go | 19 ++++++--------- x/move/keeper/querier.go | 8 +++---- x/move/keeper/vesting.go | 4 ++-- x/move/types/vm_engine.go | 6 ++--- 14 files changed, 75 insertions(+), 78 deletions(-) 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..a9eabf00 100644 --- a/go.mod +++ b/go.mod @@ -237,3 +237,5 @@ replace ( // replace broken goleveldb github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ) + +replace github.com/initia-labs/movevm => ../movevm diff --git a/go.sum b/go.sum index 1306db71..32d40602 100644 --- a/go.sum +++ b/go.sum @@ -733,8 +733,6 @@ github.com/initia-labs/OPinit/api v0.4.1 h1:Q8etW92LiwekKZxzDYVFdiHF3uOpEA4nyajy 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/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/handler.go b/x/move/keeper/handler.go index 92776524..9acf31f8 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 } @@ -511,7 +515,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 +534,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 +560,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 +570,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 +589,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..a44c88dd 100644 --- a/x/move/keeper/keeper.go +++ b/x/move/keeper/keeper.go @@ -82,22 +82,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{ diff --git a/x/move/keeper/querier.go b/x/move/keeper/querier.go index 8d36d8aa..0f9a00ac 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, @@ -312,7 +312,7 @@ func (q Querier) View(ctx context.Context, req *types.QueryViewRequest) (res *ty res = &types.QueryViewResponse{ Data: output.Ret, Events: events, - GasUsed: output.GasUsed, + GasUsed: gasUsed, } return @@ -359,7 +359,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, @@ -383,7 +383,7 @@ func (q Querier) ViewJSON(ctx context.Context, req *types.QueryViewJSONRequest) 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/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) From 19b6fa13dc4139eca1489a7d496c94cdd42d5bd8 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Wed, 14 Aug 2024 17:45:14 +0900 Subject: [PATCH 2/3] bump movevm and opinit --- Dockerfile | 2 +- go.mod | 8 +++----- go.sum | 6 ++++-- x/move/keeper/bank_test.go | 2 +- x/move/keeper/keeper.go | 10 ---------- x/move/types/keys.go | 23 +++-------------------- 6 files changed, 12 insertions(+), 39 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0222c821..96c14337 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.0 # Install necessary packages RUN set -eux; apk add --no-cache ca-certificates build-base git cmake diff --git a/go.mod b/go.mod index a9eabf00..1e8476dd 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.0 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 @@ -237,5 +237,3 @@ replace ( // replace broken goleveldb github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 ) - -replace github.com/initia-labs/movevm => ../movevm diff --git a/go.sum b/go.sum index 32d40602..270bd792 100644 --- a/go.sum +++ b/go.sum @@ -727,12 +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.4.0 h1:nqEa4b5ujmCf0hTrqst8M9N/MCMg5eU8BZYMkMa7tYc= +github.com/initia-labs/movevm v0.4.0/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/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/keeper.go b/x/move/keeper/keeper.go index a44c88dd..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" @@ -175,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 } @@ -549,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/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) From a41dcc684b19a91aeb5bcf8a6dc20e597f6d3053 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Wed, 14 Aug 2024 18:28:12 +0900 Subject: [PATCH 3/3] bump versiong --- Dockerfile | 2 +- go.mod | 2 +- go.sum | 4 ++-- x/move/keeper/handler.go | 6 +----- x/move/keeper/querier.go | 10 ++-------- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 96c14337..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.4.0 +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/go.mod b/go.mod index 1e8476dd..7ba91c08 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/hashicorp/go-metrics v0.5.3 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.0 + 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 270bd792..c8af7aba 100644 --- a/go.sum +++ b/go.sum @@ -733,8 +733,8 @@ github.com/initia-labs/OPinit/api v0.4.1 h1:Q8etW92LiwekKZxzDYVFdiHF3uOpEA4nyajy 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.4.0 h1:nqEa4b5ujmCf0hTrqst8M9N/MCMg5eU8BZYMkMa7tYc= -github.com/initia-labs/movevm v0.4.0/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/move/keeper/handler.go b/x/move/keeper/handler.go index 9acf31f8..fe9fa9f2 100644 --- a/x/move/keeper/handler.go +++ b/x/move/keeper/handler.go @@ -350,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), diff --git a/x/move/keeper/querier.go b/x/move/keeper/querier.go index 0f9a00ac..4f804f4a 100644 --- a/x/move/keeper/querier.go +++ b/x/move/keeper/querier.go @@ -303,10 +303,7 @@ 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{ @@ -374,10 +371,7 @@ 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{