@@ -105,6 +105,7 @@ pub struct RuntimeConfig {
105
105
pub cpu_cycles_per_second : Option < u64 > ,
106
106
/// Safety margin for CPU speed variations (0.0 to 1.0)
107
107
pub safety_margin : f64 ,
108
+ pub enable_metering : bool ,
108
109
}
109
110
110
111
impl Default for RuntimeConfig {
@@ -113,6 +114,7 @@ impl Default for RuntimeConfig {
113
114
max_execution_seconds : 5.0 ,
114
115
cpu_cycles_per_second : None ,
115
116
safety_margin : 0.2 ,
117
+ enable_metering : false ,
116
118
}
117
119
}
118
120
}
@@ -134,6 +136,7 @@ pub struct Runtime {
134
136
pub ( crate ) contract_store : ContractStore ,
135
137
/// loaded contract modules
136
138
pub ( super ) contract_modules : HashMap < ContractKey , Module > ,
139
+ pub ( crate ) enabled_metering : bool ,
137
140
}
138
141
139
142
impl Runtime {
@@ -171,6 +174,7 @@ impl Runtime {
171
174
172
175
contract_store,
173
176
delegate_modules : HashMap :: new ( ) ,
177
+ enabled_metering : config. enable_metering ,
174
178
} )
175
179
}
176
180
@@ -338,7 +342,9 @@ impl Runtime {
338
342
339
343
let metering = Arc :: new ( Metering :: new ( max_cycles, operation_cost) ) ;
340
344
let mut compiler_config = Singlepass :: default ( ) ;
341
- compiler_config. push_middleware ( metering) ;
345
+ if config. enable_metering {
346
+ compiler_config. push_middleware ( metering. clone ( ) ) ;
347
+ }
342
348
343
349
let engine = wasmer:: EngineBuilder :: new ( compiler_config) . engine ( ) ;
344
350
@@ -351,19 +357,24 @@ impl Runtime {
351
357
instance : & wasmer:: Instance ,
352
358
function_name : & str ,
353
359
) -> super :: error:: ContractError {
354
- let remaining_points = get_remaining_points ( self . wasm_store . as_mut ( ) . unwrap ( ) , instance) ;
355
- match remaining_points {
356
- MeteringPoints :: Remaining ( ..) => {
357
- tracing:: error!( "Error while calling {}: {:?}" , function_name, error) ;
358
- error. into ( )
359
- }
360
- MeteringPoints :: Exhausted => {
361
- tracing:: error!(
362
- "{} ran out of gas, not enough points remaining" ,
363
- function_name
364
- ) ;
365
- ContractExecError :: OutOfGas . into ( )
360
+ if self . enabled_metering {
361
+ let remaining_points =
362
+ get_remaining_points ( self . wasm_store . as_mut ( ) . unwrap ( ) , instance) ;
363
+ match remaining_points {
364
+ MeteringPoints :: Remaining ( ..) => {
365
+ tracing:: error!( "Error while calling {}: {:?}" , function_name, error) ;
366
+ error. into ( )
367
+ }
368
+ MeteringPoints :: Exhausted => {
369
+ tracing:: error!(
370
+ "{} ran out of gas, not enough points remaining" ,
371
+ function_name
372
+ ) ;
373
+ ContractExecError :: OutOfGas . into ( )
374
+ }
366
375
}
376
+ } else {
377
+ error. into ( )
367
378
}
368
379
}
369
380
}
0 commit comments