2019-03-13 20:54:30 -07:00
|
|
|
use clap::{crate_description, crate_name, crate_version, App, Arg};
|
2018-12-14 17:42:46 -08:00
|
|
|
use log::*;
|
2019-03-08 17:23:07 -08:00
|
|
|
use solana::cluster_info::{Node, FULLNODE_PORT_RANGE};
|
|
|
|
|
use solana::contact_info::ContactInfo;
|
2019-07-20 13:13:55 -07:00
|
|
|
use solana::ledger_cleanup_service::DEFAULT_MAX_LEDGER_SLOTS;
|
2019-01-10 09:21:38 -08:00
|
|
|
use solana::local_vote_signer_service::LocalVoteSignerService;
|
2019-03-03 16:44:06 -08:00
|
|
|
use solana::service::Service;
|
2019-05-03 11:01:35 -07:00
|
|
|
use solana::socketaddr;
|
2019-05-23 22:05:16 -07:00
|
|
|
use solana::validator::{Validator, ValidatorConfig};
|
2019-04-12 18:17:34 -07:00
|
|
|
use solana_netutil::parse_port_range;
|
2019-03-04 14:27:06 -08:00
|
|
|
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
|
2018-05-23 13:03:19 -07:00
|
|
|
use std::fs::File;
|
2019-04-15 16:21:06 -07:00
|
|
|
use std::net::SocketAddr;
|
2019-07-30 15:53:41 -07:00
|
|
|
use std::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;
|
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())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-07-30 19:47:24 -07:00
|
|
|
.help("Open blockstream at 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-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(
|
|
|
|
|
Arg::with_name("no_sigverify")
|
|
|
|
|
.short("v")
|
|
|
|
|
.long("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"),
|
|
|
|
|
)
|
|
|
|
|
.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(
|
|
|
|
|
Arg::with_name("accounts")
|
|
|
|
|
.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-05-30 21:31:35 -07:00
|
|
|
.arg(
|
|
|
|
|
clap::Arg::with_name("snapshot_path")
|
|
|
|
|
.long("snapshot-path")
|
|
|
|
|
.value_name("PATHS")
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
.help("Snapshot path"),
|
2019-07-12 16:58:13 -07:00
|
|
|
)
|
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-05-23 22:05:16 -07:00
|
|
|
validator_config.sigverify_disabled = matches.is_present("no_sigverify");
|
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-07-30 19:47:24 -07:00
|
|
|
validator_config.account_paths = matches.value_of("accounts").map(ToString::to_string);
|
|
|
|
|
validator_config.snapshot_path = matches.value_of("snapshot_path").map(PathBuf::from);
|
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
|
|
|
|
|
|
|
|
let keypair = Arc::new(keypair);
|
|
|
|
|
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-01-30 20:51:50 -07:00
|
|
|
&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
|
|
|
}
|