@@ -35,8 +35,9 @@ pub async fn fetch_stake_table_from_sequencer(
3535 epoch : Option < EpochNumber > ,
3636) -> Result < HSStakeTable < SeqTypes > > {
3737 tracing:: info!( "Initializing stake table from node for epoch {epoch:?}" ) ;
38+ const NUM_RETRIES : usize = 5 ;
3839
39- loop {
40+ for i in 0 .. NUM_RETRIES {
4041 match epoch {
4142 Some ( epoch) => match surf_disco:: Client :: <
4243 tide_disco:: error:: ServerError ,
@@ -46,13 +47,15 @@ pub async fn fetch_stake_table_from_sequencer(
4647 . send ( )
4748 . await
4849 {
49- Ok ( resp) => break Ok ( resp. into ( ) ) ,
50+ Ok ( resp) => return Ok ( resp. into ( ) ) ,
5051 Err ( e) => {
5152 let url = sequencer_url
5253 . join ( & format ! ( "node/stake-table/{}" , epoch. u64 ( ) ) )
5354 . unwrap ( ) ;
54- tracing:: error!( %url, "Failed to fetch the stake table: {e}" ) ;
55- sleep ( Duration :: from_secs ( 5 ) ) . await ;
55+ tracing:: warn!( %url, "Failed to fetch the stake table: {e}, num_retries left: {}" , NUM_RETRIES - i - 1 ) ;
56+ if NUM_RETRIES - i > 1 {
57+ sleep ( Duration :: from_secs ( 5 ) ) . await ;
58+ }
5659 } ,
5760 } ,
5861 None => {
@@ -67,16 +70,21 @@ pub async fn fetch_stake_table_from_sequencer(
6770 & value[ "config" ] [ "known_nodes_with_stake" ] . to_string ( ) ,
6871 )
6972 . with_context ( || "Failed to parse the stake table" ) ?;
70- break Ok ( known_nodes_with_stake. into ( ) ) ;
73+ return Ok ( known_nodes_with_stake. into ( ) ) ;
7174 } ,
7275 Err ( e) => {
73- tracing:: error!( %url, "Failed to fetch the network config: {e}" ) ;
74- sleep ( Duration :: from_secs ( 5 ) ) . await ;
76+ tracing:: warn!( %url, "Failed to fetch the network config: {e}, num_retries left: {}" , NUM_RETRIES - i - 1 ) ;
77+ if NUM_RETRIES - i > 1 {
78+ sleep ( Duration :: from_secs ( 5 ) ) . await ;
79+ }
7580 } ,
7681 }
7782 } ,
7883 }
7984 }
85+ Err ( anyhow:: anyhow!(
86+ "Failed to fetch the stake table after {NUM_RETRIES} attempts"
87+ ) )
8088}
8189
8290#[ inline]
0 commit comments