소스 검색

nit: consensus_pool and parent_ready_tracker: reduce visibility of fields and methods (#8727)

wip
Akhilesh Singhania 3 주 전
부모
커밋
fa73394ed9
2개의 변경된 파일26개의 추가작업 그리고 27개의 파일을 삭제
  1. 16 18
      votor/src/consensus_pool.rs
  2. 10 9
      votor/src/consensus_pool/parent_ready_tracker.rs

+ 16 - 18
votor/src/consensus_pool.rs

@@ -35,15 +35,15 @@ use {
 };
 
 mod certificate_builder;
-pub mod parent_ready_tracker;
+pub(crate) mod parent_ready_tracker;
 mod slot_stake_counters;
 mod stats;
 mod vote_pool;
 
-pub type PoolId = (Slot, VoteType);
+type PoolId = (Slot, VoteType);
 
 #[derive(Debug, Error, PartialEq)]
-pub enum AddVoteError {
+pub(crate) enum AddVoteError {
     #[error("Conflicting vote type: {0:?} vs existing {1:?} for slot: {2} pubkey: {3}")]
     ConflictingVoteType(VoteType, VoteType, Slot, Pubkey),
 
@@ -53,9 +53,6 @@ pub enum AddVoteError {
     #[error("Unrooted slot")]
     UnrootedSlot,
 
-    #[error("Slot in the future")]
-    SlotInFuture,
-
     #[error("Certificate builder error: {0}")]
     CertificateBuilder(#[from] CertificateBuilderError),
 
@@ -99,7 +96,7 @@ fn get_key_and_stakes(
     Ok((*vote_key, stake, epoch_stakes.total_stake()))
 }
 
-pub struct ConsensusPool {
+pub(crate) struct ConsensusPool {
     cluster_info: Arc<ClusterInfo>,
     // Vote pools to do bean counting for votes.
     vote_pools: BTreeMap<PoolId, VotePool>,
@@ -108,7 +105,7 @@ pub struct ConsensusPool {
     /// Tracks slots which have reached the parent ready condition:
     /// - They have a potential parent block with a NotarizeFallback certificate
     /// - All slots from the parent have a Skip certificate
-    pub parent_ready_tracker: ParentReadyTracker,
+    pub(crate) parent_ready_tracker: ParentReadyTracker,
     /// Highest slot that has a Finalized variant certificate
     highest_finalized_slot: Option<Slot>,
     /// Highest slot that has Finalize+Notarize or FinalizeFast, for use in standstill
@@ -121,7 +118,7 @@ pub struct ConsensusPool {
 }
 
 impl ConsensusPool {
-    pub fn new_from_root_bank(cluster_info: Arc<ClusterInfo>, bank: &Bank) -> Self {
+    pub(crate) fn new_from_root_bank(cluster_info: Arc<ClusterInfo>, bank: &Bank) -> Self {
         // To account for genesis and snapshots we allow default block id until
         // block id can be serialized  as part of the snapshot
         let root_block = (bank.slot(), bank.block_id().unwrap_or_default());
@@ -348,7 +345,7 @@ impl ConsensusPool {
     ///
     /// If this resulted in a new highest Finalize or FastFinalize certificate,
     /// return the slot
-    pub fn add_message(
+    pub(crate) fn add_message(
         &mut self,
         epoch_schedule: &EpochSchedule,
         epoch_stakes_map: &HashMap<Epoch, VersionedEpochStakes>,
@@ -472,7 +469,7 @@ impl ConsensusPool {
     }
 
     /// Get the notarized block in `slot`
-    pub fn get_notarized_block(&self, slot: Slot) -> Option<Block> {
+    fn get_notarized_block(&self, slot: Slot) -> Option<Block> {
         self.completed_certificates
             .iter()
             .find_map(|(cert_type, _)| match cert_type {
@@ -509,7 +506,7 @@ impl ConsensusPool {
             .unwrap_or(0)
     }
 
-    pub fn highest_finalized_slot(&self) -> Slot {
+    pub(crate) fn highest_finalized_slot(&self) -> Slot {
         self.completed_certificates
             .iter()
             .filter_map(|(cert_type, _)| match cert_type {
@@ -523,7 +520,7 @@ impl ConsensusPool {
     }
 
     /// Checks if any block in the slot `s` is finalized
-    pub fn is_finalized(&self, slot: Slot) -> bool {
+    fn is_finalized(&self, slot: Slot) -> bool {
         self.completed_certificates.keys().any(|cert_type| {
             matches!(cert_type, CertificateType::Finalize(s) | CertificateType::FinalizeFast(s, _) if *s == slot)
         })
@@ -532,14 +529,15 @@ impl ConsensusPool {
     /// Checks if the any block in slot `slot` has received a `NotarizeFallback` certificate, if so return
     /// the size of the certificate
     #[cfg(test)]
-    pub fn slot_has_notarized_fallback(&self, slot: Slot) -> bool {
+    fn slot_has_notarized_fallback(&self, slot: Slot) -> bool {
         self.completed_certificates.iter().any(
             |(cert_type, _)| matches!(cert_type, CertificateType::NotarizeFallback(s,_) if *s == slot),
         )
     }
 
     /// Checks if `slot` has a `Skip` certificate
-    pub fn skip_certified(&self, slot: Slot) -> bool {
+    #[cfg(test)]
+    fn skip_certified(&self, slot: Slot) -> bool {
         self.completed_certificates
             .contains_key(&CertificateType::Skip(slot))
     }
@@ -585,7 +583,7 @@ impl ConsensusPool {
     }
 
     /// Cleanup any old slots from the certificate pool
-    pub fn prune_old_state(&mut self, root_slot: Slot) {
+    pub(crate) fn prune_old_state(&mut self, root_slot: Slot) {
         // `completed_certificates`` now only contains entries >= `slot`
         self.completed_certificates
             .retain(|cert_type, _| match cert_type {
@@ -600,11 +598,11 @@ impl ConsensusPool {
         self.parent_ready_tracker.set_root(root_slot);
     }
 
-    pub fn maybe_report(&mut self) {
+    pub(crate) fn maybe_report(&mut self) {
         self.stats.maybe_report();
     }
 
-    pub fn get_certs_for_standstill(&self) -> Vec<Arc<Certificate>> {
+    pub(crate) fn get_certs_for_standstill(&self) -> Vec<Arc<Certificate>> {
         let (highest_finalized_with_notarize_slot, has_fast_finalize) =
             self.highest_finalized_with_notarize.unwrap_or((0, false));
         self.completed_certificates

+ 10 - 9
votor/src/consensus_pool/parent_ready_tracker.rs

@@ -21,13 +21,13 @@ use {
 };
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub enum BlockProductionParent {
+pub(crate) enum BlockProductionParent {
     MissedWindow,
     ParentNotReady,
     Parent(Block),
 }
 
-pub struct ParentReadyTracker {
+pub(crate) struct ParentReadyTracker {
     cluster_info: Arc<ClusterInfo>,
 
     /// Parent ready status for each slot
@@ -56,7 +56,7 @@ struct ParentReadyStatus {
 
 impl ParentReadyTracker {
     /// Creates a new tracker with the root bank as implicitely notarized fallback
-    pub fn new(cluster_info: Arc<ClusterInfo>, root_block @ (root_slot, _): Block) -> Self {
+    pub(super) fn new(cluster_info: Arc<ClusterInfo>, root_block @ (root_slot, _): Block) -> Self {
         let mut slot_statuses = HashMap::new();
         slot_statuses.insert(
             root_slot,
@@ -83,7 +83,7 @@ impl ParentReadyTracker {
     }
 
     /// Adds a new notarize fallback certificate, we can use Notarize/NotarizeFallback/FastFinalize
-    pub fn add_new_notar_fallback_or_stronger(
+    pub(super) fn add_new_notar_fallback_or_stronger(
         &mut self,
         block @ (slot, _): Block,
         events: &mut Vec<VotorEvent>,
@@ -131,7 +131,7 @@ impl ParentReadyTracker {
     }
 
     /// Adds a new skip certificate
-    pub fn add_new_skip(&mut self, slot: Slot, events: &mut Vec<VotorEvent>) {
+    pub(super) fn add_new_skip(&mut self, slot: Slot, events: &mut Vec<VotorEvent>) {
         if slot <= self.root {
             return;
         }
@@ -197,14 +197,15 @@ impl ParentReadyTracker {
         }
     }
 
-    pub fn parent_ready(&self, slot: Slot, parent: Block) -> bool {
+    #[cfg(test)]
+    fn parent_ready(&self, slot: Slot, parent: Block) -> bool {
         self.slot_statuses
             .get(&slot)
             .is_some_and(|ss| ss.parents_ready.contains(&parent))
     }
 
     /// For our leader slot `slot`, which block should we use as the parent
-    pub fn block_production_parent(&self, slot: Slot) -> BlockProductionParent {
+    pub(crate) fn block_production_parent(&self, slot: Slot) -> BlockProductionParent {
         if self.highest_parent_ready() > slot {
             // This indicates that our block has already received a certificate
             // either because we were too slow, or because we are restarting
@@ -222,11 +223,11 @@ impl ParentReadyTracker {
         }
     }
 
-    pub fn highest_parent_ready(&self) -> Slot {
+    fn highest_parent_ready(&self) -> Slot {
         self.highest_with_parent_ready
     }
 
-    pub fn set_root(&mut self, root: Slot) {
+    pub(super) fn set_root(&mut self, root: Slot) {
         self.root = root;
         self.slot_statuses.retain(|&s, _| s >= root);
     }