lunatic_process/config.rs
1use serde::{de::DeserializeOwned, Serialize};
2
3// One unit of fuel represents around 100k instructions.
4pub const UNIT_OF_COMPUTE_IN_INSTRUCTIONS: u64 = 100_000;
5
6/// Common process configuration.
7///
8/// Each process in lunatic can have specific limits and permissions. These properties are set
9/// through a process configuration that is used when a process is spawned. Once the process is
10/// spawned the configuration can't be changed anymore. The process configuration heavily depends
11/// on the [`ProcessState`](crate::state::ProcessState) that defines host functions available to
12/// the process. This host functions are the ones that consider specific configuration while
13/// performing operations.
14///
15/// However, two properties of a process are enforced by the runtime (maximum memory and maximum
16/// fuel usage). This two properties need to be part of every configuration.
17///
18/// `ProcessConfig` must be serializable in case it is used to spawn processes on other nodes.
19pub trait ProcessConfig: Clone + Serialize + DeserializeOwned {
20 fn set_max_fuel(&mut self, max_fuel: Option<u64>);
21 fn get_max_fuel(&self) -> Option<u64>;
22 fn set_max_memory(&mut self, max_memory: usize);
23 fn get_max_memory(&self) -> usize;
24}