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

fix: Revert "fix: hardcode max vm cycles in keeper" #1902

Merged
merged 1 commit into from
Apr 8, 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
7 changes: 4 additions & 3 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ func newNodeConfig(tmc *tmcfg.Config, chainid string, appstate gnoland.GnoGenesi
}

return &gnoland.InMemoryNodeConfig{
PrivValidator: pv,
TMConfig: tmc,
Genesis: genesis,
PrivValidator: pv,
TMConfig: tmc,
Genesis: genesis,
GenesisMaxVMCycles: 10_000_000,
}
}
10 changes: 9 additions & 1 deletion gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type startCfg struct {
chainID string
genesisRemote string
dataDir string
genesisMaxVMCycles int64
config string

txEventStoreType string
Expand Down Expand Up @@ -124,6 +125,13 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) {
"replacement for '%%REMOTE%%' in genesis",
)

fs.Int64Var(
&c.genesisMaxVMCycles,
"genesis-max-vm-cycles",
10_000_000,
"set maximum allowed vm cycles per operation. Zero means no limit.",
)

fs.StringVar(
&c.config,
flagConfigFlag,
Expand Down Expand Up @@ -246,7 +254,7 @@ func execStart(c *startCfg, io commands.IO) error {
cfg.TxEventStore = txEventStoreCfg

// Create application and node.
gnoApp, err := gnoland.NewApp(dataDir, c.skipFailingGenesisTxs, logger)
gnoApp, err := gnoland.NewApp(dataDir, c.skipFailingGenesisTxs, logger, c.genesisMaxVMCycles)
if err != nil {
return fmt.Errorf("error in creating new app: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
GnoRootDir string
SkipFailingGenesisTxs bool
Logger *slog.Logger
MaxCycles int64
}

func NewAppOptions() *AppOptions {
Expand Down Expand Up @@ -77,7 +78,7 @@

// XXX: Embed this ?
stdlibsDir := filepath.Join(cfg.GnoRootDir, "gnovm", "stdlibs")
vmKpr := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, stdlibsDir)
vmKpr := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, stdlibsDir, cfg.MaxCycles)

Check warning on line 81 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L81

Added line #L81 was not covered by tests

// Set InitChainer
baseApp.SetInitChainer(InitChainer(baseApp, acctKpr, bankKpr, cfg.SkipFailingGenesisTxs))
Expand Down Expand Up @@ -122,7 +123,7 @@
}

// NewApp creates the GnoLand application.
func NewApp(dataRootDir string, skipFailingGenesisTxs bool, logger *slog.Logger) (abci.Application, error) {
func NewApp(dataRootDir string, skipFailingGenesisTxs bool, logger *slog.Logger, maxCycles int64) (abci.Application, error) {

Check warning on line 126 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L126

Added line #L126 was not covered by tests
var err error

cfg := NewAppOptions()
Expand Down
9 changes: 6 additions & 3 deletions gno.land/pkg/gnoland/node_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Genesis *bft.GenesisDoc
TMConfig *tmcfg.Config
SkipFailingGenesisTxs bool
GenesisMaxVMCycles int64
}

// NewMockedPrivValidator generate a new key
Expand Down Expand Up @@ -78,9 +79,10 @@
}

return &InMemoryNodeConfig{
PrivValidator: pv,
TMConfig: tm,
Genesis: genesis,
PrivValidator: pv,
TMConfig: tm,
Genesis: genesis,
GenesisMaxVMCycles: 10_000_000,

Check warning on line 85 in gno.land/pkg/gnoland/node_inmemory.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/node_inmemory.go#L82-L85

Added lines #L82 - L85 were not covered by tests
}
}

Expand Down Expand Up @@ -113,6 +115,7 @@
Logger: logger,
GnoRootDir: cfg.TMConfig.RootDir,
SkipFailingGenesisTxs: cfg.SkipFailingGenesisTxs,
MaxCycles: cfg.GenesisMaxVMCycles,

Check warning on line 118 in gno.land/pkg/gnoland/node_inmemory.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/node_inmemory.go#L118

Added line #L118 was not covered by tests
DB: memdb.NewMemDB(),
})
if err != nil {
Expand Down
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 @@ -39,7 +39,7 @@ func setupTestEnv() testEnv {
acck := authm.NewAccountKeeper(iavlCapKey, std.ProtoBaseAccount)
bank := bankm.NewBankKeeper(acck)
stdlibsDir := filepath.Join("..", "..", "..", "..", "gnovm", "stdlibs")
vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, stdlibsDir)
vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, stdlibsDir, 10_000_000)

vmk.Initialize(ms.MultiCacheWrap())

Expand Down
8 changes: 2 additions & 6 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import (
const (
maxAllocTx = 500 * 1000 * 1000
maxAllocQuery = 1500 * 1000 * 1000 // higher limit for queries

// maxVMCycles is the maximum number of cycles allowed while executing a single VM
// message. Ideally this should not be needed, as execution should halt when out of
// gas. The worst case scenario is that this value is used as a fallback.
maxVMCycles = 10_000_000
)

// vm.VMKeeperI defines a module interface that supports Gno
Expand Down Expand Up @@ -60,6 +55,7 @@ func NewVMKeeper(
acck auth.AccountKeeper,
bank bank.BankKeeper,
stdlibsDir string,
maxCycles int64,
) *VMKeeper {
// TODO: create an Options struct to avoid too many constructor parameters
vmk := &VMKeeper{
Expand All @@ -68,7 +64,7 @@ func NewVMKeeper(
acck: acck,
bank: bank,
stdlibsDir: stdlibsDir,
maxCycles: maxVMCycles,
maxCycles: maxCycles,
}
return vmk
}
Expand Down
Loading