From 8f1b7c3ffff36192d22d9b691afeaba308942e2a Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Tue, 12 Feb 2019 15:03:11 -0800 Subject: [PATCH] Enable test_replay (#2741) * Enable test_replay * Refactor get_last_id * Fix test ledger path --- src/storage_stage.rs | 30 +++++++++++++++--------------- src/thin_client.rs | 27 +++++++++++++++++++++------ src/tvu.rs | 9 ++++----- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/storage_stage.rs b/src/storage_stage.rs index 66439f1403..72e922a419 100644 --- a/src/storage_stage.rs +++ b/src/storage_stage.rs @@ -235,25 +235,25 @@ impl StorageStage { } } - let last_id = client.get_last_id(); + if let Some(last_id) = client.try_get_last_id(10) { + tx.sign(&[keypair.as_ref()], last_id); - tx.sign(&[keypair.as_ref()], last_id); + if exit.load(Ordering::Relaxed) { + Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?; + } - if exit.load(Ordering::Relaxed) { - Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?; - } + if let Ok(signature) = client.transfer_signed(&tx) { + for _ in 0..10 { + if client.check_signature(&signature) { + return Ok(()); + } - if let Ok(signature) = client.transfer_signed(&tx) { - for _ in 0..10 { - if client.check_signature(&signature) { - return Ok(()); + if exit.load(Ordering::Relaxed) { + Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?; + } + + sleep(Duration::from_millis(200)); } - - if exit.load(Ordering::Relaxed) { - Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?; - } - - sleep(Duration::from_millis(200)); } } } diff --git a/src/thin_client.rs b/src/thin_client.rs index 45c73323da..644cc980a1 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -238,11 +238,11 @@ impl ThinClient { 0 } - /// Request the last Entry ID from the server. This method blocks - /// until the server sends a response. - pub fn get_last_id(&mut self) -> Hash { + /// Request the last Entry ID from the server without blocking. + /// Returns the last_id Hash or None if there was no response from the server. + pub fn try_get_last_id(&mut self, mut num_retries: u64) -> Option { loop { - trace!("get_last_id send_to {}", &self.rpc_addr); + trace!("try_get_last_id send_to {}", &self.rpc_addr); let response = self .rpc_client .make_rpc_request(1, RpcRequest::GetLastId, None); @@ -251,12 +251,27 @@ impl ThinClient { Ok(value) => { let last_id_str = value.as_str().unwrap(); let last_id_vec = bs58::decode(last_id_str).into_vec().unwrap(); - return Hash::new(&last_id_vec); + return Some(Hash::new(&last_id_vec)); } Err(error) => { debug!("thin_client get_last_id error: {:?}", error); + num_retries -= 1; + if num_retries == 0 { + return None; + } } - }; + } + } + } + + /// Request the last Entry ID from the server. This method blocks + /// until the server sends a response. + pub fn get_last_id(&mut self) -> Hash { + loop { + trace!("get_last_id send_to {}", &self.rpc_addr); + if let Some(hash) = self.try_get_last_id(10) { + return hash; + } } } diff --git a/src/tvu.rs b/src/tvu.rs index 57c2cb3ea9..68545a4bc0 100644 --- a/src/tvu.rs +++ b/src/tvu.rs @@ -250,7 +250,7 @@ pub mod tests { let cref1 = Arc::new(RwLock::new(cluster_info1)); let cur_hash = Hash::default(); - let blocktree_path = get_tmp_ledger_path("test_replay"); + let blocktree_path = get_tmp_ledger_path("test_tvu_exit"); let (blocktree, l_sender, l_receiver) = Blocktree::open_with_signal(&blocktree_path) .expect("Expected to successfully open ledger"); let vote_account_keypair = Arc::new(Keypair::new()); @@ -283,7 +283,6 @@ pub mod tests { /// Test that message sent from leader to target1 and replayed to target2 #[test] - #[ignore] fn test_replay() { solana_logger::setup(); let leader = Node::new_localhost(); @@ -327,6 +326,9 @@ pub mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(starting_balance); let tvu_addr = target1.info.tvu; let bank = Arc::new(Bank::new(&genesis_block)); + // 2 tokens are consumed by the genesis + let starting_balance = starting_balance - 2; + assert_eq!(bank.get_balance(&mint_keypair.pubkey()), starting_balance); //start cluster_info1 let mut cluster_info1 = ClusterInfo::new(target1.info.clone()); @@ -374,7 +376,6 @@ pub mod tests { for i in 0..num_transfers { let entry0 = Entry::new(&cur_hash, 0, i, vec![]); cur_hash = entry0.id; - bank.register_tick(&cur_hash); let entry_tick0 = Entry::new(&cur_hash, 0, i + 1, vec![]); cur_hash = entry_tick0.id; @@ -385,11 +386,9 @@ pub mod tests { cur_hash, 0, ); - bank.register_tick(&cur_hash); let entry_tick1 = Entry::new(&cur_hash, 0, i + 1, vec![]); cur_hash = entry_tick1.id; let entry1 = Entry::new(&cur_hash, 0, i + num_transfers, vec![tx0]); - bank.register_tick(&entry1.id); let entry_tick2 = Entry::new(&entry1.id, 0, i + 1, vec![]); cur_hash = entry_tick2.id;