-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simple config, env and cli * fix comp * init env first * added env override * postgres config * fmt * updated env in readme * examples * a
- Loading branch information
1 parent
1bcf7d2
commit 3eecb89
Showing
12 changed files
with
328 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## LiteRpc | ||
LITE_RPC_HTTP_ADDR=http://0.0.0.0:8890 | ||
LITE_RPC_WS_ADDR=[::]:8891 | ||
|
||
## RPC | ||
RPC_ADDR=http://0.0.0.0:8899 | ||
WS_ADDR=ws://0.0.0.0:8900 | ||
# IDENTITY=your_identity_keypair_here | ||
|
||
## Prometheus | ||
# PROMETHEUS_ADDR=your_prometheus_address_here | ||
|
||
## Fanout size and retries configuration | ||
FANOUT_SIZE=18 | ||
MAX_RETRIES=40 | ||
RETRY_TIMEOUT=3 | ||
|
||
## Quic Proxy | ||
# QUIC_PROXY_ADDR=your_quic_proxy_address_here | ||
|
||
## gRPC Configuration | ||
USE_GRPC=false | ||
GRPC_ADDR=http://127.0.0.0:10000 | ||
# GRPC_X_TOKEN=your_grpc_token_here | ||
|
||
## Postgres Configuration | ||
# PG_ENABLED=true | ||
# PG_CONFIG=your_postgres_config_here | ||
# CA_PEM_B64=your_base64_encoded_ca_pem_here | ||
# CLIENT_PKS_B64=your_base64_encoded_client_pks_here | ||
# CLIENT_PKS_PASS=your_client_pks_password_here | ||
|
||
## Gso | ||
# DISABLE_GSO=your_disable_gso_setting_here |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"rpc_addr": "http://0.0.0.0:8899", | ||
"ws_addr": "ws://0.0.0.0:8900", | ||
"lite_rpc_http_addr": "http://0.0.0.0:8890", | ||
"lite_rpc_ws_addr": "[::]:8891", | ||
"fanout_size": 18, | ||
"identity_keypair": null, | ||
"prometheus_addr": "[::]:9091", | ||
"maximum_retries_per_tx": 40, | ||
"transaction_retry_after_secs": 3, | ||
"quic_proxy_addr": null, | ||
"use_grpc": false, | ||
"grpc_addr": "http://127.0.0.0:10000", | ||
"grpc_x_token": null, | ||
"postgres": { | ||
"pg_config": "your_postgres_config", | ||
"ssl": { | ||
"ca_pem_b64": "your_base64_encoded_ca_pem", | ||
"client_pks_b64": "your_base64_encoded_client_pks", | ||
"client_pks_pass": "your_client_pks_password" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
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_from_cli: &String) -> Option<Keypair> { | ||
if let Ok(identity_env_var) = env::var("IDENTITY") { | ||
if let Ok(identity_bytes) = serde_json::from_str::<Vec<u8>>(identity_env_var.as_str()) { | ||
Some(Keypair::from_bytes(identity_bytes.as_slice()).unwrap()) | ||
} else { | ||
// must be a file | ||
let identity_file = tokio::fs::read_to_string(identity_env_var.as_str()) | ||
.await | ||
.expect("Cannot find the identity file provided"); | ||
let identity_bytes: Vec<u8> = serde_json::from_str(&identity_file).unwrap(); | ||
Some(Keypair::from_bytes(identity_bytes.as_slice()).unwrap()) | ||
} | ||
} else if identity_from_cli.is_empty() { | ||
None | ||
} else { | ||
let identity_file = tokio::fs::read_to_string(identity_from_cli.as_str()) | ||
pub async fn load_identity_keypair( | ||
identity_from_cli: Option<String>, | ||
) -> anyhow::Result<Option<Keypair>> { | ||
let identity_str = if let Some(identity_from_cli) = identity_from_cli { | ||
tokio::fs::read_to_string(identity_from_cli) | ||
.await | ||
.expect("Cannot find the identity file provided"); | ||
let identity_bytes: Vec<u8> = serde_json::from_str(&identity_file).unwrap(); | ||
Some(Keypair::from_bytes(identity_bytes.as_slice()).unwrap()) | ||
} | ||
.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>")?; | ||
|
||
Ok(Some( | ||
Keypair::from_bytes(identity_bytes.as_slice()).context("Invalid identity")?, | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod postgres_block; | ||
pub mod postgres_config; | ||
pub mod postgres_session; | ||
pub mod postgres_transaction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use anyhow::Context; | ||
use std::env; | ||
use tokio_postgres::config::SslMode; | ||
|
||
#[derive(serde::Deserialize, Debug, Clone)] | ||
pub struct PostgresSessionConfig { | ||
pub pg_config: String, | ||
pub ssl: Option<PostgresSessionSslConfig>, | ||
} | ||
|
||
#[derive(serde::Deserialize, Debug, Clone)] | ||
pub struct PostgresSessionSslConfig { | ||
pub ca_pem_b64: String, | ||
pub client_pks_b64: String, | ||
pub client_pks_pass: String, | ||
} | ||
|
||
impl PostgresSessionConfig { | ||
pub fn new_from_env() -> anyhow::Result<Option<Self>> { | ||
// pg not enabled | ||
if env::var("PG_ENABLED").is_err() { | ||
return Ok(None); | ||
} | ||
|
||
let env_pg_config = env::var("PG_CONFIG").context("PG_CONFIG not found")?; | ||
|
||
let ssl_config = if env_pg_config | ||
.parse::<tokio_postgres::Config>()? | ||
.get_ssl_mode() | ||
.eq(&SslMode::Disable) | ||
{ | ||
None | ||
} else { | ||
let env_ca_pem_b64 = env::var("CA_PEM_B64").context("CA_PEM_B64 not found")?; | ||
let env_client_pks_b64 = | ||
env::var("CLIENT_PKS_B64").context("CLIENT_PKS_B64 not found")?; | ||
let env_client_pks_pass = | ||
env::var("CLIENT_PKS_PASS").context("CLIENT_PKS_PASS not found")?; | ||
|
||
Some(PostgresSessionSslConfig { | ||
ca_pem_b64: env_ca_pem_b64, | ||
client_pks_b64: env_client_pks_b64, | ||
client_pks_pass: env_client_pks_pass, | ||
}) | ||
}; | ||
|
||
Ok(Some(Self { | ||
pg_config: env_pg_config, | ||
ssl: ssl_config, | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.