@@ -144,6 +144,7 @@ pub struct Timeouts {
144144 pub get_debug_beacon_states : Duration ,
145145 pub get_deposit_snapshot : Duration ,
146146 pub get_validator_block : Duration ,
147+ pub default : Duration ,
147148}
148149
149150impl Timeouts {
@@ -161,6 +162,7 @@ impl Timeouts {
161162 get_debug_beacon_states : timeout,
162163 get_deposit_snapshot : timeout,
163164 get_validator_block : timeout,
165+ default : timeout,
164166 }
165167 }
166168}
@@ -235,7 +237,9 @@ impl BeaconNodeHttpClient {
235237 url : U ,
236238 builder : impl FnOnce ( RequestBuilder ) -> RequestBuilder ,
237239 ) -> Result < Response , Error > {
238- let response = builder ( self . client . get ( url) ) . send ( ) . await ?;
240+ let response = builder ( self . client . get ( url) . timeout ( self . timeouts . default ) )
241+ . send ( )
242+ . await ?;
239243 ok_or_error ( response) . await
240244 }
241245
@@ -398,11 +402,10 @@ impl BeaconNodeHttpClient {
398402 body : & T ,
399403 timeout : Option < Duration > ,
400404 ) -> Result < Response , Error > {
401- let mut builder = self . client . post ( url) ;
402- if let Some ( timeout) = timeout {
403- builder = builder. timeout ( timeout) ;
404- }
405-
405+ let builder = self
406+ . client
407+ . post ( url)
408+ . timeout ( timeout. unwrap_or ( self . timeouts . default ) ) ;
406409 let response = builder. json ( body) . send ( ) . await ?;
407410 ok_or_error ( response) . await
408411 }
@@ -415,10 +418,10 @@ impl BeaconNodeHttpClient {
415418 timeout : Option < Duration > ,
416419 fork : ForkName ,
417420 ) -> Result < Response , Error > {
418- let mut builder = self . client . post ( url ) ;
419- if let Some ( timeout ) = timeout {
420- builder = builder . timeout ( timeout ) ;
421- }
421+ let builder = self
422+ . client
423+ . post ( url )
424+ . timeout ( timeout . unwrap_or ( self . timeouts . default ) ) ;
422425 let response = builder
423426 . header ( CONSENSUS_VERSION_HEADER , fork. to_string ( ) )
424427 . json ( body)
@@ -433,7 +436,7 @@ impl BeaconNodeHttpClient {
433436 url : U ,
434437 body : & T ,
435438 ) -> Result < Response , Error > {
436- let builder = self . client . post ( url) ;
439+ let builder = self . client . post ( url) . timeout ( self . timeouts . default ) ;
437440 let mut headers = HeaderMap :: new ( ) ;
438441
439442 headers. insert (
@@ -452,10 +455,10 @@ impl BeaconNodeHttpClient {
452455 timeout : Option < Duration > ,
453456 fork : ForkName ,
454457 ) -> Result < Response , Error > {
455- let mut builder = self . client . post ( url ) ;
456- if let Some ( timeout ) = timeout {
457- builder = builder . timeout ( timeout ) ;
458- }
458+ let builder = self
459+ . client
460+ . post ( url )
461+ . timeout ( timeout . unwrap_or ( self . timeouts . default ) ) ;
459462 let mut headers = HeaderMap :: new ( ) ;
460463 headers. insert (
461464 CONSENSUS_VERSION_HEADER ,
@@ -1868,7 +1871,13 @@ impl BeaconNodeHttpClient {
18681871 . push ( "node" )
18691872 . push ( "health" ) ;
18701873
1871- let status = self . client . get ( path) . send ( ) . await ?. status ( ) ;
1874+ let status = self
1875+ . client
1876+ . get ( path)
1877+ . timeout ( self . timeouts . default )
1878+ . send ( )
1879+ . await ?
1880+ . status ( ) ;
18721881 if status == StatusCode :: OK || status == StatusCode :: PARTIAL_CONTENT {
18731882 Ok ( status)
18741883 } else {
0 commit comments