From e9e04ea7dfdcce7fb47b74d0b0a4bac27cd37f49 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 13 Feb 2025 17:17:11 +0100 Subject: [PATCH] chore(gnovm): remove unused Machine.MaxCycles (#3744) The logic to manage the CPU limit is already handled by the gasmeter, which has the ability to panic the gnovm if a cpu limit is reached. It's simpler and faster to have only one path of failure. No other changes in CPU cycles accounting, still performed in gnovm. --- gnovm/pkg/gnolang/machine.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 7b89e98eb6d..ac20a6540a1 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -43,7 +43,6 @@ type Machine struct { // Configuration PreprocessorMode bool // this is used as a flag when const values are evaluated during preprocessing ReadOnly bool - MaxCycles int64 Output io.Writer Store Store Context interface{} @@ -87,7 +86,6 @@ type MachineOptions struct { Context interface{} Alloc *Allocator // or see MaxAllocBytes. MaxAllocBytes int64 // or 0 for no limit. - MaxCycles int64 // or 0 for no limit. GasMeter store.GasMeter } @@ -112,7 +110,6 @@ var machinePool = sync.Pool{ func NewMachineWithOptions(opts MachineOptions) *Machine { preprocessorMode := opts.PreprocessorMode readOnly := opts.ReadOnly - maxCycles := opts.MaxCycles vmGasMeter := opts.GasMeter output := opts.Output @@ -145,7 +142,6 @@ func NewMachineWithOptions(opts MachineOptions) *Machine { mm.Alloc = alloc mm.PreprocessorMode = preprocessorMode mm.ReadOnly = readOnly - mm.MaxCycles = maxCycles mm.Output = output mm.Store = store mm.Context = context @@ -1025,13 +1021,9 @@ const GasFactorCPU int64 = 1 func (m *Machine) incrCPU(cycles int64) { if m.GasMeter != nil { gasCPU := overflow.Mul64p(cycles, GasFactorCPU) - m.GasMeter.ConsumeGas(gasCPU, "CPUCycles") + m.GasMeter.ConsumeGas(gasCPU, "CPUCycles") // May panic if out of gas. } - m.Cycles += cycles - if m.MaxCycles != 0 && m.Cycles > m.MaxCycles { - panic("CPU cycle overrun") - } } const (