diff --git a/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs b/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs index f97411f3ee..5f70e54d65 100644 --- a/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs +++ b/radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs @@ -24,6 +24,7 @@ pub struct ScryptoRuntime<'y, Y: SystemApi> { wasm_execution_units_buffer: u32, scrypto_vm_version: ScryptoVmVersion, wasm_execution_units_base: u32, + total_wasm_execution_units: u128, } impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { @@ -39,7 +40,6 @@ impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { // Add 7,000 base units to make sure the we do not undercharge for WASM execution, // which might lead to system exploitation. // This is especially important in corner-cases such as `costing::spin_loop_v2` benchmark. - // Use larger cost unit buffer to call `consume_wasm_execution_exceeding_buffer` // less frequently. 7000 }; @@ -53,9 +53,9 @@ impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { wasm_execution_units_buffer: 0, scrypto_vm_version, wasm_execution_units_base, + total_wasm_execution_units: 0, } } - pub fn parse_blueprint_id( package_address: Vec, blueprint_name: Vec, @@ -90,6 +90,10 @@ impl<'y, Y: SystemApi> ScryptoRuntime<'y, Y> { } impl<'y, Y: SystemApi> WasmRuntime for ScryptoRuntime<'y, Y> { + fn get_total_wasm_execution_units(&self) -> u128 { + self.total_wasm_execution_units + } + fn allocate_buffer( &mut self, buffer: Vec, @@ -419,6 +423,7 @@ impl<'y, Y: SystemApi> WasmRuntime for ScryptoRuntime<'y, Y> { let n = n .checked_add(self.wasm_execution_units_base) .unwrap_or(u32::MAX); + self.total_wasm_execution_units += n as u128; if n <= self.wasm_execution_units_buffer { self.wasm_execution_units_buffer -= n;