@@ -11,18 +11,14 @@ use wasmer::{
1111} ;
1212use wasmer_middlewares:: metering as wasmer_metering;
1313
14- fn get_remaining_energy ( ctx : & mut impl AsStoreMut , instance : & Instance ) -> EnergyQuanta {
14+ fn get_remaining_points ( ctx : & mut impl AsStoreMut , instance : & Instance ) -> u64 {
1515 let remaining_points = wasmer_metering:: get_remaining_points ( ctx, instance) ;
1616 match remaining_points {
17- wasmer_metering:: MeteringPoints :: Remaining ( x) => EnergyQuanta ( x ) ,
18- wasmer_metering:: MeteringPoints :: Exhausted => EnergyQuanta :: ZERO ,
17+ wasmer_metering:: MeteringPoints :: Remaining ( x) => x ,
18+ wasmer_metering:: MeteringPoints :: Exhausted => 0 ,
1919 }
2020}
2121
22- fn set_remaining_energy ( ctx : & mut impl AsStoreMut , instance : & Instance , energy : EnergyQuanta ) {
23- wasmer_metering:: set_remaining_points ( ctx, instance, energy. 0 )
24- }
25-
2622fn log_traceback ( func_type : & str , func : & str , e : & RuntimeError ) {
2723 let frames = e. trace ( ) ;
2824 let frames_len = frames. len ( ) ;
@@ -181,8 +177,8 @@ impl module_host_actor::WasmInstancePre for WasmerModule {
181177 env. as_mut ( & mut store) . mem = Some ( mem) ;
182178
183179 // Note: this budget is just for initializers
184- let budget = EnergyQuanta :: DEFAULT_BUDGET ;
185- set_remaining_energy ( & mut store, & instance, budget) ;
180+ let budget = EnergyQuanta :: DEFAULT_BUDGET . as_points ( ) ;
181+ wasmer_metering :: set_remaining_points ( & mut store, & instance, budget) ;
186182
187183 for preinit in & func_names. preinits {
188184 let func = instance. exports . get_typed_function :: < ( ) , ( ) > ( & store, preinit) . unwrap ( ) ;
@@ -316,7 +312,8 @@ impl WasmerInstance {
316312 ) -> module_host_actor:: ExecuteResult < RuntimeError > {
317313 let store = & mut self . store ;
318314 let instance = & self . instance ;
319- set_remaining_energy ( store, instance, budget) ;
315+ let budget = budget. as_points ( ) ;
316+ wasmer_metering:: set_remaining_points ( store, instance, budget) ;
320317
321318 let reduce = instance
322319 . exports
@@ -348,10 +345,10 @@ impl WasmerInstance {
348345 // .call(store, sender_buf.ptr.cast(), timestamp, args_buf.ptr, args_buf.len)
349346 // .and_then(|_| {});
350347 let duration = start. elapsed ( ) ;
351- let remaining = get_remaining_energy ( store, instance) ;
348+ let remaining = get_remaining_points ( store, instance) ;
352349 let energy = module_host_actor:: EnergyStats {
353- used : budget - remaining,
354- remaining,
350+ used : EnergyQuanta :: from_points ( budget) - EnergyQuanta :: from_points ( remaining) ,
351+ remaining : EnergyQuanta :: from_points ( remaining ) ,
355352 } ;
356353 module_host_actor:: ExecuteResult {
357354 energy,
0 commit comments