@@ -2,8 +2,6 @@ package state
22
33import (
44 "fmt"
5- "math"
6-
75 "github.com/onflow/cadence/common"
86 "github.com/onflow/crypto/hash"
97
@@ -81,27 +79,27 @@ func (params StateParameters) WithMaxValueSizeAllowed(
8179}
8280
8381type limitsController struct {
84- enforceLimits bool
82+ meteringEnabled bool
8583 maxKeySizeAllowed uint64
8684 maxValueSizeAllowed uint64
8785}
8886
8987func newLimitsController (params StateParameters ) * limitsController {
9088 return & limitsController {
91- enforceLimits : true ,
89+ meteringEnabled : true ,
9290 maxKeySizeAllowed : params .maxKeySizeAllowed ,
9391 maxValueSizeAllowed : params .maxValueSizeAllowed ,
9492 }
9593}
9694
97- func (controller * limitsController ) RunWithAllLimitsDisabled (f func ()) {
95+ func (controller * limitsController ) RunWithMeteringDisabled (f func ()) {
9896 if f == nil {
9997 return
10098 }
101- current := controller .enforceLimits
102- controller .enforceLimits = false
99+ current := controller .meteringEnabled
100+ controller .meteringEnabled = false
103101 f ()
104- controller .enforceLimits = current
102+ controller .meteringEnabled = current
105103}
106104
107105// NewExecutionState constructs a new state
@@ -176,7 +174,7 @@ func (state *ExecutionState) Get(id flow.RegisterID) (flow.RegisterValue, error)
176174 var value []byte
177175 var err error
178176
179- if state .enforceLimits {
177+ if state .meteringEnabled {
180178 if err = state .checkSize (id , []byte {}); err != nil {
181179 return nil , err
182180 }
@@ -189,7 +187,7 @@ func (state *ExecutionState) Get(id flow.RegisterID) (flow.RegisterValue, error)
189187 return nil , fmt .Errorf ("failed to read %s: %w" , id , getError )
190188 }
191189
192- err = state .meter .MeterStorageRead (id , value , state .enforceLimits )
190+ err = state .meter .MeterStorageRead (id , value , state .meteringEnabled )
193191 return value , err
194192}
195193
@@ -199,7 +197,7 @@ func (state *ExecutionState) Set(id flow.RegisterID, value flow.RegisterValue) e
199197 return fmt .Errorf ("cannot Set on a finalized state" )
200198 }
201199
202- if state .enforceLimits {
200+ if state .meteringEnabled {
203201 if err := state .checkSize (id , value ); err != nil {
204202 return err
205203 }
@@ -212,7 +210,7 @@ func (state *ExecutionState) Set(id flow.RegisterID, value flow.RegisterValue) e
212210 return fmt .Errorf ("failed to update %s: %w" , id , setError )
213211 }
214212
215- return state .meter .MeterStorageWrite (id , value , state .enforceLimits )
213+ return state .meter .MeterStorageWrite (id , value , state .meteringEnabled )
216214}
217215
218216// MeterComputation meters computation usage
@@ -221,7 +219,7 @@ func (state *ExecutionState) MeterComputation(usage common.ComputationUsage) err
221219 return fmt .Errorf ("cannot MeterComputation on a finalized state" )
222220 }
223221
224- if state .enforceLimits {
222+ if state .meteringEnabled {
225223 return state .meter .MeterComputation (usage )
226224 }
227225 return nil
@@ -234,26 +232,12 @@ func (state *ExecutionState) ComputationAvailable(usage common.ComputationUsage)
234232 return false
235233 }
236234
237- if state .enforceLimits {
235+ if state .meteringEnabled {
238236 return state .meter .ComputationAvailable (usage )
239237 }
240238 return true
241239}
242240
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-
257241// TotalComputationUsed returns total computation used
258242func (state * ExecutionState ) TotalComputationUsed () uint64 {
259243 return state .meter .TotalComputationUsed ()
@@ -275,7 +259,7 @@ func (state *ExecutionState) MeterMemory(usage common.MemoryUsage) error {
275259 return fmt .Errorf ("cannot MeterMemory on a finalized state" )
276260 }
277261
278- if state .enforceLimits {
262+ if state .meteringEnabled {
279263 return state .meter .MeterMemory (usage )
280264 }
281265
@@ -302,7 +286,7 @@ func (state *ExecutionState) MeterEmittedEvent(byteSize uint64) error {
302286 return fmt .Errorf ("cannot MeterEmittedEvent on a finalized state" )
303287 }
304288
305- if state .enforceLimits {
289+ if state .meteringEnabled {
306290 return state .meter .MeterEmittedEvent (byteSize )
307291 }
308292
0 commit comments