2019-08-14 19:25:22 -07:00
|
|
|
use bzip2::bufread::BzDecoder;
|
2019-08-08 09:14:30 -07:00
|
|
|
use clap::{crate_description, crate_name, crate_version, value_t, App, Arg};
|
2018-12-14 17:42:46 -08:00
|
|
|
use log::*;
|
2019-08-21 18:16:40 -07:00
|
|
|
use solana_client::rpc_client::RpcClient;
|
2019-08-21 10:23:33 -07:00
|
|
|
use solana_core::bank_forks::SnapshotConfig;
|
|
|
|
|
use solana_core::cluster_info::{Node, FULLNODE_PORT_RANGE};
|
|
|
|
|
use solana_core::contact_info::ContactInfo;
|
|
|
|
|
use solana_core::gossip_service::discover;
|
|
|
|
|
use solana_core::ledger_cleanup_service::DEFAULT_MAX_LEDGER_SLOTS;
|
|
|
|
|
use solana_core::local_vote_signer_service::LocalVoteSignerService;
|
|
|
|
|
use solana_core::service::Service;
|
|
|
|
|
use solana_core::socketaddr;
|
|
|
|
|
use solana_core::validator::{Validator, ValidatorConfig};
|
2019-04-12 18:17:34 -07:00
|
|
|
use solana_netutil::parse_port_range;
|
2019-08-21 18:16:40 -07:00
|
|
|
use solana_sdk::hash::Hash;
|
2019-03-04 14:27:06 -08:00
|
|
|
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
|
2019-08-08 09:14:30 -07:00
|
|
|
use solana_sdk::timing::Slot;
|
2019-08-14 19:25:22 -07:00
|
|
|
use std::fs::{self, File};
|
2019-04-15 16:21:06 -07:00
|
|
|
use std::net::SocketAddr;
|
2019-08-14 19:25:22 -07:00
|
|
|
use std::path::{Path, PathBuf};
|
2018-04-19 22:06:19 +08:00
|
|
|
use std::process::exit;
|
2018-10-25 16:58:40 -07:00
|
|
|
use std::sync::Arc;
|
2019-08-14 19:25:22 -07:00
|
|
|
use std::time::Instant;
|
2018-02-28 18:04:35 -07:00
|
|
|
|
2019-04-12 18:17:34 -07:00
|
|
|
fn port_range_validator(port_range: String) -> Result<(), String> {
|
|
|
|
|
if parse_port_range(&port_range).is_some() {
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err("Invalid port range".to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 19:25:22 -07:00
|
|
|
fn download_archive(
|
|
|
|
|
rpc_addr: &SocketAddr,
|
|
|
|
|
archive_name: &str,
|
|
|
|
|
download_path: &Path,
|
|
|
|
|
extract: bool,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
let archive_path = download_path.join(archive_name);
|
|
|
|
|
if archive_path.is_file() {
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
let temp_archive_path = {
|
|
|
|
|
let mut p = archive_path.clone();
|
|
|
|
|
p.set_extension(".tmp");
|
|
|
|
|
p
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let url = format!("http://{}/{}", rpc_addr, archive_name);
|
|
|
|
|
println!("Downloading {}...", url);
|
|
|
|
|
let download_start = Instant::now();
|
|
|
|
|
|
|
|
|
|
let mut response = reqwest::get(&url).map_err(|err| format!("Unable to get: {:?}", err))?;
|
|
|
|
|
let mut file = File::create(&temp_archive_path)
|
|
|
|
|
.map_err(|err| format!("Unable to create {:?}: {:?}", temp_archive_path, err))?;
|
|
|
|
|
std::io::copy(&mut response, &mut file)
|
|
|
|
|
.map_err(|err| format!("Unable to write {:?}: {:?}", temp_archive_path, err))?;
|
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
"Downloaded {} in {:?}",
|
|
|
|
|
archive_name,
|
|
|
|
|
Instant::now().duration_since(download_start)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if extract {
|
|
|
|
|
println!("Extracting {:?}...", archive_path);
|
|
|
|
|
let extract_start = Instant::now();
|
|
|
|
|
let tar_bz2 = File::open(&temp_archive_path)
|
|
|
|
|
.map_err(|err| format!("Unable to open {}: {:?}", archive_name, err))?;
|
|
|
|
|
let tar = BzDecoder::new(std::io::BufReader::new(tar_bz2));
|
|
|
|
|
let mut archive = tar::Archive::new(tar);
|
|
|
|
|
archive
|
|
|
|
|
.unpack(download_path)
|
|
|
|
|
.map_err(|err| format!("Unable to unpack {}: {:?}", archive_name, err))?;
|
|
|
|
|
println!(
|
|
|
|
|
"Extracted {} in {:?}",
|
|
|
|
|
archive_name,
|
|
|
|
|
Instant::now().duration_since(extract_start)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
std::fs::rename(temp_archive_path, archive_path)
|
|
|
|
|
.map_err(|err| format!("Unable to rename: {:?}", err))?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn initialize_ledger_path(
|
|
|
|
|
entrypoint: &ContactInfo,
|
|
|
|
|
gossip_addr: &SocketAddr,
|
|
|
|
|
ledger_path: &Path,
|
|
|
|
|
no_snapshot_fetch: bool,
|
2019-08-21 18:16:40 -07:00
|
|
|
) -> Result<Hash, String> {
|
2019-08-14 19:25:22 -07:00
|
|
|
let (nodes, _replicators) = discover(
|
|
|
|
|
&entrypoint.gossip,
|
|
|
|
|
Some(1),
|
|
|
|
|
Some(60),
|
|
|
|
|
None,
|
|
|
|
|
Some(&gossip_addr),
|
|
|
|
|
)
|
|
|
|
|
.map_err(|err| err.to_string())?;
|
|
|
|
|
|
|
|
|
|
let rpc_addr = nodes
|
|
|
|
|
.iter()
|
|
|
|
|
.filter_map(ContactInfo::valid_client_facing_addr)
|
|
|
|
|
.map(|addrs| addrs.0)
|
|
|
|
|
.find(|rpc_addr| rpc_addr.ip() == entrypoint.gossip.ip())
|
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
eprintln!(
|
|
|
|
|
"Entrypoint ({:?}) is not running the RPC service",
|
|
|
|
|
entrypoint.gossip.ip()
|
|
|
|
|
);
|
|
|
|
|
exit(1);
|
|
|
|
|
});
|
|
|
|
|
|
2019-08-21 18:16:40 -07:00
|
|
|
let genesis_blockhash = RpcClient::new_socket(rpc_addr)
|
|
|
|
|
.get_genesis_blockhash()
|
|
|
|
|
.map_err(|err| err.to_string())?;
|
|
|
|
|
|
2019-08-14 19:25:22 -07:00
|
|
|
fs::create_dir_all(ledger_path).map_err(|err| err.to_string())?;
|
|
|
|
|
|
|
|
|
|
download_archive(&rpc_addr, "genesis.tar.bz2", ledger_path, true)?;
|
|
|
|
|
if !no_snapshot_fetch {
|
|
|
|
|
let _ = fs::remove_file(ledger_path.join("snapshot.tar.bz2"));
|
|
|
|
|
download_archive(&rpc_addr, "snapshot.tar.bz2", ledger_path, false)
|
|
|
|
|
.unwrap_or_else(|err| eprintln!("Warning: Unable to fetch snapshot: {:?}", err));
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 18:16:40 -07:00
|
|
|
Ok(genesis_blockhash)
|
2019-08-14 19:25:22 -07:00
|
|
|
}
|
|
|
|
|
|
2018-10-25 16:58:40 -07:00
|
|
|
fn main() {
|
2019-07-29 10:57:00 -07:00
|
|
|
solana_logger::setup_with_filter("solana=info");
|
2019-05-23 22:05:16 -07:00
|
|
|
solana_metrics::set_panic_hook("validator");
|
2019-01-19 20:03:20 -08:00
|
|
|
|
2019-04-12 18:17:34 -07:00
|
|
|
let default_dynamic_port_range =
|
|
|
|
|
&format!("{}-{}", FULLNODE_PORT_RANGE.0, FULLNODE_PORT_RANGE.1);
|
|
|
|
|
|
2019-03-13 20:54:30 -07:00
|
|
|
let matches = App::new(crate_name!()).about(crate_description!())
|
2018-08-06 20:51:12 -07:00
|
|
|
.version(crate_version!())
|
2019-01-29 00:21:27 -08:00
|
|
|
.arg(
|
2019-07-30 19:47:24 -07:00
|
|
|
Arg::with_name("blockstream_unix_socket")
|
2019-02-21 16:16:09 -07:00
|
|
|
.long("blockstream")
|
2019-01-29 00:21:27 -08:00
|
|
|
.takes_value(true)
|
|
|
|
|
.value_name("UNIX DOMAIN SOCKET")
|
2019-08-14 19:25:22 -07:00
|
|
|
.help("Stream entries to this unix domain socket path")
|
2019-01-29 00:21:27 -08:00
|
|
|
)
|
2018-12-07 20:01:28 -07:00
|
|
|
.arg(
|
2018-07-09 19:04:49 -06:00
|
|
|
Arg::with_name("identity")
|
2018-07-12 15:45:41 -07:00
|
|
|
.short("i")
|
|
|
|
|
.long("identity")
|
2018-09-14 16:32:57 -06:00
|
|
|
.value_name("PATH")
|
2018-07-09 19:04:49 -06:00
|
|
|
.takes_value(true)
|
2019-07-26 10:37:03 -07:00
|
|
|
.help("File containing the identity keypair for the validator"),
|
2018-12-07 20:01:28 -07:00
|
|
|
)
|
2019-03-08 18:29:08 -08:00
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("voting_keypair")
|
|
|
|
|
.long("voting-keypair")
|
2019-03-07 16:22:32 -07:00
|
|
|
.value_name("PATH")
|
|
|
|
|
.takes_value(true)
|
2019-07-26 10:37:03 -07:00
|
|
|
.help("File containing the authorized voting keypair. Default is an ephemeral keypair"),
|
|
|
|
|
)
|
|
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("vote_account")
|
|
|
|
|
.long("vote-account")
|
|
|
|
|
.value_name("PUBKEY")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Public key of the vote account to vote with. Default is the public key of the voting keypair"),
|
2019-03-07 16:22:32 -07:00
|
|
|
)
|
2019-05-15 15:19:29 -07:00
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("storage_keypair")
|
|
|
|
|
.long("storage-keypair")
|
|
|
|
|
.value_name("PATH")
|
|
|
|
|
.takes_value(true)
|
2019-07-26 10:37:03 -07:00
|
|
|
.help("File containing the storage account keypair. Default is an ephemeral keypair"),
|
2019-05-15 15:19:29 -07:00
|
|
|
)
|
2018-12-07 20:01:28 -07:00
|
|
|
.arg(
|
2019-01-28 12:40:24 -07:00
|
|
|
Arg::with_name("init_complete_file")
|
|
|
|
|
.long("init-complete-file")
|
|
|
|
|
.value_name("FILE")
|
2019-01-05 12:57:52 -08:00
|
|
|
.takes_value(true)
|
2019-01-28 12:40:24 -07:00
|
|
|
.help("Create this file, if it doesn't already exist, once node initialization is complete"),
|
2019-01-05 12:57:52 -08:00
|
|
|
)
|
2018-12-07 20:01:28 -07:00
|
|
|
.arg(
|
2019-07-30 15:53:41 -07:00
|
|
|
Arg::with_name("ledger_path")
|
2018-08-03 11:06:06 -07:00
|
|
|
.short("l")
|
2018-07-12 14:29:36 -07:00
|
|
|
.long("ledger")
|
2018-08-03 11:06:06 -07:00
|
|
|
.value_name("DIR")
|
2018-07-09 19:04:49 -06:00
|
|
|
.takes_value(true)
|
2018-08-03 11:06:06 -07:00
|
|
|
.required(true)
|
2018-11-05 10:50:58 -07:00
|
|
|
.help("Use DIR as persistent ledger location"),
|
2018-12-07 20:01:28 -07:00
|
|
|
)
|
|
|
|
|
.arg(
|
2019-05-03 15:00:19 -07:00
|
|
|
Arg::with_name("entrypoint")
|
2019-01-28 12:40:24 -07:00
|
|
|
.short("n")
|
2019-05-03 15:00:19 -07:00
|
|
|
.long("entrypoint")
|
2019-01-28 12:40:24 -07:00
|
|
|
.value_name("HOST:PORT")
|
2018-11-05 10:50:58 -07:00
|
|
|
.takes_value(true)
|
2019-05-03 15:00:19 -07:00
|
|
|
.help("Rendezvous with the cluster at this entry point"),
|
2018-12-07 20:01:28 -07:00
|
|
|
)
|
2019-08-14 19:25:22 -07:00
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("no_snapshot_fetch")
|
|
|
|
|
.long("no-snapshot-fetch")
|
|
|
|
|
.takes_value(false)
|
|
|
|
|
.requires("entrypoint")
|
|
|
|
|
.help("Do not attempt to fetch a snapshot from the cluster entrypoint"),
|
|
|
|
|
)
|
2019-01-23 18:05:06 -08:00
|
|
|
.arg(
|
2019-03-08 18:29:08 -08:00
|
|
|
Arg::with_name("no_voting")
|
|
|
|
|
.long("no-voting")
|
2019-01-23 18:05:06 -08:00
|
|
|
.takes_value(false)
|
2019-03-08 18:29:08 -08:00
|
|
|
.help("Launch node without voting"),
|
2019-01-23 18:05:06 -08:00
|
|
|
)
|
2019-01-28 12:40:24 -07:00
|
|
|
.arg(
|
2019-08-08 09:14:30 -07:00
|
|
|
Arg::with_name("dev_no_sigverify")
|
|
|
|
|
.long("dev-no-sigverify")
|
2019-03-04 14:27:06 -08:00
|
|
|
.takes_value(false)
|
2019-01-28 12:40:24 -07:00
|
|
|
.help("Run without signature verification"),
|
|
|
|
|
)
|
2019-08-08 09:14:30 -07:00
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("dev_halt_at_slot")
|
|
|
|
|
.long("dev-halt-at-slot")
|
|
|
|
|
.value_name("SLOT")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Halt the validator when it reaches the given slot"),
|
|
|
|
|
)
|
2019-01-28 12:40:24 -07:00
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("rpc_port")
|
|
|
|
|
.long("rpc-port")
|
|
|
|
|
.value_name("PORT")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("RPC port to use for this node"),
|
|
|
|
|
)
|
2019-03-04 15:01:48 -08:00
|
|
|
.arg(
|
|
|
|
|
Arg::with_name("enable_rpc_exit")
|
|
|
|
|
.long("enable-rpc-exit")
|
|
|
|
|
.takes_value(false)
|
|
|
|
|
.help("Enable the JSON RPC 'fullnodeExit' API. Only enable in a debug environment"),
|
|
|
|
|
)
|
2019-03-06 09:26:12 -08:00
|
|
|
.arg(
|
2019-07-26 10:37:03 -07:00
|
|
|
Arg::with_name("rpc_drone_addr")
|
2019-03-06 09:26:12 -08:00
|
|
|
.long("rpc-drone-address")
|
|
|
|
|
.value_name("HOST:PORT")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Enable the JSON RPC 'requestAirdrop' API with this drone address."),
|
|
|
|
|
)
|
2019-01-28 12:40:24 -07:00
|
|
|
.arg(
|
2019-07-26 10:37:03 -07:00
|
|
|
Arg::with_name("signer_addr")
|
|
|
|
|
.long("vote-signer-address")
|
2019-01-28 12:40:24 -07:00
|
|
|
.value_name("HOST:PORT")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Rendezvous with the vote signer at this RPC end point"),
|
|
|
|
|
)
|
2018-12-24 16:11:20 -08:00
|
|
|
.arg(
|
2019-08-14 19:25:22 -07:00
|
|
|
Arg::with_name("account_paths")
|
2018-12-24 16:11:20 -08:00
|
|
|
.long("accounts")
|
|
|
|
|
.value_name("PATHS")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Comma separated persistent accounts location"),
|
|
|
|
|
)
|
2019-03-04 14:27:06 -08:00
|
|
|
.arg(
|
|
|
|
|
clap::Arg::with_name("gossip_port")
|
|
|
|
|
.long("gossip-port")
|
2019-05-03 11:01:35 -07:00
|
|
|
.value_name("HOST:PORT")
|
2019-03-04 14:27:06 -08:00
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Gossip port number for the node"),
|
|
|
|
|
)
|
2019-04-12 18:17:34 -07:00
|
|
|
.arg(
|
|
|
|
|
clap::Arg::with_name("dynamic_port_range")
|
|
|
|
|
.long("dynamic-port-range")
|
|
|
|
|
.value_name("MIN_PORT-MAX_PORT")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.default_value(default_dynamic_port_range)
|
|
|
|
|
.validator(port_range_validator)
|
|
|
|
|
.help("Range to use for dynamically assigned ports"),
|
|
|
|
|
)
|
2019-07-31 17:58:10 -07:00
|
|
|
.arg(
|
|
|
|
|
clap::Arg::with_name("snapshot_interval_slots")
|
|
|
|
|
.long("snapshot-interval-slots")
|
|
|
|
|
.value_name("SNAPSHOT_INTERVAL_SLOTS")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Number of slots between generating snapshots"),
|
|
|
|
|
)
|
2019-07-20 13:13:55 -07:00
|
|
|
.arg(
|
|
|
|
|
clap::Arg::with_name("limit_ledger_size")
|
|
|
|
|
.long("limit-ledger-size")
|
|
|
|
|
.takes_value(false)
|
|
|
|
|
.requires("snapshot_path")
|
|
|
|
|
.help("drop older slots in the ledger"),
|
|
|
|
|
)
|
2019-07-12 16:58:13 -07:00
|
|
|
.arg(
|
|
|
|
|
clap::Arg::with_name("skip_ledger_verify")
|
|
|
|
|
.long("skip-ledger-verify")
|
|
|
|
|
.takes_value(false)
|
|
|
|
|
.help("Skip ledger verification at node bootup"),
|
2019-05-30 21:31:35 -07:00
|
|
|
)
|
|
|
|
|
.get_matches();
|
2018-04-21 21:12:57 +08:00
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
let mut validator_config = ValidatorConfig::default();
|
2019-03-04 14:27:06 -08:00
|
|
|
let keypair = if let Some(identity) = matches.value_of("identity") {
|
|
|
|
|
read_keypair(identity).unwrap_or_else(|err| {
|
|
|
|
|
eprintln!("{}: Unable to open keypair file: {}", err, identity);
|
|
|
|
|
exit(1);
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
Keypair::new()
|
|
|
|
|
};
|
2019-03-08 18:29:08 -08:00
|
|
|
let voting_keypair = if let Some(identity) = matches.value_of("voting_keypair") {
|
2019-03-07 16:22:32 -07:00
|
|
|
read_keypair(identity).unwrap_or_else(|err| {
|
|
|
|
|
eprintln!("{}: Unable to open keypair file: {}", err, identity);
|
|
|
|
|
exit(1);
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
Keypair::new()
|
|
|
|
|
};
|
2019-05-15 15:19:29 -07:00
|
|
|
let storage_keypair = if let Some(storage_keypair) = matches.value_of("storage_keypair") {
|
|
|
|
|
read_keypair(storage_keypair).unwrap_or_else(|err| {
|
|
|
|
|
eprintln!("{}: Unable to open keypair file: {}", err, storage_keypair);
|
|
|
|
|
exit(1);
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
Keypair::new()
|
|
|
|
|
};
|
2019-03-08 18:29:08 -08:00
|
|
|
|
2019-07-26 10:37:03 -07:00
|
|
|
let vote_account = matches
|
|
|
|
|
.value_of("vote_account")
|
2019-03-08 18:29:08 -08:00
|
|
|
.map_or(voting_keypair.pubkey(), |pubkey| {
|
2019-07-26 10:37:03 -07:00
|
|
|
pubkey.parse().expect("failed to parse vote_account")
|
2019-03-08 18:29:08 -08:00
|
|
|
});
|
|
|
|
|
|
2019-07-30 15:53:41 -07:00
|
|
|
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
|
2019-03-04 14:27:06 -08:00
|
|
|
|
2019-08-08 09:14:30 -07:00
|
|
|
validator_config.dev_sigverify_disabled = matches.is_present("dev_no_sigverify");
|
|
|
|
|
validator_config.dev_halt_at_slot = value_t!(matches, "dev_halt_at_slot", Slot).ok();
|
2019-03-08 18:29:08 -08:00
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
validator_config.voting_disabled = matches.is_present("no_voting");
|
2019-03-08 18:29:08 -08:00
|
|
|
|
2019-07-30 19:47:24 -07:00
|
|
|
validator_config.rpc_config.enable_fullnode_exit = matches.is_present("enable_rpc_exit");
|
|
|
|
|
|
2019-07-26 10:37:03 -07:00
|
|
|
validator_config.rpc_config.drone_addr = matches.value_of("rpc_drone_addr").map(|address| {
|
2019-04-13 19:34:27 -07:00
|
|
|
solana_netutil::parse_host_port(address).expect("failed to parse drone address")
|
|
|
|
|
});
|
2019-03-04 15:01:48 -08:00
|
|
|
|
2019-04-12 18:17:34 -07:00
|
|
|
let dynamic_port_range = parse_port_range(matches.value_of("dynamic_port_range").unwrap())
|
|
|
|
|
.expect("invalid dynamic_port_range");
|
|
|
|
|
|
2019-05-03 11:01:35 -07:00
|
|
|
let mut gossip_addr = solana_netutil::parse_port_or_addr(
|
|
|
|
|
matches.value_of("gossip_port"),
|
|
|
|
|
socketaddr!(
|
|
|
|
|
[127, 0, 0, 1],
|
2019-04-12 18:17:34 -07:00
|
|
|
solana_netutil::find_available_port_in_range(dynamic_port_range)
|
2019-05-03 11:01:35 -07:00
|
|
|
.expect("unable to find an available gossip port")
|
|
|
|
|
),
|
|
|
|
|
);
|
2019-03-04 14:27:06 -08:00
|
|
|
|
2019-08-14 19:25:22 -07:00
|
|
|
if let Some(account_paths) = matches.value_of("account_paths") {
|
|
|
|
|
validator_config.account_paths = Some(account_paths.to_string());
|
|
|
|
|
} else {
|
|
|
|
|
validator_config.account_paths =
|
|
|
|
|
Some(ledger_path.join("accounts").to_str().unwrap().to_string());
|
2019-07-31 17:58:10 -07:00
|
|
|
}
|
2019-08-06 21:41:38 -07:00
|
|
|
|
|
|
|
|
validator_config.snapshot_config = matches.value_of("snapshot_interval_slots").map(|s| {
|
|
|
|
|
let snapshots_dir = ledger_path.clone().join("snapshot");
|
|
|
|
|
fs::create_dir_all(&snapshots_dir).expect("Failed to create snapshots directory");
|
|
|
|
|
SnapshotConfig::new(
|
2019-08-14 19:25:22 -07:00
|
|
|
snapshots_dir,
|
|
|
|
|
ledger_path.clone(),
|
2019-08-06 21:41:38 -07:00
|
|
|
s.parse::<usize>().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
|
2019-07-20 13:13:55 -07:00
|
|
|
if matches.is_present("limit_ledger_size") {
|
|
|
|
|
validator_config.max_ledger_slots = Some(DEFAULT_MAX_LEDGER_SLOTS);
|
2019-05-30 21:31:35 -07:00
|
|
|
}
|
2019-05-03 15:00:19 -07:00
|
|
|
let cluster_entrypoint = matches.value_of("entrypoint").map(|entrypoint| {
|
|
|
|
|
let entrypoint_addr = solana_netutil::parse_host_port(entrypoint)
|
|
|
|
|
.expect("failed to parse entrypoint address");
|
2019-06-06 14:47:37 -07:00
|
|
|
let ip_addr = solana_netutil::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
|
|
|
|
panic!("Unable to contact entrypoint {}: {}", entrypoint_addr, err)
|
|
|
|
|
});
|
|
|
|
|
gossip_addr.set_ip(ip_addr);
|
2019-05-03 11:01:35 -07:00
|
|
|
|
|
|
|
|
ContactInfo::new_gossip_entry_point(&entrypoint_addr)
|
2019-03-06 09:26:12 -08:00
|
|
|
});
|
2019-07-26 10:37:03 -07:00
|
|
|
let (_signer_service, _signer_addr) = if let Some(signer_addr) = matches.value_of("signer_addr")
|
|
|
|
|
{
|
2019-01-19 20:03:20 -08:00
|
|
|
(
|
|
|
|
|
None,
|
|
|
|
|
signer_addr.to_string().parse().expect("Signer IP Address"),
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
// Run a local vote signer if a vote signer service address was not provided
|
2019-04-12 18:17:34 -07:00
|
|
|
let (signer_service, signer_addr) = LocalVoteSignerService::new(dynamic_port_range);
|
2019-01-19 20:03:20 -08:00
|
|
|
(Some(signer_service), signer_addr)
|
|
|
|
|
};
|
2019-04-12 18:17:34 -07:00
|
|
|
let init_complete_file = matches.value_of("init_complete_file");
|
2019-07-30 19:47:24 -07:00
|
|
|
validator_config.blockstream_unix_socket = matches
|
|
|
|
|
.value_of("blockstream_unix_socket")
|
|
|
|
|
.map(PathBuf::from);
|
2019-04-12 18:17:34 -07:00
|
|
|
|
2019-08-14 19:25:22 -07:00
|
|
|
if let Some(ref entrypoint_addr) = cluster_entrypoint {
|
2019-08-21 18:16:40 -07:00
|
|
|
let expected_genesis_blockhash = initialize_ledger_path(
|
2019-08-14 19:25:22 -07:00
|
|
|
entrypoint_addr,
|
|
|
|
|
&gossip_addr,
|
|
|
|
|
&ledger_path,
|
2019-08-15 21:41:14 -07:00
|
|
|
matches.is_present("no_snapshot_fetch"),
|
2019-08-14 19:25:22 -07:00
|
|
|
)
|
|
|
|
|
.unwrap_or_else(|err| {
|
|
|
|
|
eprintln!("Failed to download ledger: {}", err);
|
|
|
|
|
exit(1);
|
|
|
|
|
});
|
2019-08-21 18:16:40 -07:00
|
|
|
validator_config.expected_genesis_blockhash = Some(expected_genesis_blockhash);
|
2019-08-14 19:25:22 -07:00
|
|
|
} else {
|
|
|
|
|
// Without a cluster entrypoint, ledger_path must already be present
|
|
|
|
|
if !ledger_path.is_dir() {
|
|
|
|
|
eprintln!(
|
|
|
|
|
"Error: ledger directory does not exist or is not accessible: {:?}",
|
|
|
|
|
ledger_path
|
|
|
|
|
);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 18:17:34 -07:00
|
|
|
let mut node = Node::new_with_external_ip(&keypair.pubkey(), &gossip_addr, dynamic_port_range);
|
|
|
|
|
if let Some(port) = matches.value_of("rpc_port") {
|
2018-11-05 10:50:58 -07:00
|
|
|
let port_number = port.to_string().parse().expect("integer");
|
|
|
|
|
if port_number == 0 {
|
|
|
|
|
eprintln!("Invalid RPC port requested: {:?}", port);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2019-04-15 16:21:06 -07:00
|
|
|
node.info.rpc = SocketAddr::new(gossip_addr.ip(), port_number);
|
|
|
|
|
node.info.rpc_pubsub = SocketAddr::new(gossip_addr.ip(), port_number + 1);
|
2018-11-15 10:42:02 -08:00
|
|
|
};
|
2018-11-05 10:50:58 -07:00
|
|
|
|
2019-07-12 16:58:13 -07:00
|
|
|
let verify_ledger = !matches.is_present("skip_ledger_verify");
|
|
|
|
|
|
2019-05-23 22:05:16 -07:00
|
|
|
let validator = Validator::new(
|
2018-10-10 16:49:41 -07:00
|
|
|
node,
|
2019-08-14 19:25:22 -07:00
|
|
|
&Arc::new(keypair),
|
2019-07-30 15:53:41 -07:00
|
|
|
&ledger_path,
|
2019-07-26 10:37:03 -07:00
|
|
|
&vote_account,
|
2019-05-15 15:19:29 -07:00
|
|
|
&Arc::new(voting_keypair),
|
|
|
|
|
&Arc::new(storage_keypair),
|
2019-03-06 09:26:12 -08:00
|
|
|
cluster_entrypoint.as_ref(),
|
2019-07-12 16:58:13 -07:00
|
|
|
verify_ledger,
|
2019-05-23 22:05:16 -07:00
|
|
|
&validator_config,
|
2018-10-10 16:49:41 -07:00
|
|
|
);
|
2018-07-31 22:07:53 -07:00
|
|
|
|
2019-01-22 11:34:12 -08:00
|
|
|
if let Some(filename) = init_complete_file {
|
|
|
|
|
File::create(filename).unwrap_or_else(|_| panic!("Unable to create: {}", filename));
|
|
|
|
|
}
|
2019-05-23 22:05:16 -07:00
|
|
|
info!("Validator initialized");
|
|
|
|
|
validator.join().expect("validator exit");
|
|
|
|
|
info!("Validator exiting..");
|
2018-05-23 13:03:19 -07:00
|
|
|
}
|