mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 05:18:30 +00:00
Share reqwest::Client between validators when using Web3Signer (#3335)
## Issue Addressed #3302 ## Proposed Changes Move the `reqwest::Client` from being initialized per-validator, to being initialized per distinct Web3Signer. This is done by placing the `Client` into a `HashMap` keyed by the definition of the Web3Signer as specified by the `ValidatorDefintion`. This will allow multiple Web3Signers to be used with a single VC and also maintains backwards compatibility. ## Additional Info This was done to reduce the memory used by the VC when connecting to a Web3Signer. I set up a local testnet using [a custom script](https://github.com/macladson/lighthouse/tree/web3signer-local-test/scripts/local_testnet_web3signer) and ran a VC with 200 validator keys: VC with Web3Signer: - `unstable`: ~200MB - With fix: ~50MB VC with Local Signer: - `unstable`: ~35MB - With fix: ~35MB > I'm seeing some fragmentation with the VC using the Web3Signer, but not when using a local signer (this is most likely due to making lots of http requests and dealing with lots of JSON objects). I tested the above using `MALLOC_ARENA_MAX=1` to try to reduce the fragmentation. Without it, the values are around +50MB for both `unstable` and the fix.
This commit is contained in:
@@ -45,6 +45,29 @@ pub enum Error {
|
||||
UnableToCreateValidatorDir(PathBuf),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize, Hash, Eq)]
|
||||
pub struct Web3SignerDefinition {
|
||||
pub url: String,
|
||||
/// Path to a .pem file.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub root_certificate_path: Option<PathBuf>,
|
||||
/// Specifies a request timeout.
|
||||
///
|
||||
/// The timeout is applied from when the request starts connecting until the response body has finished.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub request_timeout_ms: Option<u64>,
|
||||
|
||||
/// Path to a PKCS12 file.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub client_identity_path: Option<PathBuf>,
|
||||
|
||||
/// Password for the PKCS12 file.
|
||||
///
|
||||
/// An empty password will be used if this is omitted.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub client_identity_password: Option<String>,
|
||||
}
|
||||
|
||||
/// Defines how the validator client should attempt to sign messages for this validator.
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
@@ -62,27 +85,7 @@ pub enum SigningDefinition {
|
||||
///
|
||||
/// https://github.com/ConsenSys/web3signer
|
||||
#[serde(rename = "web3signer")]
|
||||
Web3Signer {
|
||||
url: String,
|
||||
/// Path to a .pem file.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
root_certificate_path: Option<PathBuf>,
|
||||
/// Specifies a request timeout.
|
||||
///
|
||||
/// The timeout is applied from when the request starts connecting until the response body has finished.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
request_timeout_ms: Option<u64>,
|
||||
|
||||
/// Path to a PKCS12 file.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
client_identity_path: Option<PathBuf>,
|
||||
|
||||
/// Password for the PKCS12 file.
|
||||
///
|
||||
/// An empty password will be used if this is omitted.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
client_identity_password: Option<String>,
|
||||
},
|
||||
Web3Signer(Web3SignerDefinition),
|
||||
}
|
||||
|
||||
impl SigningDefinition {
|
||||
|
||||
Reference in New Issue
Block a user