Skip to content

Commit

Permalink
Add enforcement for execution fees
Browse files Browse the repository at this point in the history
  • Loading branch information
raychu86 committed Apr 19, 2023
1 parent 9072262 commit b6ca6a5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions node/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,22 @@ impl<N: Network, C: ConsensusStorage<N>> Consensus<N, C> {

/* Fee */

// TODO (raychu86): Currently ignoring this rule for executions. Revisit this in phase 3.
// Ensure transactions with a positive balance must pay for its storage in bytes.
// TODO (raychu86): TODO (raychu86): Consider fees for `finalize` execution when it is ready.
// Ensure the transaction has a sufficient fee.
let fee = transaction.fee()?;
if matches!(transaction, Transaction::Deploy(..))
&& u64::try_from(transaction.to_bytes_le()?.len())?.saturating_mul(DEPLOYMENT_FEE_FACTOR) > *fee
{
bail!("Transaction '{transaction_id}' has insufficient fee to cover its storage in bytes")
match transaction {
Transaction::Deploy(_, _, deployment, _) => {
// Check that the fee in microcredits is at least the deployment size in bytes.
if u64::try_from(deployment.to_bytes_le()?.len())?.saturating_mul(DEPLOYMENT_FEE_FACTOR) > *fee {
bail!("Transaction '{transaction_id}' has insufficient fee to cover its storage in bytes")
}
}
Transaction::Execute(_, execution, _) => {
// If the transaction is not a coinbase transaction, check that the fee in microcredits is at least the execution size in bytes.
if !transaction.is_coinbase() && u64::try_from(execution.to_bytes_le()?.len())? > *fee {
bail!("Transaction '{transaction_id}' has insufficient fee to cover its storage in bytes")
}
}
}

/* Proof(s) */
Expand Down

0 comments on commit b6ca6a5

Please sign in to comment.