1+ use std:: time:: Instant ;
2+
13use acropolis_common:: BlockInfo ;
24use config:: Config ;
35use tracing:: { error, info} ;
46
57#[ derive( Debug , Clone , PartialEq ) ]
68pub enum PauseType {
79 NoPause ,
8- Epoch ( u64 ) ,
9- Block ( u64 ) ,
10+ Epoch {
11+ number : u64 ,
12+ start_time : std:: time:: Instant ,
13+ } ,
14+ Block {
15+ number : u64 ,
16+ start_time : std:: time:: Instant ,
17+ } ,
1018}
1119
1220impl PauseType {
@@ -26,15 +34,22 @@ impl PauseType {
2634
2735 let pause_type = parts[ 0 ] . trim ( ) ;
2836 let value = parts[ 1 ] . trim ( ) . parse :: < u64 > ( ) . ok ( ) ?;
37+ let start_time = Instant :: now ( ) ;
2938
3039 match pause_type {
3140 "epoch" => {
3241 info ! ( "Pausing enabled at epoch {value}" ) ;
33- Some ( PauseType :: Epoch ( value) )
42+ Some ( PauseType :: Epoch {
43+ number : value,
44+ start_time,
45+ } )
3446 }
3547 "block" => {
3648 info ! ( "Pausing enabled at block {value}" ) ;
37- Some ( PauseType :: Block ( value) )
49+ Some ( PauseType :: Block {
50+ number : value,
51+ start_time,
52+ } )
3853 }
3954 _ => {
4055 error ! (
@@ -48,29 +63,34 @@ impl PauseType {
4863
4964 pub fn should_pause ( & self , block_info : & BlockInfo ) -> bool {
5065 match self {
51- PauseType :: Epoch ( target_epoch) => {
52- if block_info. new_epoch {
53- return block_info. epoch == * target_epoch;
54- }
55- false
56- }
57- PauseType :: Block ( target_block) => block_info. number == * target_block,
66+ PauseType :: Epoch { number, .. } => block_info. new_epoch && block_info. epoch == * number,
67+ PauseType :: Block { number, .. } => block_info. number == * number,
5868 PauseType :: NoPause => false ,
5969 }
6070 }
6171
62- pub fn get_next ( & self ) -> Self {
72+ pub fn next ( & mut self ) {
6373 match self {
64- PauseType :: Epoch ( target_epoch) => PauseType :: Epoch ( target_epoch + 1 ) ,
65- PauseType :: Block ( target_block) => PauseType :: Block ( target_block + 1 ) ,
66- PauseType :: NoPause => PauseType :: NoPause ,
74+ PauseType :: Epoch { number, start_time } => {
75+ * number += 1 ;
76+ * start_time = Instant :: now ( ) ;
77+ }
78+ PauseType :: Block { number, start_time } => {
79+ * number += 1 ;
80+ * start_time = Instant :: now ( ) ;
81+ }
82+ PauseType :: NoPause => { }
6783 }
6884 }
6985
7086 pub fn get_description ( & self ) -> String {
7187 match self {
72- PauseType :: Epoch ( target_epoch) => format ! ( "Epoch {target_epoch}" ) ,
73- PauseType :: Block ( target_block) => format ! ( "Block {target_block}" ) ,
88+ PauseType :: Epoch { number, start_time } => {
89+ format ! ( "Epoch {number} (started {:?} ago)" , start_time. elapsed( ) )
90+ }
91+ PauseType :: Block { number, start_time } => {
92+ format ! ( "Block {number} (started {:?} ago)" , start_time. elapsed( ) )
93+ }
7494 PauseType :: NoPause => "No pause" . to_string ( ) ,
7595 }
7696 }
@@ -85,14 +105,20 @@ mod tests {
85105 fn test_pause_type_from_config_epoch ( ) {
86106 let config = Config :: builder ( ) . set_override ( "pause" , "epoch:100" ) . unwrap ( ) . build ( ) . unwrap ( ) ;
87107 let pause_type = PauseType :: from_config ( & config, DEFAULT_PAUSE ) ;
88- assert_eq ! ( pause_type, Some ( PauseType :: Epoch ( 100 ) ) ) ;
108+ match pause_type {
109+ Some ( PauseType :: Epoch { number, .. } ) => assert_eq ! ( number, 100 ) ,
110+ _ => panic ! ( "Expected Some(PauseType::Epoch {{ number: 100, .. }})" ) ,
111+ }
89112 }
90113
91114 #[ test]
92115 fn test_pause_type_from_config_block ( ) {
93116 let config = Config :: builder ( ) . set_override ( "pause" , "block:100" ) . unwrap ( ) . build ( ) . unwrap ( ) ;
94117 let pause_type = PauseType :: from_config ( & config, DEFAULT_PAUSE ) ;
95- assert_eq ! ( pause_type, Some ( PauseType :: Block ( 100 ) ) ) ;
118+ match pause_type {
119+ Some ( PauseType :: Block { number, .. } ) => assert_eq ! ( number, 100 ) ,
120+ _ => panic ! ( "Expected Some(PauseType::Block {{ number: 100, .. }})" ) ,
121+ }
96122 }
97123
98124 #[ test]
0 commit comments