Skip to content

Commit

Permalink
Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubasze committed Oct 29, 2024
1 parent 046b477 commit 3b9c893
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions radix-engine/src/vm/wasm_runtime/scrypto_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ScryptoRuntime<'y, Y: SystemApi<RuntimeError>> {
wasm_execution_units_buffer: u32,
scrypto_vm_version: ScryptoVmVersion,
wasm_execution_units_base: u32,
total_wasm_execution_units: u128,
}

impl<'y, Y: SystemApi<RuntimeError>> ScryptoRuntime<'y, Y> {
Expand All @@ -39,7 +40,6 @@ impl<'y, Y: SystemApi<RuntimeError>> 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
};
Expand All @@ -53,9 +53,9 @@ impl<'y, Y: SystemApi<RuntimeError>> 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<u8>,
blueprint_name: Vec<u8>,
Expand Down Expand Up @@ -90,6 +90,10 @@ impl<'y, Y: SystemApi<RuntimeError>> ScryptoRuntime<'y, Y> {
}

impl<'y, Y: SystemApi<RuntimeError>> 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<u8>,
Expand Down Expand Up @@ -419,6 +423,7 @@ impl<'y, Y: SystemApi<RuntimeError>> 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;
Expand Down

0 comments on commit 3b9c893

Please sign in to comment.