From cef1962de603e121746169f30352f6c623e7774a Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 15 Aug 2018 15:11:38 -0600 Subject: [PATCH] Revert ill-advised jsonrpc marker, and handle jsonrpc server close --- src/bin/fullnode.rs | 4 ++-- src/drone.rs | 1 - src/fullnode.rs | 36 +++++++++-------------------- src/rpc.rs | 14 +++++++----- src/thin_client.rs | 3 --- tests/multinode.rs | 55 ++++++--------------------------------------- 6 files changed, 28 insertions(+), 85 deletions(-) diff --git a/src/bin/fullnode.rs b/src/bin/fullnode.rs index ed296b46f9ff33..35a3453a52ff7a 100644 --- a/src/bin/fullnode.rs +++ b/src/bin/fullnode.rs @@ -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); diff --git a/src/drone.rs b/src/drone.rs index 9e36b582b53bad..e3b8477089821b 100644 --- a/src/drone.rs +++ b/src/drone.rs @@ -294,7 +294,6 @@ mod tests { exit.clone(), &ledger_path, false, - false, ); //TODO: this seems unstable sleep(Duration::from_millis(900)); diff --git a/src/fullnode.rs b/src/fullnode.rs index d833e6e754e5ce..af3f2f9a96f4e0 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -55,7 +55,6 @@ impl Fullnode { keypair: Keypair, network_entry_for_validator: Option, sigverify_disabled: bool, - json_rpc_enabled: bool, ) -> Self { info!("creating bank..."); let bank = Bank::new_default(leader); @@ -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: {}", @@ -113,7 +111,6 @@ impl Fullnode { exit.clone(), ledger_path, sigverify_disabled, - json_rpc_enabled, ); info!( "leader ready... local request address: {} (advertising {})", @@ -129,7 +126,6 @@ impl Fullnode { ledger: &str, keypair: Keypair, network_entry_for_validator: Option, - json_rpc_enabled: bool, ) -> Self { Self::new_internal( node, @@ -138,7 +134,6 @@ impl Fullnode { keypair, network_entry_for_validator, false, - json_rpc_enabled, ) } @@ -148,7 +143,6 @@ impl Fullnode { ledger_path: &str, keypair: Keypair, network_entry_for_validator: Option, - json_rpc_enabled: bool, ) -> Self { Self::new_internal( node, @@ -157,7 +151,6 @@ impl Fullnode { keypair, network_entry_for_validator, true, - json_rpc_enabled, ) } @@ -185,7 +178,6 @@ impl Fullnode { /// | | `------------` /// `---------------------` /// ``` - #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] pub fn new_leader( keypair: Keypair, bank: Bank, @@ -195,7 +187,6 @@ impl Fullnode { exit: Arc, ledger_path: &str, sigverify_disabled: bool, - json_rpc_enabled: bool, ) -> Self { let tick_duration = None; // TODO: To light up PoH, uncomment the following line: @@ -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 = @@ -288,7 +277,6 @@ impl Fullnode { /// `--------` | | `------------` /// `-------------------------------` /// ``` - #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] pub fn new_validator( keypair: Keypair, bank: Bank, @@ -299,7 +287,6 @@ impl Fullnode { exit: Arc, ledger_path: Option<&str>, _sigverify_disabled: bool, - json_rpc_enabled: bool, ) -> Self { let bank = Arc::new(bank); let mut thread_hdls = vec![]; @@ -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 = @@ -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(); } @@ -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` diff --git a/src/rpc.rs b/src/rpc.rs index 20e0f6d8dae05f..a3c684a43101de 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -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}; @@ -18,7 +19,7 @@ pub struct JsonRpcService { } impl JsonRpcService { - pub fn new(bank: Arc, rpc_addr: SocketAddr) -> Self { + pub fn new(bank: Arc, rpc_addr: SocketAddr, exit: Arc) -> Self { let request_processor = JsonRpcRequestProcessor::new(bank); let thread_hdl = Builder::new() .name("solana-jsonrpc".to_string()) @@ -36,7 +37,12 @@ impl JsonRpcService { ])) .start_http(&rpc_addr) .unwrap(); - server.wait(); + loop { + if exit.load(Ordering::Relaxed) { + server.close(); + break; + } + } () }) .unwrap(); @@ -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":["{}"]}}"#, diff --git a/src/thin_client.rs b/src/thin_client.rs index aebf9018042a4d..1120ec37d5a9ba 100755 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -372,7 +372,6 @@ mod tests { exit.clone(), &ledger_path, false, - false, ); sleep(Duration::from_millis(900)); @@ -420,7 +419,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)); @@ -480,7 +478,6 @@ mod tests { exit.clone(), &ledger_path, false, - false, ); sleep(Duration::from_millis(300)); diff --git a/tests/multinode.rs b/tests/multinode.rs index da81500bf5bb84..bf8deef06121a8 100644 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -145,14 +145,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 = @@ -170,7 +163,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 @@ -226,14 +218,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 = @@ -256,7 +241,6 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> { &ledger_path, keypair, Some(leader_data.contact_info.ncp), - false, ); nodes.push(val); } @@ -292,7 +276,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 @@ -352,14 +335,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 = @@ -378,7 +354,6 @@ fn test_multi_node_basic() { &ledger_path, keypair, Some(leader_data.contact_info.ncp), - false, ); nodes.push(val); } @@ -421,14 +396,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); @@ -447,7 +415,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)); @@ -466,7 +433,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) } @@ -517,7 +484,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 @@ -572,14 +538,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( @@ -653,7 +613,6 @@ fn test_multi_node_dynamic_network() { &ledger_path, keypair, Some(leader_data.contact_info.ncp), - false, ); (rd, val) })