Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading