From 3182c5a6eda5d08a12d919fbb5a5be38f2409aab Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 10 Nov 2023 06:37:01 +0300 Subject: [PATCH 1/6] Allow tweaking connection pool settings --- validator_client/src/cli.rs | 20 +++++++++++++++++++ validator_client/src/config.rs | 20 +++++++++++++++++++ validator_client/src/http_api/test_utils.rs | 1 + .../src/initialized_validators.rs | 18 ++++++++++++++++- validator_client/src/lib.rs | 1 + 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/validator_client/src/cli.rs b/validator_client/src/cli.rs index cd3ad494dad..7ae305e2116 100644 --- a/validator_client/src/cli.rs +++ b/validator_client/src/cli.rs @@ -349,4 +349,24 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .default_value("500") .takes_value(true), ) + /* + * Experimental/development options. + */ + .arg( + Arg::with_name("web3-signer-keep-alive-timeout") + .long("web3-signer-keep-alive-timeout") + .value_name("MILLIS") + .default_value("90000") + .help("Keep-alive timeout for each web3signer connection. Set to 'null' to never \ + timeout") + .takes_value(true), + ) + .arg( + Arg::with_name("web3-signer-max-idle-connections") + .long("web3-signer-max-idle-connections") + .value_name("COUNT") + .help("Maximum number of idle connections to maintain per web3signer host. Default \ + is unlimited.") + .takes_value(true), + ) } diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index 4b7da764287..e26fa9137ee 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -77,6 +77,8 @@ pub struct Config { pub validator_registration_batch_size: usize, /// Enables block production via the block v3 endpoint. This configuration option can be removed post deneb. pub produce_block_v3: bool, + pub web3_signer_keep_alive_timeout: Option, + pub web3_signer_max_idle_connections: Option, } impl Default for Config { @@ -118,6 +120,8 @@ impl Default for Config { enable_latency_measurement_service: true, validator_registration_batch_size: 500, produce_block_v3: false, + web3_signer_keep_alive_timeout: Some(Duration::from_secs(90)), + web3_signer_max_idle_connections: None, } } } @@ -239,6 +243,22 @@ impl Config { .collect::>()?; } + /* + * Web3 signer + */ + if let Some(s) = parse_optional::(cli_args, "web3-signer-keep-alive-timeout")? { + config.web3_signer_keep_alive_timeout = if s == "null" { + None + } else { + Some(Duration::from_millis( + s.parse().map_err(|_| "invalid timeout value".to_string())?, + )) + } + } + if let Some(n) = parse_optional::(cli_args, "web3-signer-max-idle-connections")? { + config.web3_signer_max_idle_connections = Some(n); + } + /* * Http API server */ diff --git a/validator_client/src/http_api/test_utils.rs b/validator_client/src/http_api/test_utils.rs index 916c098cdd6..12784c143b2 100644 --- a/validator_client/src/http_api/test_utils.rs +++ b/validator_client/src/http_api/test_utils.rs @@ -80,6 +80,7 @@ impl ApiTester { let initialized_validators = InitializedValidators::from_definitions( validator_defs, validator_dir.path().into(), + Default::default(), log.clone(), ) .await diff --git a/validator_client/src/initialized_validators.rs b/validator_client/src/initialized_validators.rs index b65dad4c477..876f5752277 100644 --- a/validator_client/src/initialized_validators.rs +++ b/validator_client/src/initialized_validators.rs @@ -34,6 +34,7 @@ use validator_dir::Builder as ValidatorDirBuilder; use crate::key_cache; use crate::key_cache::KeyCache; +use crate::Config; /// Default timeout for a request to a remote signer for a signature. /// @@ -198,6 +199,7 @@ impl InitializedValidator { key_cache: &mut KeyCache, key_stores: &mut HashMap, web3_signer_client_map: &mut Option>, + config: &Config, ) -> Result { if !def.enabled { return Err(Error::UnableToInitializeDisabledValidator); @@ -301,6 +303,8 @@ impl InitializedValidator { web3_signer.client_identity_path.clone(), web3_signer.client_identity_password.clone(), request_timeout, + config.web3_signer_keep_alive_timeout, + config.web3_signer_max_idle_connections, )?; client_map.insert(web3_signer, client.clone()); client @@ -315,6 +319,8 @@ impl InitializedValidator { web3_signer.client_identity_path.clone(), web3_signer.client_identity_password.clone(), request_timeout, + config.web3_signer_keep_alive_timeout, + config.web3_signer_max_idle_connections, )?; new_web3_signer_client_map.insert(web3_signer, client.clone()); *web3_signer_client_map = Some(new_web3_signer_client_map); @@ -381,8 +387,13 @@ fn build_web3_signer_client( client_identity_path: Option, client_identity_password: Option, request_timeout: Duration, + keep_alive_timeout: Option, + max_idle_connections: Option, ) -> Result { - let builder = Client::builder().timeout(request_timeout); + let builder = Client::builder() + .timeout(request_timeout) + .pool_idle_timeout(keep_alive_timeout) + .pool_max_idle_per_host(max_idle_connections.unwrap_or(usize::MAX)); let builder = if let Some(path) = root_certificate_path { let certificate = load_pem_certificate(path)?; @@ -463,6 +474,7 @@ pub struct InitializedValidators { web3_signer_client_map: Option>, /// For logging via `slog`. log: Logger, + config: Config, } impl InitializedValidators { @@ -470,6 +482,7 @@ impl InitializedValidators { pub async fn from_definitions( definitions: ValidatorDefinitions, validators_dir: PathBuf, + config: Config, log: Logger, ) -> Result { let mut this = Self { @@ -477,6 +490,7 @@ impl InitializedValidators { definitions, validators: HashMap::default(), web3_signer_client_map: None, + config, log, }; this.update_validators().await?; @@ -1191,6 +1205,7 @@ impl InitializedValidators { &mut key_cache, &mut key_stores, &mut None, + &self.config, ) .await { @@ -1241,6 +1256,7 @@ impl InitializedValidators { &mut key_cache, &mut key_stores, &mut self.web3_signer_client_map, + &self.config, ) .await { diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index 89fc0376215..4828f43a0d8 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -192,6 +192,7 @@ impl ProductionValidatorClient { let validators = InitializedValidators::from_definitions( validator_defs, config.validator_dir.clone(), + config.clone(), log.clone(), ) .await From 1c220397cf10a605e1663d3ed0e7701a7fa77e18 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Sat, 11 Nov 2023 12:12:14 +0300 Subject: [PATCH 2/6] Build docker image --- .github/workflows/docker.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 007070dbb5b..487bd6981fb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,6 +5,7 @@ on: branches: - unstable - stable + - web3signer-keep-alive tags: - v* @@ -40,6 +41,11 @@ jobs: run: | echo "VERSION=latest" >> $GITHUB_ENV echo "VERSION_SUFFIX=-unstable" >> $GITHUB_ENV + - name: Extract version (if web3) + if: github.event.ref == 'refs/heads/web3signer-keep-alive' + run: | + echo "VERSION=web3signer-keep-alive" >> $GITHUB_ENV + echo "VERSION_SUFFIX=" >> $GITHUB_ENV - name: Extract version (if tagged release) if: startsWith(github.event.ref, 'refs/tags') run: | From 9006974be915c529780b4723493d997f702edce5 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 15 Jan 2024 11:48:52 +1100 Subject: [PATCH 3/6] Fix imports --- validator_client/src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index e26fa9137ee..7a564bdb8cc 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -14,6 +14,7 @@ use slog::{info, warn, Logger}; use std::fs; use std::net::IpAddr; use std::path::PathBuf; +use std::time::Duration; use types::{Address, GRAFFITI_BYTES_LEN}; pub const DEFAULT_BEACON_NODE: &str = "http://localhost:5052/"; From a2f9c92ae3265f63c025a52416ae200535005ca5 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 31 Jan 2024 11:28:45 +1100 Subject: [PATCH 4/6] Delete temp docker build stuff --- .github/workflows/docker.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 487bd6981fb..007070dbb5b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,7 +5,6 @@ on: branches: - unstable - stable - - web3signer-keep-alive tags: - v* @@ -41,11 +40,6 @@ jobs: run: | echo "VERSION=latest" >> $GITHUB_ENV echo "VERSION_SUFFIX=-unstable" >> $GITHUB_ENV - - name: Extract version (if web3) - if: github.event.ref == 'refs/heads/web3signer-keep-alive' - run: | - echo "VERSION=web3signer-keep-alive" >> $GITHUB_ENV - echo "VERSION_SUFFIX=" >> $GITHUB_ENV - name: Extract version (if tagged release) if: startsWith(github.event.ref, 'refs/tags') run: | From f428905b7ec702e80e17f3a598ac789f3c2db21c Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 31 Jan 2024 11:36:11 +1100 Subject: [PATCH 5/6] Fix tests --- testing/web3signer_tests/src/lib.rs | 3 ++- validator_client/src/http_api/tests.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/web3signer_tests/src/lib.rs b/testing/web3signer_tests/src/lib.rs index 6f3536fe461..d83ef2d59d9 100644 --- a/testing/web3signer_tests/src/lib.rs +++ b/testing/web3signer_tests/src/lib.rs @@ -301,10 +301,12 @@ mod tests { let log = environment::null_logger().unwrap(); let validator_dir = TempDir::new().unwrap(); + let config = validator_client::Config::default(); let validator_definitions = ValidatorDefinitions::from(validator_definitions); let initialized_validators = InitializedValidators::from_definitions( validator_definitions, validator_dir.path().into(), + config.clone(), log.clone(), ) .await @@ -331,7 +333,6 @@ mod tests { let slot_clock = TestingSlotClock::new(Slot::new(0), Duration::from_secs(0), Duration::from_secs(1)); - let config = validator_client::Config::default(); let validator_store = ValidatorStore::<_, E>::new( initialized_validators, diff --git a/validator_client/src/http_api/tests.rs b/validator_client/src/http_api/tests.rs index f7db76e4ad5..c58f8875056 100644 --- a/validator_client/src/http_api/tests.rs +++ b/validator_client/src/http_api/tests.rs @@ -68,6 +68,7 @@ impl ApiTester { let initialized_validators = InitializedValidators::from_definitions( validator_defs, validator_dir.path().into(), + Config::default(), log.clone(), ) .await From 943008498cbc51a5ae90b80fb13969038e74337f Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 31 Jan 2024 16:32:17 +1100 Subject: [PATCH 6/6] Update CLI text --- book/src/help_vc.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/book/src/help_vc.md b/book/src/help_vc.md index bc6deec1e99..2a0fcbf3d72 100644 --- a/book/src/help_vc.md +++ b/book/src/help_vc.md @@ -209,4 +209,9 @@ OPTIONS: --validators-dir The directory which contains the validator keystores, deposit data for each validator along with the common slashing protection database and the validator_definitions.yml + --web3-signer-keep-alive-timeout + Keep-alive timeout for each web3signer connection. Set to 'null' to never timeout [default: 90000] + + --web3-signer-max-idle-connections + Maximum number of idle connections to maintain per web3signer host. Default is unlimited. ``` \ No newline at end of file