Skip to content

Commit

Permalink
chore(gnovm): remove unused Machine.MaxCycles (#3744)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvertes authored Feb 13, 2025
1 parent 52a4198 commit e9e04ea
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit e9e04ea

Please sign in to comment.