Skip to content

Commit

Permalink
validator: renamed GasData fields
Browse files Browse the repository at this point in the history
  • Loading branch information
skoupidi committed Oct 22, 2024
1 parent 6939110 commit 233407d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/validator/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl Fork {

// Update accumulated total gas
total_gas_used += tx_gas_used;
total_gas_paid += gas_data.gas_paid;
total_gas_paid += gas_data.paid;

// Push the tx hash into the unproposed transactions vector
unproposed_txs.push(unproposed_tx);
Expand Down
20 changes: 11 additions & 9 deletions src/validator/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,21 @@ pub fn circuit_gas_use(zkbin: &ZkBinary) -> u64 {
/// resource consumption across different transactions.
#[derive(Default, Clone, Eq, PartialEq, Debug, SerialEncodable, SerialDecodable)]
pub struct GasData {
pub gas_paid: u64,
pub wasm_gas_used: u64,
pub zk_circuit_gas_used: u64,
pub signature_gas_used: u64,
pub deploy_gas_used: u64,
/// Transaction paid fee
pub paid: u64,
/// Wasm calls gas consumption
pub wasm: u64,
/// ZK circuits gas consumption
pub zk_circuits: u64,
/// Signature fee
pub signatures: u64,
/// Contract deployment gas
pub deployments: u64,
}

impl GasData {
/// Calculates the total gas used by summing all individual gas usage fields.
pub fn total_gas_used(&self) -> u64 {
self.wasm_gas_used +
self.zk_circuit_gas_used +
self.signature_gas_used +
self.deploy_gas_used
self.wasm + self.zk_circuits + self.signatures + self.deployments
}
}
16 changes: 8 additions & 8 deletions src/validator/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ pub async fn verify_transaction(

let deploy_gas_used = deploy_runtime.gas_used();
debug!(target: "validator::verification::verify_transaction", "The gas used for deployment call {:?} of transaction {}: {}", call, tx_hash, deploy_gas_used);
gas_data.deploy_gas_used += deploy_gas_used;
gas_data.deployments += deploy_gas_used;
}

// At this point we're done with the call and move on to the next one.
Expand All @@ -705,21 +705,21 @@ pub async fn verify_transaction(
debug!(target: "validator::verification::verify_transaction", "The gas used for WASM call {:?} of transaction {}: {}", call, tx_hash, wasm_gas_used);

// Append the used wasm gas
gas_data.wasm_gas_used += wasm_gas_used;
gas_data.wasm += wasm_gas_used;
}

// The signature fee is tx_size + fixed_sig_fee * n_signatures
gas_data.signature_gas_used = (PALLAS_SCHNORR_SIGNATURE_FEE * tx.signatures.len() as u64) +
gas_data.signatures = (PALLAS_SCHNORR_SIGNATURE_FEE * tx.signatures.len() as u64) +
serialize_async(tx).await.len() as u64;
debug!(target: "validator::verification::verify_transaction", "The gas used for signature of transaction {}: {}", tx_hash, gas_data.signature_gas_used);
debug!(target: "validator::verification::verify_transaction", "The gas used for signature of transaction {}: {}", tx_hash, gas_data.signatures);

// The ZK circuit fee is calculated using a function in validator/fees.rs
for zkbin in circuits_to_verify.iter() {
let zk_circuit_gas_used = circuit_gas_use(zkbin);
debug!(target: "validator::verification::verify_transaction", "The gas used for ZK circuit in namespace {} of transaction {}: {}", zkbin.namespace, tx_hash, zk_circuit_gas_used);

// Append the used zk circuit gas
gas_data.zk_circuit_gas_used += zk_circuit_gas_used;
gas_data.zk_circuits += zk_circuit_gas_used;
}

// Store the calculated total gas used to avoid recalculating it for subsequent uses
Expand Down Expand Up @@ -748,10 +748,10 @@ pub async fn verify_transaction(
);
return Err(TxVerifyFailed::InsufficientFee.into())
}
debug!(target: "validator::verification::verify_transaction", "The gas paid for transaction {}: {}", tx_hash, gas_data.gas_paid);
debug!(target: "validator::verification::verify_transaction", "The gas paid for transaction {}: {}", tx_hash, gas_data.paid);

// Store paid fee
gas_data.gas_paid = fee;
gas_data.paid = fee;
}

// When we're done looping and executing over the tx's contract calls and
Expand Down Expand Up @@ -943,7 +943,7 @@ pub async fn verify_transactions(

// Update accumulated total gas
total_gas_used += tx_gas_used;
total_gas_paid += gas_data.gas_paid;
total_gas_paid += gas_data.paid;
}

if !erroneous_txs.is_empty() {
Expand Down

0 comments on commit 233407d

Please sign in to comment.