Skip to content

Commit

Permalink
Revert ill-advised jsonrpc marker, and handle jsonrpc server close
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Aug 15, 2018
1 parent 927d55f commit 6d6fea7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 85 deletions.
4 changes: 2 additions & 2 deletions src/bin/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ fn main() -> () {
let testnet_addr: SocketAddr = testnet_address_string.parse().unwrap();
drone_addr.set_ip(testnet_addr.ip());

Fullnode::new(node, false, ledger_path, keypair, Some(testnet_addr), true)
Fullnode::new(node, false, ledger_path, keypair, Some(testnet_addr))
} else {
node.data.leader_id = node.data.id;

Fullnode::new(node, true, ledger_path, keypair, None, true)
Fullnode::new(node, true, ledger_path, keypair, None)
};

let mut client = mk_client(&repl_clone);
Expand Down
1 change: 0 additions & 1 deletion src/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
//TODO: this seems unstable
sleep(Duration::from_millis(900));
Expand Down
36 changes: 10 additions & 26 deletions src/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl Fullnode {
keypair: Keypair,
network_entry_for_validator: Option<SocketAddr>,
sigverify_disabled: bool,
json_rpc_enabled: bool,
) -> Self {
info!("creating bank...");
let bank = Bank::new_default(leader);
Expand Down Expand Up @@ -94,7 +93,6 @@ impl Fullnode {
exit.clone(),
Some(ledger_path),
sigverify_disabled,
json_rpc_enabled,
);
info!(
"validator ready... local request address: {} (advertising {}) connected to: {}",
Expand All @@ -113,7 +111,6 @@ impl Fullnode {
exit.clone(),
ledger_path,
sigverify_disabled,
json_rpc_enabled,
);
info!(
"leader ready... local request address: {} (advertising {})",
Expand All @@ -129,7 +126,6 @@ impl Fullnode {
ledger: &str,
keypair: Keypair,
network_entry_for_validator: Option<SocketAddr>,
json_rpc_enabled: bool,
) -> Self {
Self::new_internal(
node,
Expand All @@ -138,7 +134,6 @@ impl Fullnode {
keypair,
network_entry_for_validator,
false,
json_rpc_enabled,
)
}

Expand All @@ -148,7 +143,6 @@ impl Fullnode {
ledger_path: &str,
keypair: Keypair,
network_entry_for_validator: Option<SocketAddr>,
json_rpc_enabled: bool,
) -> Self {
Self::new_internal(
node,
Expand All @@ -157,7 +151,6 @@ impl Fullnode {
keypair,
network_entry_for_validator,
true,
json_rpc_enabled,
)
}

Expand Down Expand Up @@ -185,7 +178,6 @@ impl Fullnode {
/// | | `------------`
/// `---------------------`
/// ```
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
pub fn new_leader(
keypair: Keypair,
bank: Bank,
Expand All @@ -195,7 +187,6 @@ impl Fullnode {
exit: Arc<AtomicBool>,
ledger_path: &str,
sigverify_disabled: bool,
json_rpc_enabled: bool,
) -> Self {
let tick_duration = None;
// TODO: To light up PoH, uncomment the following line:
Expand All @@ -211,12 +202,10 @@ impl Fullnode {
);
thread_hdls.extend(rpu.thread_hdls());

if json_rpc_enabled {
let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr);
thread_hdls.extend(rpc_service.thread_hdls());
}
let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr, exit.clone());
thread_hdls.extend(rpc_service.thread_hdls());

let blob_recycler = BlobRecycler::default();
let window =
Expand Down Expand Up @@ -288,7 +277,6 @@ impl Fullnode {
/// `--------` | | `------------`
/// `-------------------------------`
/// ```
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
pub fn new_validator(
keypair: Keypair,
bank: Bank,
Expand All @@ -299,7 +287,6 @@ impl Fullnode {
exit: Arc<AtomicBool>,
ledger_path: Option<&str>,
_sigverify_disabled: bool,
json_rpc_enabled: bool,
) -> Self {
let bank = Arc::new(bank);
let mut thread_hdls = vec![];
Expand All @@ -311,12 +298,10 @@ impl Fullnode {
);
thread_hdls.extend(rpu.thread_hdls());

if json_rpc_enabled {
let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr);
thread_hdls.extend(rpc_service.thread_hdls());
}
let mut rpc_addr = node.data.contact_info.ncp;
rpc_addr.set_port(RPC_PORT);
let rpc_service = JsonRpcService::new(bank.clone(), rpc_addr, exit.clone());
thread_hdls.extend(rpc_service.thread_hdls());

let blob_recycler = BlobRecycler::default();
let window =
Expand Down Expand Up @@ -395,8 +380,7 @@ mod tests {
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.data.clone();
let v =
Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false, false);
let v = Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false);
v.exit();
v.join().unwrap();
}
Expand All @@ -410,7 +394,7 @@ mod tests {
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.data.clone();
Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false, false)
Fullnode::new_validator(keypair, bank, 0, &[], tn, &entry, exit, None, false)
})
.collect();
//each validator can exit in parallel to speed many sequential calls to `join`
Expand Down
14 changes: 9 additions & 5 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use service::Service;
use signature::{Pubkey, Signature};
use std::mem;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread::{self, Builder, JoinHandle};

Expand All @@ -18,7 +19,7 @@ pub struct JsonRpcService {
}

impl JsonRpcService {
pub fn new(bank: Arc<Bank>, rpc_addr: SocketAddr) -> Self {
pub fn new(bank: Arc<Bank>, rpc_addr: SocketAddr, exit: Arc<AtomicBool>) -> Self {
let request_processor = JsonRpcRequestProcessor::new(bank);
let thread_hdl = Builder::new()
.name("solana-jsonrpc".to_string())
Expand All @@ -36,7 +37,12 @@ impl JsonRpcService {
]))
.start_http(&rpc_addr)
.unwrap();
server.wait();
loop {
if exit.load(Ordering::Relaxed) {
server.close();
break;
}
}
()
})
.unwrap();
Expand Down Expand Up @@ -195,9 +201,7 @@ mod tests {
let mut io = MetaIoHandler::default();
let rpc = RpcSolImpl;
io.extend_with(rpc.to_delegate());
let meta = Meta {
request_processor: request_processor,
};
let meta = Meta { request_processor };

let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#,
Expand Down
3 changes: 0 additions & 3 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
sleep(Duration::from_millis(900));

Expand Down Expand Up @@ -413,7 +412,6 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
//TODO: remove this sleep, or add a retry so CI is stable
sleep(Duration::from_millis(300));
Expand Down Expand Up @@ -473,7 +471,6 @@ mod tests {
exit.clone(),
&ledger_path,
false,
false,
);
sleep(Duration::from_millis(300));

Expand Down
55 changes: 7 additions & 48 deletions tests/multinode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ fn test_multi_node_ledger_window() -> result::Result<()> {
writer.write_entries(entries).unwrap();
}

let leader = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);
let leader = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);

// Send leader some tokens to vote
let leader_balance =
Expand All @@ -171,7 +164,6 @@ fn test_multi_node_ledger_window() -> result::Result<()> {
&zero_ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);

// contains the leader and new node
Expand Down Expand Up @@ -227,14 +219,7 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
);
ledger_paths.push(zero_ledger_path.clone());

let server = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);
let server = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);

// Send leader some tokens to vote
let leader_balance =
Expand All @@ -257,7 +242,6 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
nodes.push(val);
}
Expand Down Expand Up @@ -293,7 +277,6 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
&zero_ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
nodes.push(val);
//contains the leader and new node
Expand Down Expand Up @@ -353,14 +336,7 @@ fn test_multi_node_basic() {

let (alice, leader_ledger_path) = genesis("multi_node_basic", 10_000);
ledger_paths.push(leader_ledger_path.clone());
let server = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);
let server = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);

// Send leader some tokens to vote
let leader_balance =
Expand All @@ -379,7 +355,6 @@ fn test_multi_node_basic() {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
nodes.push(val);
}
Expand Down Expand Up @@ -422,14 +397,7 @@ fn test_boot_validator_from_file() -> result::Result<()> {
ledger_paths.push(leader_ledger_path.clone());

let leader_data = leader.data.clone();
let leader_fullnode = Fullnode::new(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);
let leader_fullnode = Fullnode::new(leader, true, &leader_ledger_path, leader_keypair, None);
let leader_balance =
send_tx_and_retry_get_balance(&leader_data, &alice, &bob_pubkey, Some(500)).unwrap();
assert_eq!(leader_balance, 500);
Expand All @@ -448,7 +416,6 @@ fn test_boot_validator_from_file() -> result::Result<()> {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
let mut client = mk_client(&validator_data);
let getbal = retry_get_balance(&mut client, &bob_pubkey, Some(leader_balance));
Expand All @@ -467,7 +434,7 @@ fn create_leader(ledger_path: &str) -> (NodeInfo, Fullnode) {
let leader_keypair = Keypair::new();
let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey());
let leader_data = leader.data.clone();
let leader_fullnode = Fullnode::new(leader, true, &ledger_path, leader_keypair, None, false);
let leader_fullnode = Fullnode::new(leader, true, &ledger_path, leader_keypair, None);
(leader_data, leader_fullnode)
}

Expand Down Expand Up @@ -518,7 +485,6 @@ fn test_leader_restart_validator_start_from_old_ledger() -> result::Result<()> {
&stale_ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);

// trigger broadcast, validator should catch up from leader, whose window contains
Expand Down Expand Up @@ -581,14 +547,8 @@ fn test_multi_node_dynamic_network() {
let alice_arc = Arc::new(RwLock::new(alice));
let leader_data = leader.data.clone();

let server = Fullnode::new_without_sigverify(
leader,
true,
&leader_ledger_path,
leader_keypair,
None,
false,
);
let server =
Fullnode::new_without_sigverify(leader, true, &leader_ledger_path, leader_keypair, None);

// Send leader some tokens to vote
let leader_balance = send_tx_and_retry_get_balance(
Expand Down Expand Up @@ -662,7 +622,6 @@ fn test_multi_node_dynamic_network() {
&ledger_path,
keypair,
Some(leader_data.contact_info.ncp),
false,
);
(rd, val)
})
Expand Down

0 comments on commit 6d6fea7

Please sign in to comment.