@@ -2,7 +2,6 @@ package state
22
33import (
44 "fmt"
5- "math"
65
76 "github.com/onflow/cadence/common"
87 "github.com/onflow/crypto/hash"
@@ -81,27 +80,27 @@ func (params StateParameters) WithMaxValueSizeAllowed(
8180}
8281
8382type limitsController struct {
84- enforceLimits bool
83+ meteringEnabled bool
8584 maxKeySizeAllowed uint64
8685 maxValueSizeAllowed uint64
8786}
8887
8988func newLimitsController (params StateParameters ) * limitsController {
9089 return & limitsController {
91- enforceLimits : true ,
90+ meteringEnabled : true ,
9291 maxKeySizeAllowed : params .maxKeySizeAllowed ,
9392 maxValueSizeAllowed : params .maxValueSizeAllowed ,
9493 }
9594}
9695
97- func (controller * limitsController ) RunWithAllLimitsDisabled (f func ()) {
96+ func (controller * limitsController ) RunWithMeteringDisabled (f func ()) {
9897 if f == nil {
9998 return
10099 }
101- current := controller .enforceLimits
102- controller .enforceLimits = false
100+ current := controller .meteringEnabled
101+ controller .meteringEnabled = false
103102 f ()
104- controller .enforceLimits = current
103+ controller .meteringEnabled = current
105104}
106105
107106// NewExecutionState constructs a new state
@@ -176,7 +175,7 @@ func (state *ExecutionState) Get(id flow.RegisterID) (flow.RegisterValue, error)
176175 var value []byte
177176 var err error
178177
179- if state .enforceLimits {
178+ if state .meteringEnabled {
180179 if err = state .checkSize (id , []byte {}); err != nil {
181180 return nil , err
182181 }
@@ -189,7 +188,7 @@ func (state *ExecutionState) Get(id flow.RegisterID) (flow.RegisterValue, error)
189188 return nil , fmt .Errorf ("failed to read %s: %w" , id , getError )
190189 }
191190
192- err = state .meter .MeterStorageRead (id , value , state .enforceLimits )
191+ err = state .meter .MeterStorageRead (id , value , state .meteringEnabled )
193192 return value , err
194193}
195194
@@ -199,7 +198,7 @@ func (state *ExecutionState) Set(id flow.RegisterID, value flow.RegisterValue) e
199198 return fmt .Errorf ("cannot Set on a finalized state" )
200199 }
201200
202- if state .enforceLimits {
201+ if state .meteringEnabled {
203202 if err := state .checkSize (id , value ); err != nil {
204203 return err
205204 }
@@ -212,7 +211,7 @@ func (state *ExecutionState) Set(id flow.RegisterID, value flow.RegisterValue) e
212211 return fmt .Errorf ("failed to update %s: %w" , id , setError )
213212 }
214213
215- return state .meter .MeterStorageWrite (id , value , state .enforceLimits )
214+ return state .meter .MeterStorageWrite (id , value , state .meteringEnabled )
216215}
217216
218217// MeterComputation meters computation usage
@@ -221,7 +220,7 @@ func (state *ExecutionState) MeterComputation(usage common.ComputationUsage) err
221220 return fmt .Errorf ("cannot MeterComputation on a finalized state" )
222221 }
223222
224- if state .enforceLimits {
223+ if state .meteringEnabled {
225224 return state .meter .MeterComputation (usage )
226225 }
227226 return nil
@@ -234,26 +233,12 @@ func (state *ExecutionState) ComputationAvailable(usage common.ComputationUsage)
234233 return false
235234 }
236235
237- if state .enforceLimits {
236+ if state .meteringEnabled {
238237 return state .meter .ComputationAvailable (usage )
239238 }
240239 return true
241240}
242241
243- // ComputationRemaining returns the available computation capacity without metering
244- func (state * ExecutionState ) ComputationRemaining (kind common.ComputationKind ) uint64 {
245- if state .finalized {
246- // if state is finalized return 0
247- return 0
248- }
249-
250- if state .enforceLimits {
251- return state .meter .ComputationRemaining (kind )
252- }
253-
254- return math .MaxUint64
255- }
256-
257242// TotalComputationUsed returns total computation used
258243func (state * ExecutionState ) TotalComputationUsed () uint64 {
259244 return state .meter .TotalComputationUsed ()
@@ -275,7 +260,7 @@ func (state *ExecutionState) MeterMemory(usage common.MemoryUsage) error {
275260 return fmt .Errorf ("cannot MeterMemory on a finalized state" )
276261 }
277262
278- if state .enforceLimits {
263+ if state .meteringEnabled {
279264 return state .meter .MeterMemory (usage )
280265 }
281266
@@ -302,7 +287,7 @@ func (state *ExecutionState) MeterEmittedEvent(byteSize uint64) error {
302287 return fmt .Errorf ("cannot MeterEmittedEvent on a finalized state" )
303288 }
304289
305- if state .enforceLimits {
290+ if state .meteringEnabled {
306291 return state .meter .MeterEmittedEvent (byteSize )
307292 }
308293
0 commit comments