diff --git a/rusk/src/lib/builder/node.rs b/rusk/src/lib/builder/node.rs index f67ffa1efa..ac38f733d9 100644 --- a/rusk/src/lib/builder/node.rs +++ b/rusk/src/lib/builder/node.rs @@ -44,6 +44,7 @@ pub struct RuskNodeBuilder { gas_per_deploy_byte: Option, min_deployment_gas_price: Option, min_gas_limit: Option, + min_deploy_points: Option, block_gas_limit: u64, feeder_call_gas: u64, state_dir: PathBuf, @@ -56,6 +57,7 @@ pub struct RuskNodeBuilder { const DEFAULT_GAS_PER_DEPLOY_BYTE: u64 = 100; const DEFAULT_MIN_DEPLOYMENT_GAS_PRICE: u64 = 2000; const DEFAULT_MIN_GAS_LIMIT: u64 = 75000; +const DEFAULT_MIN_DEPLOY_POINTS: u64 = 5_000_000; impl RuskNodeBuilder { pub fn with_consensus_keys(mut self, consensus_keys_path: String) -> Self { @@ -142,6 +144,14 @@ impl RuskNodeBuilder { self } + pub fn with_min_deploy_points( + mut self, + min_deploy_points: Option, + ) -> Self { + self.min_deploy_points = min_deploy_points; + self + } + pub fn with_block_gas_limit(mut self, block_gas_limit: u64) -> Self { self.block_gas_limit = block_gas_limit; self @@ -187,6 +197,8 @@ impl RuskNodeBuilder { .min_deployment_gas_price .unwrap_or(DEFAULT_MIN_DEPLOYMENT_GAS_PRICE); let min_gas_limit = self.min_gas_limit.unwrap_or(DEFAULT_MIN_GAS_LIMIT); + let min_deploy_points = + self.min_deploy_points.unwrap_or(DEFAULT_MIN_DEPLOY_POINTS); let rusk = Rusk::new( self.state_dir, @@ -195,6 +207,7 @@ impl RuskNodeBuilder { gas_per_deploy_byte, min_deployment_gas_price, min_gas_limit, + min_deploy_points, self.block_gas_limit, self.feeder_call_gas, rues_sender.clone(), diff --git a/rusk/src/lib/node.rs b/rusk/src/lib/node.rs index c6423b2905..3b0e00dfe6 100644 --- a/rusk/src/lib/node.rs +++ b/rusk/src/lib/node.rs @@ -44,6 +44,7 @@ pub struct Rusk { pub(crate) gas_per_deploy_byte: u64, pub(crate) min_deployment_gas_price: u64, pub(crate) min_gas_limit: u64, + pub(crate) min_deploy_points: u64, pub(crate) feeder_gas_limit: u64, pub(crate) block_gas_limit: u64, pub(crate) event_sender: broadcast::Sender, diff --git a/rusk/src/lib/node/rusk.rs b/rusk/src/lib/node/rusk.rs index b762236572..ca356353c1 100644 --- a/rusk/src/lib/node/rusk.rs +++ b/rusk/src/lib/node/rusk.rs @@ -61,6 +61,7 @@ impl Rusk { gas_per_deploy_byte: u64, min_deployment_gas_price: u64, min_gas_limit: u64, + min_deploy_points: u64, block_gas_limit: u64, feeder_gas_limit: u64, event_sender: broadcast::Sender, @@ -101,6 +102,7 @@ impl Rusk { gas_per_deploy_byte, min_deployment_gas_price, min_gas_limit, + min_deploy_points, feeder_gas_limit, event_sender, #[cfg(feature = "archive")] @@ -169,6 +171,7 @@ impl Rusk { &mut session, &unspent_tx.inner, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, ) { Ok(receipt) => { @@ -188,6 +191,7 @@ impl Rusk { &mut session, &spent_tx.inner.inner, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, ); } @@ -279,6 +283,7 @@ impl Rusk { slashing, voters, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, ) .map(|(a, b, _, _)| (a, b)) @@ -317,6 +322,7 @@ impl Rusk { slashing, voters, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, )?; @@ -572,6 +578,7 @@ fn accept( slashing: Vec, voters: &[Voter], gas_per_deploy_byte: u64, + min_deploy_points: u64, min_deployment_gas_price: u64, ) -> Result<( Vec, @@ -596,6 +603,7 @@ fn accept( &mut session, tx, gas_per_deploy_byte, + min_deploy_points, min_deployment_gas_price, )?; @@ -675,9 +683,14 @@ fn contract_deploy( deploy: &ContractDeploy, gas_limit: u64, gas_per_deploy_byte: u64, + min_deploy_points: u64, receipt: &mut CallReceipt, ContractError>>, ) { - let deploy_charge = bytecode_charge(&deploy.bytecode, gas_per_deploy_byte); + let deploy_charge = bytecode_charge( + &deploy.bytecode, + gas_per_deploy_byte, + min_deploy_points, + ); let min_gas_limit = receipt.gas_spent + deploy_charge; let hash = blake3::hash(deploy.bytecode.bytes.as_slice()); if gas_limit < min_gas_limit { @@ -747,13 +760,17 @@ fn execute( session: &mut Session, tx: &ProtocolTransaction, gas_per_deploy_byte: u64, + min_deploy_points: u64, min_deployment_gas_price: u64, ) -> Result, ContractError>>, PiecrustError> { // Transaction will be discarded if it is a deployment transaction // with gas limit smaller than deploy charge. if let Some(deploy) = tx.deploy() { - let deploy_charge = - bytecode_charge(&deploy.bytecode, gas_per_deploy_byte); + let deploy_charge = bytecode_charge( + &deploy.bytecode, + gas_per_deploy_byte, + min_deploy_points, + ); if tx.gas_price() < min_deployment_gas_price { return Err(PiecrustError::Panic( "gas price too low to deploy".into(), @@ -785,6 +802,7 @@ fn execute( deploy, gas_left, gas_per_deploy_byte, + min_deploy_points, &mut receipt, ); } diff --git a/rusk/tests/common/state.rs b/rusk/tests/common/state.rs index 79e7f964e9..4e5345393f 100644 --- a/rusk/tests/common/state.rs +++ b/rusk/tests/common/state.rs @@ -33,6 +33,7 @@ const CHAIN_ID: u8 = 0xFA; pub const DEFAULT_GAS_PER_DEPLOY_BYTE: u64 = 100; pub const DEFAULT_MIN_DEPLOYMENT_GAS_PRICE: u64 = 2000; pub const DEFAULT_MIN_GAS_LIMIT: u64 = 75000; +pub const DEFAULT_MIN_DEPLOY_POINTS: u64 = 5000000; // Creates a Rusk initial state in the given directory pub fn new_state>( @@ -64,6 +65,7 @@ pub fn new_state_with_chainid>( DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_DEPLOYMENT_GAS_PRICE, DEFAULT_MIN_GAS_LIMIT, + DEFAULT_MIN_DEPLOY_POINTS, block_gas_limit, u64::MAX, sender, diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index a40099a67f..bf50c3d559 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -25,6 +25,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::DEFAULT_MIN_DEPLOYMENT_GAS_PRICE; +use crate::common::state::DEFAULT_MIN_DEPLOY_POINTS; use crate::common::state::{generator_procedure, ExecuteResult}; use crate::common::state::{ DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_GAS_LIMIT, @@ -106,6 +107,7 @@ fn initial_state>(dir: P, deploy_bob: bool) -> Result { DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_DEPLOYMENT_GAS_PRICE, DEFAULT_MIN_GAS_LIMIT, + DEFAULT_MIN_DEPLOY_POINTS, BLOCK_GAS_LIMIT, u64::MAX, sender, diff --git a/rusk/tests/services/owner_calls.rs b/rusk/tests/services/owner_calls.rs index c580ada478..cfd57383fe 100644 --- a/rusk/tests/services/owner_calls.rs +++ b/rusk/tests/services/owner_calls.rs @@ -32,6 +32,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::DEFAULT_MIN_DEPLOYMENT_GAS_PRICE; +use crate::common::state::DEFAULT_MIN_DEPLOY_POINTS; use crate::common::state::{ DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_GAS_LIMIT, }; @@ -85,6 +86,7 @@ fn initial_state>( DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_DEPLOYMENT_GAS_PRICE, DEFAULT_MIN_GAS_LIMIT, + DEFAULT_MIN_DEPLOY_POINTS, BLOCK_GAS_LIMIT, u64::MAX, sender,