Skip to content

Commit

Permalink
Bugfix,379 identity key pair loading must be optional (#381)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
grooviegermanikus committed Apr 2, 2024
1 parent 12a6832 commit 944a931
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
15 changes: 7 additions & 8 deletions core/src/keypair_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?,
Expand Down
7 changes: 2 additions & 5 deletions lite-rpc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions quic-forward-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 944a931

Please sign in to comment.