Files
solana/fullnode/src/main.rs

264 lines
9.4 KiB
Rust
Raw Normal View History

use clap::{crate_description, crate_name, crate_version, App, Arg};
use log::*;
2019-03-08 17:23:07 -08:00
use solana::cluster_info::{Node, FULLNODE_PORT_RANGE};
use solana::contact_info::ContactInfo;
use solana::fullnode::{Fullnode, FullnodeConfig};
use solana::local_vote_signer_service::LocalVoteSignerService;
use solana::service::Service;
use solana::socketaddr;
use solana_netutil::parse_port_range;
2019-03-04 14:27:06 -08:00
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
use std::fs::File;
use std::net::SocketAddr;
2018-04-19 22:06:19 +08:00
use std::process::exit;
use std::sync::Arc;
2018-02-28 18:04:35 -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())
}
}
fn main() {
solana_logger::setup();
2018-11-16 08:45:59 -08:00
solana_metrics::set_panic_hook("fullnode");
2019-01-19 20:03:20 -08:00
let default_dynamic_port_range =
&format!("{}-{}", FULLNODE_PORT_RANGE.0, FULLNODE_PORT_RANGE.1);
let matches = App::new(crate_name!()).about(crate_description!())
.version(crate_version!())
.arg(
2019-02-21 16:16:09 -07:00
Arg::with_name("blockstream")
.long("blockstream")
.takes_value(true)
.value_name("UNIX DOMAIN SOCKET")
2019-02-21 16:16:09 -07:00
.help("Open blockstream at this unix domain socket location")
)
.arg(
Arg::with_name("identity")
.short("i")
.long("identity")
2018-09-14 16:32:57 -06:00
.value_name("PATH")
.takes_value(true)
2019-03-04 14:27:06 -08:00
.help("File containing an identity (keypair)"),
)
.arg(
Arg::with_name("vote_account")
.long("vote-account")
.value_name("PUBKEY_BASE58_STR")
.takes_value(true)
.help("Public key of the vote account, where to send votes"),
)
.arg(
Arg::with_name("voting_keypair")
.long("voting-keypair")
.value_name("PATH")
.takes_value(true)
.help("File containing the authorized voting keypair"),
)
.arg(
Arg::with_name("init_complete_file")
.long("init-complete-file")
.value_name("FILE")
.takes_value(true)
.help("Create this file, if it doesn't already exist, once node initialization is complete"),
)
.arg(
Arg::with_name("ledger")
.short("l")
.long("ledger")
.value_name("DIR")
.takes_value(true)
.required(true)
2018-11-05 10:50:58 -07:00
.help("Use DIR as persistent ledger location"),
)
.arg(
Arg::with_name("entrypoint")
.short("n")
.long("entrypoint")
.value_name("HOST:PORT")
2018-11-05 10:50:58 -07:00
.takes_value(true)
.help("Rendezvous with the cluster at this entry point"),
)
2019-01-23 18:05:06 -08:00
.arg(
Arg::with_name("no_voting")
.long("no-voting")
2019-01-23 18:05:06 -08:00
.takes_value(false)
.help("Launch node without voting"),
2019-01-23 18:05:06 -08:00
)
.arg(
Arg::with_name("no_sigverify")
.short("v")
.long("no-sigverify")
2019-03-04 14:27:06 -08:00
.takes_value(false)
.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"),
)
.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(
Arg::with_name("rpc_drone_address")
.long("rpc-drone-address")
.value_name("HOST:PORT")
.takes_value(true)
.help("Enable the JSON RPC 'requestAirdrop' API with this drone address."),
)
.arg(
Arg::with_name("signer")
.short("s")
.long("signer")
.value_name("HOST:PORT")
.takes_value(true)
.help("Rendezvous with the vote signer at this RPC end point"),
)
.arg(
Arg::with_name("accounts")
.short("a")
.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")
.value_name("HOST:PORT")
2019-03-04 14:27:06 -08:00
.takes_value(true)
.help("Gossip port number for the node"),
)
.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"),
)
.arg(
clap::Arg::with_name("use_snapshot")
.long("use-snapshot")
.takes_value(false)
.help("Load / Store bank snapshots"),
)
.get_matches();
2018-04-21 21:12:57 +08:00
let mut fullnode_config = FullnodeConfig::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()
};
let voting_keypair = if let Some(identity) = matches.value_of("voting_keypair") {
read_keypair(identity).unwrap_or_else(|err| {
eprintln!("{}: Unable to open keypair file: {}", err, identity);
exit(1);
})
} else {
Keypair::new()
};
let staking_account = matches
.value_of("staking_account")
.map_or(voting_keypair.pubkey(), |pubkey| {
pubkey.parse().expect("failed to parse staking_account")
});
2019-03-04 14:27:06 -08:00
let ledger_path = matches.value_of("ledger").unwrap();
fullnode_config.sigverify_disabled = matches.is_present("no_sigverify");
fullnode_config.use_snapshot = matches.is_present("use_snapshot");
fullnode_config.voting_disabled = matches.is_present("no_voting");
if matches.is_present("enable_rpc_exit") {
fullnode_config.rpc_config.enable_fullnode_exit = true;
}
2019-04-13 19:34:27 -07:00
fullnode_config.rpc_config.drone_addr = matches.value_of("rpc_drone_address").map(|address| {
solana_netutil::parse_host_port(address).expect("failed to parse drone address")
});
let dynamic_port_range = parse_port_range(matches.value_of("dynamic_port_range").unwrap())
.expect("invalid dynamic_port_range");
let mut gossip_addr = solana_netutil::parse_port_or_addr(
matches.value_of("gossip_port"),
socketaddr!(
[127, 0, 0, 1],
solana_netutil::find_available_port_in_range(dynamic_port_range)
.expect("unable to find an available gossip port")
),
);
2019-03-04 14:27:06 -08:00
if let Some(paths) = matches.value_of("accounts") {
2019-02-25 21:22:00 -08:00
fullnode_config.account_paths = Some(paths.to_string());
} else {
fullnode_config.account_paths = None;
}
let cluster_entrypoint = matches.value_of("entrypoint").map(|entrypoint| {
let entrypoint_addr = solana_netutil::parse_host_port(entrypoint)
.expect("failed to parse entrypoint address");
gossip_addr.set_ip(solana_netutil::get_public_ip_addr(&entrypoint_addr).unwrap());
ContactInfo::new_gossip_entry_point(&entrypoint_addr)
2019-03-06 09:26:12 -08:00
});
let (_signer_service, _signer_addr) = if let Some(signer_addr) = matches.value_of("signer") {
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
let (signer_service, signer_addr) = LocalVoteSignerService::new(dynamic_port_range);
2019-01-19 20:03:20 -08:00
(Some(signer_service), signer_addr)
};
let init_complete_file = matches.value_of("init_complete_file");
fullnode_config.blockstream = matches.value_of("blockstream").map(ToString::to_string);
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);
}
node.info.rpc = SocketAddr::new(gossip_addr.ip(), port_number);
node.info.rpc_pubsub = SocketAddr::new(gossip_addr.ip(), port_number + 1);
};
2018-11-05 10:50:58 -07:00
let fullnode = Fullnode::new(
Leader scheduler plumbing (#1440) * Added LeaderScheduler module and tests * plumbing for LeaderScheduler in Fullnode + tests. Add vote processing for active set to ReplicateStage and WriteStage * Add LeaderScheduler plumbing for Tvu, window, and tests * Fix bank and switch tests to use new LeaderScheduler * move leader rotation check from window service to replicate stage * Add replicate_stage leader rotation exit test * removed leader scheduler from the window service and associated modules/tests * Corrected is_leader calculation in repair() function in window.rs * Integrate LeaderScheduler with write_stage for leader to validator transitions * Integrated LeaderScheduler with BroadcastStage * Removed gossip leader rotation from crdt * Add multi validator, leader test * Comments and cleanup * Remove unneeded checks from broadcast stage * Fix case where a validator/leader need to immediately transition on startup after reading ledger and seeing they are not in the correct role * Set new leader in validator -> validator transitions * Clean up for PR comments, refactor LeaderScheduler from process_entry/process_ledger_tail * Cleaned out LeaderScheduler options, implemented LeaderScheduler strategy that only picks the bootstrap leader to support existing tests, drone/airdrops * Ignore test_full_leader_validator_network test due to bug where the next leader in line fails to get the last entry before rotation (b/c it hasn't started up yet). Added a test test_dropped_handoff_recovery go track this bug
2018-10-10 16:49:41 -07:00
node,
&keypair,
ledger_path,
&staking_account,
voting_keypair,
2019-03-06 09:26:12 -08:00
cluster_entrypoint.as_ref(),
&fullnode_config,
Leader scheduler plumbing (#1440) * Added LeaderScheduler module and tests * plumbing for LeaderScheduler in Fullnode + tests. Add vote processing for active set to ReplicateStage and WriteStage * Add LeaderScheduler plumbing for Tvu, window, and tests * Fix bank and switch tests to use new LeaderScheduler * move leader rotation check from window service to replicate stage * Add replicate_stage leader rotation exit test * removed leader scheduler from the window service and associated modules/tests * Corrected is_leader calculation in repair() function in window.rs * Integrate LeaderScheduler with write_stage for leader to validator transitions * Integrated LeaderScheduler with BroadcastStage * Removed gossip leader rotation from crdt * Add multi validator, leader test * Comments and cleanup * Remove unneeded checks from broadcast stage * Fix case where a validator/leader need to immediately transition on startup after reading ledger and seeing they are not in the correct role * Set new leader in validator -> validator transitions * Clean up for PR comments, refactor LeaderScheduler from process_entry/process_ledger_tail * Cleaned out LeaderScheduler options, implemented LeaderScheduler strategy that only picks the bootstrap leader to support existing tests, drone/airdrops * Ignore test_full_leader_validator_network test due to bug where the next leader in line fails to get the last entry before rotation (b/c it hasn't started up yet). Added a test test_dropped_handoff_recovery go track this bug
2018-10-10 16:49:41 -07:00
);
if let Some(filename) = init_complete_file {
File::create(filename).unwrap_or_else(|_| panic!("Unable to create: {}", filename));
}
info!("Node initialized");
fullnode.join().expect("fullnode exit");
info!("Node exiting..");
}