Skip to content

Commit

Permalink
rusk: change RuskVMConfig to not be const
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jan 29, 2025
1 parent c912ba5 commit 93b5619
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 32 deletions.
2 changes: 1 addition & 1 deletion rusk/src/lib/node/vm/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Default for Config {
}

impl Config {
pub const fn new() -> Self {
pub fn new() -> Self {
Self {
gas_per_deploy_byte: DEFAULT_GAS_PER_DEPLOY_BYTE,
min_deploy_gas_price: DEFAULT_MIN_DEPLOYMENT_GAS_PRICE,
Expand Down
1 change: 0 additions & 1 deletion rusk/tests/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use tokio::sync::broadcast;
use tracing::info;

const CHAIN_ID: u8 = 0xFA;
pub const DEFAULT_VM_CONFIG: RuskVmConfig = RuskVmConfig::new();
pub const DEFAULT_MIN_GAS_LIMIT: u64 = 75000;

// Creates a Rusk initial state in the given directory
Expand Down
3 changes: 1 addition & 2 deletions rusk/tests/services/contract_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use tracing::info;
use crate::common::logger;
use crate::common::state::{
generator_procedure, ExecuteResult, DEFAULT_MIN_GAS_LIMIT,
DEFAULT_VM_CONFIG,
};
use crate::common::wallet::{
test_wallet as wallet, TestStateClient, TestStore, Wallet,
Expand Down Expand Up @@ -105,7 +104,7 @@ fn initial_state<P: AsRef<Path>>(dir: P, deploy_bob: bool) -> Result<Rusk> {
let rusk = Rusk::new(
dir,
CHAIN_ID,
DEFAULT_VM_CONFIG,
RuskVmConfig::new(),
DEFAULT_MIN_GAS_LIMIT,
u64::MAX,
sender,
Expand Down
5 changes: 2 additions & 3 deletions rusk/tests/services/contract_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ use crate::common::*;

const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 100_000_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

const GAS_LIMIT: u64 = 10_000_000_000;
const GAS_PRICE: u64 = 1;
Expand All @@ -42,8 +40,9 @@ fn stake_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot =
toml::from_str(include_str!("../config/stake_from_contract.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

#[tokio::test(flavor = "multi_thread")]
Expand Down
5 changes: 2 additions & 3 deletions rusk/tests/services/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use crate::common::wallet::{
};

const BLOCK_GAS_LIMIT: u64 = 100_000_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

const INITIAL_PHOENIX_BALANCE: u64 = 10_000_000_000;
const INITIAL_MOONLIGHT_BALANCE: u64 = 10_000_000_000;
Expand All @@ -32,8 +30,9 @@ const INITIAL_MOONLIGHT_BALANCE: u64 = 10_000_000_000;
fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/convert.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

/// Makes a transaction that converts Dusk from Phoenix to Moonlight, and
Expand Down
5 changes: 2 additions & 3 deletions rusk/tests/services/finalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ use tempfile::tempdir;
use crate::common::state::{generator_procedure2, new_state};

const BLOCK_GAS_LIMIT: u64 = 24_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);
const BLOCKS_NUM: u64 = 10;

// Creates the Rusk initial state for the tests below
fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot =
toml::from_str(include_str!("../config/multi_transfer.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

#[tokio::test(flavor = "multi_thread")]
Expand Down
5 changes: 2 additions & 3 deletions rusk/tests/services/gas_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use crate::common::wallet::{

const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

const INITIAL_BALANCE: u64 = 10_000_000_000;

Expand All @@ -41,8 +39,9 @@ const DEPOSIT: u64 = 0;
fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/gas-behavior.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

const SENDER_INDEX_0: u8 = 0;
Expand Down
5 changes: 2 additions & 3 deletions rusk/tests/services/moonlight_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ use crate::common::*;

const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 100_000_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);
const GAS_LIMIT: u64 = 10_000_000_000;
const GAS_PRICE: u64 = 1;

// Creates the Rusk initial state for the tests below
fn stake_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/stake.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

/// Stakes an amount Dusk and produces a block with this single transaction,
Expand Down
8 changes: 4 additions & 4 deletions rusk/tests/services/multi_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const BLOCK_HEIGHT: u64 = 1;
// This is purposefully chosen to be low to trigger the discarding of a
// perfectly good transaction.
const BLOCK_GAS_LIMIT: u64 = 24_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

const GAS_LIMIT: u64 = 12_000_000; // Lowest value for a transfer
const INITIAL_BALANCE: u64 = 10_000_000_000;
Expand All @@ -41,17 +39,19 @@ fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot =
toml::from_str(include_str!("../config/multi_transfer.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

// Creates the Rusk initial state for the tests below
fn initial_state_deploy<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot =
toml::from_str(include_str!("../config/multi_transfer_deploy.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

/// Executes three different transactions in the same block, expecting only two
Expand Down
5 changes: 3 additions & 2 deletions rusk/tests/services/owner_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rand::rngs::StdRng;
use rand::SeedableRng;
use rkyv::validation::validators::DefaultValidator;
use rkyv::{Archive, Deserialize, Infallible, Serialize};
use rusk::node::RuskVmConfig;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
Expand All @@ -27,7 +28,7 @@ use tokio::sync::broadcast;
use tracing::info;

use crate::common::logger;
use crate::common::state::{DEFAULT_MIN_GAS_LIMIT, DEFAULT_VM_CONFIG};
use crate::common::state::DEFAULT_MIN_GAS_LIMIT;
use crate::common::wallet::{
test_wallet as wallet, test_wallet::Wallet, TestStateClient, TestStore,
};
Expand Down Expand Up @@ -79,7 +80,7 @@ fn initial_state<P: AsRef<Path>>(
let rusk = Rusk::new(
dir,
CHAIN_ID,
DEFAULT_VM_CONFIG,
RuskVmConfig::new(),
DEFAULT_MIN_GAS_LIMIT,
u64::MAX,
sender,
Expand Down
8 changes: 4 additions & 4 deletions rusk/tests/services/phoenix_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ use crate::common::*;

const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 100_000_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);
const GAS_LIMIT: u64 = 10_000_000_000;
const GAS_PRICE: u64 = 1;
const DEPOSIT: u64 = 0;
Expand All @@ -41,16 +39,18 @@ const DEPOSIT: u64 = 0;
fn stake_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/stake.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

// Creates the Rusk initial state for the tests below
fn slash_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/slash.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

/// Stakes an amount Dusk and produces a block with this single transaction,
Expand Down
5 changes: 2 additions & 3 deletions rusk/tests/services/unspendable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use crate::common::wallet::{

const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000;
const VM_CONFIG: RuskVmConfig =
RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);
const INITIAL_BALANCE: u64 = 10_000_000_000;

const GAS_LIMIT_0: u64 = 20_000_000; // Enough to spend, but OOG during ICC
Expand All @@ -41,8 +39,9 @@ const DEPOSIT: u64 = 0;
fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/unspendable.toml"))
.expect("Cannot deserialize config");
let vm_config = RuskVmConfig::new().with_block_gas_limit(BLOCK_GAS_LIMIT);

new_state(dir, &snapshot, VM_CONFIG)
new_state(dir, &snapshot, vm_config)
}

const SENDER_INDEX_0: u8 = 0;
Expand Down

0 comments on commit 93b5619

Please sign in to comment.