Skip to content

Commit

Permalink
rusk: Pass proper block_gas_limit value to new_state
Browse files Browse the repository at this point in the history
  • Loading branch information
Goshawk committed Aug 19, 2024
1 parent bfa3ade commit 4592fe2
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
5 changes: 4 additions & 1 deletion rusk/benches/block_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use tempfile::tempdir;

use common::state::new_state;

const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000;

fn load_phoenix_txs() -> Vec<Transaction> {
// The file "phoenix-txs" can be generated using
// `generate_phoenix_txs()` in "tests/rusk-state.rs".
Expand Down Expand Up @@ -164,7 +166,8 @@ pub fn accept_benchmark(c: &mut Criterion) {
let snapshot = toml::from_str(include_str!("../tests/config/bench.toml"))
.expect("Cannot deserialize config");

let rusk = new_state(&tmp, &snapshot).expect("Creating state should work");
let rusk = new_state(&tmp, &snapshot, BLOCK_GAS_LIMIT)
.expect("Creating state should work");

let phoenix_txs = load_phoenix_txs();
let moonlight_txs = load_moonlight_txs();
Expand Down
9 changes: 6 additions & 3 deletions rusk/tests/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ use tracing::info;
use crate::common::keys::STAKE_SK;

// Creates a Rusk initial state in the given directory
pub fn new_state<P: AsRef<Path>>(dir: P, snapshot: &Snapshot) -> Result<Rusk> {
pub fn new_state<P: AsRef<Path>>(
dir: P,
snapshot: &Snapshot,
block_gas_limit: u64,
) -> Result<Rusk> {
let dir = dir.as_ref();

let (_, commit_id) = state::deploy(dir, snapshot, |_| {})
.expect("Deploying initial state should succeed");

let (sender, _) = broadcast::channel(10);

let rusk = Rusk::new(dir, None, None, u64::MAX, sender)
let rusk = Rusk::new(dir, None, None, block_gas_limit, u64::MAX, sender)
.expect("Instantiating rusk should succeed");

assert_eq!(
Expand Down Expand Up @@ -109,7 +113,6 @@ pub fn generator_procedure(

let call_params = CallParams {
round,
block_gas_limit,
generator_pubkey,
to_slash,
voters_pubkey: None,
Expand Down
7 changes: 4 additions & 3 deletions rusk/tests/rusk-state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ use tracing::info;
use crate::common::state::new_state;

const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 100_000_000_000;
const INITIAL_BALANCE: u64 = 10_000_000_000;

// 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/rusk-state.toml"))
.expect("Cannot deserialize config");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

fn leaves_from_height(rusk: &Rusk, height: u64) -> Result<Vec<TreeLeaf>> {
Expand Down Expand Up @@ -183,7 +184,7 @@ async fn generate_phoenix_txs() -> Result<(), Box<dyn std::error::Error>> {
let snapshot = toml::from_str(include_str!("./config/bench.toml"))
.expect("Cannot deserialize config");

let rusk = new_state(&tmp, &snapshot)?;
let rusk = new_state(&tmp, &snapshot, 100_000_000_000)?;

let cache =
Arc::new(std::sync::RwLock::new(std::collections::HashMap::new()));
Expand Down Expand Up @@ -248,7 +249,7 @@ async fn generate_moonlight_txs() -> Result<(), Box<dyn std::error::Error>> {
let snapshot = toml::from_str(include_str!("./config/bench.toml"))
.expect("Cannot deserialize config");

let rusk = new_state(&tmp, &snapshot)?;
let rusk = new_state(&tmp, &snapshot, 100_000_000_000)?;

let cache =
Arc::new(std::sync::RwLock::new(std::collections::HashMap::new()));
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/contract_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn initial_state<P: AsRef<Path>>(dir: P, deploy_bob: bool) -> Result<Rusk> {

let (sender, _) = broadcast::channel(10);

let rusk = Rusk::new(dir, None, None, u64::MAX, sender)
let rusk = Rusk::new(dir, None, None, BLOCK_GAS_LIMIT, u64::MAX, sender)
.expect("Instantiating rusk should succeed");
Ok(rusk)
}
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/gas_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

const SENDER_INDEX_0: u64 = 0;
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/multi_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
toml::from_str(include_str!("../config/multi_transfer.toml"))
.expect("Cannot deserialize config");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

/// Executes three different transactions in the same block, expecting only two
Expand Down
4 changes: 2 additions & 2 deletions rusk/tests/services/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ fn stake_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/stake.toml"))
.expect("Cannot deserialize config");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

// 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");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

/// Stakes an amount Dusk and produces a block with this single transaction,
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/transfer.toml"))
.expect("Cannot deserialize config");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

/// Transacts between two accounts on the in the same wallet and produces a
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/unspendable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!("../config/unspendable.toml"))
.expect("Cannot deserialize config");

new_state(dir, &snapshot)
new_state(dir, &snapshot, BLOCK_GAS_LIMIT)
}

const SENDER_INDEX_0: u64 = 0;
Expand Down

0 comments on commit 4592fe2

Please sign in to comment.