Skip to content
Open
Changes from all 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
40 changes: 10 additions & 30 deletions node/bft/ledger-service/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ use snarkvm::{
bail,
cfg_into_iter,
consensus_config_value_by_version,
deploy_compute_cost_in_microcredits,
deployment_cost,
execute_compute_cost_in_microcredits,
execution_cost,
transaction_compute_spend_in_microcredits,
},
};

Expand Down Expand Up @@ -543,32 +540,15 @@ impl<N: Network, C: ConsensusStorage<N>> LedgerService<N> for CoreLedgerService<
let transaction_spend_limit =
consensus_config_value_by_version!(N, TRANSACTION_SPEND_LIMIT, consensus_version).unwrap();
let id = transaction.id();
match transaction {
Transaction::Deploy(_, _, _, deployment, _) => {
let (_, cost_details) = deployment_cost(self.ledger.vm().process(), deployment, consensus_version)?;
let compute_spend = deploy_compute_cost_in_microcredits(cost_details, consensus_version);
ensure!(
compute_spend <= transaction_spend_limit,
"Transaction '{id}' exceeds the transaction spend limit with compute_spend: '{compute_spend}'"
);
Ok(compute_spend)
}
Transaction::Execute(_, _, execution, _) => {
let (_, cost_details) = execution_cost(self.ledger.vm().process(), execution, consensus_version)?;
let compute_spend = execute_compute_cost_in_microcredits(cost_details, consensus_version);
if consensus_version >= ConsensusVersion::V11 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this consensus version gate still active with this refactor? Does transaction_compute_spend_in_microcredits exhibit the same behavior?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it isn't, it would be harmless to remove it as the network is already past that consensus version.

// From V11, add this check for consistency with our deployment checks.
ensure!(
compute_spend <= transaction_spend_limit,
"Transaction '{id}' exceeds the transaction spend limit with compute_spend: '{compute_spend}'"
);
}
Ok(compute_spend)
}
Transaction::Fee(..) => {
bail!("Fee transactions are internal to the VM, transaction {id} is invalid.")
}
}

let compute_spend =
transaction_compute_spend_in_microcredits(self.ledger.vm().process(), transaction, consensus_version)?;
ensure!(
compute_spend <= transaction_spend_limit,
"Transaction '{id}' exceeds the transaction spend limit with compute_spend: '{compute_spend}'"
);

Ok(compute_spend)
}

fn is_stopped(&self) -> bool {
Expand Down