2019-09-08 17:53:34 -07:00
|
|
|
use crate::cluster::{Cluster, ClusterValidatorInfo, ValidatorInfo};
|
2019-12-03 16:31:59 -08:00
|
|
|
use itertools::izip;
|
2019-11-12 19:30:35 -08:00
|
|
|
use log::*;
|
2020-01-16 08:29:36 -08:00
|
|
|
use solana_archiver_lib::archiver::Archiver;
|
2019-08-21 10:23:33 -07:00
|
|
|
use solana_client::thin_client::{create_client, ThinClient};
|
|
|
|
use solana_core::{
|
2019-10-10 16:33:00 -07:00
|
|
|
cluster_info::{Node, VALIDATOR_PORT_RANGE},
|
2019-08-17 12:28:36 -07:00
|
|
|
contact_info::ContactInfo,
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
|
2019-08-17 12:28:36 -07:00
|
|
|
gossip_service::discover_cluster,
|
|
|
|
validator::{Validator, ValidatorConfig},
|
|
|
|
};
|
2019-11-13 07:14:09 -08:00
|
|
|
use solana_ledger::create_new_tmp_ledger;
|
2019-08-17 12:28:36 -07:00
|
|
|
use solana_sdk::{
|
|
|
|
client::SyncClient,
|
2019-11-16 20:53:54 -08:00
|
|
|
clock::{DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT},
|
2019-11-06 13:15:00 -08:00
|
|
|
commitment_config::CommitmentConfig,
|
2019-10-08 22:34:26 -07:00
|
|
|
epoch_schedule::EpochSchedule,
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config::{GenesisConfig, OperatingMode},
|
2019-08-17 12:28:36 -07:00
|
|
|
message::Message,
|
|
|
|
poh_config::PohConfig,
|
|
|
|
pubkey::Pubkey,
|
2020-02-20 13:28:55 -08:00
|
|
|
signature::{Keypair, Signer},
|
2019-08-17 12:28:36 -07:00
|
|
|
system_transaction,
|
|
|
|
transaction::Transaction,
|
|
|
|
};
|
2019-11-20 10:12:43 -08:00
|
|
|
use solana_stake_program::{
|
2019-09-26 13:29:29 -07:00
|
|
|
config as stake_config, stake_instruction,
|
2019-12-14 04:38:24 -08:00
|
|
|
stake_state::{Authorized, Lockup, StakeState},
|
2019-09-26 13:29:29 -07:00
|
|
|
};
|
2019-11-20 16:32:19 -08:00
|
|
|
use solana_storage_program::{
|
2019-10-04 14:18:19 -07:00
|
|
|
storage_contract,
|
|
|
|
storage_instruction::{self, StorageAccountType},
|
|
|
|
};
|
2019-11-20 10:12:43 -08:00
|
|
|
use solana_vote_program::{
|
2019-09-25 13:53:49 -07:00
|
|
|
vote_instruction,
|
|
|
|
vote_state::{VoteInit, VoteState},
|
|
|
|
};
|
2019-08-17 12:28:36 -07:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
fs::remove_dir_all,
|
|
|
|
io::{Error, ErrorKind, Result},
|
2019-12-03 16:31:59 -08:00
|
|
|
iter,
|
2019-08-17 12:28:36 -07:00
|
|
|
path::PathBuf,
|
|
|
|
sync::Arc,
|
|
|
|
};
|
2019-03-01 10:36:52 -08:00
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
pub struct ArchiverInfo {
|
|
|
|
pub archiver_storage_pubkey: Pubkey,
|
2019-07-30 15:53:41 -07:00
|
|
|
pub ledger_path: PathBuf,
|
2019-03-27 15:54:09 -07:00
|
|
|
}
|
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
impl ArchiverInfo {
|
2019-07-30 15:53:41 -07:00
|
|
|
fn new(storage_pubkey: Pubkey, ledger_path: PathBuf) -> Self {
|
2019-03-27 15:54:09 -07:00
|
|
|
Self {
|
2019-10-21 10:29:37 -07:00
|
|
|
archiver_storage_pubkey: storage_pubkey,
|
2019-03-27 15:54:09 -07:00
|
|
|
ledger_path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:27:45 -07:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
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-10-21 10:29:37 -07:00
|
|
|
/// Number of archivers in the cluster
|
|
|
|
/// Note- archivers will timeout if ticks_per_slot is much larger than the default 8
|
|
|
|
pub num_archivers: usize,
|
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,
|
2019-12-03 16:31:59 -08:00
|
|
|
/// The specific pubkeys of each node if specified
|
|
|
|
pub validator_keys: Option<Vec<Arc<Keypair>>>,
|
2019-04-15 15:27:45 -07:00
|
|
|
/// The stakes of each node
|
|
|
|
pub node_stakes: Vec<u64>,
|
|
|
|
/// The total lamports available to the cluster
|
|
|
|
pub cluster_lamports: u64,
|
|
|
|
pub ticks_per_slot: u64,
|
|
|
|
pub slots_per_epoch: u64,
|
2019-07-10 13:33:29 -07:00
|
|
|
pub slots_per_segment: u64,
|
2019-05-24 19:20:09 -07:00
|
|
|
pub stakers_slot_offset: u64,
|
2019-04-15 15:27:45 -07:00
|
|
|
pub native_instruction_processors: Vec<(String, Pubkey)>,
|
2019-10-23 11:50:10 -07:00
|
|
|
pub operating_mode: OperatingMode,
|
2019-05-18 14:01:36 -07:00
|
|
|
pub poh_config: PohConfig,
|
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-10-21 10:29:37 -07:00
|
|
|
num_archivers: 0,
|
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![],
|
|
|
|
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,
|
2019-07-10 13:33:29 -07:00
|
|
|
slots_per_segment: DEFAULT_SLOTS_PER_SEGMENT,
|
2019-11-16 20:53:54 -08:00
|
|
|
stakers_slot_offset: DEFAULT_DEV_SLOTS_PER_EPOCH,
|
2019-04-15 15:27:45 -07:00
|
|
|
native_instruction_processors: vec![],
|
2019-10-23 11:50:10 -07:00
|
|
|
operating_mode: OperatingMode::Development,
|
2019-05-18 14:01:36 -07:00
|
|
|
poh_config: PohConfig::default(),
|
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-10-21 10:29:37 -07:00
|
|
|
archivers: Vec<Archiver>,
|
|
|
|
pub archiver_infos: HashMap<Pubkey, ArchiverInfo>,
|
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,
|
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();
|
|
|
|
let config = ClusterConfig {
|
|
|
|
node_stakes: stakes,
|
2019-03-19 06:36:45 -07:00
|
|
|
cluster_lamports,
|
2019-06-19 00:13:19 -07:00
|
|
|
validator_configs: vec![ValidatorConfig::default(); num_nodes],
|
2019-04-15 15:27:45 -07:00
|
|
|
..ClusterConfig::default()
|
|
|
|
};
|
|
|
|
Self::new(&config)
|
2019-03-13 14:23:32 -07:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:27:45 -07:00
|
|
|
pub fn new(config: &ClusterConfig) -> Self {
|
2019-06-19 00:13:19 -07:00
|
|
|
assert_eq!(config.validator_configs.len(), config.node_stakes.len());
|
2019-12-03 16:31:59 -08:00
|
|
|
let validator_keys = {
|
|
|
|
if let Some(ref keys) = config.validator_keys {
|
|
|
|
assert_eq!(config.validator_configs.len(), keys.len());
|
|
|
|
keys.clone()
|
|
|
|
} else {
|
|
|
|
iter::repeat_with(|| Arc::new(Keypair::new()))
|
|
|
|
.take(config.validator_configs.len())
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let leader_keypair = &validator_keys[0];
|
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);
|
2019-11-08 20:56:57 -08:00
|
|
|
let GenesisConfigInfo {
|
|
|
|
mut genesis_config,
|
2019-05-22 20:39:00 -07:00
|
|
|
mint_keypair,
|
|
|
|
voting_keypair,
|
2019-11-08 20:56:57 -08:00
|
|
|
} = create_genesis_config_with_leader(
|
2019-04-15 15:27:45 -07:00
|
|
|
config.cluster_lamports,
|
|
|
|
&leader_pubkey,
|
|
|
|
config.node_stakes[0],
|
|
|
|
);
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.ticks_per_slot = config.ticks_per_slot;
|
|
|
|
genesis_config.slots_per_segment = config.slots_per_segment;
|
|
|
|
genesis_config.epoch_schedule =
|
2019-10-08 22:34:26 -07:00
|
|
|
EpochSchedule::custom(config.slots_per_epoch, config.stakers_slot_offset, true);
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.operating_mode = config.operating_mode;
|
|
|
|
genesis_config.poh_config = config.poh_config.clone();
|
2019-10-23 11:50:10 -07:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
match genesis_config.operating_mode {
|
2020-02-19 16:48:58 -08:00
|
|
|
OperatingMode::Stable | OperatingMode::Preview => {
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.native_instruction_processors =
|
2019-11-26 19:23:37 -08:00
|
|
|
solana_genesis_programs::get_programs(genesis_config.operating_mode, 0)
|
|
|
|
.unwrap()
|
|
|
|
.into_iter()
|
|
|
|
.collect()
|
2019-10-23 11:50:10 -07:00
|
|
|
}
|
2019-12-06 22:16:28 -08:00
|
|
|
OperatingMode::Development => {
|
|
|
|
genesis_config
|
|
|
|
.native_instruction_processors
|
|
|
|
.push(solana_storage_program!());
|
|
|
|
}
|
2019-10-23 11:50:10 -07:00
|
|
|
}
|
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config.inflation =
|
|
|
|
solana_genesis_programs::get_inflation(genesis_config.operating_mode, 0).unwrap();
|
2019-11-07 18:33:14 -08:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config
|
2019-04-08 11:15:58 -07:00
|
|
|
.native_instruction_processors
|
2019-04-15 15:27:45 -07:00
|
|
|
.extend_from_slice(&config.native_instruction_processors);
|
2019-07-31 14:28:14 -07:00
|
|
|
|
2019-06-11 10:27:22 -07:00
|
|
|
let storage_keypair = Keypair::new();
|
2019-11-26 19:23:37 -08:00
|
|
|
genesis_config.add_account(
|
2019-06-11 10:27:22 -07:00
|
|
|
storage_keypair.pubkey(),
|
|
|
|
storage_contract::create_validator_storage_account(leader_pubkey, 1),
|
2019-11-26 19:23:37 -08:00
|
|
|
);
|
2019-06-11 10:27:22 -07:00
|
|
|
|
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(),
|
|
|
|
stake_config::create_account(
|
|
|
|
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();
|
2019-05-23 14:50:23 -07:00
|
|
|
let leader_storage_keypair = Arc::new(storage_keypair);
|
2019-05-15 15:19:29 -07:00
|
|
|
let leader_voting_keypair = Arc::new(voting_keypair);
|
2019-11-20 15:43:10 -08:00
|
|
|
let mut leader_config = config.validator_configs[0].clone();
|
2020-01-30 10:58:39 -08:00
|
|
|
leader_config.rpc_ports = Some((
|
|
|
|
leader_node.info.rpc.port(),
|
|
|
|
leader_node.info.rpc_pubsub.port(),
|
|
|
|
));
|
2019-05-23 22:05:16 -07:00
|
|
|
let leader_server = Validator::new(
|
2019-03-01 10:36:52 -08:00
|
|
|
leader_node,
|
|
|
|
&leader_keypair,
|
|
|
|
&leader_ledger_path,
|
2019-05-15 15:19:29 -07:00
|
|
|
&leader_voting_keypair.pubkey(),
|
|
|
|
&leader_voting_keypair,
|
|
|
|
&leader_storage_keypair,
|
2019-03-01 10:36:52 -08:00
|
|
|
None,
|
2019-07-12 16:58:13 -07:00
|
|
|
true,
|
2019-11-20 15:43:10 -08:00
|
|
|
&leader_config,
|
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-12-03 16:31:59 -08:00
|
|
|
error!("leader_pubkey: {}", leader_pubkey);
|
2019-06-19 00:13:19 -07:00
|
|
|
let leader_info = ValidatorInfo {
|
2019-12-03 16:31:59 -08:00
|
|
|
keypair: leader_keypair.clone(),
|
2019-06-19 00:13:19 -07:00
|
|
|
voting_keypair: leader_voting_keypair,
|
|
|
|
storage_keypair: leader_storage_keypair,
|
|
|
|
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,
|
|
|
|
config.validator_configs[0].clone(),
|
|
|
|
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-10-21 10:29:37 -07:00
|
|
|
archivers: vec![],
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config,
|
2019-10-21 10:29:37 -07:00
|
|
|
archiver_infos: HashMap::new(),
|
2019-03-13 14:23:32 -07:00
|
|
|
};
|
|
|
|
|
2019-12-03 16:31:59 -08:00
|
|
|
for (stake, validator_config, key) in izip!(
|
|
|
|
(&config.node_stakes[1..]).iter(),
|
|
|
|
config.validator_configs[1..].iter(),
|
|
|
|
validator_keys[1..].iter(),
|
|
|
|
) {
|
|
|
|
cluster.add_validator(validator_config, *stake, key.clone());
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
let listener_config = ValidatorConfig {
|
2019-04-15 15:27:45 -07:00
|
|
|
voting_disabled: true,
|
2019-06-19 00:13:19 -07:00
|
|
|
..config.validator_configs[0].clone()
|
2019-04-15 15:27:45 -07:00
|
|
|
};
|
2019-12-03 16:31:59 -08:00
|
|
|
(0..config.num_listeners).for_each(|_| {
|
|
|
|
cluster.add_validator(&listener_config, 0, Arc::new(Keypair::new()));
|
|
|
|
});
|
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,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
for _ in 0..config.num_archivers {
|
|
|
|
cluster.add_archiver();
|
2019-03-13 14:23:32 -07:00
|
|
|
}
|
|
|
|
|
2019-05-16 07:14:58 -07:00
|
|
|
discover_cluster(
|
2019-03-27 15:54:09 -07:00
|
|
|
&cluster.entry_point_info.gossip,
|
2019-10-21 10:29:37 -07:00
|
|
|
config.node_stakes.len() + config.num_archivers as usize,
|
2019-03-27 15:54:09 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
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() {
|
|
|
|
v.join().unwrap();
|
|
|
|
}
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
while let Some(archiver) = self.archivers.pop() {
|
|
|
|
archiver.close();
|
2019-03-13 14:23:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 16:31:59 -08:00
|
|
|
pub fn add_validator(
|
|
|
|
&mut self,
|
|
|
|
validator_config: &ValidatorConfig,
|
|
|
|
stake: u64,
|
|
|
|
validator_keypair: Arc<Keypair>,
|
|
|
|
) -> Pubkey {
|
2019-03-16 08:31:19 -07:00
|
|
|
let client = create_client(
|
2019-03-13 14:23:32 -07:00
|
|
|
self.entry_point_info.client_facing_addr(),
|
2019-10-10 16:33:00 -07:00
|
|
|
VALIDATOR_PORT_RANGE,
|
2019-03-13 14:23:32 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
// Must have enough tokens to fund vote account and set delegate
|
|
|
|
let voting_keypair = Keypair::new();
|
2019-05-15 15:19:29 -07:00
|
|
|
let storage_keypair = 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
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
if validator_config.voting_disabled {
|
2019-04-15 15:27:45 -07:00
|
|
|
// setup as a listener
|
|
|
|
info!("listener {} ", validator_pubkey,);
|
|
|
|
} else {
|
2019-05-23 14:50:23 -07:00
|
|
|
// Give the validator some lamports to setup vote and storage accounts
|
2019-04-15 15:27:45 -07:00
|
|
|
let validator_balance = Self::transfer_with_client(
|
|
|
|
&client,
|
|
|
|
&self.funding_keypair,
|
|
|
|
&validator_pubkey,
|
2019-05-23 14:50:23 -07:00
|
|
|
stake * 2 + 2,
|
2019-04-15 15:27:45 -07:00
|
|
|
);
|
|
|
|
info!(
|
|
|
|
"validator {} balance {}",
|
|
|
|
validator_pubkey, validator_balance
|
|
|
|
);
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2019-05-15 12:15:31 -07:00
|
|
|
Self::setup_vote_and_stake_accounts(
|
2019-04-15 15:27:45 -07:00
|
|
|
&client,
|
|
|
|
&voting_keypair,
|
|
|
|
&validator_keypair,
|
2019-05-15 12:15:31 -07:00
|
|
|
stake,
|
2019-04-15 15:27:45 -07:00
|
|
|
)
|
2019-03-16 08:31:19 -07:00
|
|
|
.unwrap();
|
2019-05-23 14:50:23 -07:00
|
|
|
|
|
|
|
Self::setup_storage_account(&client, &storage_keypair, &validator_keypair, false)
|
|
|
|
.unwrap();
|
2019-04-15 15:27:45 -07:00
|
|
|
}
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2019-11-20 15:43:10 -08:00
|
|
|
let mut config = validator_config.clone();
|
2020-01-30 10:58:39 -08:00
|
|
|
config.rpc_ports = Some((
|
|
|
|
validator_node.info.rpc.port(),
|
|
|
|
validator_node.info.rpc_pubsub.port(),
|
|
|
|
));
|
2019-05-15 15:19:29 -07:00
|
|
|
let voting_keypair = Arc::new(voting_keypair);
|
2019-05-23 22:05:16 -07:00
|
|
|
let validator_server = Validator::new(
|
2019-03-13 14:23:32 -07:00
|
|
|
validator_node,
|
|
|
|
&validator_keypair,
|
|
|
|
&ledger_path,
|
|
|
|
&voting_keypair.pubkey(),
|
2019-05-15 15:19:29 -07:00
|
|
|
&voting_keypair,
|
|
|
|
&storage_keypair,
|
2019-03-13 14:23:32 -07:00
|
|
|
Some(&self.entry_point_info),
|
2019-07-12 16:58:13 -07:00
|
|
|
true,
|
2019-11-20 15:43:10 -08:00
|
|
|
&config,
|
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,
|
|
|
|
storage_keypair,
|
|
|
|
ledger_path,
|
|
|
|
contact_info,
|
|
|
|
},
|
|
|
|
validator_config.clone(),
|
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
|
|
|
}
|
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
fn add_archiver(&mut self) {
|
|
|
|
let archiver_keypair = Arc::new(Keypair::new());
|
|
|
|
let archiver_pubkey = archiver_keypair.pubkey();
|
2019-03-27 15:54:09 -07:00
|
|
|
let storage_keypair = Arc::new(Keypair::new());
|
2019-05-23 14:50:23 -07:00
|
|
|
let storage_pubkey = storage_keypair.pubkey();
|
2019-03-16 08:31:19 -07:00
|
|
|
let client = create_client(
|
2019-03-13 14:23:32 -07:00
|
|
|
self.entry_point_info.client_facing_addr(),
|
2019-10-10 16:33:00 -07:00
|
|
|
VALIDATOR_PORT_RANGE,
|
2019-03-13 14:23:32 -07:00
|
|
|
);
|
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
// Give the archiver some lamports to setup its storage accounts
|
2019-03-22 11:39:25 -07:00
|
|
|
Self::transfer_with_client(
|
2019-03-16 08:31:19 -07:00
|
|
|
&client,
|
2019-03-13 14:23:32 -07:00
|
|
|
&self.funding_keypair,
|
2019-10-21 10:29:37 -07:00
|
|
|
&archiver_keypair.pubkey(),
|
2019-05-23 14:50:23 -07:00
|
|
|
42,
|
2019-03-13 14:23:32 -07:00
|
|
|
);
|
2019-10-21 10:29:37 -07:00
|
|
|
let archiver_node = Node::new_localhost_archiver(&archiver_pubkey);
|
2019-05-23 14:50:23 -07:00
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
Self::setup_storage_account(&client, &storage_keypair, &archiver_keypair, true).unwrap();
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let (archiver_ledger_path, _blockhash) = create_new_tmp_ledger!(&self.genesis_config);
|
2019-10-21 10:29:37 -07:00
|
|
|
let archiver = Archiver::new(
|
|
|
|
&archiver_ledger_path,
|
|
|
|
archiver_node,
|
2019-03-13 14:23:32 -07:00
|
|
|
self.entry_point_info.clone(),
|
2019-10-21 10:29:37 -07:00
|
|
|
archiver_keypair,
|
2019-03-27 15:54:09 -07:00
|
|
|
storage_keypair,
|
2019-11-06 13:15:00 -08:00
|
|
|
CommitmentConfig::recent(),
|
2019-03-13 14:23:32 -07:00
|
|
|
)
|
2019-10-21 10:29:37 -07:00
|
|
|
.unwrap_or_else(|err| panic!("Archiver::new() failed: {:?}", err));
|
2019-03-13 14:23:32 -07:00
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
self.archivers.push(archiver);
|
|
|
|
self.archiver_infos.insert(
|
|
|
|
archiver_pubkey,
|
|
|
|
ArchiverInfo::new(storage_pubkey, archiver_ledger_path),
|
2019-03-27 15:54:09 -07:00
|
|
|
);
|
2019-03-07 15:49:07 -08:00
|
|
|
}
|
|
|
|
|
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-23 19:19:55 -07:00
|
|
|
for ledger_path in self
|
2019-12-03 16:31:59 -08:00
|
|
|
.validators
|
2019-03-23 19:19:55 -07:00
|
|
|
.values()
|
2019-06-19 00:13:19 -07:00
|
|
|
.map(|f| &f.info.ledger_path)
|
2019-10-21 10:29:37 -07:00
|
|
|
.chain(self.archiver_infos.values().map(|info| &info.ledger_path))
|
2019-03-23 19:19:55 -07:00
|
|
|
{
|
|
|
|
remove_dir_all(&ledger_path)
|
2019-07-30 15:53:41 -07:00
|
|
|
.unwrap_or_else(|_| panic!("Unable to remove {:?}", ledger_path));
|
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 {
|
|
|
|
let client = create_client(
|
|
|
|
self.entry_point_info.client_facing_addr(),
|
2019-10-10 16:33:00 -07:00
|
|
|
VALIDATOR_PORT_RANGE,
|
2019-03-22 11:39:25 -07:00
|
|
|
);
|
|
|
|
Self::transfer_with_client(&client, source_keypair, dest_pubkey, lamports)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn transfer_with_client(
|
2019-03-16 08:31:19 -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");
|
2019-11-06 13:15:00 -08:00
|
|
|
let (blockhash, _fee_calculator) = client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap();
|
2019-10-19 18:23:27 -07:00
|
|
|
let mut tx =
|
2019-10-23 22:01:22 -07:00
|
|
|
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
|
2019-10-23 12:11:04 -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),
|
|
|
|
CommitmentConfig::recent(),
|
|
|
|
)
|
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(
|
2019-03-16 08:31:19 -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();
|
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
|
|
|
|
.poll_get_balance_with_commitment(&vote_account_pubkey, CommitmentConfig::recent())
|
|
|
|
.unwrap_or(0)
|
|
|
|
== 0
|
|
|
|
{
|
2019-03-05 13:23:12 -08:00
|
|
|
// 1) Create vote account
|
2019-05-15 12:15:31 -07:00
|
|
|
|
|
|
|
let mut transaction = Transaction::new_signed_instructions(
|
2019-11-08 02:27:35 -08:00
|
|
|
&[from_account.as_ref(), vote_account],
|
2019-05-15 12:15:31 -07:00
|
|
|
vote_instruction::create_account(
|
|
|
|
&from_account.pubkey(),
|
|
|
|
&vote_account_pubkey,
|
2019-09-25 13:53:49 -07:00
|
|
|
&VoteInit {
|
|
|
|
node_pubkey,
|
|
|
|
authorized_voter: vote_account_pubkey,
|
|
|
|
authorized_withdrawer: vote_account_pubkey,
|
|
|
|
commission: 0,
|
|
|
|
},
|
2019-05-15 12:15:31 -07:00
|
|
|
amount,
|
|
|
|
),
|
2019-11-06 13:15:00 -08:00
|
|
|
client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap()
|
|
|
|
.0,
|
2019-04-03 08:45:57 -07:00
|
|
|
);
|
2019-05-15 12:15:31 -07:00
|
|
|
client
|
2019-10-23 12:11:04 -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),
|
|
|
|
CommitmentConfig::recent(),
|
|
|
|
)
|
2019-05-15 12:15:31 -07:00
|
|
|
.expect("get balance");
|
|
|
|
|
2019-03-25 15:08:22 -07:00
|
|
|
let mut transaction = Transaction::new_signed_instructions(
|
2019-06-10 12:17:29 -07:00
|
|
|
&[from_account.as_ref(), &stake_account_keypair],
|
2019-12-14 04:38:24 -08:00
|
|
|
stake_instruction::create_account_and_delegate_stake(
|
2019-05-15 12:15:31 -07:00
|
|
|
&from_account.pubkey(),
|
|
|
|
&stake_account_pubkey,
|
2019-06-10 12:17:29 -07:00
|
|
|
&vote_account_pubkey,
|
2019-12-14 04:38:24 -08:00
|
|
|
&Authorized::auto(&stake_account_pubkey),
|
|
|
|
&Lockup::default(),
|
2019-09-29 21:18:15 -07:00
|
|
|
amount,
|
2019-05-21 07:32:38 -07:00
|
|
|
),
|
2019-11-06 13:15:00 -08:00
|
|
|
client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.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),
|
|
|
|
CommitmentConfig::recent(),
|
|
|
|
)
|
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 (
|
2019-11-06 13:15:00 -08:00
|
|
|
client.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent()),
|
|
|
|
client.get_account_with_commitment(&vote_account_pubkey, CommitmentConfig::recent()),
|
2019-08-16 15:46:19 -07:00
|
|
|
) {
|
|
|
|
(Ok(Some(stake_account)), Ok(Some(vote_account))) => {
|
|
|
|
match (
|
|
|
|
StakeState::stake_from(&stake_account),
|
|
|
|
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-05-23 14:50:23 -07:00
|
|
|
|
2019-10-21 10:29:37 -07:00
|
|
|
/// Sets up the storage account for validators/archivers and assumes the funder is the owner
|
2019-05-23 14:50:23 -07:00
|
|
|
fn setup_storage_account(
|
|
|
|
client: &ThinClient,
|
|
|
|
storage_keypair: &Keypair,
|
|
|
|
from_keypair: &Arc<Keypair>,
|
2019-10-21 10:29:37 -07:00
|
|
|
archiver: bool,
|
2019-05-23 14:50:23 -07:00
|
|
|
) -> Result<()> {
|
2019-10-21 10:29:37 -07:00
|
|
|
let storage_account_type = if archiver {
|
|
|
|
StorageAccountType::Archiver
|
2019-10-04 14:18:19 -07:00
|
|
|
} else {
|
|
|
|
StorageAccountType::Validator
|
|
|
|
};
|
2019-05-23 14:50:23 -07:00
|
|
|
let message = Message::new_with_payer(
|
2019-10-04 14:18:19 -07:00
|
|
|
storage_instruction::create_storage_account(
|
|
|
|
&from_keypair.pubkey(),
|
|
|
|
&from_keypair.pubkey(),
|
|
|
|
&storage_keypair.pubkey(),
|
|
|
|
1,
|
|
|
|
storage_account_type,
|
|
|
|
),
|
2019-05-23 14:50:23 -07:00
|
|
|
Some(&from_keypair.pubkey()),
|
|
|
|
);
|
2019-11-08 02:27:35 -08:00
|
|
|
|
|
|
|
let signer_keys = vec![from_keypair.as_ref(), &storage_keypair];
|
2019-11-06 13:15:00 -08:00
|
|
|
let blockhash = client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap()
|
|
|
|
.0;
|
2019-05-23 14:50:23 -07:00
|
|
|
let mut transaction = Transaction::new(&signer_keys, message, blockhash);
|
|
|
|
client
|
2019-10-23 12:11:04 -07:00
|
|
|
.retry_transfer(&from_keypair, &mut transaction, 10)
|
2019-05-23 14:50:23 -07:00
|
|
|
.map(|_signature| ())
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-06-12 16:43:05 -07:00
|
|
|
fn get_validator_client(&self, pubkey: &Pubkey) -> Option<ThinClient> {
|
2019-12-03 16:31:59 -08:00
|
|
|
self.validators.get(pubkey).map(|f| {
|
2019-06-19 00:13:19 -07:00
|
|
|
create_client(
|
|
|
|
f.info.contact_info.client_facing_addr(),
|
2019-10-10 16:33:00 -07:00
|
|
|
VALIDATOR_PORT_RANGE,
|
2019-06-19 00:13:19 -07:00
|
|
|
)
|
|
|
|
})
|
2019-06-12 16:43:05 -07:00
|
|
|
}
|
|
|
|
|
2019-09-08 17:53:34 -07:00
|
|
|
fn exit_node(&mut self, pubkey: &Pubkey) -> ClusterValidatorInfo {
|
2019-10-11 12:30:52 -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();
|
|
|
|
validator.join().unwrap();
|
|
|
|
node
|
2019-09-08 17:53:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn restart_node(&mut self, pubkey: &Pubkey, mut cluster_validator_info: ClusterValidatorInfo) {
|
2019-08-21 23:59:11 -07:00
|
|
|
// Update the stored ContactInfo for this node
|
2019-09-08 17:53:34 -07:00
|
|
|
let node = Node::new_localhost_with_pubkey(&pubkey);
|
|
|
|
cluster_validator_info.info.contact_info = node.info.clone();
|
2020-01-30 10:58:39 -08:00
|
|
|
cluster_validator_info.config.rpc_ports =
|
|
|
|
Some((node.info.rpc.port(), node.info.rpc_pubsub.port()));
|
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 {
|
|
|
|
Some(&self.entry_point_info)
|
|
|
|
}
|
|
|
|
};
|
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;
|
2019-08-21 23:59:11 -07:00
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
let restarted_node = Validator::new(
|
2019-03-23 19:19:55 -07:00
|
|
|
node,
|
2019-10-11 12:30:52 -07:00
|
|
|
&validator_info.keypair,
|
|
|
|
&validator_info.ledger_path,
|
|
|
|
&validator_info.voting_keypair.pubkey(),
|
|
|
|
&validator_info.voting_keypair,
|
|
|
|
&validator_info.storage_keypair,
|
2019-09-08 17:53:34 -07:00
|
|
|
entry_point_info,
|
2019-07-12 16:58:13 -07:00
|
|
|
true,
|
2019-09-08 17:53:34 -07:00
|
|
|
&cluster_validator_info.config,
|
2019-03-23 19:19:55 -07:00
|
|
|
);
|
|
|
|
|
2019-12-03 16:31:59 -08:00
|
|
|
cluster_validator_info.validator = Some(restarted_node);
|
|
|
|
self.validators.insert(*pubkey, cluster_validator_info);
|
2019-09-08 17:53:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn exit_restart_node(&mut self, pubkey: &Pubkey, validator_config: ValidatorConfig) {
|
|
|
|
let mut cluster_validator_info = self.exit_node(pubkey);
|
|
|
|
cluster_validator_info.config = validator_config;
|
|
|
|
self.restart_node(pubkey, cluster_validator_info);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2019-08-21 10:23:33 -07:00
|
|
|
use solana_core::storage_stage::SLOTS_PER_TURN_TEST;
|
2019-10-08 22:34:26 -07:00
|
|
|
use solana_sdk::epoch_schedule::MINIMUM_SLOTS_PER_EPOCH;
|
2019-03-01 10:36:52 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_local_cluster_start_and_exit() {
|
|
|
|
solana_logger::setup();
|
2019-03-13 14:23:32 -07:00
|
|
|
let num_nodes = 1;
|
2019-04-15 15:27:45 -07:00
|
|
|
let cluster = LocalCluster::new_with_equal_stakes(num_nodes, 100, 3);
|
2019-10-11 12:30:52 -07:00
|
|
|
assert_eq!(cluster.validators.len(), num_nodes);
|
2019-10-21 10:29:37 -07:00
|
|
|
assert_eq!(cluster.archivers.len(), 0);
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
2019-03-03 22:01:09 -08:00
|
|
|
|
|
|
|
#[test]
|
2019-03-04 09:59:36 -08:00
|
|
|
fn test_local_cluster_start_and_exit_with_config() {
|
2019-03-03 22:01:09 -08:00
|
|
|
solana_logger::setup();
|
2019-05-23 22:05:16 -07:00
|
|
|
let mut validator_config = ValidatorConfig::default();
|
2019-10-11 12:30:52 -07:00
|
|
|
validator_config.rpc_config.enable_validator_exit = true;
|
2019-07-10 13:33:29 -07:00
|
|
|
validator_config.storage_slots_per_turn = SLOTS_PER_TURN_TEST;
|
2019-03-13 14:23:32 -07:00
|
|
|
const NUM_NODES: usize = 1;
|
2019-10-21 10:29:37 -07:00
|
|
|
let num_archivers = 1;
|
2019-04-15 15:27:45 -07:00
|
|
|
let config = ClusterConfig {
|
2019-06-19 00:13:19 -07:00
|
|
|
validator_configs: vec![ValidatorConfig::default(); NUM_NODES],
|
2019-10-21 10:29:37 -07:00
|
|
|
num_archivers,
|
2019-04-15 15:27:45 -07:00
|
|
|
node_stakes: vec![3; NUM_NODES],
|
|
|
|
cluster_lamports: 100,
|
2019-05-03 16:27:53 -07:00
|
|
|
ticks_per_slot: 8,
|
2019-06-14 11:38:37 -07:00
|
|
|
slots_per_epoch: MINIMUM_SLOTS_PER_EPOCH as u64,
|
2020-01-03 09:30:36 -08:00
|
|
|
stakers_slot_offset: MINIMUM_SLOTS_PER_EPOCH as u64,
|
2019-04-15 15:27:45 -07:00
|
|
|
..ClusterConfig::default()
|
|
|
|
};
|
|
|
|
let cluster = LocalCluster::new(&config);
|
2019-10-11 12:30:52 -07:00
|
|
|
assert_eq!(cluster.validators.len(), NUM_NODES);
|
2019-10-21 10:29:37 -07:00
|
|
|
assert_eq!(cluster.archivers.len(), num_archivers);
|
2019-03-03 22:01:09 -08:00
|
|
|
}
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|