@@ -387,17 +387,14 @@ impl Tower {
387387    pub  fn  record_bank_vote ( & mut  self ,  vote :  Vote )  -> Option < Slot >  { 
388388        let  slot = vote. last_voted_slot ( ) . unwrap_or ( 0 ) ; 
389389        trace ! ( "{} record_vote for {}" ,  self . node_pubkey,  slot) ; 
390-         let  root_slot  = self . lockouts . root_slot ; 
390+         let  old_root  = self . root ( ) ; 
391391        self . lockouts . process_vote_unchecked ( & vote) ; 
392392        self . last_vote  = vote; 
393+         let  new_root = self . root ( ) ; 
393394
394-         datapoint_info ! ( 
395-             "tower-vote" , 
396-             ( "latest" ,  slot,  i64 ) , 
397-             ( "root" ,  self . lockouts. root_slot. unwrap_or( 0 ) ,  i64 ) 
398-         ) ; 
399-         if  root_slot != self . lockouts . root_slot  { 
400-             Some ( self . lockouts . root_slot . unwrap ( ) ) 
395+         datapoint_info ! ( "tower-vote" ,  ( "latest" ,  slot,  i64 ) ,  ( "root" ,  new_root,  i64 ) ) ; 
396+         if  old_root != new_root { 
397+             Some ( new_root) 
401398        }  else  { 
402399            None 
403400        } 
@@ -446,8 +443,8 @@ impl Tower {
446443    // which establishes the origin of trust (i.e. root) whether booting from genesis (slot 0) or 
447444    // snapshot (slot N). In other words, there should be no possibility a Tower doesn't have 
448445    // root, unlike young vote accounts. 
449-     pub  fn  root ( & self )  -> Option < Slot >  { 
450-         self . lockouts . root_slot 
446+     pub  fn  root ( & self )  -> Slot  { 
447+         self . lockouts . root_slot . unwrap ( ) 
451448    } 
452449
453450    // a slot is recent if it's newer than the last vote we have 
@@ -514,7 +511,7 @@ impl Tower {
514511    )  -> SwitchForkDecision  { 
515512        self . last_voted_slot ( ) 
516513            . map ( |last_voted_slot| { 
517-                 let  root = self . lockouts . root_slot . unwrap_or ( 0 ) ; 
514+                 let  root = self . root ( ) ; 
518515                let  empty_ancestors = HashSet :: default ( ) ; 
519516
520517                let  last_vote_ancestors =
@@ -837,8 +834,7 @@ impl Tower {
837834        slot_history :  & SlotHistory , 
838835    )  -> Result < Self >  { 
839836        // sanity assertions for roots 
840-         assert ! ( self . root( ) . is_some( ) ) ; 
841-         let  tower_root = self . root ( ) . unwrap ( ) ; 
837+         let  tower_root = self . root ( ) ; 
842838        info ! ( 
843839            "adjusting lockouts (after replay up to {}): {:?} tower root: {}" , 
844840            replayed_root, 
@@ -1160,28 +1156,27 @@ pub fn reconcile_blockstore_roots_with_tower(
11601156    tower :  & Tower , 
11611157    blockstore :  & Blockstore , 
11621158)  -> blockstore_db:: Result < ( ) >  { 
1163-     if   let  Some ( tower_root)  = tower. root ( )   { 
1164-          let  last_blockstore_root = blockstore. last_root ( ) ; 
1165-          if  last_blockstore_root < tower_root { 
1166-              // Ensure tower_root itself to exist and be marked as rooted in the blockstore 
1167-              // in addition to its ancestors. 
1168-              let  new_roots:  Vec < _ >  = AncestorIterator :: new_inclusive ( tower_root,  & blockstore) 
1169-                  . take_while ( |current| match  current. cmp ( & last_blockstore_root)  { 
1170-                      Ordering :: Greater  => true , 
1171-                      Ordering :: Equal  => false , 
1172-                      Ordering :: Less  => panic ! ( 
1173-                          "couldn't find a last_blockstore_root upwards from: {}!?" , 
1174-                          tower_root
1175-                      ) , 
1176-                  } ) 
1177-                  . collect ( ) ; 
1178-              assert ! ( 
1179-                  !new_roots. is_empty( ) , 
1180-                  "at least 1 parent slot must be found" 
1181-              ) ; 
1159+     let  tower_root = tower. root ( ) ; 
1160+     let  last_blockstore_root = blockstore. last_root ( ) ; 
1161+     if  last_blockstore_root < tower_root { 
1162+         // Ensure tower_root itself to exist and be marked as rooted in the blockstore 
1163+         // in addition to its ancestors. 
1164+         let  new_roots:  Vec < _ >  = AncestorIterator :: new_inclusive ( tower_root,  & blockstore) 
1165+             . take_while ( |current| match  current. cmp ( & last_blockstore_root)  { 
1166+                 Ordering :: Greater  => true , 
1167+                 Ordering :: Equal  => false , 
1168+                 Ordering :: Less  => panic ! ( 
1169+                     "couldn't find a last_blockstore_root upwards from: {}!?" , 
1170+                     tower_root
1171+                 ) , 
1172+             } ) 
1173+             . collect ( ) ; 
1174+         assert ! ( 
1175+             !new_roots. is_empty( ) , 
1176+             "at least 1 parent slot must be found" 
1177+         ) ; 
11821178
1183-             blockstore. set_roots ( & new_roots) ?
1184-         } 
1179+         blockstore. set_roots ( & new_roots) ?
11851180    } 
11861181    Ok ( ( ) ) 
11871182} 
@@ -2744,13 +2739,13 @@ pub mod test {
27442739            . unwrap ( ) ; 
27452740
27462741        assert_eq ! ( tower. voted_slots( ) ,  vec![ 2 ,  3 ] ) ; 
2747-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2742+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
27482743
27492744        tower = tower
27502745            . adjust_lockouts_after_replay ( replayed_root_slot,  & slot_history) 
27512746            . unwrap ( ) ; 
27522747        assert_eq ! ( tower. voted_slots( ) ,  vec![ 2 ,  3 ] ) ; 
2753-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2748+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
27542749    } 
27552750
27562751    #[ test]  
@@ -2772,7 +2767,7 @@ pub mod test {
27722767            . unwrap ( ) ; 
27732768
27742769        assert_eq ! ( tower. voted_slots( ) ,  vec![ 2 ,  3 ] ) ; 
2775-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2770+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
27762771    } 
27772772
27782773    #[ test]  
@@ -2796,7 +2791,7 @@ pub mod test {
27962791            . unwrap ( ) ; 
27972792
27982793        assert_eq ! ( tower. voted_slots( ) ,  vec![ ]  as  Vec <Slot >) ; 
2799-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2794+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
28002795        assert_eq ! ( tower. stray_restored_slot,  None ) ; 
28012796    } 
28022797
@@ -2819,7 +2814,7 @@ pub mod test {
28192814            . adjust_lockouts_after_replay ( MAX_ENTRIES ,  & slot_history) 
28202815            . unwrap ( ) ; 
28212816        assert_eq ! ( tower. voted_slots( ) ,  vec![ ]  as  Vec <Slot >) ; 
2822-         assert_eq ! ( tower. root( ) ,  Some ( MAX_ENTRIES ) ) ; 
2817+         assert_eq ! ( tower. root( ) ,  MAX_ENTRIES ) ; 
28232818    } 
28242819
28252820    #[ test]  
@@ -2842,7 +2837,7 @@ pub mod test {
28422837            . unwrap ( ) ; 
28432838
28442839        assert_eq ! ( tower. voted_slots( ) ,  vec![ 3 ,  4 ] ) ; 
2845-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2840+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
28462841    } 
28472842
28482843    #[ test]  
@@ -2863,7 +2858,7 @@ pub mod test {
28632858            . unwrap ( ) ; 
28642859
28652860        assert_eq ! ( tower. voted_slots( ) ,  vec![ 5 ,  6 ] ) ; 
2866-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2861+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
28672862    } 
28682863
28692864    #[ test]  
@@ -2907,7 +2902,7 @@ pub mod test {
29072902            . unwrap ( ) ; 
29082903
29092904        assert_eq ! ( tower. voted_slots( ) ,  vec![ 3 ,  4 ,  5 ] ) ; 
2910-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2905+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
29112906    } 
29122907
29132908    #[ test]  
@@ -2923,7 +2918,7 @@ pub mod test {
29232918            . unwrap ( ) ; 
29242919
29252920        assert_eq ! ( tower. voted_slots( ) ,  vec![ ]  as  Vec <Slot >) ; 
2926-         assert_eq ! ( tower. root( ) ,  Some ( replayed_root_slot) ) ; 
2921+         assert_eq ! ( tower. root( ) ,  replayed_root_slot) ; 
29272922    } 
29282923
29292924    #[ test]  
0 commit comments