Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime fuzz: fuzz epoch_length and gas_limit #5132

Merged
merged 8 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions test-utils/runtime-tester/src/fuzzing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::str::FromStr;

pub type ContractId = usize;

pub const MAX_BLOCKS: usize = 2500;
pub const MAX_BLOCKS: usize = 250;
pub const MAX_TXS: usize = 50;
pub const MAX_TX_DIFF: usize = 10;
pub const MAX_ACCOUNTS: usize = 100;
Expand All @@ -36,7 +36,11 @@ impl Arbitrary<'_> for Scenario {
let mut scope = Scope::from_seeds(&seeds);

let network_config = NetworkConfig { seeds };
let runtime_config = RuntimeConfig { max_total_prepaid_gas: GAS_1 * 100 };
let runtime_config = RuntimeConfig {
max_total_prepaid_gas: GAS_1 * 100,
gas_limit: (GAS_1 as f64 * *u.choose(&[0.01, 0.1, 1., 10., 100.])?) as u64,
epoch_length: *u.choose(&[5, 10, 100, 500])? as u64,
Comment on lines +41 to +42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are these numbers chosen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intuitively, because I didn't have any ideas on how to do it properly. Open to any suggestions.

};

let mut blocks = vec![];

Expand Down
6 changes: 5 additions & 1 deletion test-utils/runtime-tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ fn scenario_smoke_test() {

let mut scenario = Scenario {
network_config: NetworkConfig { seeds: seeds },
runtime_config: RuntimeConfig { max_total_prepaid_gas: 300 * 10u64.pow(12) },
runtime_config: RuntimeConfig {
max_total_prepaid_gas: 300 * 10u64.pow(12),
gas_limit: 1_000_000_000_000_000,
epoch_length: 500,
},
blocks: Vec::new(),
use_in_memory_store: true,
};
Expand Down
6 changes: 5 additions & 1 deletion test-utils/runtime-tester/src/run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use near_client_primitives::types::Error;
use near_crypto::InMemorySigner;
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, SignedTransaction};
use near_primitives::types::{AccountId, BlockHeight, Gas, Nonce};
use near_primitives::types::{AccountId, BlockHeight, BlockHeightDelta, Gas, Nonce};
use near_store::create_store;
use near_store::test_utils::create_test_store;
use nearcore::{config::GenesisExt, NightshadeRuntime};
Expand Down Expand Up @@ -40,6 +40,8 @@ impl Scenario {
let mut runtime_config = near_primitives::runtime::config::RuntimeConfig::test();
runtime_config.wasm_config.limit_config.max_total_prepaid_gas =
self.runtime_config.max_total_prepaid_gas;
genesis.config.epoch_length = self.runtime_config.epoch_length;
genesis.config.gas_limit = self.runtime_config.gas_limit;
let runtime_config_store = RuntimeConfigStore::with_one_config(runtime_config);

let (tempdir, store) = if self.use_in_memory_store {
Expand Down Expand Up @@ -112,6 +114,8 @@ pub struct NetworkConfig {
#[derive(Serialize, Deserialize)]
pub struct RuntimeConfig {
pub max_total_prepaid_gas: Gas,
pub gas_limit: Gas,
pub epoch_length: BlockHeightDelta,
}

#[derive(Serialize, Deserialize)]
Expand Down
20 changes: 18 additions & 2 deletions test-utils/runtime-tester/src/scenario_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::run_test::{BlockConfig, NetworkConfig, RuntimeConfig, Scenario, Trans
use near_crypto::{InMemorySigner, KeyType};
use near_primitives::{
transaction::Action,
types::{AccountId, BlockHeight, Gas, Nonce},
types::{AccountId, BlockHeight, BlockHeightDelta, Gas, Nonce},
};

use std::str::FromStr;
Expand Down Expand Up @@ -47,7 +47,11 @@ impl ScenarioBuilder {
/// Default `use_in_memory_store` -- true.
pub fn new() -> Self {
let network_config = NetworkConfig { seeds: (0..4).map(|x| id_to_seed(x)).collect() };
let runtime_config = RuntimeConfig { max_total_prepaid_gas: 300 * 10u64.pow(12) };
let runtime_config = RuntimeConfig {
max_total_prepaid_gas: 300 * 10u64.pow(12),
gas_limit: 1_000_000_000_000_000,
epoch_length: 500,
};

ScenarioBuilder {
height: 1,
Expand All @@ -74,6 +78,18 @@ impl ScenarioBuilder {
self
}

/// Changes gas_limit
pub fn gas_limit(mut self, gas_limit: Gas) -> Self {
self.scenario.runtime_config.gas_limit = gas_limit;
self
}

/// Changes epoch_length
pub fn epoch_length(mut self, epoch_length: BlockHeightDelta) -> Self {
self.scenario.runtime_config.epoch_length = epoch_length;
self
}

/// Changes `use_in_memory_store`.
pub fn in_memory_store(mut self, in_memory_store: bool) -> Self {
self.scenario.use_in_memory_store = in_memory_store;
Expand Down