Skip to content

Commit

Permalink
node: Move bytecode_charge function to core
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Dec 21, 2024
1 parent 1a8ce21 commit e1a4413
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
14 changes: 6 additions & 8 deletions node/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl MempoolSrv {
return Err(TxAcceptanceError::GasPriceTooLow(1));
}

if let Some(deploy) = tx.inner.deploy() {
if tx.inner.deploy().is_some() {
let vm = vm.read().await;
let min_deployment_gas_price = vm.min_deployment_gas_price();
if tx.gas_price() < min_deployment_gas_price {
Expand All @@ -222,13 +222,11 @@ impl MempoolSrv {
}

let gas_per_deploy_byte = vm.gas_per_deploy_byte();
let min_gas_limit = vm::bytecode_charge(
&deploy.bytecode,
gas_per_deploy_byte,
vm.min_deploy_points(),
);
if tx.inner.gas_limit() < min_gas_limit {
return Err(TxAcceptanceError::GasLimitTooLow(min_gas_limit));
let deploy_charge = tx
.inner
.deploy_charge(gas_per_deploy_byte, vm.min_deploy_points());
if tx.inner.gas_limit() < deploy_charge {
return Err(TxAcceptanceError::GasLimitTooLow(deploy_charge));
}
} else {
let vm = vm.read().await;
Expand Down
14 changes: 0 additions & 14 deletions node/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ use dusk_consensus::operations::{CallParams, VerificationOutput, Voter};
use dusk_consensus::user::provisioners::Provisioners;
use dusk_consensus::user::stake::Stake;
use dusk_core::signatures::bls::PublicKey as BlsPublicKey;
use dusk_core::transfer::data::ContractBytecode;
use dusk_core::transfer::moonlight::AccountData;
use node_data::events::contract::ContractEvent;
use node_data::ledger::{Block, SpentTransaction, Transaction};
use std::cmp::max;

#[derive(Default)]
pub struct Config {}
Expand Down Expand Up @@ -102,15 +100,3 @@ pub enum PreverificationResult {
nonce_used: u64,
},
}

// Returns gas charge for bytecode deployment.
pub fn bytecode_charge(
bytecode: &ContractBytecode,
gas_per_deploy_byte: u64,
min_deploy_points: u64,
) -> u64 {
max(
bytecode.bytes.len() as u64 * gas_per_deploy_byte,
min_deploy_points,
)
}

0 comments on commit e1a4413

Please sign in to comment.