Skip to content

Commit 56c77a3

Browse files
author
Aaron Blankstein
authored
Merge pull request #2195 from blockstack/next
Release `next` to `master`: non-consensus breaking
2 parents fe81b98 + bcc51a1 commit 56c77a3

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

testnet/stacks-node/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ impl Config {
421421
pox_sync_sample_secs: node
422422
.pox_sync_sample_secs
423423
.unwrap_or(default_node_config.pox_sync_sample_secs),
424+
use_test_genesis_chainstate: node.use_test_genesis_chainstate,
424425
};
425426
node_config.set_bootstrap_node(node.bootstrap_node);
426427
if let Some(deny_nodes) = node.deny_nodes {
@@ -913,6 +914,7 @@ pub struct NodeConfig {
913914
pub wait_time_for_microblocks: u64,
914915
pub prometheus_bind: Option<String>,
915916
pub pox_sync_sample_secs: u64,
917+
pub use_test_genesis_chainstate: Option<bool>,
916918
}
917919

918920
impl NodeConfig {
@@ -950,6 +952,7 @@ impl NodeConfig {
950952
wait_time_for_microblocks: 5000,
951953
prometheus_bind: None,
952954
pox_sync_sample_secs: 30,
955+
use_test_genesis_chainstate: None,
953956
}
954957
}
955958

@@ -1081,6 +1084,7 @@ pub struct NodeConfigFile {
10811084
pub wait_time_for_microblocks: Option<u64>,
10821085
pub prometheus_bind: Option<String>,
10831086
pub pox_sync_sample_secs: Option<u64>,
1087+
pub use_test_genesis_chainstate: Option<bool>,
10841088
}
10851089

10861090
#[derive(Clone, Deserialize, Default)]
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
use stx_genesis::GenesisData;
2-
31
// Uses the full production genesis chainstate.txt data when compiled regularly, .e.g. `cargo build`.
42
// Uses a small test chainstate.txt file when tests are ran regularly, .e.g. `cargo test`.
53
// The production file can be used in tests by specifying the `prod-genesis-chainstate` feature
64
// flag, .e.g. `cargo test --features prod-genesis-chainstate`
75

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

139
#[cfg(all(test, not(feature = "prod-genesis-chainstate")))]
14-
lazy_static! {
15-
pub static ref GENESIS_DATA: GenesisData = GenesisData::new(true);
16-
}
10+
pub const USE_TEST_GENESIS_CHAINSTATE: bool = true;

testnet/stacks-node/src/node.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use super::{
2-
genesis_data::GENESIS_DATA, BurnchainController, BurnchainTip, Config, EventDispatcher,
3-
Keychain, Tenure,
4-
};
5-
use crate::run_loop::RegisteredKey;
1+
use super::{BurnchainController, BurnchainTip, Config, EventDispatcher, Keychain, Tenure};
2+
use crate::{genesis_data::USE_TEST_GENESIS_CHAINSTATE, run_loop::RegisteredKey};
63

7-
use std::collections::HashSet;
84
use std::convert::TryFrom;
95
use std::default::Default;
106
use std::net::SocketAddr;
7+
use std::{collections::HashSet, env};
118
use std::{thread, thread::JoinHandle, time};
129

1310
use stacks::chainstate::burn::db::sortdb::SortitionDB;
@@ -87,9 +84,11 @@ pub struct Node {
8784
nonce: u64,
8885
}
8986

90-
pub fn get_account_lockups() -> Box<dyn Iterator<Item = ChainstateAccountLockup>> {
87+
pub fn get_account_lockups(
88+
use_test_chainstate_data: bool,
89+
) -> Box<dyn Iterator<Item = ChainstateAccountLockup>> {
9190
Box::new(
92-
GENESIS_DATA
91+
stx_genesis::GenesisData::new(use_test_chainstate_data)
9392
.read_lockups()
9493
.map(|item| ChainstateAccountLockup {
9594
address: item.address,
@@ -99,9 +98,11 @@ pub fn get_account_lockups() -> Box<dyn Iterator<Item = ChainstateAccountLockup>
9998
)
10099
}
101100

102-
pub fn get_account_balances() -> Box<dyn Iterator<Item = ChainstateAccountBalance>> {
101+
pub fn get_account_balances(
102+
use_test_chainstate_data: bool,
103+
) -> Box<dyn Iterator<Item = ChainstateAccountBalance>> {
103104
Box::new(
104-
GENESIS_DATA
105+
stx_genesis::GenesisData::new(use_test_chainstate_data)
105106
.read_balances()
106107
.map(|item| ChainstateAccountBalance {
107108
address: item.address,
@@ -181,6 +182,22 @@ fn spawn_peer(
181182
impl Node {
182183
/// Instantiate and initialize a new node, given a config
183184
pub fn new(config: Config, boot_block_exec: Box<dyn FnOnce(&mut ClarityTx) -> ()>) -> Self {
185+
let use_test_genesis_data = if config.burnchain.mode == "mocknet" {
186+
// When running in mocknet mode allow the small test genesis chainstate data to be enabled.
187+
// First check env var, then config file, then use default.
188+
if env::var("BLOCKSTACK_USE_TEST_GENESIS_CHAINSTATE") == Ok("1".to_string()) {
189+
true
190+
} else if let Some(use_test_genesis_chainstate) =
191+
config.node.use_test_genesis_chainstate
192+
{
193+
use_test_genesis_chainstate
194+
} else {
195+
USE_TEST_GENESIS_CHAINSTATE
196+
}
197+
} else {
198+
USE_TEST_GENESIS_CHAINSTATE
199+
};
200+
184201
let keychain = Keychain::default(config.node.seed.clone());
185202

186203
let initial_balances = config
@@ -195,8 +212,12 @@ impl Node {
195212
first_burnchain_block_height: 0,
196213
first_burnchain_block_timestamp: 0,
197214
post_flight_callback: Some(boot_block_exec),
198-
get_bulk_initial_lockups: Some(Box::new(get_account_lockups)),
199-
get_bulk_initial_balances: Some(Box::new(get_account_balances)),
215+
get_bulk_initial_lockups: Some(Box::new(move || {
216+
get_account_lockups(use_test_genesis_data)
217+
})),
218+
get_bulk_initial_balances: Some(Box::new(move || {
219+
get_account_balances(use_test_genesis_data)
220+
})),
200221
};
201222

202223
let chain_state_result = StacksChainState::open_and_exec(

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{
2+
genesis_data::USE_TEST_GENESIS_CHAINSTATE,
23
neon_node,
34
node::{get_account_balances, get_account_lockups},
45
BitcoinRegtestController, BurnchainController, Config, EventDispatcher, Keychain,
@@ -198,8 +199,12 @@ impl RunLoop {
198199
first_burnchain_block_hash: coordinator_burnchain_config.first_block_hash,
199200
first_burnchain_block_height: coordinator_burnchain_config.first_block_height as u32,
200201
first_burnchain_block_timestamp: coordinator_burnchain_config.first_block_timestamp,
201-
get_bulk_initial_lockups: Some(Box::new(get_account_lockups)),
202-
get_bulk_initial_balances: Some(Box::new(get_account_balances)),
202+
get_bulk_initial_lockups: Some(Box::new(|| {
203+
get_account_lockups(USE_TEST_GENESIS_CHAINSTATE)
204+
})),
205+
get_bulk_initial_balances: Some(Box::new(|| {
206+
get_account_balances(USE_TEST_GENESIS_CHAINSTATE)
207+
})),
203208
};
204209

205210
let (chain_state_db, receipts) = StacksChainState::open_and_exec(

0 commit comments

Comments
 (0)