Bugfix,379 identity key pair loading must be optional (#381)

fix identity keypair loading logic

reverting to this logic
1. check if env variable IDENTITY is present
2. check if cli arg --identity-keypair is present
3. assume no identity
This commit is contained in:
Groovie | Mango 2024-04-02 15:52:06 +02:00 committed by GitHub
parent 12a6832c56
commit 944a93114c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 15 deletions

View File

@ -2,22 +2,21 @@ use anyhow::Context;
use solana_sdk::signature::Keypair;
use std::env;
// note this is duplicated from lite-rpc module
pub async fn load_identity_keypair(
identity_path: Option<String>,
identity_keyfile_path: Option<String>,
) -> anyhow::Result<Option<Keypair>> {
let identity_str = if let Some(identity_from_cli) = identity_path {
tokio::fs::read_to_string(identity_from_cli)
let identity_jsonarray_str = if let Ok(identity_env_var) = env::var("IDENTITY") {
identity_env_var
} else if let Some(identity_path) = identity_keyfile_path {
tokio::fs::read_to_string(identity_path)
.await
.context("Cannot find the identity file provided")?
} else if let Ok(identity_env_var) = env::var("IDENTITY") {
identity_env_var
} else {
return Ok(None);
};
let identity_bytes: Vec<u8> =
serde_json::from_str(&identity_str).context("Invalid identity format expected Vec<u8>")?;
let identity_bytes: Vec<u8> = serde_json::from_str(&identity_jsonarray_str)
.context("Invalid identity format expected Vec<u8>")?;
Ok(Some(
Keypair::from_bytes(identity_bytes.as_slice()).context("Invalid identity")?,

View File

@ -142,11 +142,8 @@ impl Config {
.map(|size| size.parse().unwrap())
.unwrap_or(config.fanout_size);
// IDENTITY env sets value of identity_keypair
// config.identity_keypair = env::var("IDENTITY")
// .map(Some)
// .unwrap_or(config.identity_keypair);
// note: identity config is handled in load_identity_keypair
// the behavior is different from the other config values as it does either take a file path or the keypair as json array
config.prometheus_addr = env::var("PROMETHEUS_ADDR").unwrap_or(config.prometheus_addr);

View File

@ -35,8 +35,10 @@ pub async fn main() -> anyhow::Result<()> {
dotenv().ok();
let proxy_listener_addr = proxy_listen_addr.parse().unwrap();
let validator_identity =
ValidatorIdentity::new(load_identity_keypair(Some(identity_keypair)).await?);
let validator_identity = ValidatorIdentity::new(
load_identity_keypair(Some(identity_keypair).filter(|s| !s.is_empty())).await?,
);
let tls_config = Arc::new(SelfSignedTlsConfigProvider::new_singleton_self_signed_localhost());
let main_services = QuicForwardProxy::new(proxy_listener_addr, tls_config, validator_identity)