Skip to content

Commit e9e04ea

Browse files
authored
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.
1 parent 52a4198 commit e9e04ea

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

gnovm/pkg/gnolang/machine.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type Machine struct {
4343
// Configuration
4444
PreprocessorMode bool // this is used as a flag when const values are evaluated during preprocessing
4545
ReadOnly bool
46-
MaxCycles int64
4746
Output io.Writer
4847
Store Store
4948
Context interface{}
@@ -87,7 +86,6 @@ type MachineOptions struct {
8786
Context interface{}
8887
Alloc *Allocator // or see MaxAllocBytes.
8988
MaxAllocBytes int64 // or 0 for no limit.
90-
MaxCycles int64 // or 0 for no limit.
9189
GasMeter store.GasMeter
9290
}
9391

@@ -112,7 +110,6 @@ var machinePool = sync.Pool{
112110
func NewMachineWithOptions(opts MachineOptions) *Machine {
113111
preprocessorMode := opts.PreprocessorMode
114112
readOnly := opts.ReadOnly
115-
maxCycles := opts.MaxCycles
116113
vmGasMeter := opts.GasMeter
117114

118115
output := opts.Output
@@ -145,7 +142,6 @@ func NewMachineWithOptions(opts MachineOptions) *Machine {
145142
mm.Alloc = alloc
146143
mm.PreprocessorMode = preprocessorMode
147144
mm.ReadOnly = readOnly
148-
mm.MaxCycles = maxCycles
149145
mm.Output = output
150146
mm.Store = store
151147
mm.Context = context
@@ -1025,13 +1021,9 @@ const GasFactorCPU int64 = 1
10251021
func (m *Machine) incrCPU(cycles int64) {
10261022
if m.GasMeter != nil {
10271023
gasCPU := overflow.Mul64p(cycles, GasFactorCPU)
1028-
m.GasMeter.ConsumeGas(gasCPU, "CPUCycles")
1024+
m.GasMeter.ConsumeGas(gasCPU, "CPUCycles") // May panic if out of gas.
10291025
}
1030-
10311026
m.Cycles += cycles
1032-
if m.MaxCycles != 0 && m.Cycles > m.MaxCycles {
1033-
panic("CPU cycle overrun")
1034-
}
10351027
}
10361028

10371029
const (

0 commit comments

Comments
 (0)