solana-validator set-identity now loads the tower file for the new identity

This commit is contained in:
Michael Vines
2021-07-20 20:53:14 -07:00
parent 71bd434297
commit 61865c0ee0
5 changed files with 44 additions and 7 deletions

View File

@ -13,7 +13,7 @@ use {
},
std::{
net::SocketAddr,
path::Path,
path::{Path, PathBuf},
sync::{Arc, RwLock},
thread::{self, Builder},
time::{Duration, SystemTime},
@ -28,6 +28,7 @@ pub struct AdminRpcRequestMetadata {
pub validator_exit: Arc<RwLock<Exit>>,
pub authorized_voter_keypairs: Arc<RwLock<Vec<Arc<Keypair>>>>,
pub cluster_info: Arc<RwLock<Option<Arc<ClusterInfo>>>>,
pub tower_path: PathBuf,
}
impl Metadata for AdminRpcRequestMetadata {}
@ -137,8 +138,22 @@ impl AdminRpc for AdminRpcImpl {
fn set_identity(&self, meta: Self::Metadata, keypair_file: String) -> Result<()> {
debug!("set_identity request received");
let identity_keypair = read_keypair_file(keypair_file)
.map_err(|err| jsonrpc_core::error::Error::invalid_params(format!("{}", err)))?;
let identity_keypair = read_keypair_file(&keypair_file).map_err(|err| {
jsonrpc_core::error::Error::invalid_params(format!(
"Failed to read identity keypair from {}: {}",
keypair_file, err
))
})?;
// Ensure a Tower exists for the new identity and exit gracefully.
// ReplayStage will be less forgiving if it fails to load the new tower.
solana_core::consensus::Tower::restore(&meta.tower_path, &identity_keypair.pubkey())
.map_err(|err| {
jsonrpc_core::error::Error::invalid_params(format!(
"Unable to load tower file for new identity: {}",
err
))
})?;
if let Some(cluster_info) = meta.cluster_info.read().unwrap().as_ref() {
solana_metrics::set_host_id(identity_keypair.pubkey().to_string());

View File

@ -513,6 +513,7 @@ fn main() {
validator_exit: genesis.validator_exit.clone(),
authorized_voter_keypairs: genesis.authorized_voter_keypairs.clone(),
cluster_info: admin_service_cluster_info.clone(),
tower_path: ledger_path.clone(),
},
);
let dashboard = if output == Output::Dashboard {

View File

@ -2234,7 +2234,9 @@ pub fn main() {
let mut validator_config = ValidatorConfig {
require_tower: matches.is_present("require_tower"),
tower_path: value_t!(matches, "tower", PathBuf).ok(),
tower_path: value_t!(matches, "tower", PathBuf)
.ok()
.or_else(|| Some(ledger_path.clone())),
dev_halt_at_slot: value_t!(matches, "dev_halt_at_slot", Slot).ok(),
cuda: matches.is_present("cuda"),
expected_genesis_hash: matches
@ -2539,6 +2541,7 @@ pub fn main() {
start_progress: start_progress.clone(),
authorized_voter_keypairs: authorized_voter_keypairs.clone(),
cluster_info: admin_service_cluster_info.clone(),
tower_path: validator_config.tower_path.clone().unwrap(),
},
);