2021-07-20 22:25:13 -07:00
|
|
|
use {
|
|
|
|
crate::{
|
|
|
|
cluster::{Cluster, ClusterValidatorInfo, ValidatorInfo},
|
|
|
|
cluster_tests,
|
|
|
|
validator_configs::*,
|
|
|
|
},
|
|
|
|
itertools::izip,
|
|
|
|
log::*,
|
2022-03-31 12:47:00 -07:00
|
|
|
solana_client::thin_client::{create_client, ThinClient},
|
2021-07-20 22:25:13 -07:00
|
|
|
solana_core::{
|
2021-08-09 11:32:48 -07:00
|
|
|
tower_storage::FileTowerStorage,
|
2021-07-20 22:25:13 -07:00
|
|
|
validator::{Validator, ValidatorConfig, ValidatorStartProgress},
|
|
|
|
},
|
|
|
|
solana_gossip::{
|
2022-03-31 12:47:00 -07:00
|
|
|
cluster_info::Node, contact_info::ContactInfo, gossip_service::discover_cluster,
|
2021-07-20 22:25:13 -07:00
|
|
|
},
|
|
|
|
solana_ledger::create_new_tmp_ledger,
|
|
|
|
solana_runtime::genesis_utils::{
|
|
|
|
create_genesis_config_with_vote_accounts_and_cluster_type, GenesisConfigInfo,
|
|
|
|
ValidatorVoteKeypairs,
|
|
|
|
},
|
|
|
|
solana_sdk::{
|
2021-12-03 09:00:31 -08:00
|
|
|
account::{Account, AccountSharedData},
|
2021-07-20 22:25:13 -07:00
|
|
|
client::SyncClient,
|
|
|
|
clock::{DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
|
|
|
commitment_config::CommitmentConfig,
|
|
|
|
epoch_schedule::EpochSchedule,
|
|
|
|
genesis_config::{ClusterType, GenesisConfig},
|
|
|
|
message::Message,
|
|
|
|
poh_config::PohConfig,
|
|
|
|
pubkey::Pubkey,
|
|
|
|
signature::{Keypair, Signer},
|
|
|
|
stake::{
|
|
|
|
config as stake_config, instruction as stake_instruction,
|
|
|
|
state::{Authorized, Lockup},
|
|
|
|
},
|
|
|
|
system_transaction,
|
|
|
|
transaction::Transaction,
|
|
|
|
},
|
|
|
|
solana_stake_program::{config::create_account as create_stake_config_account, stake_state},
|
|
|
|
solana_streamer::socket::SocketAddrSpace,
|
|
|
|
solana_vote_program::{
|
|
|
|
vote_instruction,
|
|
|
|
vote_state::{VoteInit, VoteState},
|
|
|
|
},
|
|
|
|
std::{
|
|
|
|
collections::HashMap,
|
|
|
|
io::{Error, ErrorKind, Result},
|
|
|
|
iter,
|
|
|
|
sync::{Arc, RwLock},
|
2021-06-15 09:04:00 -07:00
|
|
|
},
|
2019-08-17 12:28:36 -07:00
|
|
|
};
|
2019-03-01 10:36:52 -08:00
|
|
|
|
2019-04-15 15:27:45 -07:00
|
|
|
pub struct ClusterConfig {
|
2019-10-11 12:30:52 -07:00
|
|
|
/// The validator config that should be applied to every node in the cluster
|
2019-06-19 00:13:19 -07:00
|
|
|
pub validator_configs: Vec<ValidatorConfig>,
|
2019-04-15 15:27:45 -07:00
|
|
|
/// Number of nodes that are unstaked and not voting (a.k.a listening)
|
|
|
|
pub num_listeners: u64,
|
2020-07-23 18:50:42 -07:00
|
|
|
/// List of tuples (pubkeys, in_genesis) of each node if specified. If
|
|
|
|
/// `in_genesis` == true, the validator's vote and stake accounts
|
|
|
|
// will be inserted into the genesis block instead of warming up through
|
|
|
|
// creating the vote accounts. The first validator (bootstrap leader) automatically
|
|
|
|
// is assumed to be `in_genesis` == true.
|
|
|
|
pub validator_keys: Option<Vec<(Arc<Keypair>, bool)>>,
|
2019-04-15 15:27:45 -07:00
|
|
|
/// The stakes of each node
|
|
|
|
pub node_stakes: Vec<u64>,
|
2022-01-09 21:58:21 -08:00
|
|
|
/// Optional vote keypairs to use for each node
|
|
|
|
pub node_vote_keys: Option<Vec<Arc<Keypair>>>,
|
2019-04-15 15:27:45 -07:00
|
|
|
/// The total lamports available to the cluster
|
|
|
|
pub cluster_lamports: u64,
|
|
|
|
pub ticks_per_slot: u64,
|
|
|
|
pub slots_per_epoch: u64,
|
2019-05-24 19:20:09 -07:00
|
|
|
pub stakers_slot_offset: u64,
|
2020-07-23 18:50:42 -07:00
|
|
|
pub skip_warmup_slots: bool,
|
2020-04-08 14:36:18 -07:00
|
|
|
pub native_instruction_processors: Vec<(String, Pubkey)>,
|
2020-09-08 07:55:09 -07:00
|
|
|
pub cluster_type: ClusterType,
|
2019-05-18 14:01:36 -07:00
|
|
|
pub poh_config: PohConfig,
|
2021-03-09 13:06:07 -08:00
|
|
|
pub additional_accounts: Vec<(Pubkey, AccountSharedData)>,
|
2019-04-15 15:27:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ClusterConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
ClusterConfig {
|
2019-06-19 00:13:19 -07:00
|
|
|
validator_configs: vec![],
|
2019-04-15 15:27:45 -07:00
|
|
|
num_listeners: 0,
|
2019-12-03 16:31:59 -08:00
|
|
|
validator_keys: None,
|
2019-04-15 15:27:45 -07:00
|
|
|
node_stakes: vec![],
|
2022-01-09 21:58:21 -08:00
|
|
|
node_vote_keys: None,
|
2019-04-15 15:27:45 -07:00
|
|
|
cluster_lamports: 0,
|
|
|
|
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
|
2019-11-16 20:53:54 -08:00
|
|
|
slots_per_epoch: DEFAULT_DEV_SLOTS_PER_EPOCH,
|
|
|
|
stakers_slot_offset: DEFAULT_DEV_SLOTS_PER_EPOCH,
|
2019-04-15 15:27:45 -07:00
|
|
|
native_instruction_processors: vec![],
|
2020-09-08 07:55:09 -07:00
|
|
|
cluster_type: ClusterType::Development,
|
2019-05-18 14:01:36 -07:00
|
|
|
poh_config: PohConfig::default(),
|
2020-07-23 18:50:42 -07:00
|
|
|
skip_warmup_slots: false,
|
2020-11-20 03:17:19 -08:00
|
|
|
additional_accounts: vec![],
|
2019-04-15 15:27:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 10:36:52 -08:00
|
|
|
pub struct LocalCluster {
|
2019-04-15 15:27:45 -07:00
|
|
|
/// Keypair with funding to participate in the network
|
2019-03-01 10:36:52 -08:00
|
|
|
pub funding_keypair: Keypair,
|
|
|
|
/// Entry point from which the rest of the network can be discovered
|
2019-03-08 17:23:07 -08:00
|
|
|
pub entry_point_info: ContactInfo,
|
2019-12-03 16:31:59 -08:00
|
|
|
pub validators: HashMap<Pubkey, ClusterValidatorInfo>,
|
2019-11-08 20:56:57 -08:00
|
|
|
pub genesis_config: GenesisConfig,
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LocalCluster {
|
2019-04-15 15:27:45 -07:00
|
|
|
pub fn new_with_equal_stakes(
|
|
|
|
num_nodes: usize,
|
2019-03-03 22:01:09 -08:00
|
|
|
cluster_lamports: u64,
|
2019-04-15 15:27:45 -07:00
|
|
|
lamports_per_node: u64,
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space: SocketAddrSpace,
|
2019-03-13 14:23:32 -07:00
|
|
|
) -> Self {
|
2019-04-15 15:27:45 -07:00
|
|
|
let stakes: Vec<_> = (0..num_nodes).map(|_| lamports_per_node).collect();
|
2020-11-20 03:17:19 -08:00
|
|
|
let mut config = ClusterConfig {
|
2019-04-15 15:27:45 -07:00
|
|
|
node_stakes: stakes,
|
2019-03-19 06:36:45 -07:00
|
|
|
cluster_lamports,
|
2021-03-02 20:21:30 -08:00
|
|
|
validator_configs: make_identical_validator_configs(
|
2022-01-28 18:00:18 -08:00
|
|
|
&ValidatorConfig::default_for_test(),
|
2021-03-02 20:21:30 -08:00
|
|
|
num_nodes,
|
|
|
|
),
|
2019-04-15 15:27:45 -07:00
|
|
|
..ClusterConfig::default()
|
|
|
|
};
|
2021-07-23 08:25:03 -07:00
|
|
|
Self::new(&mut config, socket_addr_space)
|
2019-03-13 14:23:32 -07:00
|
|
|
}
|
|
|
|
|
2021-07-23 08:25:03 -07:00
|
|
|
pub fn new(config: &mut ClusterConfig, socket_addr_space: SocketAddrSpace) -> Self {
|
2019-06-19 00:13:19 -07:00
|
|
|
assert_eq!(config.validator_configs.len(), config.node_stakes.len());
|
2022-01-09 21:58:21 -08:00
|
|
|
|
2020-07-23 18:50:42 -07:00
|
|
|
let mut validator_keys = {
|
2019-12-03 16:31:59 -08:00
|
|
|
if let Some(ref keys) = config.validator_keys {
|
|
|
|
assert_eq!(config.validator_configs.len(), keys.len());
|
|
|
|
keys.clone()
|
|
|
|
} else {
|
2020-07-23 18:50:42 -07:00
|
|
|
iter::repeat_with(|| (Arc::new(Keypair::new()), false))
|
2019-12-03 16:31:59 -08:00
|
|
|
.take(config.validator_configs.len())
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-09 21:58:21 -08:00
|
|
|
let vote_keys = {
|
|
|
|
if let Some(ref node_vote_keys) = config.node_vote_keys {
|
|
|
|
assert_eq!(config.validator_configs.len(), node_vote_keys.len());
|
|
|
|
node_vote_keys.clone()
|
|
|
|
} else {
|
|
|
|
iter::repeat_with(|| Arc::new(Keypair::new()))
|
|
|
|
.take(config.validator_configs.len())
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-23 18:50:42 -07:00
|
|
|
// Bootstrap leader should always be in genesis block
|
|
|
|
validator_keys[0].1 = true;
|
|
|
|
let (keys_in_genesis, stakes_in_genesis): (Vec<ValidatorVoteKeypairs>, Vec<u64>) =
|
|
|
|
validator_keys
|
|
|
|
.iter()
|
|
|
|
.zip(&config.node_stakes)
|
2022-01-09 21:58:21 -08:00
|
|
|
.zip(&vote_keys)
|
|
|
|
.filter_map(|(((node_keypair, in_genesis), stake), vote_keypair)| {
|
2021-08-27 17:53:24 -07:00
|
|
|
info!(
|
2022-01-09 21:58:21 -08:00
|
|
|
"STARTING LOCAL CLUSTER: key {} vote_key {} has {} stake",
|
2021-08-27 17:53:24 -07:00
|
|
|
node_keypair.pubkey(),
|
2022-01-09 21:58:21 -08:00
|
|
|
vote_keypair.pubkey(),
|
2021-08-27 17:53:24 -07:00
|
|
|
stake
|
|
|
|
);
|
2020-07-23 18:50:42 -07:00
|
|
|
if *in_genesis {
|
|
|
|
Some((
|
|
|
|
ValidatorVoteKeypairs {
|
2020-08-19 22:04:38 -07:00
|
|
|
node_keypair: Keypair::from_bytes(&node_keypair.to_bytes())
|
|
|
|
.unwrap(),
|
2022-01-09 21:58:21 -08:00
|
|
|
vote_keypair: Keypair::from_bytes(&vote_keypair.to_bytes())
|
|
|
|
.unwrap(),
|
2020-08-19 22:04:38 -07:00
|
|
|
stake_keypair: Keypair::new(),
|
2020-07-23 18:50:42 -07:00
|
|
|
},
|
|
|
|
stake,
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unzip();
|
|
|
|
let leader_keypair = &keys_in_genesis[0].node_keypair;
|
|
|
|
let leader_vote_keypair = &keys_in_genesis[0].vote_keypair;
|
2019-03-01 10:36:52 -08:00
|
|
|
let leader_pubkey = leader_keypair.pubkey();
|
2019-12-03 16:31:59 -08:00
|
|
|
let leader_node = Node::new_localhost_with_pubkey(&leader_pubkey);
|
2022-01-09 21:58:21 -08:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let GenesisConfigInfo {
|
|
|
|
mut genesis_config,
|
2019-05-22 20:39:00 -07:00
|
|
|
mint_keypair,
|
2020-07-23 18:50:42 -07:00
|
|
|
..
|
2020-09-24 12:23:09 -07:00
|
|
|
} = create_genesis_config_with_vote_accounts_and_cluster_type(
|
2019-04-15 15:27:45 -07:00
|
|
|
config.cluster_lamports,
|
2020-07-23 18:50:42 -07:00
|
|
|
&keys_in_genesis,
|
|
|
|
stakes_in_genesis,
|
2020-09-24 12:23:09 -07:00
|
|
|
config.cluster_type,
|
2019-04-15 15:27:45 -07:00
|
|
|
);
|
2021-03-09 13:06:07 -08:00
|
|
|
genesis_config.accounts.extend(
|
|
|
|
config
|
|
|
|
.additional_accounts
|
|
|
|
.drain(..)
|
|
|
|
.map(|(key, account)| (key, Account::from(account))),
|
|
|
|
);
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.ticks_per_slot = config.ticks_per_slot;
|
2020-07-23 18:50:42 -07:00
|
|
|
genesis_config.epoch_schedule = EpochSchedule::custom(
|
|
|
|
config.slots_per_epoch,
|
|
|
|
config.stakers_slot_offset,
|
|
|
|
!config.skip_warmup_slots,
|
|
|
|
);
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.poh_config = config.poh_config.clone();
|
2020-04-08 14:36:18 -07:00
|
|
|
genesis_config
|
|
|
|
.native_instruction_processors
|
|
|
|
.extend_from_slice(&config.native_instruction_processors);
|
|
|
|
|
2019-10-05 18:50:27 -07:00
|
|
|
// Replace staking config
|
2019-11-26 19:23:37 -08:00
|
|
|
genesis_config.add_account(
|
2019-08-17 12:28:36 -07:00
|
|
|
stake_config::id(),
|
2021-06-15 09:04:00 -07:00
|
|
|
create_stake_config_account(
|
2019-08-17 12:28:36 -07:00
|
|
|
1,
|
|
|
|
&stake_config::Config {
|
2019-11-25 13:14:32 -08:00
|
|
|
warmup_cooldown_rate: 1_000_000_000.0f64,
|
2019-08-17 12:28:36 -07:00
|
|
|
slash_penalty: std::u8::MAX,
|
|
|
|
},
|
|
|
|
),
|
2019-11-26 19:23:37 -08:00
|
|
|
);
|
2019-08-17 12:28:36 -07:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
2019-03-08 17:23:07 -08:00
|
|
|
let leader_contact_info = leader_node.info.clone();
|
2021-03-02 20:21:30 -08:00
|
|
|
let mut leader_config = safe_clone_config(&config.validator_configs[0]);
|
2020-12-01 19:25:09 -08:00
|
|
|
leader_config.rpc_addrs = Some((leader_node.info.rpc, leader_node.info.rpc_pubsub));
|
2020-06-30 19:38:59 -07:00
|
|
|
leader_config.account_paths = vec![leader_ledger_path.join("accounts")];
|
2021-07-20 22:25:13 -07:00
|
|
|
leader_config.tower_storage = Arc::new(FileTowerStorage::new(leader_ledger_path.clone()));
|
2020-08-19 22:04:38 -07:00
|
|
|
let leader_keypair = Arc::new(Keypair::from_bytes(&leader_keypair.to_bytes()).unwrap());
|
|
|
|
let leader_vote_keypair =
|
|
|
|
Arc::new(Keypair::from_bytes(&leader_vote_keypair.to_bytes()).unwrap());
|
2021-03-04 13:01:11 -08:00
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
let leader_server = Validator::new(
|
2019-03-01 10:36:52 -08:00
|
|
|
leader_node,
|
2021-06-17 13:51:06 -07:00
|
|
|
leader_keypair.clone(),
|
2019-03-01 10:36:52 -08:00
|
|
|
&leader_ledger_path,
|
2020-07-23 18:50:42 -07:00
|
|
|
&leader_vote_keypair.pubkey(),
|
2021-04-11 20:38:30 -07:00
|
|
|
Arc::new(RwLock::new(vec![leader_vote_keypair.clone()])),
|
2020-12-18 10:54:48 -08:00
|
|
|
vec![],
|
2019-11-20 15:43:10 -08:00
|
|
|
&leader_config,
|
2021-02-03 08:26:17 -08:00
|
|
|
true, // should_check_duplicate_instance
|
2021-03-04 13:01:11 -08:00
|
|
|
Arc::new(RwLock::new(ValidatorStartProgress::default())),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2019-03-01 10:36:52 -08:00
|
|
|
);
|
2019-03-01 13:48:28 -08:00
|
|
|
|
2019-10-11 12:30:52 -07:00
|
|
|
let mut validators = HashMap::new();
|
2019-06-19 00:13:19 -07:00
|
|
|
let leader_info = ValidatorInfo {
|
2020-08-19 22:04:38 -07:00
|
|
|
keypair: leader_keypair,
|
|
|
|
voting_keypair: leader_vote_keypair,
|
2019-06-19 00:13:19 -07:00
|
|
|
ledger_path: leader_ledger_path,
|
|
|
|
contact_info: leader_contact_info.clone(),
|
|
|
|
};
|
2019-12-03 16:31:59 -08:00
|
|
|
let cluster_leader = ClusterValidatorInfo::new(
|
|
|
|
leader_info,
|
2021-03-02 20:21:30 -08:00
|
|
|
safe_clone_config(&config.validator_configs[0]),
|
2019-12-03 16:31:59 -08:00
|
|
|
leader_server,
|
|
|
|
);
|
2019-06-19 00:13:19 -07:00
|
|
|
|
2019-12-03 16:31:59 -08:00
|
|
|
validators.insert(leader_pubkey, cluster_leader);
|
2019-03-13 14:23:32 -07:00
|
|
|
|
|
|
|
let mut cluster = Self {
|
2019-03-01 10:36:52 -08:00
|
|
|
funding_keypair: mint_keypair,
|
2019-03-08 17:23:07 -08:00
|
|
|
entry_point_info: leader_contact_info,
|
2019-10-11 12:30:52 -07:00
|
|
|
validators,
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config,
|
2019-03-13 14:23:32 -07:00
|
|
|
};
|
|
|
|
|
2020-07-23 18:50:42 -07:00
|
|
|
let node_pubkey_to_vote_key: HashMap<Pubkey, Arc<Keypair>> = keys_in_genesis
|
|
|
|
.into_iter()
|
2020-08-19 22:04:38 -07:00
|
|
|
.map(|keypairs| {
|
|
|
|
(
|
|
|
|
keypairs.node_keypair.pubkey(),
|
|
|
|
Arc::new(Keypair::from_bytes(&keypairs.vote_keypair.to_bytes()).unwrap()),
|
|
|
|
)
|
|
|
|
})
|
2020-07-23 18:50:42 -07:00
|
|
|
.collect();
|
|
|
|
for (stake, validator_config, (key, _)) in izip!(
|
2019-12-03 16:31:59 -08:00
|
|
|
(&config.node_stakes[1..]).iter(),
|
|
|
|
config.validator_configs[1..].iter(),
|
|
|
|
validator_keys[1..].iter(),
|
|
|
|
) {
|
2020-07-23 18:50:42 -07:00
|
|
|
cluster.add_validator(
|
|
|
|
validator_config,
|
|
|
|
*stake,
|
|
|
|
key.clone(),
|
|
|
|
node_pubkey_to_vote_key.get(&key.pubkey()).cloned(),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2020-07-23 18:50:42 -07:00
|
|
|
);
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2021-03-02 20:21:30 -08:00
|
|
|
let mut listener_config = safe_clone_config(&config.validator_configs[0]);
|
|
|
|
listener_config.voting_disabled = true;
|
2019-12-03 16:31:59 -08:00
|
|
|
(0..config.num_listeners).for_each(|_| {
|
2021-12-06 14:14:38 -08:00
|
|
|
cluster.add_validator_listener(
|
2021-07-23 08:25:03 -07:00
|
|
|
&listener_config,
|
|
|
|
0,
|
|
|
|
Arc::new(Keypair::new()),
|
|
|
|
None,
|
|
|
|
socket_addr_space,
|
|
|
|
);
|
2019-12-03 16:31:59 -08:00
|
|
|
});
|
2019-03-27 13:10:33 -07:00
|
|
|
|
2019-05-16 07:14:58 -07:00
|
|
|
discover_cluster(
|
2019-04-15 15:27:45 -07:00
|
|
|
&cluster.entry_point_info.gossip,
|
|
|
|
config.node_stakes.len() + config.num_listeners as usize,
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2019-04-15 15:27:45 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2021-07-23 08:25:03 -07:00
|
|
|
discover_cluster(
|
|
|
|
&cluster.entry_point_info.gossip,
|
|
|
|
config.node_stakes.len(),
|
|
|
|
socket_addr_space,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2019-03-27 15:54:09 -07:00
|
|
|
|
2019-03-13 14:23:32 -07:00
|
|
|
cluster
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
|
2019-08-20 23:59:31 -07:00
|
|
|
pub fn exit(&mut self) {
|
2019-10-11 12:30:52 -07:00
|
|
|
for node in self.validators.values_mut() {
|
2019-12-03 16:31:59 -08:00
|
|
|
if let Some(ref mut v) = node.validator {
|
|
|
|
v.exit();
|
|
|
|
}
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
}
|
2019-03-07 15:49:07 -08:00
|
|
|
|
|
|
|
pub fn close_preserve_ledgers(&mut self) {
|
2019-03-01 10:36:52 -08:00
|
|
|
self.exit();
|
2019-12-03 16:31:59 -08:00
|
|
|
for (_, node) in self.validators.iter_mut() {
|
|
|
|
if let Some(v) = node.validator.take() {
|
2020-12-10 17:28:52 -08:00
|
|
|
v.join();
|
2019-12-03 16:31:59 -08:00
|
|
|
}
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:14:38 -08:00
|
|
|
/// Set up validator without voting or staking accounts
|
|
|
|
pub fn add_validator_listener(
|
|
|
|
&mut self,
|
|
|
|
validator_config: &ValidatorConfig,
|
|
|
|
stake: u64,
|
|
|
|
validator_keypair: Arc<Keypair>,
|
|
|
|
voting_keypair: Option<Arc<Keypair>>,
|
|
|
|
socket_addr_space: SocketAddrSpace,
|
|
|
|
) -> Pubkey {
|
|
|
|
self.do_add_validator(
|
|
|
|
validator_config,
|
|
|
|
true,
|
|
|
|
stake,
|
|
|
|
validator_keypair,
|
|
|
|
voting_keypair,
|
|
|
|
socket_addr_space,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set up validator with voting and staking accounts
|
2019-12-03 16:31:59 -08:00
|
|
|
pub fn add_validator(
|
|
|
|
&mut self,
|
|
|
|
validator_config: &ValidatorConfig,
|
|
|
|
stake: u64,
|
|
|
|
validator_keypair: Arc<Keypair>,
|
2021-12-06 14:14:38 -08:00
|
|
|
voting_keypair: Option<Arc<Keypair>>,
|
|
|
|
socket_addr_space: SocketAddrSpace,
|
|
|
|
) -> Pubkey {
|
|
|
|
self.do_add_validator(
|
|
|
|
validator_config,
|
|
|
|
false,
|
|
|
|
stake,
|
|
|
|
validator_keypair,
|
|
|
|
voting_keypair,
|
|
|
|
socket_addr_space,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_add_validator(
|
|
|
|
&mut self,
|
|
|
|
validator_config: &ValidatorConfig,
|
|
|
|
is_listener: bool,
|
|
|
|
stake: u64,
|
|
|
|
validator_keypair: Arc<Keypair>,
|
2020-07-23 18:50:42 -07:00
|
|
|
mut voting_keypair: Option<Arc<Keypair>>,
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space: SocketAddrSpace,
|
2019-12-03 16:31:59 -08:00
|
|
|
) -> Pubkey {
|
2022-04-06 08:03:38 -07:00
|
|
|
let (rpc, tpu) = self.entry_point_info.client_facing_addr();
|
|
|
|
let client = create_client(rpc, tpu);
|
2019-03-13 14:23:32 -07:00
|
|
|
|
|
|
|
// Must have enough tokens to fund vote account and set delegate
|
2020-07-23 18:50:42 -07:00
|
|
|
let should_create_vote_pubkey = voting_keypair.is_none();
|
|
|
|
if voting_keypair.is_none() {
|
|
|
|
voting_keypair = Some(Arc::new(Keypair::new()));
|
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
let validator_pubkey = validator_keypair.pubkey();
|
|
|
|
let validator_node = Node::new_localhost_with_pubkey(&validator_keypair.pubkey());
|
2019-06-12 16:43:05 -07:00
|
|
|
let contact_info = validator_node.info.clone();
|
2019-11-08 20:56:57 -08:00
|
|
|
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&self.genesis_config);
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2021-12-06 14:14:38 -08:00
|
|
|
// Give the validator some lamports to setup vote accounts
|
|
|
|
if is_listener {
|
2019-04-15 15:27:45 -07:00
|
|
|
// setup as a listener
|
|
|
|
info!("listener {} ", validator_pubkey,);
|
2021-12-06 14:14:38 -08:00
|
|
|
} else if should_create_vote_pubkey {
|
|
|
|
let validator_balance = Self::transfer_with_client(
|
|
|
|
&client,
|
|
|
|
&self.funding_keypair,
|
|
|
|
&validator_pubkey,
|
|
|
|
stake * 2 + 2,
|
|
|
|
);
|
|
|
|
info!(
|
|
|
|
"validator {} balance {}",
|
|
|
|
validator_pubkey, validator_balance
|
|
|
|
);
|
|
|
|
Self::setup_vote_and_stake_accounts(
|
|
|
|
&client,
|
|
|
|
voting_keypair.as_ref().unwrap(),
|
|
|
|
&validator_keypair,
|
|
|
|
stake,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2019-04-15 15:27:45 -07:00
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2021-03-02 20:21:30 -08:00
|
|
|
let mut config = safe_clone_config(validator_config);
|
2020-12-01 19:25:09 -08:00
|
|
|
config.rpc_addrs = Some((validator_node.info.rpc, validator_node.info.rpc_pubsub));
|
2020-06-30 19:38:59 -07:00
|
|
|
config.account_paths = vec![ledger_path.join("accounts")];
|
2021-07-20 22:25:13 -07:00
|
|
|
config.tower_storage = Arc::new(FileTowerStorage::new(ledger_path.clone()));
|
2020-07-23 18:50:42 -07:00
|
|
|
let voting_keypair = voting_keypair.unwrap();
|
2019-05-23 22:05:16 -07:00
|
|
|
let validator_server = Validator::new(
|
2019-03-13 14:23:32 -07:00
|
|
|
validator_node,
|
2021-06-17 13:51:06 -07:00
|
|
|
validator_keypair.clone(),
|
2019-03-13 14:23:32 -07:00
|
|
|
&ledger_path,
|
|
|
|
&voting_keypair.pubkey(),
|
2021-04-11 20:38:30 -07:00
|
|
|
Arc::new(RwLock::new(vec![voting_keypair.clone()])),
|
2020-12-18 10:54:48 -08:00
|
|
|
vec![self.entry_point_info.clone()],
|
2019-11-20 15:43:10 -08:00
|
|
|
&config,
|
2021-02-03 08:26:17 -08:00
|
|
|
true, // should_check_duplicate_instance
|
2021-03-04 13:01:11 -08:00
|
|
|
Arc::new(RwLock::new(ValidatorStartProgress::default())),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2019-03-13 14:23:32 -07:00
|
|
|
);
|
|
|
|
|
2019-06-19 00:13:19 -07:00
|
|
|
let validator_pubkey = validator_keypair.pubkey();
|
|
|
|
let validator_info = ClusterValidatorInfo::new(
|
|
|
|
ValidatorInfo {
|
|
|
|
keypair: validator_keypair,
|
|
|
|
voting_keypair,
|
|
|
|
ledger_path,
|
|
|
|
contact_info,
|
|
|
|
},
|
2021-03-02 20:21:30 -08:00
|
|
|
safe_clone_config(validator_config),
|
2019-12-03 16:31:59 -08:00
|
|
|
validator_server,
|
2019-06-19 00:13:19 -07:00
|
|
|
);
|
|
|
|
|
2019-12-03 16:31:59 -08:00
|
|
|
self.validators.insert(validator_pubkey, validator_info);
|
|
|
|
validator_pubkey
|
2019-03-13 14:23:32 -07:00
|
|
|
}
|
|
|
|
|
2020-10-19 00:37:03 -07:00
|
|
|
pub fn ledger_path(&self, validator_pubkey: &Pubkey) -> std::path::PathBuf {
|
|
|
|
self.validators
|
|
|
|
.get(validator_pubkey)
|
|
|
|
.unwrap()
|
|
|
|
.info
|
|
|
|
.ledger_path
|
|
|
|
.clone()
|
|
|
|
}
|
|
|
|
|
2019-03-07 13:03:55 -08:00
|
|
|
fn close(&mut self) {
|
2019-03-07 15:49:07 -08:00
|
|
|
self.close_preserve_ledgers();
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
|
2019-03-22 11:39:25 -07:00
|
|
|
pub fn transfer(&self, source_keypair: &Keypair, dest_pubkey: &Pubkey, lamports: u64) -> u64 {
|
2022-04-06 08:03:38 -07:00
|
|
|
let (rpc, tpu) = self.entry_point_info.client_facing_addr();
|
|
|
|
let client = create_client(rpc, tpu);
|
2019-03-22 11:39:25 -07:00
|
|
|
Self::transfer_with_client(&client, source_keypair, dest_pubkey, lamports)
|
|
|
|
}
|
|
|
|
|
2021-07-23 08:25:03 -07:00
|
|
|
pub fn check_for_new_roots(
|
|
|
|
&self,
|
|
|
|
num_new_roots: usize,
|
|
|
|
test_name: &str,
|
|
|
|
socket_addr_space: SocketAddrSpace,
|
|
|
|
) {
|
2020-06-04 23:32:53 -07:00
|
|
|
let alive_node_contact_infos: Vec<_> = self
|
|
|
|
.validators
|
|
|
|
.values()
|
|
|
|
.map(|v| v.info.contact_info.clone())
|
|
|
|
.collect();
|
|
|
|
assert!(!alive_node_contact_infos.is_empty());
|
|
|
|
info!("{} discovering nodes", test_name);
|
|
|
|
let cluster_nodes = discover_cluster(
|
|
|
|
&alive_node_contact_infos[0].gossip,
|
|
|
|
alive_node_contact_infos.len(),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2020-06-04 23:32:53 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
info!("{} discovered {} nodes", test_name, cluster_nodes.len());
|
|
|
|
info!("{} looking for new roots on all nodes", test_name);
|
|
|
|
cluster_tests::check_for_new_roots(num_new_roots, &alive_node_contact_infos, test_name);
|
|
|
|
info!("{} done waiting for roots", test_name);
|
|
|
|
}
|
|
|
|
|
2021-07-23 08:25:03 -07:00
|
|
|
pub fn check_no_new_roots(
|
|
|
|
&self,
|
|
|
|
num_slots_to_wait: usize,
|
|
|
|
test_name: &str,
|
|
|
|
socket_addr_space: SocketAddrSpace,
|
|
|
|
) {
|
2020-07-21 23:04:24 -07:00
|
|
|
let alive_node_contact_infos: Vec<_> = self
|
|
|
|
.validators
|
|
|
|
.values()
|
|
|
|
.map(|v| v.info.contact_info.clone())
|
|
|
|
.collect();
|
|
|
|
assert!(!alive_node_contact_infos.is_empty());
|
|
|
|
info!("{} discovering nodes", test_name);
|
|
|
|
let cluster_nodes = discover_cluster(
|
|
|
|
&alive_node_contact_infos[0].gossip,
|
|
|
|
alive_node_contact_infos.len(),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2020-07-21 23:04:24 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
info!("{} discovered {} nodes", test_name, cluster_nodes.len());
|
|
|
|
info!("{} making sure no new roots on any nodes", test_name);
|
|
|
|
cluster_tests::check_no_new_roots(num_slots_to_wait, &alive_node_contact_infos, test_name);
|
|
|
|
info!("{} done waiting for roots", test_name);
|
|
|
|
}
|
|
|
|
|
2019-03-22 11:39:25 -07:00
|
|
|
fn transfer_with_client(
|
2022-03-31 12:47:00 -07:00
|
|
|
client: &ThinClient,
|
2019-03-01 10:36:52 -08:00
|
|
|
source_keypair: &Keypair,
|
|
|
|
dest_pubkey: &Pubkey,
|
|
|
|
lamports: u64,
|
|
|
|
) -> u64 {
|
2019-03-02 10:25:16 -08:00
|
|
|
trace!("getting leader blockhash");
|
2021-08-13 09:08:20 -07:00
|
|
|
let (blockhash, _) = client
|
|
|
|
.get_latest_blockhash_with_commitment(CommitmentConfig::processed())
|
2019-11-06 13:15:00 -08:00
|
|
|
.unwrap();
|
2021-06-18 06:34:58 -07:00
|
|
|
let mut tx = system_transaction::transfer(source_keypair, dest_pubkey, lamports, blockhash);
|
2019-03-01 10:36:52 -08:00
|
|
|
info!(
|
|
|
|
"executing transfer of {} from {} to {}",
|
|
|
|
lamports,
|
|
|
|
source_keypair.pubkey(),
|
|
|
|
*dest_pubkey
|
|
|
|
);
|
|
|
|
client
|
2021-06-18 06:34:46 -07:00
|
|
|
.retry_transfer(source_keypair, &mut tx, 10)
|
2019-03-01 10:36:52 -08:00
|
|
|
.expect("client transfer");
|
2019-03-16 23:29:11 -07:00
|
|
|
client
|
2019-11-06 13:15:00 -08:00
|
|
|
.wait_for_balance_with_commitment(
|
|
|
|
dest_pubkey,
|
|
|
|
Some(lamports),
|
2021-01-26 11:23:07 -08:00
|
|
|
CommitmentConfig::processed(),
|
2019-11-06 13:15:00 -08:00
|
|
|
)
|
2019-03-16 23:29:11 -07:00
|
|
|
.expect("get balance")
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
2019-03-01 13:48:28 -08:00
|
|
|
|
2019-05-15 12:15:31 -07:00
|
|
|
fn setup_vote_and_stake_accounts(
|
2022-03-31 12:47:00 -07:00
|
|
|
client: &ThinClient,
|
2019-03-05 13:23:12 -08:00
|
|
|
vote_account: &Keypair,
|
2019-03-01 13:48:28 -08:00
|
|
|
from_account: &Arc<Keypair>,
|
|
|
|
amount: u64,
|
|
|
|
) -> Result<()> {
|
2019-03-05 13:23:12 -08:00
|
|
|
let vote_account_pubkey = vote_account.pubkey();
|
2019-05-23 23:20:04 -07:00
|
|
|
let node_pubkey = from_account.pubkey();
|
2020-07-23 18:50:42 -07:00
|
|
|
info!(
|
|
|
|
"setup_vote_and_stake_accounts: {}, {}",
|
|
|
|
node_pubkey, vote_account_pubkey
|
|
|
|
);
|
2019-08-16 15:46:19 -07:00
|
|
|
let stake_account_keypair = Keypair::new();
|
|
|
|
let stake_account_pubkey = stake_account_keypair.pubkey();
|
2019-05-15 12:15:31 -07:00
|
|
|
|
2019-03-01 13:48:28 -08:00
|
|
|
// Create the vote account if necessary
|
2019-11-06 13:15:00 -08:00
|
|
|
if client
|
2021-01-26 11:23:07 -08:00
|
|
|
.poll_get_balance_with_commitment(&vote_account_pubkey, CommitmentConfig::processed())
|
2019-11-06 13:15:00 -08:00
|
|
|
.unwrap_or(0)
|
|
|
|
== 0
|
|
|
|
{
|
2019-03-05 13:23:12 -08:00
|
|
|
// 1) Create vote account
|
2019-05-15 12:15:31 -07:00
|
|
|
|
2020-06-24 13:52:38 -07:00
|
|
|
let instructions = vote_instruction::create_account(
|
|
|
|
&from_account.pubkey(),
|
|
|
|
&vote_account_pubkey,
|
|
|
|
&VoteInit {
|
|
|
|
node_pubkey,
|
|
|
|
authorized_voter: vote_account_pubkey,
|
|
|
|
authorized_withdrawer: vote_account_pubkey,
|
|
|
|
commission: 0,
|
|
|
|
},
|
|
|
|
amount,
|
|
|
|
);
|
|
|
|
let message = Message::new(&instructions, Some(&from_account.pubkey()));
|
|
|
|
let mut transaction = Transaction::new(
|
2019-11-08 02:27:35 -08:00
|
|
|
&[from_account.as_ref(), vote_account],
|
2020-06-24 13:52:38 -07:00
|
|
|
message,
|
2019-11-06 13:15:00 -08:00
|
|
|
client
|
2021-08-13 09:08:20 -07:00
|
|
|
.get_latest_blockhash_with_commitment(CommitmentConfig::processed())
|
2019-11-06 13:15:00 -08:00
|
|
|
.unwrap()
|
|
|
|
.0,
|
2019-04-03 08:45:57 -07:00
|
|
|
);
|
2019-05-15 12:15:31 -07:00
|
|
|
client
|
2021-06-18 06:34:46 -07:00
|
|
|
.retry_transfer(from_account, &mut transaction, 10)
|
2019-05-15 12:15:31 -07:00
|
|
|
.expect("fund vote");
|
|
|
|
client
|
2019-11-06 13:15:00 -08:00
|
|
|
.wait_for_balance_with_commitment(
|
|
|
|
&vote_account_pubkey,
|
|
|
|
Some(amount),
|
2021-01-26 11:23:07 -08:00
|
|
|
CommitmentConfig::processed(),
|
2019-11-06 13:15:00 -08:00
|
|
|
)
|
2019-05-15 12:15:31 -07:00
|
|
|
.expect("get balance");
|
|
|
|
|
2020-06-24 13:52:38 -07:00
|
|
|
let instructions = stake_instruction::create_account_and_delegate_stake(
|
|
|
|
&from_account.pubkey(),
|
|
|
|
&stake_account_pubkey,
|
|
|
|
&vote_account_pubkey,
|
|
|
|
&Authorized::auto(&stake_account_pubkey),
|
|
|
|
&Lockup::default(),
|
|
|
|
amount,
|
|
|
|
);
|
|
|
|
let message = Message::new(&instructions, Some(&from_account.pubkey()));
|
|
|
|
let mut transaction = Transaction::new(
|
2019-06-10 12:17:29 -07:00
|
|
|
&[from_account.as_ref(), &stake_account_keypair],
|
2020-06-24 13:52:38 -07:00
|
|
|
message,
|
2019-11-06 13:15:00 -08:00
|
|
|
client
|
2021-08-13 09:08:20 -07:00
|
|
|
.get_latest_blockhash_with_commitment(CommitmentConfig::processed())
|
2019-11-06 13:15:00 -08:00
|
|
|
.unwrap()
|
|
|
|
.0,
|
2019-03-01 17:16:49 -08:00
|
|
|
);
|
2019-03-01 13:48:28 -08:00
|
|
|
|
2019-05-15 12:15:31 -07:00
|
|
|
client
|
|
|
|
.send_and_confirm_transaction(
|
|
|
|
&[from_account.as_ref(), &stake_account_keypair],
|
|
|
|
&mut transaction,
|
|
|
|
5,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
.expect("delegate stake");
|
2019-06-10 12:17:29 -07:00
|
|
|
client
|
2019-11-06 13:15:00 -08:00
|
|
|
.wait_for_balance_with_commitment(
|
|
|
|
&stake_account_pubkey,
|
|
|
|
Some(amount),
|
2021-01-26 11:23:07 -08:00
|
|
|
CommitmentConfig::processed(),
|
2019-11-06 13:15:00 -08:00
|
|
|
)
|
2019-06-10 12:17:29 -07:00
|
|
|
.expect("get balance");
|
2019-08-16 15:46:19 -07:00
|
|
|
} else {
|
|
|
|
warn!(
|
|
|
|
"{} vote_account already has a balance?!?",
|
|
|
|
vote_account_pubkey
|
|
|
|
);
|
2019-03-01 13:48:28 -08:00
|
|
|
}
|
2019-08-16 15:46:19 -07:00
|
|
|
info!("Checking for vote account registration of {}", node_pubkey);
|
|
|
|
match (
|
2021-01-26 11:23:07 -08:00
|
|
|
client
|
|
|
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::processed()),
|
|
|
|
client.get_account_with_commitment(&vote_account_pubkey, CommitmentConfig::processed()),
|
2019-08-16 15:46:19 -07:00
|
|
|
) {
|
|
|
|
(Ok(Some(stake_account)), Ok(Some(vote_account))) => {
|
|
|
|
match (
|
2021-06-15 09:04:00 -07:00
|
|
|
stake_state::stake_from(&stake_account),
|
2019-08-16 15:46:19 -07:00
|
|
|
VoteState::from(&vote_account),
|
|
|
|
) {
|
|
|
|
(Some(stake_state), Some(vote_state)) => {
|
2019-11-25 13:14:32 -08:00
|
|
|
if stake_state.delegation.voter_pubkey != vote_account_pubkey
|
|
|
|
|| stake_state.delegation.stake != amount
|
2019-08-16 15:46:19 -07:00
|
|
|
{
|
|
|
|
Err(Error::new(ErrorKind::Other, "invalid stake account state"))
|
|
|
|
} else if vote_state.node_pubkey != node_pubkey {
|
|
|
|
Err(Error::new(ErrorKind::Other, "invalid vote account state"))
|
|
|
|
} else {
|
|
|
|
info!("node {} {:?} {:?}", node_pubkey, stake_state, vote_state);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(None, _) => Err(Error::new(ErrorKind::Other, "invalid stake account data")),
|
|
|
|
(_, None) => Err(Error::new(ErrorKind::Other, "invalid vote account data")),
|
2019-03-01 13:48:28 -08:00
|
|
|
}
|
|
|
|
}
|
2019-08-17 12:28:20 -07:00
|
|
|
(Ok(None), _) | (Err(_), _) => Err(Error::new(
|
2019-08-16 15:46:19 -07:00
|
|
|
ErrorKind::Other,
|
|
|
|
"unable to retrieve stake account data",
|
|
|
|
)),
|
2019-08-17 12:28:20 -07:00
|
|
|
(_, Ok(None)) | (_, Err(_)) => Err(Error::new(
|
2019-08-16 15:46:19 -07:00
|
|
|
ErrorKind::Other,
|
|
|
|
"unable to retrieve vote account data",
|
|
|
|
)),
|
2019-03-01 13:48:28 -08:00
|
|
|
}
|
|
|
|
}
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
|
2019-03-23 19:19:55 -07:00
|
|
|
impl Cluster for LocalCluster {
|
2019-05-23 23:20:04 -07:00
|
|
|
fn get_node_pubkeys(&self) -> Vec<Pubkey> {
|
2019-10-11 12:30:52 -07:00
|
|
|
self.validators.keys().cloned().collect()
|
2019-04-15 15:27:45 -07:00
|
|
|
}
|
|
|
|
|
2022-03-31 12:47:00 -07:00
|
|
|
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient> {
|
2022-04-06 08:03:38 -07:00
|
|
|
self.validators.get(pubkey).map(|f| {
|
|
|
|
let (rpc, tpu) = f.info.contact_info.client_facing_addr();
|
|
|
|
create_client(rpc, tpu)
|
|
|
|
})
|
2019-06-12 16:43:05 -07:00
|
|
|
}
|
|
|
|
|
2019-09-08 17:53:34 -07:00
|
|
|
fn exit_node(&mut self, pubkey: &Pubkey) -> ClusterValidatorInfo {
|
2021-06-18 06:34:46 -07:00
|
|
|
let mut node = self.validators.remove(pubkey).unwrap();
|
2019-09-08 17:53:34 -07:00
|
|
|
|
2019-10-11 12:30:52 -07:00
|
|
|
// Shut down the validator
|
2019-12-03 16:31:59 -08:00
|
|
|
let mut validator = node.validator.take().expect("Validator must be running");
|
|
|
|
validator.exit();
|
2020-12-10 17:28:52 -08:00
|
|
|
validator.join();
|
2019-12-03 16:31:59 -08:00
|
|
|
node
|
2019-09-08 17:53:34 -07:00
|
|
|
}
|
|
|
|
|
2020-11-12 06:29:04 -08:00
|
|
|
fn create_restart_context(
|
|
|
|
&mut self,
|
|
|
|
pubkey: &Pubkey,
|
|
|
|
cluster_validator_info: &mut ClusterValidatorInfo,
|
2021-05-26 08:15:46 -07:00
|
|
|
) -> (Node, Option<ContactInfo>) {
|
2019-08-21 23:59:11 -07:00
|
|
|
// Update the stored ContactInfo for this node
|
2021-06-18 06:34:46 -07:00
|
|
|
let node = Node::new_localhost_with_pubkey(pubkey);
|
2019-09-08 17:53:34 -07:00
|
|
|
cluster_validator_info.info.contact_info = node.info.clone();
|
2020-12-01 19:25:09 -08:00
|
|
|
cluster_validator_info.config.rpc_addrs = Some((node.info.rpc, node.info.rpc_pubsub));
|
2019-09-08 17:53:34 -07:00
|
|
|
|
|
|
|
let entry_point_info = {
|
|
|
|
if *pubkey == self.entry_point_info.id {
|
|
|
|
self.entry_point_info = node.info.clone();
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-12 06:29:04 -08:00
|
|
|
Some(self.entry_point_info.clone())
|
2019-09-08 17:53:34 -07:00
|
|
|
}
|
|
|
|
};
|
2019-08-21 23:59:11 -07:00
|
|
|
|
2020-11-12 06:29:04 -08:00
|
|
|
(node, entry_point_info)
|
|
|
|
}
|
|
|
|
|
2021-07-23 08:25:03 -07:00
|
|
|
fn restart_node(
|
|
|
|
&mut self,
|
|
|
|
pubkey: &Pubkey,
|
|
|
|
mut cluster_validator_info: ClusterValidatorInfo,
|
|
|
|
socket_addr_space: SocketAddrSpace,
|
|
|
|
) {
|
2020-11-12 06:29:04 -08:00
|
|
|
let restart_context = self.create_restart_context(pubkey, &mut cluster_validator_info);
|
2021-07-23 08:25:03 -07:00
|
|
|
let cluster_validator_info = Self::restart_node_with_context(
|
|
|
|
cluster_validator_info,
|
|
|
|
restart_context,
|
|
|
|
socket_addr_space,
|
|
|
|
);
|
2020-11-12 06:29:04 -08:00
|
|
|
self.add_node(pubkey, cluster_validator_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn add_node(&mut self, pubkey: &Pubkey, cluster_validator_info: ClusterValidatorInfo) {
|
|
|
|
self.validators.insert(*pubkey, cluster_validator_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn restart_node_with_context(
|
|
|
|
mut cluster_validator_info: ClusterValidatorInfo,
|
|
|
|
(node, entry_point_info): (Node, Option<ContactInfo>),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space: SocketAddrSpace,
|
2020-11-12 06:29:04 -08:00
|
|
|
) -> ClusterValidatorInfo {
|
2019-08-21 23:59:11 -07:00
|
|
|
// Restart the node
|
2019-10-11 12:30:52 -07:00
|
|
|
let validator_info = &cluster_validator_info.info;
|
2020-06-30 19:38:59 -07:00
|
|
|
cluster_validator_info.config.account_paths =
|
|
|
|
vec![validator_info.ledger_path.join("accounts")];
|
2021-07-20 22:25:13 -07:00
|
|
|
cluster_validator_info.config.tower_storage =
|
|
|
|
Arc::new(FileTowerStorage::new(validator_info.ledger_path.clone()));
|
2019-05-23 22:05:16 -07:00
|
|
|
let restarted_node = Validator::new(
|
2019-03-23 19:19:55 -07:00
|
|
|
node,
|
2021-06-17 13:51:06 -07:00
|
|
|
validator_info.keypair.clone(),
|
2019-10-11 12:30:52 -07:00
|
|
|
&validator_info.ledger_path,
|
|
|
|
&validator_info.voting_keypair.pubkey(),
|
2021-04-11 20:38:30 -07:00
|
|
|
Arc::new(RwLock::new(vec![validator_info.voting_keypair.clone()])),
|
2020-12-18 10:54:48 -08:00
|
|
|
entry_point_info
|
|
|
|
.map(|entry_point_info| vec![entry_point_info])
|
|
|
|
.unwrap_or_default(),
|
2021-02-26 21:42:09 -08:00
|
|
|
&safe_clone_config(&cluster_validator_info.config),
|
2021-02-03 08:26:17 -08:00
|
|
|
true, // should_check_duplicate_instance
|
2021-03-04 13:01:11 -08:00
|
|
|
Arc::new(RwLock::new(ValidatorStartProgress::default())),
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space,
|
2019-03-23 19:19:55 -07:00
|
|
|
);
|
2019-12-03 16:31:59 -08:00
|
|
|
cluster_validator_info.validator = Some(restarted_node);
|
2020-11-12 06:29:04 -08:00
|
|
|
cluster_validator_info
|
2019-09-08 17:53:34 -07:00
|
|
|
}
|
|
|
|
|
2021-07-23 08:25:03 -07:00
|
|
|
fn exit_restart_node(
|
|
|
|
&mut self,
|
|
|
|
pubkey: &Pubkey,
|
|
|
|
validator_config: ValidatorConfig,
|
|
|
|
socket_addr_space: SocketAddrSpace,
|
|
|
|
) {
|
2019-09-08 17:53:34 -07:00
|
|
|
let mut cluster_validator_info = self.exit_node(pubkey);
|
|
|
|
cluster_validator_info.config = validator_config;
|
2021-07-23 08:25:03 -07:00
|
|
|
self.restart_node(pubkey, cluster_validator_info, socket_addr_space);
|
2019-03-23 19:19:55 -07:00
|
|
|
}
|
2020-01-30 21:51:11 -08:00
|
|
|
|
|
|
|
fn get_contact_info(&self, pubkey: &Pubkey) -> Option<&ContactInfo> {
|
|
|
|
self.validators.get(pubkey).map(|v| &v.info.contact_info)
|
|
|
|
}
|
2019-03-23 19:19:55 -07:00
|
|
|
}
|
|
|
|
|
2019-03-01 10:36:52 -08:00
|
|
|
impl Drop for LocalCluster {
|
|
|
|
fn drop(&mut self) {
|
2019-03-07 15:49:07 -08:00
|
|
|
self.close();
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
}
|