Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ impl Config {
pox_sync_sample_secs: node
.pox_sync_sample_secs
.unwrap_or(default_node_config.pox_sync_sample_secs),
use_test_genesis_chainstate: node.use_test_genesis_chainstate,
};
node_config.set_bootstrap_node(node.bootstrap_node);
if let Some(deny_nodes) = node.deny_nodes {
Expand Down Expand Up @@ -913,6 +914,7 @@ pub struct NodeConfig {
pub wait_time_for_microblocks: u64,
pub prometheus_bind: Option<String>,
pub pox_sync_sample_secs: u64,
pub use_test_genesis_chainstate: Option<bool>,
}

impl NodeConfig {
Expand Down Expand Up @@ -950,6 +952,7 @@ impl NodeConfig {
wait_time_for_microblocks: 5000,
prometheus_bind: None,
pox_sync_sample_secs: 30,
use_test_genesis_chainstate: None,
}
}

Expand Down Expand Up @@ -1081,6 +1084,7 @@ pub struct NodeConfigFile {
pub wait_time_for_microblocks: Option<u64>,
pub prometheus_bind: Option<String>,
pub pox_sync_sample_secs: Option<u64>,
pub use_test_genesis_chainstate: Option<bool>,
}

#[derive(Clone, Deserialize, Default)]
Expand Down
10 changes: 2 additions & 8 deletions testnet/stacks-node/src/genesis_data.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use stx_genesis::GenesisData;

// Uses the full production genesis chainstate.txt data when compiled regularly, .e.g. `cargo build`.
// Uses a small test chainstate.txt file when tests are ran regularly, .e.g. `cargo test`.
// The production file can be used in tests by specifying the `prod-genesis-chainstate` feature
// flag, .e.g. `cargo test --features prod-genesis-chainstate`

#[cfg(any(not(test), feature = "prod-genesis-chainstate"))]
lazy_static! {
pub static ref GENESIS_DATA: GenesisData = GenesisData::new(false);
}
pub const USE_TEST_GENESIS_CHAINSTATE: bool = false;

#[cfg(all(test, not(feature = "prod-genesis-chainstate")))]
lazy_static! {
pub static ref GENESIS_DATA: GenesisData = GenesisData::new(true);
}
pub const USE_TEST_GENESIS_CHAINSTATE: bool = true;
45 changes: 33 additions & 12 deletions testnet/stacks-node/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use super::{
genesis_data::GENESIS_DATA, BurnchainController, BurnchainTip, Config, EventDispatcher,
Keychain, Tenure,
};
use crate::run_loop::RegisteredKey;
use super::{BurnchainController, BurnchainTip, Config, EventDispatcher, Keychain, Tenure};
use crate::{genesis_data::USE_TEST_GENESIS_CHAINSTATE, run_loop::RegisteredKey};

use std::collections::HashSet;
use std::convert::TryFrom;
use std::default::Default;
use std::net::SocketAddr;
use std::{collections::HashSet, env};
use std::{thread, thread::JoinHandle, time};

use stacks::chainstate::burn::db::sortdb::SortitionDB;
Expand Down Expand Up @@ -87,9 +84,11 @@ pub struct Node {
nonce: u64,
}

pub fn get_account_lockups() -> Box<dyn Iterator<Item = ChainstateAccountLockup>> {
pub fn get_account_lockups(
use_test_chainstate_data: bool,
) -> Box<dyn Iterator<Item = ChainstateAccountLockup>> {
Box::new(
GENESIS_DATA
stx_genesis::GenesisData::new(use_test_chainstate_data)
.read_lockups()
.map(|item| ChainstateAccountLockup {
address: item.address,
Expand All @@ -99,9 +98,11 @@ pub fn get_account_lockups() -> Box<dyn Iterator<Item = ChainstateAccountLockup>
)
}

pub fn get_account_balances() -> Box<dyn Iterator<Item = ChainstateAccountBalance>> {
pub fn get_account_balances(
use_test_chainstate_data: bool,
) -> Box<dyn Iterator<Item = ChainstateAccountBalance>> {
Box::new(
GENESIS_DATA
stx_genesis::GenesisData::new(use_test_chainstate_data)
.read_balances()
.map(|item| ChainstateAccountBalance {
address: item.address,
Expand Down Expand Up @@ -181,6 +182,22 @@ fn spawn_peer(
impl Node {
/// Instantiate and initialize a new node, given a config
pub fn new(config: Config, boot_block_exec: Box<dyn FnOnce(&mut ClarityTx) -> ()>) -> Self {
let use_test_genesis_data = if config.burnchain.mode == "mocknet" {
// When running in mocknet mode allow the small test genesis chainstate data to be enabled.
// First check env var, then config file, then use default.
if env::var("BLOCKSTACK_USE_TEST_GENESIS_CHAINSTATE") == Ok("1".to_string()) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of making this an envar, could we add this as a config option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, although env vars are easier to deal with in the tooling than config files. How strongly do you prefer config file vs env var?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice for the competition to set this as a config option

Copy link
Contributor Author

@zone117x zone117x Dec 18, 2020

Choose a reason for hiding this comment

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

Are we okay with allowing both methods? Config and env var

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jcnelson @friedger Please see latest commit where support for both config toml and env var is added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great

Copy link
Member

Choose a reason for hiding this comment

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

Both are fine.

true
} else if let Some(use_test_genesis_chainstate) =
config.node.use_test_genesis_chainstate
{
use_test_genesis_chainstate
} else {
USE_TEST_GENESIS_CHAINSTATE
}
} else {
USE_TEST_GENESIS_CHAINSTATE
};

let keychain = Keychain::default(config.node.seed.clone());

let initial_balances = config
Expand All @@ -195,8 +212,12 @@ impl Node {
first_burnchain_block_height: 0,
first_burnchain_block_timestamp: 0,
post_flight_callback: Some(boot_block_exec),
get_bulk_initial_lockups: Some(Box::new(get_account_lockups)),
get_bulk_initial_balances: Some(Box::new(get_account_balances)),
get_bulk_initial_lockups: Some(Box::new(move || {
get_account_lockups(use_test_genesis_data)
})),
get_bulk_initial_balances: Some(Box::new(move || {
get_account_balances(use_test_genesis_data)
})),
};

let chain_state_result = StacksChainState::open_and_exec(
Expand Down
9 changes: 7 additions & 2 deletions testnet/stacks-node/src/run_loop/neon.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
genesis_data::USE_TEST_GENESIS_CHAINSTATE,
neon_node,
node::{get_account_balances, get_account_lockups},
BitcoinRegtestController, BurnchainController, Config, EventDispatcher, Keychain,
Expand Down Expand Up @@ -198,8 +199,12 @@ impl RunLoop {
first_burnchain_block_hash: coordinator_burnchain_config.first_block_hash,
first_burnchain_block_height: coordinator_burnchain_config.first_block_height as u32,
first_burnchain_block_timestamp: coordinator_burnchain_config.first_block_timestamp,
get_bulk_initial_lockups: Some(Box::new(get_account_lockups)),
get_bulk_initial_balances: Some(Box::new(get_account_balances)),
get_bulk_initial_lockups: Some(Box::new(|| {
get_account_lockups(USE_TEST_GENESIS_CHAINSTATE)
})),
get_bulk_initial_balances: Some(Box::new(|| {
get_account_balances(USE_TEST_GENESIS_CHAINSTATE)
})),
};

let (chain_state_db, receipts) = StacksChainState::open_and_exec(
Expand Down