Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request stacks-network#4749 from stacks-network/fix/4735
Browse files Browse the repository at this point in the history
Fix/4735
  • Loading branch information
jcnelson authored May 6, 2024
2 parents 1886013 + 61b37c0 commit de17b4b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl BitcoinRegtestController {
block_height: u64,
) -> Option<UTXOSet> {
// if mock mining, do not even bother requesting UTXOs
if self.config.get_node_config().mock_mining {
if self.config.get_node_config(false).mock_mining {
return None;
}

Expand Down
47 changes: 34 additions & 13 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ mod tests {
seed = "invalid-hex-value"
"#,
)
.unwrap()
.unwrap(),
false
)
.unwrap_err()
);
Expand All @@ -115,7 +116,8 @@ mod tests {
local_peer_seed = "invalid-hex-value"
"#,
)
.unwrap()
.unwrap(),
false
)
.unwrap_err()
);
Expand All @@ -130,14 +132,15 @@ mod tests {
"#,
)
.unwrap(),
false,
)
.unwrap_err();
assert_eq!(
expected_err_prefix,
&actual_err_msg[..expected_err_prefix.len()]
);

assert!(Config::from_config_file(ConfigFile::from_str("").unwrap()).is_ok());
assert!(Config::from_config_file(ConfigFile::from_str("").unwrap(), false).is_ok());
}

#[test]
Expand Down Expand Up @@ -195,6 +198,7 @@ mod tests {
"#,
)
.unwrap(),
false,
)
.expect("Expected to be able to parse block proposal token from file");

Expand All @@ -218,6 +222,7 @@ mod tests {
"#
))
.expect("Expected to be able to parse config file from string"),
false,
)
.expect("Expected to be able to parse affirmation map from file");

Expand All @@ -241,14 +246,15 @@ mod tests {
))
.expect("Expected to be able to parse config file from string");

assert!(Config::from_config_file(file).is_err());
assert!(Config::from_config_file(file, false).is_err());
}

#[test]
fn should_load_empty_affirmation_map() {
let config = Config::from_config_file(
ConfigFile::from_str(r#""#)
.expect("Expected to be able to parse config file from string"),
false,
)
.expect("Expected to be able to parse affirmation map from file");

Expand All @@ -266,6 +272,7 @@ mod tests {
"#,
)
.expect("Expected to be able to parse config file from string"),
false,
)
.expect("Expected to be able to parse affirmation map from file");
// Should default add xenon affirmation overrides
Expand All @@ -291,6 +298,7 @@ mod tests {
"#,
))
.expect("Expected to be able to parse config file from string"),
false,
)
.expect("Expected to be able to parse affirmation map from file");
// Should default add xenon affirmation overrides, but overwrite with the configured one above
Expand Down Expand Up @@ -537,7 +545,7 @@ impl Config {
let Ok(config_file) = ConfigFile::from_path(path.as_str()) else {
return self.burnchain.clone();
};
let Ok(config) = Config::from_config_file(config_file) else {
let Ok(config) = Config::from_config_file(config_file, false) else {
return self.burnchain.clone();
};
config.burnchain
Expand All @@ -552,20 +560,20 @@ impl Config {
let Ok(config_file) = ConfigFile::from_path(path.as_str()) else {
return self.miner.clone();
};
let Ok(config) = Config::from_config_file(config_file) else {
let Ok(config) = Config::from_config_file(config_file, false) else {
return self.miner.clone();
};
return config.miner;
}

pub fn get_node_config(&self) -> NodeConfig {
pub fn get_node_config(&self, resolve_bootstrap_nodes: bool) -> NodeConfig {
let Some(path) = &self.config_path else {
return self.node.clone();
};
let Ok(config_file) = ConfigFile::from_path(path.as_str()) else {
return self.node.clone();
};
let Ok(config) = Config::from_config_file(config_file) else {
let Ok(config) = Config::from_config_file(config_file, resolve_bootstrap_nodes) else {
return self.node.clone();
};
return config.node;
Expand Down Expand Up @@ -941,11 +949,18 @@ impl Config {
Ok(out_epochs)
}

pub fn from_config_file(config_file: ConfigFile) -> Result<Config, String> {
Self::from_config_default(config_file, Config::default())
pub fn from_config_file(
config_file: ConfigFile,
resolve_bootstrap_nodes: bool,
) -> Result<Config, String> {
Self::from_config_default(config_file, Config::default(), resolve_bootstrap_nodes)
}

fn from_config_default(config_file: ConfigFile, default: Config) -> Result<Config, String> {
fn from_config_default(
config_file: ConfigFile,
default: Config,
resolve_bootstrap_nodes: bool,
) -> Result<Config, String> {
let Config {
node: default_node_config,
burnchain: default_burnchain_config,
Expand Down Expand Up @@ -996,9 +1011,15 @@ impl Config {
};

if let Some(bootstrap_node) = bootstrap_node {
node.set_bootstrap_nodes(bootstrap_node, burnchain.chain_id, burnchain.peer_version);
if resolve_bootstrap_nodes {
node.set_bootstrap_nodes(
bootstrap_node,
burnchain.chain_id,
burnchain.peer_version,
);
}
} else {
if is_mainnet {
if is_mainnet && resolve_bootstrap_nodes {
let bootstrap_node = ConfigFile::mainnet().node.unwrap().bootstrap_node.unwrap();
node.set_bootstrap_nodes(
bootstrap_node,
Expand Down
16 changes: 9 additions & 7 deletions testnet/stacks-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static GLOBAL: Jemalloc = Jemalloc;
fn cli_pick_best_tip(config_path: &str, at_stacks_height: Option<u64>) -> TipCandidate {
info!("Loading config at path {}", config_path);
let config = match ConfigFile::from_path(config_path) {
Ok(config_file) => Config::from_config_file(config_file).unwrap(),
Ok(config_file) => Config::from_config_file(config_file, true).unwrap(),
Err(e) => {
warn!("Invalid config file: {}", e);
process::exit(1);
Expand Down Expand Up @@ -105,7 +105,7 @@ fn cli_get_miner_spend(
) -> u64 {
info!("Loading config at path {}", config_path);
let config = match ConfigFile::from_path(&config_path) {
Ok(config_file) => Config::from_config_file(config_file).unwrap(),
Ok(config_file) => Config::from_config_file(config_file, true).unwrap(),
Err(e) => {
warn!("Invalid config file: {}", e);
process::exit(1);
Expand Down Expand Up @@ -334,7 +334,7 @@ fn main() {
process::exit(1);
}
};
match Config::from_config_file(config_file) {
match Config::from_config_file(config_file, true) {
Ok(_) => {
info!("Loaded config!");
process::exit(0);
Expand Down Expand Up @@ -365,9 +365,11 @@ fn main() {
let seed = {
let config_path: Option<String> = args.opt_value_from_str("--config").unwrap();
if let Some(config_path) = config_path {
let conf =
Config::from_config_file(ConfigFile::from_path(&config_path).unwrap())
.unwrap();
let conf = Config::from_config_file(
ConfigFile::from_path(&config_path).unwrap(),
true,
)
.unwrap();
args.finish();
conf.node.seed
} else {
Expand Down Expand Up @@ -416,7 +418,7 @@ fn main() {
}
};

let conf = match Config::from_config_file(config_file) {
let conf = match Config::from_config_file(config_file, true) {
Ok(conf) => conf,
Err(e) => {
warn!("Invalid config: {}", e);
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/nakamoto_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl StacksNode {
let local_peer = p2p_net.local_peer.clone();

// setup initial key registration
let leader_key_registration_state = if config.get_node_config().mock_mining {
let leader_key_registration_state = if config.get_node_config(false).mock_mining {
// mock mining, pretend to have a registered key
let (vrf_public_key, _) = keychain.make_vrf_keypair(VRF_MOCK_MINER_KEY);
LeaderKeyRegistrationState::Active(RegisteredKey {
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl BlockMinerThread {
fn make_vrf_proof(&mut self) -> Option<VRFProof> {
// if we're a mock miner, then make sure that the keychain has a keypair for the mocked VRF
// key
let vrf_proof = if self.config.get_node_config().mock_mining {
let vrf_proof = if self.config.get_node_config(false).mock_mining {
self.keychain.generate_proof(
VRF_MOCK_MINER_KEY,
self.burn_block.sortition_hash.as_bytes(),
Expand Down
8 changes: 4 additions & 4 deletions testnet/stacks-node/src/neon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ impl BlockMinerThread {
fn make_vrf_proof(&mut self) -> Option<VRFProof> {
// if we're a mock miner, then make sure that the keychain has a keypair for the mocked VRF
// key
let vrf_proof = if self.config.get_node_config().mock_mining {
let vrf_proof = if self.config.get_node_config(false).mock_mining {
self.keychain.generate_proof(
VRF_MOCK_MINER_KEY,
self.burn_block.sortition_hash.as_bytes(),
Expand Down Expand Up @@ -2535,7 +2535,7 @@ impl BlockMinerThread {
let res = bitcoin_controller.submit_operation(target_epoch_id, op, &mut op_signer, attempt);
if res.is_none() {
self.failed_to_submit_last_attempt = true;
if !self.config.get_node_config().mock_mining {
if !self.config.get_node_config(false).mock_mining {
warn!("Relayer: Failed to submit Bitcoin transaction");
return None;
}
Expand Down Expand Up @@ -3518,7 +3518,7 @@ impl RelayerThread {
return false;
}

if !self.config.get_node_config().mock_mining {
if !self.config.get_node_config(false).mock_mining {
// mock miner can't mine microblocks yet, so don't stop it from trying multiple
// anchored blocks
if self.mined_stacks_block && self.config.node.mine_microblocks {
Expand Down Expand Up @@ -4777,7 +4777,7 @@ impl StacksNode {
let local_peer = p2p_net.local_peer.clone();

// setup initial key registration
let leader_key_registration_state = if config.get_node_config().mock_mining {
let leader_key_registration_state = if config.get_node_config(false).mock_mining {
// mock mining, pretend to have a registered key
let (vrf_public_key, _) = keychain.make_vrf_keypair(VRF_MOCK_MINER_KEY);
LeaderKeyRegistrationState::Active(RegisteredKey {
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/run_loop/nakamoto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl RunLoop {
return true;
}
}
if self.config.get_node_config().mock_mining {
if self.config.get_node_config(false).mock_mining {
info!("No UTXOs found, but configured to mock mine");
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/run_loop/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl RunLoop {
return true;
}
}
if self.config.get_node_config().mock_mining {
if self.config.get_node_config(false).mock_mining {
info!("No UTXOs found, but configured to mock mine");
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/tests/neon_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn inner_neon_integration_test_conf(seed: Option<Vec<u8>>) -> (Config, StacksAdd
burnchain.peer_host = Some("127.0.0.1".to_string());
}

let magic_bytes = Config::from_config_file(cfile)
let magic_bytes = Config::from_config_file(cfile, false)
.unwrap()
.burnchain
.magic_bytes;
Expand Down

0 comments on commit de17b4b

Please sign in to comment.