core/validator: Wrap std::process:exit(1) for easier testing (#13990)
This commit is contained in:
parent
82c75c3786
commit
3d9d7557c8
|
@ -62,7 +62,6 @@ use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process,
|
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
sync::mpsc::Receiver,
|
sync::mpsc::Receiver,
|
||||||
sync::{mpsc::channel, Arc, Mutex, RwLock},
|
sync::{mpsc::channel, Arc, Mutex, RwLock},
|
||||||
|
@ -199,6 +198,15 @@ pub struct Validator {
|
||||||
ip_echo_server: solana_net_utils::IpEchoServer,
|
ip_echo_server: solana_net_utils::IpEchoServer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in the distant future, get rid of ::new()/exit() and use Result properly...
|
||||||
|
fn abort() -> ! {
|
||||||
|
#[cfg(not(test))]
|
||||||
|
std::process::exit(1);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
panic!("process::exit(1) is intercepted for friendly test failure...");
|
||||||
|
}
|
||||||
|
|
||||||
impl Validator {
|
impl Validator {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
mut node: Node,
|
mut node: Node,
|
||||||
|
@ -240,7 +248,7 @@ impl Validator {
|
||||||
"ledger directory does not exist or is not accessible: {:?}",
|
"ledger directory does not exist or is not accessible: {:?}",
|
||||||
ledger_path
|
ledger_path
|
||||||
);
|
);
|
||||||
process::exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(shred_version) = config.expected_shred_version {
|
if let Some(shred_version) = config.expected_shred_version {
|
||||||
|
@ -331,7 +339,7 @@ impl Validator {
|
||||||
"shred version mismatch: expected {} found: {}",
|
"shred version mismatch: expected {} found: {}",
|
||||||
expected_shred_version, node.info.shred_version,
|
expected_shred_version, node.info.shred_version,
|
||||||
);
|
);
|
||||||
process::exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +503,7 @@ impl Validator {
|
||||||
};
|
};
|
||||||
|
|
||||||
if wait_for_supermajority(config, &bank, &cluster_info, rpc_override_health_check) {
|
if wait_for_supermajority(config, &bank, &cluster_info, rpc_override_health_check) {
|
||||||
std::process::exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
let poh_service = PohService::new(poh_recorder.clone(), &poh_config, &exit);
|
let poh_service = PohService::new(poh_recorder.clone(), &poh_config, &exit);
|
||||||
|
@ -777,7 +785,7 @@ fn post_process_restored_tower(
|
||||||
"And there is an existing vote_account containing actual votes. \
|
"And there is an existing vote_account containing actual votes. \
|
||||||
Aborting due to possible conflicting duplicate votes",
|
Aborting due to possible conflicting duplicate votes",
|
||||||
);
|
);
|
||||||
process::exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
if err.is_file_missing() && !voting_has_been_active {
|
if err.is_file_missing() && !voting_has_been_active {
|
||||||
// Currently, don't protect against spoofed snapshots with no tower at all
|
// Currently, don't protect against spoofed snapshots with no tower at all
|
||||||
|
@ -837,7 +845,7 @@ fn new_banks_from_ledger(
|
||||||
if genesis_hash != expected_genesis_hash {
|
if genesis_hash != expected_genesis_hash {
|
||||||
error!("genesis hash mismatch: expected {}", expected_genesis_hash);
|
error!("genesis hash mismatch: expected {}", expected_genesis_hash);
|
||||||
error!("Delete the ledger directory to continue: {:?}", ledger_path);
|
error!("Delete the ledger directory to continue: {:?}", ledger_path);
|
||||||
process::exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,7 +862,7 @@ fn new_banks_from_ledger(
|
||||||
if let Ok(tower) = &restored_tower {
|
if let Ok(tower) = &restored_tower {
|
||||||
reconcile_blockstore_roots_with_tower(&tower, &blockstore).unwrap_or_else(|err| {
|
reconcile_blockstore_roots_with_tower(&tower, &blockstore).unwrap_or_else(|err| {
|
||||||
error!("Failed to reconcile blockstore with tower: {:?}", err);
|
error!("Failed to reconcile blockstore with tower: {:?}", err);
|
||||||
std::process::exit(1);
|
abort()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,7 +896,7 @@ fn new_banks_from_ledger(
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
error!("Failed to load ledger: {:?}", err);
|
error!("Failed to load ledger: {:?}", err);
|
||||||
process::exit(1);
|
abort()
|
||||||
});
|
});
|
||||||
|
|
||||||
let tower = post_process_restored_tower(
|
let tower = post_process_restored_tower(
|
||||||
|
@ -1110,7 +1118,7 @@ unsafe fn check_avx() {
|
||||||
error!(
|
error!(
|
||||||
"Your machine does not have AVX support, please rebuild from source on your machine"
|
"Your machine does not have AVX support, please rebuild from source on your machine"
|
||||||
);
|
);
|
||||||
process::exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue