Skip to content

Commit

Permalink
Add a node-specific ip echo service to remove dependency on ifconfig.…
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 3, 2019
1 parent 6e6fe5b commit 504415f
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 275 deletions.
6 changes: 3 additions & 3 deletions book/src/testnet-participation.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ Then the following command will start a new validator node.
If this is a `solana-install`-installation:
```bash
$ clear-fullnode-config.sh
$ fullnode.sh --public-address --poll-for-new-genesis-block testnet.solana.com
$ fullnode.sh --poll-for-new-genesis-block testnet.solana.com
```

Alternatively, the `solana-install run` command can be used to run the validator
node while periodically checking for and applying software updates:
```bash
$ clear-fullnode-config.sh
$ solana-install run fullnode.sh -- --public-address --poll-for-new-genesis-block testnet.solana.com
$ solana-install run fullnode.sh -- --poll-for-new-genesis-block testnet.solana.com
```

If you built from source:
```bash
$ USE_INSTALL=1 ./multinode-demo/clear-fullnode-config.sh
$ USE_INSTALL=1 ./multinode-demo/fullnode.sh --public-address --poll-for-new-genesis-block testnet.solana.com
$ USE_INSTALL=1 ./multinode-demo/fullnode.sh --poll-for-new-genesis-block testnet.solana.com
```

#### Controlling local network port allocation
Expand Down
12 changes: 6 additions & 6 deletions ci/nits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ declare prints=(
# Parts of the tree that are expected to be print free
declare print_free_tree=(
'core/src'
'drone'
'metrics'
'netutil'
'runtime'
'sdk'
'drone/src'
'metrics/src'
'netutil/src'
'runtime/src'
'sdk/src'
)

if _ git grep "${prints[@]/#/-e }" -- "${print_free_tree[@]}"; then
if _ git grep --max-depth=0 "${prints[@]/#/-e }" -- "${print_free_tree[@]}"; then
exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions core/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::signature::{Signable, Signature};
use solana_sdk::timing::timestamp;
use std::cmp::{Ord, Ordering, PartialEq, PartialOrd};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::net::{IpAddr, SocketAddr};

/// Structure representing a node on the network
#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Eq for ContactInfo {}
#[macro_export]
macro_rules! socketaddr {
($ip:expr, $port:expr) => {
std::net::SocketAddr::from((Ipv4Addr::from($ip), $port))
std::net::SocketAddr::from((std::net::Ipv4Addr::from($ip), $port))
};
($str:expr) => {{
let a: std::net::SocketAddr = $str.parse().unwrap();
Expand Down
6 changes: 6 additions & 0 deletions core/src/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct Fullnode {
poh_service: PohService,
tpu: Tpu,
tvu: Tvu,
ip_echo_server: solana_netutil::IpEchoServer,
}

impl Fullnode {
Expand Down Expand Up @@ -159,6 +160,9 @@ impl Fullnode {
))
};

let ip_echo_server =
solana_netutil::ip_echo_server(node.sockets.gossip.local_addr().unwrap().port());

let subscriptions = Arc::new(RpcSubscriptions::default());
let rpc_pubsub_service = if node.info.rpc_pubsub.port() == 0 {
None
Expand Down Expand Up @@ -271,6 +275,7 @@ impl Fullnode {
exit,
poh_service,
poh_recorder,
ip_echo_server,
}
}

Expand Down Expand Up @@ -330,6 +335,7 @@ impl Service for Fullnode {
self.gossip_service.join()?;
self.tpu.join()?;
self.tvu.join()?;
self.ip_echo_server.shutdown_now();

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ mod tests {
use solana_sdk::system_transaction;
use std::io;
use std::io::Write;
use std::net::{Ipv4Addr, SocketAddr, UdpSocket};
use std::net::{SocketAddr, UdpSocket};

#[test]
fn test_packets_set_addr() {
Expand Down
34 changes: 13 additions & 21 deletions fullnode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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;
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
use std::fs::File;
Expand Down Expand Up @@ -131,16 +132,10 @@ 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")
.value_name("HOST:PORT")
.takes_value(true)
.help("Gossip port number for the node"),
)
Expand Down Expand Up @@ -195,29 +190,26 @@ fn main() {
let dynamic_port_range = parse_port_range(matches.value_of("dynamic_port_range").unwrap())
.expect("invalid dynamic_port_range");

let gossip_addr = {
let mut addr = solana_netutil::parse_port_or_addr(
matches.value_of("gossip_port"),
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 allocate gossip_port"),
);
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
};
.expect("unable to find an available gossip port")
),
);

if let Some(paths) = matches.value_of("accounts") {
fullnode_config.account_paths = Some(paths.to_string());
} else {
fullnode_config.account_paths = None;
}
let cluster_entrypoint = matches.value_of("network").map(|network| {
let gossip_addr =
let entrypoint_addr =
solana_netutil::parse_host_port(network).expect("failed to parse network address");
ContactInfo::new_gossip_entry_point(&gossip_addr)
gossip_addr.set_ip(solana_netutil::get_public_ip_addr(&entrypoint_addr).unwrap());

ContactInfo::new_gossip_entry_point(&entrypoint_addr)
});
let (_signer_service, _signer_addr) = if let Some(signer_addr) = matches.value_of("signer") {
(
Expand Down
23 changes: 12 additions & 11 deletions multinode-demo/bootstrap-leader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ bootstrap_leader_vote_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-id.json
bootstrap_leader_vote_id=$($solana_keygen pubkey "$bootstrap_leader_vote_id_path")

trap 'kill "$pid" && wait "$pid"' INT TERM ERR
$program \
--identity "$bootstrap_leader_id_path" \
--voting-keypair "$bootstrap_leader_vote_id_path" \
--vote-account "$bootstrap_leader_vote_id" \
--ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger \
--accounts "$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts \
--gossip-port 8001 \
--rpc-port 8899 \
--rpc-drone-address 127.0.0.1:9900 \
"${extra_fullnode_args[@]}" \
> >($bootstrap_leader_logger) 2>&1 &

default_fullnode_arg --identity "$bootstrap_leader_id_path"
default_fullnode_arg --voting-keypair "$bootstrap_leader_vote_id_path"
default_fullnode_arg --vote-account "$bootstrap_leader_vote_id"
default_fullnode_arg --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger
default_fullnode_arg --accounts "$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts
default_fullnode_arg --rpc-port 8899
default_fullnode_arg --rpc-drone-address 127.0.0.1:9900
default_fullnode_arg --gossip-port 8001

echo "$PS4 $program ${extra_fullnode_args[*]}"
$program "${extra_fullnode_args[@]}" > >($bootstrap_leader_logger) 2>&1 &
pid=$!
oom_score_adj "$pid" 1000

Expand Down
1 change: 0 additions & 1 deletion multinode-demo/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ Start a full node
--label LABEL - Append the given label to the fullnode configuration files, useful when running
multiple fullnodes from the same filesystem location
--stake LAMPORTS - Number of lamports to stake
--public-address - advertise public machine address in gossip. By default the local machine address is advertised
--no-voting - start node without vote signer
--rpc-port port - custom RPC port for this node
Expand Down
20 changes: 17 additions & 3 deletions multinode-demo/extra-fullnode-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ while [[ ${1:0:1} = - ]]; do
elif [[ $1 = --init-complete-file ]]; then
extra_fullnode_args+=("$1" "$2")
shift 2
elif [[ $1 = --public-address ]]; then
extra_fullnode_args+=("$1")
shift
elif [[ $1 = --stake ]]; then
stake="$2"
shift 2
Expand Down Expand Up @@ -64,3 +61,20 @@ done
if [[ -n $3 ]]; then
fullnode_usage "$@"
fi

default_fullnode_arg() {
declare name=$1
declare value=$2

for arg in "${extra_fullnode_args[@]}"; do
if [[ $arg = "$name" ]]; then
return
fi
done

if [[ -n $value ]]; then
extra_fullnode_args+=("$name" "$value")
else
extra_fullnode_args+=("$name")
fi
}
22 changes: 10 additions & 12 deletions multinode-demo/fullnode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,21 @@ while true; do
if ((stake)); then
setup_vote_account "${leader_address%:*}" "$fullnode_id_path" "$fullnode_vote_id_path" "$stake"
fi
set +x

$program \
--identity "$fullnode_id_path" \
--voting-keypair "$fullnode_vote_id_path" \
--vote-account "$fullnode_vote_id" \
--network "$leader_address" \
--ledger "$ledger_config_dir" \
--accounts "$accounts_config_dir" \
--rpc-drone-address "${leader_address%:*}:9900" \
"${extra_fullnode_args[@]}" \
> >($fullnode_logger) 2>&1 &
default_fullnode_arg --identity "$fullnode_id_path"
default_fullnode_arg --voting-keypair "$fullnode_vote_id_path"
default_fullnode_arg --vote-account "$fullnode_vote_id"
default_fullnode_arg --network "$leader_address"
default_fullnode_arg --ledger "$ledger_config_dir"
default_fullnode_arg --accounts "$accounts_config_dir"
default_fullnode_arg --rpc-drone-address "${leader_address%:*}:9900"
echo "$PS4 $program ${extra_fullnode_args[*]}"
$program "${extra_fullnode_args[@]}" > >($fullnode_logger) 2>&1 &
pid=$!
oom_score_adj "$pid" 1000

set +x
while true; do

if ! kill -0 "$pid"; then
wait "$pid"
exit 0
Expand Down
2 changes: 1 addition & 1 deletion net/gce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ EOF
echo "Waiting for $name to finish booting..."
(
set -x +e
for i in $(seq 1 30); do
for i in $(seq 1 60); do
timeout --preserve-status --foreground 20s ssh "${sshOptions[@]}" "$publicIp" "ls -l /.instance-startup-complete"
ret=$?
if [[ $ret -eq 0 ]]; then
Expand Down
2 changes: 0 additions & 2 deletions net/net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ startBootstrapLeader() {
"./solana/net/remote/remote-node.sh \
$deployMethod \
bootstrap-leader \
$publicNetwork \
$entrypointIp \
$((${#fullnodeIpList[@]} + ${#blockstreamerIpList[@]})) \
\"$RUST_LOG\" \
Expand Down Expand Up @@ -319,7 +318,6 @@ startNode() {
"./solana/net/remote/remote-node.sh \
$deployMethod \
$nodeType \
$publicNetwork \
$entrypointIp \
$((${#fullnodeIpList[@]} + ${#blockstreamerIpList[@]})) \
\"$RUST_LOG\" \
Expand Down
26 changes: 10 additions & 16 deletions net/remote/remote-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ cd "$(dirname "$0")"/../..
set -x
deployMethod="$1"
nodeType="$2"
publicNetwork="$3"
entrypointIp="$4"
numNodes="$5"
RUST_LOG="$6"
skipSetup="$7"
leaderRotation="$8"
failOnValidatorBootupFailure="$9"
entrypointIp="$3"
numNodes="$4"
RUST_LOG="$5"
skipSetup="$6"
leaderRotation="$7"
failOnValidatorBootupFailure="$8"
set +x
export RUST_LOG

Expand All @@ -31,7 +30,6 @@ missing() {

[[ -n $deployMethod ]] || missing deployMethod
[[ -n $nodeType ]] || missing nodeType
[[ -n $publicNetwork ]] || missing publicNetwork
[[ -n $entrypointIp ]] || missing entrypointIp
[[ -n $numNodes ]] || missing numNodes
[[ -n $skipSetup ]] || missing skipSetup
Expand Down Expand Up @@ -84,11 +82,10 @@ local|tar)
fi
./multinode-demo/drone.sh > drone.log 2>&1 &

args=()
if $publicNetwork; then
args+=(--public-address)
fi
args+=(--enable-rpc-exit)
args=(
--enable-rpc-exit
--gossip-port "$entrypointIp":8001
)

./multinode-demo/bootstrap-leader.sh "${args[@]}" > bootstrap-leader.log 2>&1 &
ln -sTf bootstrap-leader.log fullnode.log
Expand All @@ -102,9 +99,6 @@ local|tar)
fi

args=()
if $publicNetwork; then
args+=("--public-address")
fi
if [[ $nodeType = blockstreamer ]]; then
args+=(
--blockstream /tmp/solana-blockstream.sock
Expand Down
16 changes: 11 additions & 5 deletions netutil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ homepage = "https://solana.com/"
edition = "2018"

[dependencies]
bincode = "1.1.3"
clap = "2.33.0"
log = "0.4.2"
ipnetwork = "0.12.7"
nix = "0.12.0"
pnet_datalink = "0.21.0"
rand = "0.6.1"
reqwest = "0.9.0"
socket2 = "0.3.8"

[dev-dependencies]
solana-logger = { path = "../logger", version = "0.14.1" }
tokio = "0.1"

[lib]
name = "solana_netutil"

[[bin]]
name = "solana-ip-address"
path = "src/bin/ip_address.rs"

[[bin]]
name = "solana-ip-address-server"
path = "src/bin/ip_address_server.rs"
Loading

0 comments on commit 504415f

Please sign in to comment.