Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Add documentation to document-execute/os_usage module #897

Merged
merged 7 commits into from
Dec 12, 2023
Merged
5 changes: 5 additions & 0 deletions src/execution/os_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ pub(crate) const ESTIMATED_DEPLOY_STEPS: usize = 0;
pub(crate) const ESTIMATED_DEPLOY_ACCOUNT_STEPS: usize = 3612;
pub(crate) const ESTIMATED_L1_HANDLER_STEPS: usize = 1068;

/// Represents the operating system resources associated with syscalls and transactions.
#[derive(Debug, Clone)]
pub struct OsResources {
execute_syscalls: HashMap<String, ExecutionResources>,
execute_txs_inner: HashMap<TransactionType, ExecutionResources>,
}

impl Default for OsResources {
/// Provide default values for `OsResources`.
fn default() -> Self {
let execute_txs_inner: HashMap<TransactionType, ExecutionResources> = HashMap::from([
(
Expand Down Expand Up @@ -261,6 +263,8 @@ impl Default for OsResources {
}
}

/// Calculate the additional operating system resources required to execute a transaction
/// given a set of syscalls invoked and a transaction type.
pub fn get_additional_os_resources(
syscall_counter: HashMap<String, u64>,
tx_type: &TransactionType,
Expand Down Expand Up @@ -289,6 +293,7 @@ pub fn get_additional_os_resources(
Ok(additional_os_resources)
}

/// Test for the `get_additional_os_resources` function.
#[test]
fn get_additional_os_resources_test() {
let syscall_counter = HashMap::from([("storage_read".into(), 2), ("storage_write".into(), 3)]);
Expand Down