Remove Tpu::is_leader(), fullnode doesn't need it anymore

This commit is contained in:
Michael Vines
2019-02-27 09:27:58 -08:00
committed by Grimes
parent b5d7ac3ce3
commit 140954a53c
3 changed files with 19 additions and 30 deletions

View File

@@ -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
}
}

View File

@@ -255,14 +255,6 @@ impl Tpu {
self.tpu_mode = Some(TpuMode::Leader(svcs));
}
pub fn is_leader(&self) -> Option<bool> {
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);
}

View File

@@ -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 {