From 7b49c9f09c608acddab743dce9530c7b878e8712 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 4 Mar 2019 14:27:06 -0800 Subject: [PATCH] Delete fullnode-config/ --- Cargo.lock | 19 +------- Cargo.toml | 1 - ci/publish-crate.sh | 1 - fullnode-config/Cargo.toml | 26 ---------- fullnode-config/src/lib.rs | 41 ---------------- fullnode-config/src/main.rs | 56 --------------------- fullnode/Cargo.toml | 1 - fullnode/src/main.rs | 78 ++++++++++++++++-------------- multinode-demo/bootstrap-leader.sh | 30 ++---------- multinode-demo/common.sh | 1 - multinode-demo/fullnode.sh | 53 ++++++++++---------- multinode-demo/setup.sh | 23 --------- net/remote/remote-node.sh | 20 ++++---- netutil/src/lib.rs | 8 +-- replicator/Cargo.toml | 3 +- replicator/src/main.rs | 54 ++++++++++----------- run.sh | 4 +- scripts/cargo-install-all.sh | 1 - 18 files changed, 117 insertions(+), 303 deletions(-) delete mode 100644 fullnode-config/Cargo.toml delete mode 100644 fullnode-config/src/lib.rs delete mode 100644 fullnode-config/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 556f760c97..732384908a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2118,7 +2118,6 @@ dependencies = [ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "solana 0.12.0", "solana-drone 0.12.0", - "solana-fullnode-config 0.12.0", "solana-logger 0.12.0", "solana-metrics 0.12.0", "solana-netutil 0.12.0", @@ -2128,21 +2127,6 @@ dependencies = [ "solana-vote-signer 0.12.0", ] -[[package]] -name = "solana-fullnode-config" -version = "0.12.0" -dependencies = [ - "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "solana-netutil 0.12.0", - "solana-sdk 0.12.0", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "solana-genesis" version = "0.12.0" @@ -2224,10 +2208,9 @@ name = "solana-replicator" version = "0.12.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "solana 0.12.0", - "solana-fullnode-config 0.12.0", "solana-logger 0.12.0", + "solana-netutil 0.12.0", "solana-sdk 0.12.0", ] diff --git a/Cargo.toml b/Cargo.toml index 260772a024..f04c5dee17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,6 @@ members = [ "core", "drone", "fullnode", - "fullnode-config", "genesis", "keygen", "ledger-tool", diff --git a/ci/publish-crate.sh b/ci/publish-crate.sh index c9c045c9ab..d92b0c51a2 100755 --- a/ci/publish-crate.sh +++ b/ci/publish-crate.sh @@ -19,7 +19,6 @@ CRATES=( drone programs/{budget,bpf_loader,native_loader,noop,system,vote} core - fullnode-config fullnode genesis ledger-tool diff --git a/fullnode-config/Cargo.toml b/fullnode-config/Cargo.toml deleted file mode 100644 index 3aa5cdecea..0000000000 --- a/fullnode-config/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -authors = ["Solana Maintainers "] -edition = "2018" -name = "solana-fullnode-config" -description = "Blockchain, Rebuilt for Scale" -version = "0.12.0" -repository = "https://github.com/solana-labs/solana" -license = "Apache-2.0" -homepage = "https://solana.com/" - -[features] -cuda = [] - -[dependencies] -clap = "2.32.0" -dirs = "1.0.5" -log = "0.4.2" -serde = "1.0.89" -serde_derive = "1.0.89" -serde_json = "1.0.39" -solana-netutil = { path = "../netutil", version = "0.12.0" } -solana-sdk = { path = "../sdk", version = "0.12.0" } -untrusted = "0.6.2" - -[lib] -name = "solana_fullnode_config" diff --git a/fullnode-config/src/lib.rs b/fullnode-config/src/lib.rs deleted file mode 100644 index 2921773ea6..0000000000 --- a/fullnode-config/src/lib.rs +++ /dev/null @@ -1,41 +0,0 @@ -use serde_derive::{Deserialize, Serialize}; -use solana_sdk::signature::Keypair; -use std::net::SocketAddr; -use untrusted::Input; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -#[serde(rename_all = "PascalCase")] -pub struct Config { - /// Bind to port or address - pub bind_port_or_address: Option, - - /// Detect public network address using public servers - pub use_public_address: bool, - - /// Detect network address from local machine configuration - pub use_local_address: bool, - - /// Fullnode identity - pub identity_pkcs8: Vec, -} - -impl Config { - pub fn bind_addr(&self, default_port: u16) -> SocketAddr { - let mut bind_addr = - solana_netutil::parse_port_or_addr(&self.bind_port_or_address, default_port); - if self.use_local_address { - let ip = solana_netutil::get_ip_addr(false).unwrap(); - bind_addr.set_ip(ip); - } - if self.use_public_address { - let ip = solana_netutil::get_public_ip_addr().unwrap(); - bind_addr.set_ip(ip); - } - bind_addr - } - - pub fn keypair(&self) -> Keypair { - Keypair::from_pkcs8(Input::from(&self.identity_pkcs8)) - .expect("from_pkcs8 in fullnode::Config keypair") - } -} diff --git a/fullnode-config/src/main.rs b/fullnode-config/src/main.rs deleted file mode 100644 index 073377b330..0000000000 --- a/fullnode-config/src/main.rs +++ /dev/null @@ -1,56 +0,0 @@ -use solana_sdk::signature::read_pkcs8; -use std::io; - -fn main() { - let matches = clap::App::new("solana-fullnode-config") - .version(clap::crate_version!()) - .arg( - clap::Arg::with_name("local") - .short("l") - .long("local") - .takes_value(false) - .help("Detect network address from local machine configuration"), - ) - .arg( - clap::Arg::with_name("keypair") - .short("k") - .long("keypair") - .value_name("PATH") - .takes_value(true) - .help("/path/to/id.json"), - ) - .arg( - clap::Arg::with_name("public") - .short("p") - .long("public") - .takes_value(false) - .help("Detect public network address using public servers"), - ) - .arg( - clap::Arg::with_name("bind") - .short("b") - .long("bind") - .value_name("PORT") - .takes_value(true) - .help("Bind to port or address"), - ) - .get_matches(); - - let mut path = dirs::home_dir().expect("home directory"); - let id_path = if matches.is_present("keypair") { - matches.value_of("keypair").unwrap() - } else { - path.extend(&[".config", "solana", "id.json"]); - path.to_str().unwrap() - }; - - let config = solana_fullnode_config::Config { - bind_port_or_address: matches.value_of("bind").map(|s| s.to_string()), - use_local_address: matches.is_present("local"), - use_public_address: matches.is_present("public"), - identity_pkcs8: read_pkcs8(id_path).expect("invalid keypair"), - }; - - let stdout = io::stdout(); - serde_json::to_writer(stdout, &config).expect("serialize"); -} diff --git a/fullnode/Cargo.toml b/fullnode/Cargo.toml index 5f1f63330e..18e5f39e6a 100644 --- a/fullnode/Cargo.toml +++ b/fullnode/Cargo.toml @@ -14,7 +14,6 @@ log = "0.4.2" serde_json = "1.0.39" solana = { path = "../core", version = "0.12.0" } solana-drone = { path = "../drone", version = "0.12.0" } -solana-fullnode-config = { path = "../fullnode-config", version = "0.12.0" } solana-logger = { path = "../logger", version = "0.12.0" } solana-netutil = { path = "../netutil", version = "0.12.0" } solana-metrics = { path = "../metrics", version = "0.12.0" } diff --git a/fullnode/src/main.rs b/fullnode/src/main.rs index 904ff0183f..de59cfc096 100644 --- a/fullnode/src/main.rs +++ b/fullnode/src/main.rs @@ -1,53 +1,23 @@ -use clap::{crate_version, App, Arg, ArgMatches}; +use clap::{crate_version, App, Arg}; use log::*; use solana::client::mk_client; use solana::cluster_info::{Node, NodeInfo, FULLNODE_PORT_RANGE}; use solana::fullnode::{Fullnode, FullnodeConfig}; use solana::local_vote_signer_service::LocalVoteSignerService; use solana::service::Service; -use solana::socketaddr; use solana::thin_client::{poll_gossip_for_leader, ThinClient}; use solana::voting_keypair::{RemoteVoteSigner, VotingKeypair}; use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::pubkey::Pubkey; -use solana_sdk::signature::{Keypair, KeypairUtil}; +use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil}; use solana_vote_api::vote_state::VoteState; use solana_vote_api::vote_transaction::VoteTransaction; use solana_vote_signer::rpc::{LocalVoteSigner, VoteSigner}; use std::fs::File; use std::io::{Error, ErrorKind, Result}; -use std::net::{Ipv4Addr, SocketAddr}; use std::process::exit; use std::sync::Arc; -fn parse_identity(matches: &ArgMatches<'_>) -> (Keypair, SocketAddr) { - if let Some(i) = matches.value_of("identity") { - let path = i.to_string(); - if let Ok(file) = File::open(path.clone()) { - let parse: serde_json::Result = - serde_json::from_reader(file); - - if let Ok(config_data) = parse { - let keypair = config_data.keypair(); - let node_info = NodeInfo::new_with_pubkey_socketaddr( - keypair.pubkey(), - &config_data.bind_addr(FULLNODE_PORT_RANGE.0), - ); - - (keypair, node_info.gossip) - } else { - eprintln!("failed to parse {}", path); - exit(1); - } - } else { - eprintln!("failed to read {}", path); - exit(1); - } - } else { - (Keypair::new(), socketaddr!(0, 8000)) - } -} - fn create_and_fund_vote_account( client: &mut ThinClient, vote_account: Pubkey, @@ -141,7 +111,7 @@ fn main() { .long("identity") .value_name("PATH") .takes_value(true) - .help("Run with the identity found in FILE"), + .help("File containing an identity (keypair)"), ) .arg( Arg::with_name("init_complete_file") @@ -183,6 +153,7 @@ fn main() { Arg::with_name("no_sigverify") .short("v") .long("no-sigverify") + .takes_value(false) .help("Run without signature verification"), ) .arg( @@ -208,15 +179,50 @@ fn main() { .takes_value(true) .help("Comma separated persistent accounts location"), ) + .arg( + clap::Arg::with_name("public_address") + .long("public-address") + .takes_value(false) + .help("Advertise public machine address in gossip. By default the local machine address is advertised"), + ) + .arg( + clap::Arg::with_name("gossip_port") + .long("gossip-port") + .value_name("PORT") + .takes_value(true) + .help("Gossip port number for the node"), + ) .get_matches(); let mut fullnode_config = FullnodeConfig::default(); + 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 ledger_path = matches.value_of("ledger").unwrap(); + fullnode_config.sigverify_disabled = matches.is_present("no_sigverify"); let no_signer = matches.is_present("no_signer"); fullnode_config.voting_disabled = no_signer; let use_only_bootstrap_leader = matches.is_present("no_leader_rotation"); - let (keypair, gossip) = parse_identity(&matches); - let ledger_path = matches.value_of("ledger").unwrap(); + + let gossip_addr = { + let mut addr = solana_netutil::parse_port_or_addr( + &matches.value_of("gossip_port"), + FULLNODE_PORT_RANGE.0 + 1, + ); + if matches.is_present("public_address") { + addr.set_ip(solana_netutil::get_public_ip_addr().unwrap()); + } else { + addr.set_ip(solana_netutil::get_ip_addr(false).unwrap()); + } + addr + }; + if let Some(paths) = matches.value_of("accounts") { fullnode_config.account_paths = Some(paths.to_string()); } else { @@ -254,7 +260,7 @@ fn main() { fullnode_config.blockstream = matches.value_of("blockstream").map(|s| s.to_string()); let keypair = Arc::new(keypair); - let mut node = Node::new_with_external_ip(keypair.pubkey(), &gossip); + let mut node = Node::new_with_external_ip(keypair.pubkey(), &gossip_addr); node.info.rpc.set_port(rpc_port); node.info.rpc_pubsub.set_port(rpc_pubsub_port); diff --git a/multinode-demo/bootstrap-leader.sh b/multinode-demo/bootstrap-leader.sh index 37500fc637..8e019b77aa 100755 --- a/multinode-demo/bootstrap-leader.sh +++ b/multinode-demo/bootstrap-leader.sh @@ -10,8 +10,8 @@ source "$here"/common.sh # shellcheck source=scripts/oom-score-adj.sh source "$here"/../scripts/oom-score-adj.sh -[[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader.json ]] || { - echo "$SOLANA_CONFIG_DIR/bootstrap-leader.json not found, create it by running:" +[[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json ]] || { + echo "$SOLANA_CONFIG_DIR/bootstrap-leader-id.json not found, create it by running:" echo echo " ${here}/setup.sh" exit 1 @@ -23,26 +23,6 @@ else program="$solana_fullnode" fi -maybe_blockstream= -maybe_init_complete_file= -maybe_no_leader_rotation= - -while [[ -n $1 ]]; do - if [[ $1 = --init-complete-file ]]; then - maybe_init_complete_file="--init-complete-file $2" - shift 2 - elif [[ $1 = --blockstream ]]; then - maybe_blockstream="$1 $2" - shift 2 - elif [[ $1 = --no-leader-rotation ]]; then - maybe_no_leader_rotation="--no-leader-rotation" - shift - else - echo "Unknown argument: $1" - exit 1 - fi -done - tune_system trap 'kill "$pid" && wait "$pid"' INT TERM @@ -50,13 +30,11 @@ $solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify # shellcheck disable=SC2086 # Don't want to double quote maybe_blockstream or maybe_init_complete_file $program \ - $maybe_blockstream \ - $maybe_init_complete_file \ - $maybe_no_leader_rotation \ - --identity "$SOLANA_CONFIG_DIR"/bootstrap-leader.json \ + --identity "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json \ --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger \ --accounts "$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts \ --rpc-port 8899 \ + "$@" \ > >($bootstrap_leader_logger) 2>&1 & pid=$! oom_score_adj "$pid" 1000 diff --git a/multinode-demo/common.sh b/multinode-demo/common.sh index 3700856296..7806dc47f5 100644 --- a/multinode-demo/common.sh +++ b/multinode-demo/common.sh @@ -60,7 +60,6 @@ solana_bench_tps=$(solana_program bench-tps) solana_wallet=$(solana_program wallet) solana_drone=$(solana_program drone) solana_fullnode=$(solana_program fullnode) -solana_fullnode_config=$(solana_program fullnode-config) solana_fullnode_cuda=$(solana_program fullnode-cuda) solana_genesis=$(solana_program genesis) solana_keygen=$(solana_program keygen) diff --git a/multinode-demo/fullnode.sh b/multinode-demo/fullnode.sh index e85d196965..89751f5ab4 100755 --- a/multinode-demo/fullnode.sh +++ b/multinode-demo/fullnode.sh @@ -25,6 +25,7 @@ Start a full node on the specified network --blockstream PATH - open blockstream at this unix domain socket location --init-complete-file FILE - create this file, if it doesn't already exist, once node initialization is complete --no-leader-rotation - disable leader rotation + --public-address - advertise public machine address in gossip. By default the local machine address is advertised --no-signer - start node without vote signer --rpc-port port - custom RPC port for this node @@ -36,7 +37,9 @@ if [[ $1 = -h ]]; then usage fi +gossip_port=9000 maybe_blockstream= +maybe_public_address= maybe_init_complete_file= maybe_no_leader_rotation= maybe_no_signer= @@ -56,13 +59,16 @@ while [[ ${1:0:1} = - ]]; do maybe_blockstream="$1 $2" shift 2 elif [[ $1 = --init-complete-file ]]; then - maybe_init_complete_file="--init-complete-file $2" + maybe_init_complete_file="$1 $2" shift 2 elif [[ $1 = --no-leader-rotation ]]; then - maybe_no_leader_rotation="--no-leader-rotation" + maybe_no_leader_rotation=$1 + shift + elif [[ $1 = --public-address ]]; then + maybe_public_address=$1 shift elif [[ $1 = --no-signer ]]; then - maybe_no_signer="--no-signer" + maybe_no_signer=$1 shift elif [[ $1 = --rpc-port ]]; then maybe_rpc_port="$1 $2" @@ -119,14 +125,13 @@ else fi if ((!self_setup)); then - [[ -f $SOLANA_CONFIG_DIR/fullnode.json ]] || { - echo "$SOLANA_CONFIG_DIR/fullnode.json not found, create it by running:" + [[ -f $SOLANA_CONFIG_DIR/fullnode-id.json ]] || { + echo "$SOLANA_CONFIG_DIR/fullnode-id.json not found, create it by running:" echo echo " ${here}/setup.sh" exit 1 } fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id.json - fullnode_json_path=$SOLANA_CONFIG_DIR/fullnode.json ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts else @@ -134,24 +139,18 @@ else fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id-x$self_setup_label.json [[ -f "$fullnode_id_path" ]] || $solana_keygen -o "$fullnode_id_path" - mkdir -p "$SOLANA_CONFIG_DIR" - fullnode_json_path=$SOLANA_CONFIG_DIR/fullnode-x$self_setup_label.json - [[ -f "$fullnode_json_path" ]] || { - echo "Finding a port.." - # Find an available port in the range 9100-9899 - (( port = 9100 + ($$ % 800) )) - while true; do - (( port = port >= 9900 ? 9100 : ++port )) - echo "Testing $port" - if ! nc -w 10 -z 127.0.0.1 $port; then - echo "Selected port $port" - break; - fi - echo "Port $port is in use" - done - $solana_fullnode_config --keypair="$fullnode_id_path" -l -b "$port" > "$fullnode_json_path" - } - + echo "Finding a port.." + # Find an available port in the range 9100-9899 + (( gossip_port = 9100 + ($$ % 800) )) + while true; do + (( gossip_port = gossip_port >= 9900 ? 9100 : ++gossip_port )) + echo "Testing $gossip_port" + if ! nc -w 10 -z 127.0.0.1 $gossip_port; then + echo "Selected gossip_port $gossip_port" + break; + fi + echo "Port $gossip_port is in use" + done ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger-x$self_setup_label accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts-x$self_setup_label fi @@ -219,14 +218,16 @@ if [[ ! -d "$ledger_config_dir" ]]; then fi trap 'kill "$pid" && wait "$pid"' INT TERM -# shellcheck disable=SC2086 # Don't want to double quote maybe_blockstream or maybe_init_complete_file or maybe_no_signer or maybe_rpc_port +# shellcheck disable=SC2086 # Don't want to double quote maybe_blockstream or maybe_init_complete_file or ... $program \ $maybe_blockstream \ $maybe_init_complete_file \ $maybe_no_leader_rotation \ $maybe_no_signer \ $maybe_rpc_port \ - --identity "$fullnode_json_path" \ + $maybe_public_address \ + --gossip-port "$gossip_port" \ + --identity "$fullnode_id_path" \ --network "$leader_address" \ --ledger "$ledger_config_dir" \ --accounts "$accounts_config_dir" \ diff --git a/multinode-demo/setup.sh b/multinode-demo/setup.sh index 48618d8b2b..bfee95ed95 100755 --- a/multinode-demo/setup.sh +++ b/multinode-demo/setup.sh @@ -19,9 +19,6 @@ usage: $0 [-n num_tokens] [-l] [-p] [-t node_type] Creates a fullnode configuration -n num_tokens - Number of tokens to create - -l - Detect network address from local machine configuration, which - may be a private IP address unaccessible on the Intenet (default) - -p - Detect public address using public Internet servers -t node_type - Create configuration files only for this kind of node. Valid options are bootstrap-leader or fullnode. Creates configuration files for both by default @@ -30,7 +27,6 @@ EOF exit $exitcode } -ip_address_arg=-l num_tokens=1000000000 bootstrap_leader=true fullnode=true @@ -40,12 +36,6 @@ while getopts "h?n:lpt:" opt; do usage exit 0 ;; - l) - ip_address_arg=-l - ;; - p) - ip_address_arg=-p - ;; n) num_tokens="$OPTARG" ;; @@ -91,26 +81,13 @@ if $bootstrap_leader; then --ledger "$SOLANA_RSYNC_CONFIG_DIR"/ledger \ --mint "$SOLANA_CONFIG_DIR"/mint-id.json \ --num_tokens "$num_tokens" - ) - - # Create bootstrap leader configuration - ( - set -x - $solana_fullnode_config \ - --keypair="$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json \ - "$ip_address_arg" > "$SOLANA_CONFIG_DIR"/bootstrap-leader.json - cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger ) fi - if $fullnode; then ( set -x $solana_keygen -o "$SOLANA_CONFIG_DIR"/fullnode-id.json - $solana_fullnode_config \ - --keypair="$SOLANA_CONFIG_DIR"/fullnode-id.json \ - "$ip_address_arg" -b 9000 > "$SOLANA_CONFIG_DIR"/fullnode.json ) fi diff --git a/net/remote/remote-node.sh b/net/remote/remote-node.sh index f84ee50b83..dfc887dcef 100755 --- a/net/remote/remote-node.sh +++ b/net/remote/remote-node.sh @@ -38,12 +38,6 @@ EOF source net/common.sh loadConfigFile -if [[ $publicNetwork = true ]]; then - setupArgs="-p" -else - setupArgs="-l" -fi - case $deployMethod in local|tar) PATH="$HOME"/.cargo/bin:"$PATH" @@ -76,7 +70,7 @@ local|tar) fi set -x if [[ $skipSetup != true ]]; then - ./multinode-demo/setup.sh -t bootstrap-leader $setupArgs + ./multinode-demo/setup.sh -t bootstrap-leader fi ./multinode-demo/drone.sh > drone.log 2>&1 & @@ -84,7 +78,12 @@ local|tar) if ! $leaderRotation; then maybeNoLeaderRotation="--no-leader-rotation" fi - ./multinode-demo/bootstrap-leader.sh $maybeNoLeaderRotation > bootstrap-leader.log 2>&1 & + maybePublicAddress= + if $publicNetwork; then + maybePublicAddress="--public-address" + fi + + ./multinode-demo/bootstrap-leader.sh $maybeNoLeaderRotation $maybePublicAddress > bootstrap-leader.log 2>&1 & ln -sTf bootstrap-leader.log fullnode.log ;; fullnode|blockstreamer) @@ -99,6 +98,9 @@ local|tar) if ! $leaderRotation; then args+=("--no-leader-rotation") fi + if $publicNetwork; then + args+=("--public-address") + fi if [[ $nodeType = blockstreamer ]]; then args+=( --blockstream /tmp/solana-blockstream.sock @@ -108,7 +110,7 @@ local|tar) set -x if [[ $skipSetup != true ]]; then - ./multinode-demo/setup.sh -t fullnode $setupArgs + ./multinode-demo/setup.sh -t fullnode fi if [[ $nodeType = blockstreamer ]]; then diff --git a/netutil/src/lib.rs b/netutil/src/lib.rs index 0d7fb48c69..2364cf8781 100644 --- a/netutil/src/lib.rs +++ b/netutil/src/lib.rs @@ -30,7 +30,7 @@ pub fn get_public_ip_addr() -> Result { } } -pub fn parse_port_or_addr(optstr: &Option, default_port: u16) -> SocketAddr { +pub fn parse_port_or_addr(optstr: &Option<&str>, default_port: u16) -> SocketAddr { let daddr = SocketAddr::from(([0, 0, 0, 0], default_port)); if let Some(addrstr) = optstr { @@ -293,11 +293,11 @@ mod tests { #[test] fn test_parse_port_or_addr() { - let p1 = parse_port_or_addr(&Some("9000".to_string()), 1); + let p1 = parse_port_or_addr(&Some("9000"), 1); assert_eq!(p1.port(), 9000); - let p2 = parse_port_or_addr(&Some("127.0.0.1:7000".to_string()), 1); + let p2 = parse_port_or_addr(&Some("127.0.0.1:7000"), 1); assert_eq!(p2.port(), 7000); - let p2 = parse_port_or_addr(&Some("hi there".to_string()), 1); + let p2 = parse_port_or_addr(&Some("hi there"), 1); assert_eq!(p2.port(), 1); let p3 = parse_port_or_addr(&None, 1); assert_eq!(p3.port(), 1); diff --git a/replicator/Cargo.toml b/replicator/Cargo.toml index d6c2f77c14..28bfb4e293 100644 --- a/replicator/Cargo.toml +++ b/replicator/Cargo.toml @@ -9,10 +9,9 @@ homepage = "https://solana.com/" [dependencies] clap = "2.32.0" -serde_json = "1.0.39" solana = { path = "../core", version = "0.12.0" } solana-logger = { path = "../logger", version = "0.12.0" } -solana-fullnode-config = { path = "../fullnode-config", version = "0.12.0" } +solana-netutil = { path = "../netutil", version = "0.12.0" } solana-sdk = { path = "../sdk", version = "0.12.0" } [features] diff --git a/replicator/src/main.rs b/replicator/src/main.rs index c7896afed9..bfbe7033b0 100644 --- a/replicator/src/main.rs +++ b/replicator/src/main.rs @@ -1,10 +1,8 @@ use clap::{crate_version, App, Arg}; -use serde_json; -use solana::cluster_info::{Node, NodeInfo, FULLNODE_PORT_RANGE}; +use solana::cluster_info::{Node, NodeInfo}; use solana::replicator::Replicator; use solana::socketaddr; -use solana_sdk::signature::{Keypair, KeypairUtil}; -use std::fs::File; +use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil}; use std::net::{Ipv4Addr, SocketAddr}; use std::process::exit; @@ -19,7 +17,7 @@ fn main() { .long("identity") .value_name("PATH") .takes_value(true) - .help("Run with the identity found in FILE"), + .help("File containing an identity (keypair)"), ) .arg( Arg::with_name("network") @@ -39,40 +37,40 @@ fn main() { .required(true) .help("use DIR as persistent ledger location"), ) + .arg( + clap::Arg::with_name("public_address") + .long("public-address") + .takes_value(false) + .help("Advertise public machine address in gossip. By default the local machine address is advertised"), + ) .get_matches(); let ledger_path = matches.value_of("ledger").unwrap(); - let (keypair, gossip) = if let Some(i) = matches.value_of("identity") { - let path = i.to_string(); - if let Ok(file) = File::open(path.clone()) { - let parse: serde_json::Result = - serde_json::from_reader(file); - if let Ok(config_data) = parse { - let keypair = config_data.keypair(); - let node_info = NodeInfo::new_with_pubkey_socketaddr( - keypair.pubkey(), - &config_data.bind_addr(FULLNODE_PORT_RANGE.0), - ); - (keypair, node_info.gossip) - } else { - eprintln!("failed to parse {}", path); - exit(1); - } - } else { - eprintln!("failed to read {}", path); + 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(), socketaddr!([127, 0, 0, 1], 8700)) + Keypair::new() }; - let node = Node::new_with_external_ip(keypair.pubkey(), &gossip); + let gossip_addr = { + let mut addr = socketaddr!([127, 0, 0, 1], 8700); + if matches.is_present("public_address") { + addr.set_ip(solana_netutil::get_public_ip_addr().unwrap()); + } else { + addr.set_ip(solana_netutil::get_ip_addr(false).unwrap()); + } + addr + }; + let node = Node::new_with_external_ip(keypair.pubkey(), &gossip_addr); println!( - "replicating the data with keypair: {:?} gossip:{:?}", + "replicating the data with keypair={:?} gossip_addr={:?}", keypair.pubkey(), - gossip + gossip_addr ); let network_addr = matches diff --git a/run.sh b/run.sh index a7ba821e98..5103b338e7 100755 --- a/run.sh +++ b/run.sh @@ -42,8 +42,6 @@ set -x solana-keygen -o "$dataDir"/config/leader-keypair.json solana-keygen -o "$dataDir"/config/drone-keypair.json -solana-fullnode-config \ - --keypair="$dataDir"/config/leader-keypair.json -l > "$dataDir"/config/leader-config.json solana-genesis \ --num_tokens 1000000000 \ --mint "$dataDir"/config/drone-keypair.json \ @@ -54,7 +52,7 @@ solana-drone --keypair "$dataDir"/config/drone-keypair.json & drone=$! args=( - --identity "$dataDir"/config/leader-config.json + --identity "$dataDir"/config/leader-keypair.json --ledger "$dataDir"/ledger/ --rpc-port 8899 ) diff --git a/scripts/cargo-install-all.sh b/scripts/cargo-install-all.sh index 61d7d3914d..3cc0c6aeee 100755 --- a/scripts/cargo-install-all.sh +++ b/scripts/cargo-install-all.sh @@ -27,7 +27,6 @@ BIN_CRATES=( fullnode bench-streamer bench-tps - fullnode-config genesis ledger-tool wallet