Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: checksum cache #92

Merged
merged 16 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion images/private/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/move/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
27 changes: 19 additions & 8 deletions x/move/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -17,22 +20,25 @@ 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"`
}

// DefaultMoveConfig returns the default settings for MoveConfig
func DefaultMoveConfig() MoveConfig {
return MoveConfig{
CacheCapacity: DefaultCacheCapacity,
ModuleCacheCapacity: DefaultModuleCacheCapacity,
ScriptCacheCapacity: DefaultScriptCacheCapacity,
ContractSimulationGasLimit: DefaultContractSimulationGasLimit,
ContractQueryGasLimit: DefaultContractQueryGasLimit,
}
Expand All @@ -41,15 +47,17 @@ 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)),
}
}

// 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")
}
Expand All @@ -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 }}"
Expand Down
10 changes: 7 additions & 3 deletions x/move/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@
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 {
Expand All @@ -90,7 +94,7 @@
moveConfig.ContractQueryGasLimit = moveconfig.DefaultContractQueryGasLimit
}

moveVM := vm.NewVM(moveConfig.CacheCapacity)
moveVM := vm.NewVM(moveConfig.ModuleCacheCapacity, moveConfig.ScriptCacheCapacity)

sb := collections.NewSchemaBuilder(storeService)
k := &Keeper{
Expand Down Expand Up @@ -582,7 +586,7 @@

return k.moveVM.ExecuteViewFunction(
types.NewVMStore(ctx, k.VMStore),
api,

Check failure on line 589 in x/move/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / Run test and upload codecov

cannot use api (variable of type GoApi) as "github.com/initia-labs/initiavm/api".GoAPI value in argument to k.moveVM.ExecuteViewFunction: GoApi does not implement "github.com/initia-labs/initiavm/api".GoAPI (missing method Query)
env,
k.config.ContractQueryGasLimit,
payload,
Expand Down
Loading