Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixed execution cost #2294

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions console/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub trait Network:
const DEPLOYMENT_FEE_MULTIPLIER: u64 = 1_000; // 1 millicredit per byte
/// The maximum number of microcredits that can be spent as a fee.
const MAX_FEE: u64 = 1_000_000_000_000_000;
/// The fixed cost in microcredits to verify Executions.
const EXECUTION_FEE: u64 = 25_000; // 25 millicredits

/// The anchor height, defined as the expected number of blocks to reach the coinbase target.
const ANCHOR_HEIGHT: u32 = Self::ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32;
Expand Down
2 changes: 1 addition & 1 deletion synthesizer/src/vm/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
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.
Expand Down
11 changes: 6 additions & 5 deletions synthesizer/src/vm/helpers/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ pub fn deployment_cost<N: Network>(deployment: &Deployment<N>) -> Result<(u64, (
}

/// Returns the *minimum* cost in microcredits to publish the given execution (total cost, (storage cost, namespace cost)).
pub fn execution_cost<N: Network, C: ConsensusStorage<N>>(
vm: &VM<N, C>,
execution: &Execution<N>,
) -> Result<(u64, (u64, u64))> {
pub fn execution_cost<N: Network, C: ConsensusStorage<N>>(vm: &VM<N, C>, execution: &Execution<N>) -> Result<u64> {
iamalwaysuncomfortable marked this conversation as resolved.
Show resolved Hide resolved
// Compute the storage cost in microcredits.
let storage_cost = execution.size_in_bytes()?;

Expand Down Expand Up @@ -89,12 +86,16 @@ pub fn execution_cost<N: Network, C: ConsensusStorage<N>>(
.ok_or(anyhow!("The finalize cost computation overflowed for an execution"))?;
}

// Compute the fixed execution cost in microcredits
let execution_cost = N::EXECUTION_FEE;

// Compute the total cost in microcredits.
let total_cost = storage_cost
.checked_add(finalize_cost)
.and_then(|x| x.checked_add(execution_cost))
.ok_or(anyhow!("The total cost computation overflowed for an execution"))?;

Ok((total_cost, (storage_cost, finalize_cost)))
Ok(total_cost)
}

/// Returns the minimum number of microcredits required to run the finalize.
Expand Down
2 changes: 1 addition & 1 deletion synthesizer/src/vm/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
// 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!(
Expand Down