pub struct WasmLimits {
pub max_wasm_stack: usize,
pub memory_size: usize,
pub max_single_alloc: usize,
pub max_total_memory: usize,
pub max_table_elements: usize,
pub aggressive_compilation: bool,
}Expand description
Resolved wasmtime resource limits, ready to configure the engine and stores.
All limits are security upper-bounds. Typical digital-twin contracts use kilobytes of state — these caps prevent runaway allocations by malicious or buggy contracts.
Fields§
§max_wasm_stack: usizeMaximum WASM stack depth in bytes. Fixed for security regardless of RAM.
memory_size: usizeMaximum WASM linear memory per contract instance (demand-paged virtual).
max_single_alloc: usizeMaximum single host-side I/O allocation (state_in, event_in, or result_out).
max_total_memory: usizeMaximum total host-side I/O buffer per contract call.
max_table_elements: usizeWASM function-table cap. Scales with CPU: more cores → heavier contracts supported.
aggressive_compilation: boolUse Cranelift SpeedAndSize opt level (true when cpu_cores ≥ 4).
Produces smaller, faster code at the cost of longer JIT compilation.
Implementations§
Source§impl WasmLimits
impl WasmLimits
Sourcepub fn build(ram_mb: u64, cpu_cores: usize) -> Self
pub fn build(ram_mb: u64, cpu_cores: usize) -> Self
Derive resource limits from total machine RAM and CPU cores.
§Scaling rationale
-
memory_size(WASM linear memory): virtual and demand-paged, so the cost is proportional to pages actually touched, not the cap. Scales from 4 MB (Nano) to 32 MB (Large+) to bound worst-case VM RSS per instance. -
max_total_memory(host I/O): bounds the total byte-transfer between host and WASM per call (state_in + event_in + result_out). Scales from 3 MB (Nano) to 24 MB (Medium+). -
max_single_alloc: cap on a single buffer; ≈ ⅓ of total I/O budget. -
max_wasm_stack: fixed at 1 MB — a security/correctness bound independent of available RAM. -
max_table_elements(WASM function table): scales with CPU cores. Each Rust contract uses <50 real entries; this cap prevents runaway tables in adversarial modules. 256 entries per core, floor 512, cap 2 048. -
aggressive_compilation: enables CraneliftSpeedAndSizewhen cpu_cores ≥ 4. Produces smaller, faster JIT code at the cost of longer compilation time — only worthwhile when spare cores are available. -
Fuel limits (
MAX_FUEL,MAX_FUEL_COMPILATION): DOS-prevention constants, machine-independent.
Trait Implementations§
Source§impl Clone for WasmLimits
impl Clone for WasmLimits
Source§fn clone(&self) -> WasmLimits
fn clone(&self) -> WasmLimits
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WasmLimits
impl Debug for WasmLimits
Auto Trait Implementations§
impl Freeze for WasmLimits
impl RefUnwindSafe for WasmLimits
impl Send for WasmLimits
impl Sync for WasmLimits
impl Unpin for WasmLimits
impl UnsafeUnpin for WasmLimits
impl UnwindSafe for WasmLimits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more