@@ -34,6 +34,7 @@ use validator_dir::Builder as ValidatorDirBuilder;
3434
3535use crate :: key_cache;
3636use crate :: key_cache:: KeyCache ;
37+ use crate :: Config ;
3738
3839/// Default timeout for a request to a remote signer for a signature.
3940///
@@ -208,6 +209,7 @@ impl InitializedValidator {
208209 key_cache : & mut KeyCache ,
209210 key_stores : & mut HashMap < PathBuf , Keystore > ,
210211 web3_signer_client_map : & mut Option < HashMap < Web3SignerDefinition , Client > > ,
212+ config : & Config ,
211213 ) -> Result < Self , Error > {
212214 if !def. enabled {
213215 return Err ( Error :: UnableToInitializeDisabledValidator ) ;
@@ -311,6 +313,8 @@ impl InitializedValidator {
311313 web3_signer. client_identity_path . clone ( ) ,
312314 web3_signer. client_identity_password . clone ( ) ,
313315 request_timeout,
316+ config. web3_signer_keep_alive_timeout ,
317+ config. web3_signer_max_idle_connections ,
314318 ) ?;
315319 client_map. insert ( web3_signer, client. clone ( ) ) ;
316320 client
@@ -325,6 +329,8 @@ impl InitializedValidator {
325329 web3_signer. client_identity_path . clone ( ) ,
326330 web3_signer. client_identity_password . clone ( ) ,
327331 request_timeout,
332+ config. web3_signer_keep_alive_timeout ,
333+ config. web3_signer_max_idle_connections ,
328334 ) ?;
329335 new_web3_signer_client_map. insert ( web3_signer, client. clone ( ) ) ;
330336 * web3_signer_client_map = Some ( new_web3_signer_client_map) ;
@@ -393,8 +399,13 @@ fn build_web3_signer_client(
393399 client_identity_path : Option < PathBuf > ,
394400 client_identity_password : Option < String > ,
395401 request_timeout : Duration ,
402+ keep_alive_timeout : Option < Duration > ,
403+ max_idle_connections : Option < usize > ,
396404) -> Result < Client , Error > {
397- let builder = Client :: builder ( ) . timeout ( request_timeout) ;
405+ let builder = Client :: builder ( )
406+ . timeout ( request_timeout)
407+ . pool_idle_timeout ( keep_alive_timeout)
408+ . pool_max_idle_per_host ( max_idle_connections. unwrap_or ( usize:: MAX ) ) ;
398409
399410 let builder = if let Some ( path) = root_certificate_path {
400411 let certificate = load_pem_certificate ( path) ?;
@@ -475,20 +486,23 @@ pub struct InitializedValidators {
475486 web3_signer_client_map : Option < HashMap < Web3SignerDefinition , Client > > ,
476487 /// For logging via `slog`.
477488 log : Logger ,
489+ config : Config ,
478490}
479491
480492impl InitializedValidators {
481493 /// Instantiates `Self`, initializing all validators in `definitions`.
482494 pub async fn from_definitions (
483495 definitions : ValidatorDefinitions ,
484496 validators_dir : PathBuf ,
497+ config : Config ,
485498 log : Logger ,
486499 ) -> Result < Self , Error > {
487500 let mut this = Self {
488501 validators_dir,
489502 definitions,
490503 validators : HashMap :: default ( ) ,
491504 web3_signer_client_map : None ,
505+ config,
492506 log,
493507 } ;
494508 this. update_validators ( ) . await ?;
@@ -1234,6 +1248,7 @@ impl InitializedValidators {
12341248 & mut key_cache,
12351249 & mut key_stores,
12361250 & mut None ,
1251+ & self . config ,
12371252 )
12381253 . await
12391254 {
@@ -1284,6 +1299,7 @@ impl InitializedValidators {
12841299 & mut key_cache,
12851300 & mut key_stores,
12861301 & mut self . web3_signer_client_map ,
1302+ & self . config ,
12871303 )
12881304 . await
12891305 {
0 commit comments