diff --git a/Dockerfile b/Dockerfile index 8bc2c5e2..50cd5442 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.21-alpine AS go-builder #ARG arch=x86_64 # See https://github.com/initia-labs/initiavm/releases -ENV LIBINITIAVM_VERSION=v0.2.0-beta.2 +ENV LIBINITIAVM_VERSION=v0.2.0-beta.2.1 # this comes from standard alpine nightly file # https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile diff --git a/go.mod b/go.mod index b72ebf13..24ee4236 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( cosmossdk.io/x/tx v0.13.0 cosmossdk.io/x/upgrade v0.1.1 github.com/IGLOU-EU/go-wildcard v1.0.3 + github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang v0.0.0-20231213012317-73b6bbf74833 github.com/bits-and-blooms/bitset v1.13.0 github.com/cometbft/cometbft v0.38.5 github.com/cosmos/cosmos-db v1.0.0 @@ -38,8 +39,7 @@ require ( github.com/hashicorp/go-metrics v0.5.2 github.com/initia-labs/OPinit v0.2.0-beta.1 // we also need to update `LIBINITIAVM_VERSION` of images/private/Dockerfile#5 - github.com/initia-labs/initiavm v0.2.0-beta.2 - github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20220519162058-e5cd3c3b3f3a + github.com/initia-labs/initiavm v0.2.0-beta.2.0.20240226025020-6e778c96c52f github.com/pelletier/go-toml v1.9.5 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 @@ -73,7 +73,6 @@ require ( github.com/99designs/keyring v1.2.1 // indirect github.com/DataDog/datadog-go v3.2.0+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect - github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang v0.0.0-20231213012317-73b6bbf74833 // indirect github.com/aws/aws-sdk-go v1.44.224 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect diff --git a/go.sum b/go.sum index d7071a3d..2bf84a9e 100644 --- a/go.sum +++ b/go.sum @@ -725,8 +725,8 @@ github.com/initia-labs/cosmos-sdk v0.0.0-20240123082052-77e8b246064a h1:wD9ynlE7 github.com/initia-labs/cosmos-sdk v0.0.0-20240123082052-77e8b246064a/go.mod h1:tlrkY1sntOt1q0OX/rqF0zRJtmXNoffAS6VFTcky+w8= github.com/initia-labs/iavl v0.0.0-20240208034922-5d81c449d4c0 h1:GQ7/UD5mB6q104roqZK5jxb6ff9sBk0/uwFxgERQIaU= github.com/initia-labs/iavl v0.0.0-20240208034922-5d81c449d4c0/go.mod h1:CmTGqMnRnucjxbjduneZXT+0vPgNElYvdefjX2q9tYc= -github.com/initia-labs/initiavm v0.2.0-beta.2 h1:aSUZok4fQAWVJF9RA5mkF2mrdZq1gtqDllCHgBPjV58= -github.com/initia-labs/initiavm v0.2.0-beta.2/go.mod h1:KTdC3W2wgeOiL0YYIu6MEvK4j8envSpLjH14sMKMD6k= +github.com/initia-labs/initiavm v0.2.0-beta.2.0.20240226025020-6e778c96c52f h1:zNxqfWC8MymWOakk2JL+PkzVHIX309cNBCnMJJRfUJM= +github.com/initia-labs/initiavm v0.2.0-beta.2.0.20240226025020-6e778c96c52f/go.mod h1:Yq+GksFbLNwnyNHKd84yDUTqFpzye3F1ic7Ax9sur10= 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= @@ -842,8 +842,6 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20220519162058-e5cd3c3b3f3a h1:oMG8C4E7DFkat7WQicw4JNa/dYUaqO7RvLPbkFdADIA= -github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20220519162058-e5cd3c3b3f3a/go.mod h1:NrRYJCFtaewjIRr4B9V2AyWsAEMW0Zqdjs8Bm+bACbM= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= diff --git a/images/private/Dockerfile b/images/private/Dockerfile index e1323cc6..84a7ce86 100644 --- a/images/private/Dockerfile +++ b/images/private/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.21-alpine AS go-builder #ARG arch=x86_64 # See https://github.com/initia-labs/initiavm/releases -ARG LIBINITIAVM_VERSION=v0.2.0-beta.2 +ARG LIBINITIAVM_VERSION=v0.2.0-beta.2.1 # this comes from standard alpine nightly file # https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile diff --git a/x/move/client/cli/utils.go b/x/move/client/cli/utils.go index e478f892..3094438f 100644 --- a/x/move/client/cli/utils.go +++ b/x/move/client/cli/utils.go @@ -12,9 +12,9 @@ import ( "cosmossdk.io/core/address" sdkmath "cosmossdk.io/math" + "github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang/bcs" + "github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang/serde" "github.com/initia-labs/initia/x/move/types" - "github.com/novifinancial/serde-reflection/serde-generate/runtime/golang/bcs" - "github.com/novifinancial/serde-reflection/serde-generate/runtime/golang/serde" flag "github.com/spf13/pflag" ) diff --git a/x/move/config/config.go b/x/move/config/config.go index 42a63f35..260817e0 100644 --- a/x/move/config/config.go +++ b/x/move/config/config.go @@ -7,8 +7,11 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" ) -// DefaultCacheCapacity the number of modules can be stay in module cache -const DefaultCacheCapacity = uint64(1_000) +// DefaultModuleCacheCapacity the number of modules can be stay in module cache +const DefaultModuleCacheCapacity = uint64(5_000) + +// DefaultScriptCacheCapacity the number of modules can be stay in module cache +const DefaultScriptCacheCapacity = uint64(1_000) // DefaultContractQueryGasLimit - default max query gas for external query const DefaultContractQueryGasLimit = uint64(3_000_000) @@ -17,14 +20,16 @@ const DefaultContractQueryGasLimit = uint64(3_000_000) const DefaultContractSimulationGasLimit = uint64(3_000_000) const ( - flagCacheCapacity = "move.cache-capacity" + flagModuleCacheCapacity = "move.module-cache-capacity" + flagScriptCacheCapacity = "move.script-cache-capacity" flagContractSimulationGasLimit = "move.contract-simulation-gas-limit" flagContractQueryGasLimit = "move.contract-query-gas-limit" ) // MoveConfig is the extra config required for move type MoveConfig struct { - CacheCapacity uint64 `mapstructure:"cache-capacity"` + ModuleCacheCapacity uint64 `mapstructure:"module-cache-capacity"` + ScriptCacheCapacity uint64 `mapstructure:"script-cache-capacity"` ContractSimulationGasLimit uint64 `mapstructure:"contract-simulation-gas-limit"` ContractQueryGasLimit uint64 `mapstructure:"contract-query-gas-limit"` } @@ -32,7 +37,8 @@ type MoveConfig struct { // DefaultMoveConfig returns the default settings for MoveConfig func DefaultMoveConfig() MoveConfig { return MoveConfig{ - CacheCapacity: DefaultCacheCapacity, + ModuleCacheCapacity: DefaultModuleCacheCapacity, + ScriptCacheCapacity: DefaultScriptCacheCapacity, ContractSimulationGasLimit: DefaultContractSimulationGasLimit, ContractQueryGasLimit: DefaultContractQueryGasLimit, } @@ -41,7 +47,8 @@ func DefaultMoveConfig() MoveConfig { // GetConfig load config values from the app options func GetConfig(appOpts servertypes.AppOptions) MoveConfig { return MoveConfig{ - CacheCapacity: cast.ToUint64(appOpts.Get(flagCacheCapacity)), + ModuleCacheCapacity: cast.ToUint64(appOpts.Get(flagModuleCacheCapacity)), + ScriptCacheCapacity: cast.ToUint64(appOpts.Get(flagScriptCacheCapacity)), ContractSimulationGasLimit: cast.ToUint64(appOpts.Get(flagContractSimulationGasLimit)), ContractQueryGasLimit: cast.ToUint64(appOpts.Get(flagContractQueryGasLimit)), } @@ -49,7 +56,8 @@ func GetConfig(appOpts servertypes.AppOptions) MoveConfig { // AddConfigFlags implements servertypes.MoveConfigFlags interface. func AddConfigFlags(startCmd *cobra.Command) { - startCmd.Flags().Uint64(flagCacheCapacity, DefaultCacheCapacity, "Set the max simulation gas for move contract execution") + 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") startCmd.Flags().Uint64(flagContractQueryGasLimit, DefaultContractQueryGasLimit, "Set the max gas that can be spent on executing a query with a Move contract") } @@ -62,7 +70,10 @@ const DefaultConfigTemplate = ` [move] # The number of modules can be live in module cache. -cache-capacity = "{{ .MoveConfig.CacheCapacity }}" +module-cache-capacity = "{{ .MoveConfig.ModuleCacheCapacity }}" + +# The number of modules can be live in script cache. +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/keeper.go b/x/move/keeper/keeper.go index 2ed0fd06..3b28ada2 100644 --- a/x/move/keeper/keeper.go +++ b/x/move/keeper/keeper.go @@ -78,8 +78,12 @@ func NewKeeper( panic("authority is not a valid acc address") } - if moveConfig.CacheCapacity == 0 { - moveConfig.CacheCapacity = moveconfig.DefaultCacheCapacity + if moveConfig.ModuleCacheCapacity == 0 { + moveConfig.ModuleCacheCapacity = moveconfig.DefaultModuleCacheCapacity + } + + if moveConfig.ScriptCacheCapacity == 0 { + moveConfig.ScriptCacheCapacity = moveconfig.DefaultScriptCacheCapacity } if moveConfig.ContractSimulationGasLimit == 0 { @@ -90,7 +94,7 @@ func NewKeeper( moveConfig.ContractQueryGasLimit = moveconfig.DefaultContractQueryGasLimit } - moveVM := vm.NewVM(moveConfig.CacheCapacity) + moveVM := vm.NewVM(moveConfig.ModuleCacheCapacity, moveConfig.ScriptCacheCapacity) sb := collections.NewSchemaBuilder(storeService) k := &Keeper{