From 140954a53c0c2bbb8008b4442babac7f2f397e62 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 27 Feb 2019 09:27:58 -0800 Subject: [PATCH] Remove Tpu::is_leader(), fullnode doesn't need it anymore --- src/fullnode.rs | 36 ++++++++++++++++-------------------- src/tpu.rs | 8 -------- tests/multinode.rs | 5 +++-- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/fullnode.rs b/src/fullnode.rs index 7cffec2f58..c6ebbed9de 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -63,6 +63,7 @@ pub enum FullnodeReturnType { LeaderToValidatorRotation, ValidatorToLeaderRotation, LeaderToLeaderRotation, + ValidatorToValidatorRotation, } pub struct FullnodeConfig { @@ -278,6 +279,7 @@ impl Fullnode { rotation_info.leader_id, rotation_info.last_entry_id, ); + let was_leader = LeaderScheduler::default().slot_leader(&rotation_info.bank) == self.id; if let Some(ref mut rpc_service) = self.rpc_service { // TODO: This is not the correct bank. Instead TVU should pass along the @@ -287,24 +289,12 @@ impl Fullnode { } if rotation_info.leader_id == self.id { - let transition = match self.node_services.tpu.is_leader() { - Some(was_leader) => { - if was_leader { - debug!("{:?} remaining in leader role", self.id); - FullnodeReturnType::LeaderToLeaderRotation - } else { - debug!("{:?} rotating to leader role", self.id); - FullnodeReturnType::ValidatorToLeaderRotation - } - } - None => { - let bank = self.bank_forks.read().unwrap().working_bank(); - if LeaderScheduler::default().prev_slot_leader(&bank) == self.id { - FullnodeReturnType::LeaderToLeaderRotation - } else { - FullnodeReturnType::ValidatorToLeaderRotation - } - } + let transition = if was_leader { + debug!("{:?} remaining in leader role", self.id); + FullnodeReturnType::LeaderToLeaderRotation + } else { + debug!("{:?} rotating to leader role", self.id); + FullnodeReturnType::ValidatorToLeaderRotation }; self.node_services.tpu.switch_to_leader( &self.bank_forks.read().unwrap().working_bank(), @@ -322,7 +312,13 @@ impl Fullnode { ); transition } else { - debug!("{:?} rotating to validator role", self.id); + let transition = if was_leader { + debug!("{:?} rotating to validator role", self.id); + FullnodeReturnType::LeaderToValidatorRotation + } else { + debug!("{:?} remaining in validator role", self.id); + FullnodeReturnType::ValidatorToValidatorRotation + }; self.node_services.tpu.switch_to_forwarder( rotation_info.leader_id, self.tpu_sockets @@ -330,7 +326,7 @@ impl Fullnode { .map(|s| s.try_clone().expect("Failed to clone TPU sockets")) .collect(), ); - FullnodeReturnType::LeaderToValidatorRotation + transition } } diff --git a/src/tpu.rs b/src/tpu.rs index 02b3729028..c5448daf73 100644 --- a/src/tpu.rs +++ b/src/tpu.rs @@ -255,14 +255,6 @@ impl Tpu { self.tpu_mode = Some(TpuMode::Leader(svcs)); } - pub fn is_leader(&self) -> Option { - match self.tpu_mode { - Some(TpuMode::Leader(_)) => Some(true), - Some(TpuMode::Forwarder(_)) => Some(false), - None => None, - } - } - pub fn exit(&self) { self.exit.store(true, Ordering::Relaxed); } diff --git a/tests/multinode.rs b/tests/multinode.rs index 3158617477..b7aaf71aff 100644 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -479,8 +479,9 @@ fn test_boot_validator_from_file() { // TODO: it would be nice to determine the slot that the leader processed the transactions // in, and only wait for that slot here let expected_rotations = vec![ - (FullnodeReturnType::LeaderToValidatorRotation, 1), - (FullnodeReturnType::LeaderToValidatorRotation, 2), + (FullnodeReturnType::ValidatorToValidatorRotation, 1), + (FullnodeReturnType::ValidatorToValidatorRotation, 2), + (FullnodeReturnType::ValidatorToValidatorRotation, 3), ]; for expected_rotation in expected_rotations {