Add stop node command to solana-gossip (#3928)
This commit is contained in:
		
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -2483,6 +2483,7 @@ dependencies = [
 | 
			
		||||
 "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
 | 
			
		||||
 "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
 | 
			
		||||
 "solana 0.14.0",
 | 
			
		||||
 "solana-client 0.14.0",
 | 
			
		||||
 "solana-netutil 0.14.0",
 | 
			
		||||
 "solana-sdk 0.14.0",
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ Inspect the blockexplorer at [http://beta.testnet.solana.com/](http://beta.testn
 | 
			
		||||
 | 
			
		||||
Run the following command to join the gossip network and view all the other nodes in the cluster:
 | 
			
		||||
```bash
 | 
			
		||||
$ solana-gossip --network beta.testnet.solana.com:8001
 | 
			
		||||
$ solana-gossip --network beta.testnet.solana.com:8001 spy
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
View the [metrics dashboard](
 | 
			
		||||
 
 | 
			
		||||
@@ -306,8 +306,7 @@ while [[ $iteration -le $iterations ]]; do
 | 
			
		||||
    set -x
 | 
			
		||||
    client_id=/tmp/client-id.json-$$
 | 
			
		||||
    $solana_keygen -o $client_id || exit $?
 | 
			
		||||
    $solana_gossip \
 | 
			
		||||
      --num-nodes-exactly $numNodes || exit $?
 | 
			
		||||
    $solana_gossip spy --num-nodes-exactly $numNodes || exit $?
 | 
			
		||||
    rm -rf $client_id
 | 
			
		||||
  ) || flag_error
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ homepage = "https://solana.com/"
 | 
			
		||||
clap = "2.33.0"
 | 
			
		||||
env_logger = "0.6.1"
 | 
			
		||||
solana = { path = "../core", version = "0.14.0" }
 | 
			
		||||
solana-client = { path = "../client", version = "0.14.0"  }
 | 
			
		||||
solana-netutil = { path = "../netutil", version = "0.14.0" }
 | 
			
		||||
solana-sdk = { path = "../sdk", version = "0.14.0" }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,9 @@
 | 
			
		||||
//! A command-line executable for monitoring a cluster's gossip plane.
 | 
			
		||||
 | 
			
		||||
use clap::{crate_description, crate_name, crate_version, App, Arg};
 | 
			
		||||
use clap::{crate_description, crate_name, crate_version, App, AppSettings, Arg, SubCommand};
 | 
			
		||||
use solana::contact_info::ContactInfo;
 | 
			
		||||
use solana::gossip_service::discover;
 | 
			
		||||
use solana_client::rpc_client::RpcClient;
 | 
			
		||||
use solana_sdk::pubkey::Pubkey;
 | 
			
		||||
use std::error;
 | 
			
		||||
use std::net::SocketAddr;
 | 
			
		||||
@@ -22,6 +24,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
 | 
			
		||||
    let matches = App::new(crate_name!())
 | 
			
		||||
        .about(crate_description!())
 | 
			
		||||
        .version(crate_version!())
 | 
			
		||||
        .setting(AppSettings::SubcommandRequiredElseHelp)
 | 
			
		||||
        .arg(
 | 
			
		||||
            Arg::with_name("network")
 | 
			
		||||
                .short("n")
 | 
			
		||||
@@ -31,6 +34,10 @@ fn main() -> Result<(), Box<dyn error::Error>> {
 | 
			
		||||
                .default_value(&network_string)
 | 
			
		||||
                .help("Rendezvous with the cluster at this gossip entry point"),
 | 
			
		||||
        )
 | 
			
		||||
        .subcommand(
 | 
			
		||||
            SubCommand::with_name("spy")
 | 
			
		||||
                .about("Monitor the gossip network")
 | 
			
		||||
                .setting(AppSettings::DisableVersion)
 | 
			
		||||
                .arg(
 | 
			
		||||
                    Arg::with_name("num_nodes")
 | 
			
		||||
                        .short("N")
 | 
			
		||||
@@ -62,7 +69,23 @@ fn main() -> Result<(), Box<dyn error::Error>> {
 | 
			
		||||
                        .long("timeout")
 | 
			
		||||
                        .value_name("SECS")
 | 
			
		||||
                        .takes_value(true)
 | 
			
		||||
                .help("Maximum time to wait for cluster to converge [default: wait forever]"),
 | 
			
		||||
                        .help(
 | 
			
		||||
                            "Maximum time to wait for cluster to converge [default: wait forever]",
 | 
			
		||||
                        ),
 | 
			
		||||
                ),
 | 
			
		||||
        )
 | 
			
		||||
        .subcommand(
 | 
			
		||||
            SubCommand::with_name("stop")
 | 
			
		||||
                .about("Send stop request to a node")
 | 
			
		||||
                .setting(AppSettings::DisableVersion)
 | 
			
		||||
                .arg(
 | 
			
		||||
                    Arg::with_name("node_pubkey")
 | 
			
		||||
                        .index(1)
 | 
			
		||||
                        .required(true)
 | 
			
		||||
                        .value_name("PUBKEY")
 | 
			
		||||
                        .validator(pubkey_validator)
 | 
			
		||||
                        .help("Public key of a specific node to stop"),
 | 
			
		||||
                ),
 | 
			
		||||
        )
 | 
			
		||||
        .get_matches();
 | 
			
		||||
 | 
			
		||||
@@ -72,7 +95,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
 | 
			
		||||
            exit(1)
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    match matches.subcommand() {
 | 
			
		||||
        ("spy", Some(matches)) => {
 | 
			
		||||
            let num_nodes_exactly = matches
 | 
			
		||||
                .value_of("num_nodes_exactly")
 | 
			
		||||
                .map(|num| num.to_string().parse().unwrap());
 | 
			
		||||
@@ -115,5 +139,30 @@ fn main() -> Result<(), Box<dyn error::Error>> {
 | 
			
		||||
                    num_nodes_exactly.unwrap()
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        ("stop", Some(matches)) => {
 | 
			
		||||
            let pubkey = matches
 | 
			
		||||
                .value_of("node_pubkey")
 | 
			
		||||
                .unwrap()
 | 
			
		||||
                .parse::<Pubkey>()
 | 
			
		||||
                .unwrap();
 | 
			
		||||
            let nodes = discover(&network_addr, None, None, Some(pubkey))?;
 | 
			
		||||
            let node = nodes.iter().find(|x| x.id == pubkey).unwrap();
 | 
			
		||||
 | 
			
		||||
            if !ContactInfo::is_valid_address(&node.rpc) {
 | 
			
		||||
                eprintln!("Error: RPC service is not enabled on node {:?}", pubkey);
 | 
			
		||||
            }
 | 
			
		||||
            println!("\nSending stop request to node {:?}", pubkey);
 | 
			
		||||
 | 
			
		||||
            let result = RpcClient::new_socket(node.rpc).fullnode_exit()?;
 | 
			
		||||
            if result {
 | 
			
		||||
                println!("Stop signal accepted");
 | 
			
		||||
            } else {
 | 
			
		||||
                eprintln!("Error: Stop signal ignored");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        _ => unreachable!(),
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -81,12 +81,13 @@ local|tar)
 | 
			
		||||
    fi
 | 
			
		||||
    ./multinode-demo/drone.sh > drone.log 2>&1 &
 | 
			
		||||
 | 
			
		||||
    maybePublicAddress=
 | 
			
		||||
    args=()
 | 
			
		||||
    if $publicNetwork; then
 | 
			
		||||
      maybePublicAddress="--public-address"
 | 
			
		||||
      args+=(--public-address)
 | 
			
		||||
    fi
 | 
			
		||||
    args+=(--enable-rpc-exit)
 | 
			
		||||
 | 
			
		||||
    ./multinode-demo/bootstrap-leader.sh $maybePublicAddress > bootstrap-leader.log 2>&1 &
 | 
			
		||||
    ./multinode-demo/bootstrap-leader.sh "${args[@]}" > bootstrap-leader.log 2>&1 &
 | 
			
		||||
    ln -sTf bootstrap-leader.log fullnode.log
 | 
			
		||||
    ;;
 | 
			
		||||
  fullnode|blockstreamer)
 | 
			
		||||
@@ -116,6 +117,7 @@ local|tar)
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    args+=(
 | 
			
		||||
      --enable-rpc-exit
 | 
			
		||||
      --gossip-port 8001
 | 
			
		||||
      --rpc-port 8899
 | 
			
		||||
    )
 | 
			
		||||
@@ -147,7 +149,9 @@ local|tar)
 | 
			
		||||
      # Confirm the blockexplorer is now globally accessible
 | 
			
		||||
      curl --head "$(curl ifconfig.io)"
 | 
			
		||||
    fi
 | 
			
		||||
    ./multinode-demo/fullnode.sh "${args[@]}" "$entrypointIp":~/solana "$entrypointIp:8001" > fullnode.log 2>&1 &
 | 
			
		||||
 | 
			
		||||
    args+=("$entrypointIp":~/solana "$entrypointIp:8001")
 | 
			
		||||
    ./multinode-demo/fullnode.sh "${args[@]}" > fullnode.log 2>&1 &
 | 
			
		||||
    ;;
 | 
			
		||||
  *)
 | 
			
		||||
    echo "Error: unknown node type: $nodeType"
 | 
			
		||||
 
 | 
			
		||||
@@ -89,9 +89,8 @@ echo "+++ $entrypointIp: node count ($numNodes expected)"
 | 
			
		||||
    nodeArg="num-nodes-exactly"
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  timeout 2m $solana_gossip \
 | 
			
		||||
    --network "$entrypointIp:8001" \
 | 
			
		||||
    --$nodeArg "$numNodes" \
 | 
			
		||||
  timeout 2m $solana_gossip --network "$entrypointIp:8001" \
 | 
			
		||||
    spy --$nodeArg "$numNodes" \
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
echo "--- RPC API: getTransactionCount"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user