Skip to content

Commit

Permalink
chore: remove vmkeeper.maxcycles (#2993)
Browse files Browse the repository at this point in the history
Let's remove the `vn.maxCycles` variable from the VM keeper so that it
relies solely on the built-in gas system.

`maxCycles` remains an option on `gno.Machine` for blockchainless and
gasless experiences.

---------

Signed-off-by: moul <[email protected]>
Co-authored-by: Morgan Bazalgette <[email protected]>
  • Loading branch information
moul and thehowl authored Oct 22, 2024
1 parent 8417ca4 commit 1154172
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
7 changes: 3 additions & 4 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,8 @@ func newNodeConfig(tmc *tmcfg.Config, chainid string, appstate gnoland.GnoGenesi
}

return &gnoland.InMemoryNodeConfig{
PrivValidator: pv,
TMConfig: tmc,
Genesis: genesis,
GenesisMaxVMCycles: 100_000_000,
PrivValidator: pv,
TMConfig: tmc,
Genesis: genesis,
}
}
3 changes: 1 addition & 2 deletions gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type AppOptions struct {
DB dbm.DB // required
Logger *slog.Logger // required
EventSwitch events.EventSwitch // required
MaxCycles int64 // hard limit for cycles in GnoVM
InitChainerConfig // options related to InitChainer
}

Expand Down Expand Up @@ -88,7 +87,7 @@ func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) {
// Construct keepers.
acctKpr := auth.NewAccountKeeper(mainKey, ProtoGnoAccount)
bankKpr := bank.NewBankKeeper(acctKpr)
vmk := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, cfg.MaxCycles)
vmk := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr)

// Set InitChainer
icc := cfg.InitChainerConfig
Expand Down
10 changes: 4 additions & 6 deletions gno.land/pkg/gnoland/node_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import (
)

type InMemoryNodeConfig struct {
PrivValidator bft.PrivValidator // identity of the validator
Genesis *bft.GenesisDoc
TMConfig *tmcfg.Config
GenesisMaxVMCycles int64
DB *memdb.MemDB // will be initialized if nil
PrivValidator bft.PrivValidator // identity of the validator
Genesis *bft.GenesisDoc
TMConfig *tmcfg.Config
DB *memdb.MemDB // will be initialized if nil

// If StdlibDir not set, then it's filepath.Join(TMConfig.RootDir, "gnovm", "stdlibs")
InitChainerConfig
Expand Down Expand Up @@ -106,7 +105,6 @@ func NewInMemoryNode(logger *slog.Logger, cfg *InMemoryNodeConfig) (*node.Node,
// Initialize the application with the provided options
gnoApp, err := NewAppWithOptions(&AppOptions{
Logger: logger,
MaxCycles: cfg.GenesisMaxVMCycles,
DB: cfg.DB,
EventSwitch: evsw,
InitChainerConfig: cfg.InitChainerConfig,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion gno.land/pkg/sdk/vm/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func _setupTestEnv(cacheStdlibs bool) testEnv {
ctx := sdk.NewContext(sdk.RunTxModeDeliver, ms, &bft.Header{ChainID: "test-chain-id"}, log.NewNoopLogger())
acck := authm.NewAccountKeeper(iavlCapKey, std.ProtoBaseAccount)
bank := bankm.NewBankKeeper(acck)
vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, 100_000_000)
vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank)

mcw := ms.MultiCacheWrap()
vmk.Initialize(log.NewNoopLogger(), mcw)
Expand Down
103 changes: 46 additions & 57 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ type VMKeeper struct {

// cached, the DeliverTx persistent state.
gnoStore gno.Store

maxCycles int64 // max allowed cylces on VM executions
}

// NewVMKeeper returns a new VMKeeper.
Expand All @@ -72,15 +70,13 @@ func NewVMKeeper(
iavlKey store.StoreKey,
acck auth.AccountKeeper,
bank bank.BankKeeper,
maxCycles int64,
) *VMKeeper {
// TODO: create an Options struct to avoid too many constructor parameters
vmk := &VMKeeper{
baseKey: baseKey,
iavlKey: iavlKey,
acck: acck,
bank: bank,
maxCycles: maxCycles,
baseKey: baseKey,
iavlKey: iavlKey,
acck: acck,
bank: bank,
}
return vmk
}
Expand Down Expand Up @@ -267,13 +263,12 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add

m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Store: store,
Context: msgCtx,
Alloc: store.GetAllocator(),
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: "",
Output: os.Stdout, // XXX
Store: store,
Context: msgCtx,
Alloc: store.GetAllocator(),
GasMeter: ctx.GasMeter(),
})
defer m.Release()

Expand Down Expand Up @@ -368,13 +363,12 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) {
// Parse and run the files, construct *PV.
m2 := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: "",
Output: os.Stdout, // XXX
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
GasMeter: ctx.GasMeter(),
})
defer m2.Release()
defer func() {
Expand Down Expand Up @@ -469,13 +463,12 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) {
// Construct machine and evaluate.
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: os.Stdout, // XXX
Store: gnostore,
Context: msgCtx,
Alloc: gnostore.GetAllocator(),
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: "",
Output: os.Stdout, // XXX
Store: gnostore,
Context: msgCtx,
Alloc: gnostore.GetAllocator(),
GasMeter: ctx.GasMeter(),
})
defer m.Release()
m.SetActivePackage(mpv)
Expand Down Expand Up @@ -569,13 +562,12 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {
buf := new(bytes.Buffer)
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: buf,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: "",
Output: buf,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
GasMeter: ctx.GasMeter(),
})
// XXX MsgRun does not have pkgPath. How do we find it on chain?
defer m.Release()
Expand All @@ -596,13 +588,12 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {

m2 := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: "",
Output: buf,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: "",
Output: buf,
Store: gnostore,
Alloc: gnostore.GetAllocator(),
Context: msgCtx,
GasMeter: ctx.GasMeter(),
})
defer m2.Release()
m2.SetActivePackage(pv)
Expand Down Expand Up @@ -728,13 +719,12 @@ func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res
}
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: pkgPath,
Output: os.Stdout, // XXX
Store: gnostore,
Context: msgCtx,
Alloc: alloc,
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: pkgPath,
Output: os.Stdout, // XXX
Store: gnostore,
Context: msgCtx,
Alloc: alloc,
GasMeter: ctx.GasMeter(),
})
defer m.Release()
defer func() {
Expand Down Expand Up @@ -795,13 +785,12 @@ func (vm *VMKeeper) QueryEvalString(ctx sdk.Context, pkgPath string, expr string
}
m := gno.NewMachineWithOptions(
gno.MachineOptions{
PkgPath: pkgPath,
Output: os.Stdout, // XXX
Store: gnostore,
Context: msgCtx,
Alloc: alloc,
MaxCycles: vm.maxCycles,
GasMeter: ctx.GasMeter(),
PkgPath: pkgPath,
Output: os.Stdout, // XXX
Store: gnostore,
Context: msgCtx,
Alloc: alloc,
GasMeter: ctx.GasMeter(),
})
defer m.Release()
defer func() {
Expand Down

1 comment on commit 1154172

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Go Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 1154172 Previous: 88a0c4e Ratio
BenchmarkBinary/EmptyStruct:encode 435.1 ns/op 96 B/op 2 allocs/op 290.5 ns/op 96 B/op 2 allocs/op 1.50
BenchmarkBinary/EmptyStruct:encode - ns/op 435.1 ns/op 290.5 ns/op 1.50
BenchmarkBinary/EmptyStruct:decode 235.5 ns/op 0 B/op 0 allocs/op 134.5 ns/op 0 B/op 0 allocs/op 1.75
BenchmarkBinary/EmptyStruct:decode - ns/op 235.5 ns/op 134.5 ns/op 1.75
BenchmarkBinary/PrimitivesStruct:encode 5176 ns/op 1724 B/op 60 allocs/op 4136 ns/op 1724 B/op 60 allocs/op 1.25
BenchmarkBinary/PrimitivesStruct:encode - ns/op 5176 ns/op 4136 ns/op 1.25
BenchmarkBinary/ShortArraysStruct:decode 405 ns/op 0 B/op 0 allocs/op 217.8 ns/op 0 B/op 0 allocs/op 1.86
BenchmarkBinary/ShortArraysStruct:decode - ns/op 405 ns/op 217.8 ns/op 1.86
BenchmarkBinary/EmbeddedSt1:encode 6063 ns/op 2037 B/op 65 allocs/op 4701 ns/op 2037 B/op 65 allocs/op 1.29
BenchmarkBinary/EmbeddedSt1:encode - ns/op 6063 ns/op 4701 ns/op 1.29
BenchmarkRemoved 39.08 ns/op 0 B/op 0 allocs/op 29.25 ns/op 0 B/op 0 allocs/op 1.34
BenchmarkRemoved - ns/op 39.08 ns/op 29.25 ns/op 1.34
BenchmarkBcryptGenerateFromPassword/benchmark-security-param 63797850 ns/op 5130 B/op 9 allocs/op 31926591 ns/op 5125 B/op 9 allocs/op 2.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op 63797850 ns/op 31926591 ns/op 2.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param 127826844 ns/op 5139 B/op 9 allocs/op 31926591 ns/op 5125 B/op 9 allocs/op 4.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op 127826844 ns/op 31926591 ns/op 4.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param 255568646 ns/op 5158 B/op 9 allocs/op 31926591 ns/op 5125 B/op 9 allocs/op 8.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op 255568646 ns/op 31926591 ns/op 8.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param 510898132 ns/op 5196 B/op 10 allocs/op 31926591 ns/op 5125 B/op 9 allocs/op 16.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op 510898132 ns/op 31926591 ns/op 16.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param 1019441784 ns/op 5736 B/op 15 allocs/op 31926591 ns/op 5125 B/op 9 allocs/op 31.93
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op 1019441784 ns/op 31926591 ns/op 31.93
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - allocs/op 15 allocs/op 9 allocs/op 1.67
BenchmarkBcryptGenerateFromPassword/benchmark-security-param 2038677858 ns/op 5528 B/op 13 allocs/op 31926591 ns/op 5125 B/op 9 allocs/op 63.86
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op 2038677858 ns/op 31926591 ns/op 63.86
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - allocs/op 13 allocs/op 9 allocs/op 1.44
BenchmarkSigning 84326 ns/op 1856 B/op 36 allocs/op 25733 ns/op 64 B/op 1 allocs/op 3.28
BenchmarkSigning - ns/op 84326 ns/op 25733 ns/op 3.28
BenchmarkSigning - B/op 1856 B/op 64 B/op 29
BenchmarkSigning - allocs/op 36 allocs/op 1 allocs/op 36
BenchmarkSigning 84315 ns/op 1856 B/op 36 allocs/op 25733 ns/op 64 B/op 1 allocs/op 3.28
BenchmarkSigning - ns/op 84315 ns/op 25733 ns/op 3.28
BenchmarkSigning - B/op 1856 B/op 64 B/op 29
BenchmarkSigning - allocs/op 36 allocs/op 1 allocs/op 36
BenchmarkVerification 162743 ns/op 864 B/op 19 allocs/op 61648 ns/op 0 B/op 0 allocs/op 2.64
BenchmarkVerification - ns/op 162743 ns/op 61648 ns/op 2.64
BenchmarkVerification - B/op 864 B/op 0 B/op +∞
BenchmarkVerification - allocs/op 19 allocs/op 0 allocs/op +∞
BenchmarkVerification 166255 ns/op 864 B/op 19 allocs/op 61648 ns/op 0 B/op 0 allocs/op 2.70
BenchmarkVerification - ns/op 166255 ns/op 61648 ns/op 2.70
BenchmarkVerification - B/op 864 B/op 0 B/op +∞
BenchmarkVerification - allocs/op 19 allocs/op 0 allocs/op +∞
BenchmarkRandomBytes/random 68.37 ns/op 16 B/op 1 allocs/op 33.11 ns/op 4 B/op 1 allocs/op 2.06
BenchmarkRandomBytes/random - ns/op 68.37 ns/op 33.11 ns/op 2.06
BenchmarkRandomBytes/random - B/op 16 B/op 4 B/op 4
BenchmarkRandomBytes/random 104 ns/op 32 B/op 1 allocs/op 33.11 ns/op 4 B/op 1 allocs/op 3.14
BenchmarkRandomBytes/random - ns/op 104 ns/op 33.11 ns/op 3.14
BenchmarkRandomBytes/random - B/op 32 B/op 4 B/op 8
BenchmarkRandomBytes/random 268.2 ns/op 112 B/op 1 allocs/op 33.11 ns/op 4 B/op 1 allocs/op 8.10
BenchmarkRandomBytes/random - ns/op 268.2 ns/op 33.11 ns/op 8.10
BenchmarkRandomBytes/random - B/op 112 B/op 4 B/op 28
BenchmarkRandomBytes/random 2307 ns/op 1024 B/op 1 allocs/op 33.11 ns/op 4 B/op 1 allocs/op 69.68
BenchmarkRandomBytes/random - ns/op 2307 ns/op 33.11 ns/op 69.68
BenchmarkRandomBytes/random - B/op 1024 B/op 4 B/op 256
BenchmarkSmall/boltdb-1000-100-16-40/update 1508790 ns/op 45657 B/op 405 allocs/op 984983 ns/op 37521 B/op 373 allocs/op 1.53
BenchmarkSmall/boltdb-1000-100-16-40/update - ns/op 1508790 ns/op 984983 ns/op 1.53
BenchmarkSmall/boltdb-1000-100-16-40/update - B/op 45657 B/op 37521 B/op 1.22
BenchmarkSmall/memdb-1000-100-16-40/block 16798988 ns/op 9328889 B/op 170320 allocs/op 12505432 ns/op 6572434 B/op 116641 allocs/op 1.34
BenchmarkSmall/memdb-1000-100-16-40/block - ns/op 16798988 ns/op 12505432 ns/op 1.34
BenchmarkSmall/memdb-1000-100-16-40/block - B/op 9328889 B/op 6572434 B/op 1.42
BenchmarkSmall/memdb-1000-100-16-40/block - allocs/op 170320 allocs/op 116641 allocs/op 1.46
BenchmarkMedium/boltdb-100000-100-16-40/update 6649576 ns/op 125146 B/op 979 allocs/op 5090235 ns/op 97780 B/op 829 allocs/op 1.31
BenchmarkMedium/boltdb-100000-100-16-40/update - ns/op 6649576 ns/op 5090235 ns/op 1.31
BenchmarkMedium/boltdb-100000-100-16-40/update - B/op 125146 B/op 97780 B/op 1.28
BenchmarkMedium/memdb-100000-100-16-40/update - B/op 370098 B/op 252310 B/op 1.47
BenchmarkMedium/memdb-100000-100-16-40/update - allocs/op 7333 allocs/op 4860 allocs/op 1.51
BenchmarkLevelDBBatchSizes/goleveldb-100000-400-16-40/update - B/op 48218 B/op 38060 B/op 1.27
BenchmarkLevelDBBatchSizes/goleveldb-100000-400-16-40/update - allocs/op 579 allocs/op 446 allocs/op 1.30
BenchmarkLevelDBBatchSizes/goleveldb-100000-2000-16-40/block - B/op 104276482 B/op 78670622 B/op 1.33
BenchmarkLevelDBBatchSizes/goleveldb-100000-2000-16-40/block - allocs/op 1218846 allocs/op 973166 allocs/op 1.25
BenchmarkHash/ripemd160 2831 ns/op 25 B/op 1 allocs/op 704.7 ns/op 25 B/op 1 allocs/op 4.02
BenchmarkHash/ripemd160 - ns/op 2831 ns/op 704.7 ns/op 4.02
BenchmarkHash/sha2-256 523.1 ns/op 33 B/op 1 allocs/op 169.4 ns/op 33 B/op 1 allocs/op 3.09
BenchmarkHash/sha2-256 - ns/op 523.1 ns/op 169.4 ns/op 3.09
BenchmarkHash/sha3-256 1836 ns/op 33 B/op 1 allocs/op 717.4 ns/op 33 B/op 1 allocs/op 2.56
BenchmarkHash/sha3-256 - ns/op 1836 ns/op 717.4 ns/op 2.56
BenchmarkWriteSecretConnection 5689 ns/op 0 B/op 0 allocs/op 4015 ns/op 0 B/op 0 allocs/op 1.42
BenchmarkWriteSecretConnection - ns/op 5689 ns/op 4015 ns/op 1.42
BenchmarkReadSecretConnection 3758 ns/op 0 B/op 0 allocs/op 2348 ns/op 0 B/op 0 allocs/op 1.60
BenchmarkReadSecretConnection - ns/op 3758 ns/op 2348 ns/op 1.60
BenchmarkCacheStoreIterator100000 - allocs/op 28405 allocs/op 22732 allocs/op 1.25

This comment was automatically generated by workflow using github-action-benchmark.

CC: @ajnavarro @thehowl @zivkovicmilos

Please sign in to comment.