Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse request UDP port for responses in fullnode #530

Merged
merged 5 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Cargo.lock
/config-private/
/config-drone/
/config-validator/
/config-client-demo/
/config-client/
2 changes: 1 addition & 1 deletion multinode-demo/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
here=$(dirname "$0")
# shellcheck source=multinode-demo/common.sh
source "$here"/common.sh
SOLANA_CONFIG_DIR=config-client-demo
SOLANA_CONFIG_DIR=config-client

leader=${1:-${here}/..} # Default to local solana repo
count=${2:-1}
Expand Down
35 changes: 35 additions & 0 deletions multinode-demo/test/wallet-sanity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -e
#
# Wallet sanity test
#

here=$(dirname "$0")
cd "$here"

wallet="../wallet.sh $1"

# Tokens transferred to this address are lost forever...
garbage_address=vS3ngn1TfQmpsW1Z4NkLuqNAQFF3dYQw8UZ6TCx9bmq

check_balance_output() {
declare expected_output="$1"
exec 42>&1
output=$($wallet balance | tee >(cat - >&42))
if [[ ! "$output" =~ $expected_output ]]; then
echo "Balance is incorrect. Expected: $expected_output"
exit 1
fi
}

# Ensure a fresh client configuration every time
rm -rf config-client

$wallet address
check_balance_output "No account found! Request an airdrop to get started"
$wallet airdrop --tokens 100
check_balance_output "Your balance is: 100"
$wallet pay --to $garbage_address --tokens 100
check_balance_output "Your balance is: 0"

echo PASS
exit 0
2 changes: 1 addition & 1 deletion multinode-demo/wallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
here=$(dirname "$0")
# shellcheck source=multinode-demo/common.sh
source "$here"/common.sh
SOLANA_CONFIG_DIR=config-client-demo
SOLANA_CONFIG_DIR=config-client

leader=${1:-${here}/..} # Default to local solana repo
shift
Expand Down
12 changes: 5 additions & 7 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,18 @@ fn main() {
}

fn mk_client(r: &ReplicatedData) -> ThinClient {
let transactions_socket_pair = udp_public_bind("transactions");
let requests_socket_pair = udp_public_bind("requests");
let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();

requests_socket_pair
.receiver
requests_socket
.set_read_timeout(Some(Duration::new(1, 0)))
.unwrap();

ThinClient::new(
r.requests_addr,
requests_socket_pair.sender,
requests_socket_pair.receiver,
requests_socket,
r.transactions_addr,
transactions_socket_pair.sender,
transactions_socket,
)
}

Expand Down
5 changes: 2 additions & 3 deletions src/bin/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern crate tokio_io;
use atty::{is, Stream as atty_stream};
use bincode::deserialize;
use getopts::Options;
use solana::crdt::{get_ip_addr, ReplicatedData};
use solana::crdt::ReplicatedData;
use solana::drone::{Drone, DroneRequest};
use solana::mint::Mint;
use std::env;
Expand Down Expand Up @@ -103,8 +103,7 @@ fn main() {

let mint_keypair = mint.keypair();

let mut drone_addr: SocketAddr = "0.0.0.0:9900".parse().unwrap();
drone_addr.set_ip(get_ip_addr().unwrap());
let drone_addr: SocketAddr = "0.0.0.0:9900".parse().unwrap();

let drone = Arc::new(Mutex::new(Drone::new(
mint_keypair,
Expand Down
10 changes: 8 additions & 2 deletions src/bin/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,22 @@ fn main() {
Box::new(stdout())
};

let requests_socket = UdpSocket::bind(local_requests_addr).unwrap();
// Responses are sent from the same Udp port as requests are received
// from, in hopes that a NAT sitting in the middle will route the
// response Udp packet correctly back to the requester.
let respond_socket = requests_socket.try_clone().unwrap();

let server = Server::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
repl_data.clone(),
UdpSocket::bind(local_requests_addr).unwrap(),
requests_socket,
UdpSocket::bind(local_transactions_addr).unwrap(),
UdpSocket::bind("0.0.0.0:0").unwrap(),
UdpSocket::bind("0.0.0.0:0").unwrap(),
respond_socket,
UdpSocket::bind(local_gossip_addr).unwrap(),
exit.clone(),
outfile,
Expand Down
15 changes: 6 additions & 9 deletions src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ use clap::{App, Arg, SubCommand};
use solana::crdt::ReplicatedData;
use solana::drone::DroneRequest;
use solana::mint::Mint;
use solana::nat::udp_public_bind;
use solana::signature::{PublicKey, Signature};
use solana::thin_client::ThinClient;
use std::error;
use std::fmt;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream, UdpSocket};
use std::process::exit;
use std::thread::sleep;
use std::time::Duration;
Expand Down Expand Up @@ -288,19 +287,17 @@ fn read_mint(path: String) -> Result<Mint, Box<error::Error>> {
}

fn mk_client(r: &ReplicatedData) -> io::Result<ThinClient> {
let transactions_socket_pair = udp_public_bind("transactions");
let requests_socket_pair = udp_public_bind("requests");
requests_socket_pair
.receiver
let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
requests_socket
.set_read_timeout(Some(Duration::new(1, 0)))
.unwrap();

Ok(ThinClient::new(
r.requests_addr,
requests_socket_pair.sender,
requests_socket_pair.receiver,
requests_socket,
r.transactions_addr,
transactions_socket_pair.sender,
transactions_socket,
))
}

Expand Down
2 changes: 0 additions & 2 deletions src/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl Drone {

let mut client = ThinClient::new(
self.requests_addr,
requests_socket.try_clone().unwrap(),
requests_socket,
self.transactions_addr,
transactions_socket,
Expand Down Expand Up @@ -293,7 +292,6 @@ mod tests {

let mut client = ThinClient::new(
leader.data.requests_addr,
requests_socket.try_clone().unwrap(),
requests_socket,
leader.data.transactions_addr,
transactions_socket,
Expand Down
22 changes: 8 additions & 14 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use transaction::Transaction;
/// An object for querying and sending transactions to the network.
pub struct ThinClient {
requests_addr: SocketAddr,
requests_sender: UdpSocket,
requests_receiver: UdpSocket,
requests_socket: UdpSocket,
transactions_addr: SocketAddr,
transactions_socket: UdpSocket,
last_id: Option<Hash>,
Expand All @@ -31,15 +30,13 @@ impl ThinClient {
/// to a public address before invoking ThinClient methods.
pub fn new(
requests_addr: SocketAddr,
requests_sender: UdpSocket,
requests_receiver: UdpSocket,
requests_socket: UdpSocket,
transactions_addr: SocketAddr,
transactions_socket: UdpSocket,
) -> Self {
let client = ThinClient {
requests_addr,
requests_sender,
requests_receiver,
requests_socket,
transactions_addr,
transactions_socket,
last_id: None,
Expand All @@ -53,7 +50,7 @@ impl ThinClient {
pub fn recv_response(&self) -> io::Result<Response> {
let mut buf = vec![0u8; 1024];
trace!("start recv_from");
self.requests_receiver.recv_from(&mut buf)?;
self.requests_socket.recv_from(&mut buf)?;
trace!("end recv_from");
let resp = deserialize(&buf).expect("deserialize balance in thin_client");
Ok(resp)
Expand Down Expand Up @@ -115,7 +112,7 @@ impl ThinClient {
trace!("get_balance");
let req = Request::GetBalance { key: *pubkey };
let data = serialize(&req).expect("serialize GetBalance in pub fn get_balance");
self.requests_sender
self.requests_socket
.send_to(&data, &self.requests_addr)
.expect("buffer error in pub fn get_balance");
let mut done = false;
Expand All @@ -139,7 +136,7 @@ impl ThinClient {
serialize(&req).expect("serialize GetTransactionCount in pub fn transaction_count");
let mut done = false;
while !done {
self.requests_sender
self.requests_socket
.send_to(&data, &self.requests_addr)
.expect("buffer error in pub fn transaction_count");

Expand All @@ -163,7 +160,7 @@ impl ThinClient {
let mut done = false;
while !done {
debug!("get_last_id send_to {}", &self.requests_addr);
self.requests_sender
self.requests_socket
.send_to(&data, &self.requests_addr)
.expect("buffer error in pub fn get_last_id");

Expand Down Expand Up @@ -205,7 +202,7 @@ impl ThinClient {
let data = serialize(&req).expect("serialize GetSignature in pub fn check_signature");
let mut done = false;
while !done {
self.requests_sender
self.requests_socket
.send_to(&data, &self.requests_addr)
.expect("buffer error in pub fn get_last_id");

Expand Down Expand Up @@ -267,7 +264,6 @@ mod tests {

let mut client = ThinClient::new(
leader.data.requests_addr,
requests_socket.try_clone().unwrap(),
requests_socket,
leader.data.transactions_addr,
transactions_socket,
Expand Down Expand Up @@ -315,7 +311,6 @@ mod tests {
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let mut client = ThinClient::new(
leader.data.requests_addr,
requests_socket.try_clone().unwrap(),
requests_socket,
leader.data.transactions_addr,
transactions_socket,
Expand Down Expand Up @@ -374,7 +369,6 @@ mod tests {
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let mut client = ThinClient::new(
leader.data.requests_addr,
requests_socket.try_clone().unwrap(),
requests_socket,
leader.data.transactions_addr,
transactions_socket,
Expand Down
1 change: 0 additions & 1 deletion tests/multinode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ fn mk_client(leader: &ReplicatedData) -> ThinClient {

ThinClient::new(
leader.requests_addr,
requests_socket.try_clone().unwrap(),
requests_socket,
leader.transactions_addr,
transactions_socket,
Expand Down