diff --git a/synthesizer/src/vm/execute.rs b/synthesizer/src/vm/execute.rs index b75e4ebeb6..e08d23ef5f 100644 --- a/synthesizer/src/vm/execute.rs +++ b/synthesizer/src/vm/execute.rs @@ -45,7 +45,7 @@ impl> VM { let fee = match is_fee_required || is_priority_fee_declared { true => { // Compute the minimum execution cost. - let minimum_execution_cost = execution_cost(self, &execution)?; + let (minimum_execution_cost, _) = execution_cost(self, &execution)?; // Compute the execution ID. let execution_id = execution.to_execution_id()?; // Authorize the fee. diff --git a/synthesizer/src/vm/helpers/cost.rs b/synthesizer/src/vm/helpers/cost.rs index c5f0e63eab..f88e133436 100644 --- a/synthesizer/src/vm/helpers/cost.rs +++ b/synthesizer/src/vm/helpers/cost.rs @@ -23,6 +23,14 @@ use synthesizer_program::{Command, Finalize, Instruction}; use std::collections::HashMap; +#[allow(unused)] +/// Helper struct for i.a. SDK to return costs for users. +pub struct ExecutionCosts { + storage_cost: u64, + finalize_cost: u64, + execution_cost: u64, +} + /// Returns the *minimum* cost in microcredits to publish the given deployment (total cost, (storage cost, namespace cost)). pub fn deployment_cost(deployment: &Deployment) -> Result<(u64, (u64, u64))> { // Determine the number of bytes in the deployment. @@ -52,7 +60,10 @@ pub fn deployment_cost(deployment: &Deployment) -> Result<(u64, ( } /// Returns the *minimum* cost in microcredits to publish the given execution (total cost, (storage cost, namespace cost)). -pub fn execution_cost>(vm: &VM, execution: &Execution) -> Result { +pub fn execution_cost>( + vm: &VM, + execution: &Execution, +) -> Result<(u64, ExecutionCosts)> { // Compute the storage cost in microcredits. let storage_cost = execution.size_in_bytes()?; @@ -95,7 +106,9 @@ pub fn execution_cost>(vm: &VM, executi .and_then(|x| x.checked_add(execution_cost)) .ok_or(anyhow!("The total cost computation overflowed for an execution"))?; - Ok(total_cost) + let execution_costs = ExecutionCosts { storage_cost, execution_cost, finalize_cost }; + + Ok((total_cost, execution_costs)) } /// Returns the minimum number of microcredits required to run the finalize. diff --git a/synthesizer/src/vm/verify.rs b/synthesizer/src/vm/verify.rs index 1cdd32393b..fe036b7e3a 100644 --- a/synthesizer/src/vm/verify.rs +++ b/synthesizer/src/vm/verify.rs @@ -168,7 +168,7 @@ impl> VM { // If the fee is required, then check that the base fee amount is satisfied. if is_fee_required { // Compute the execution cost. - let cost = execution_cost(self, execution)?; + let (cost, _) = execution_cost(self, execution)?; // Ensure the fee is sufficient to cover the cost. if *fee.base_amount()? < cost { bail!(