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

geyser: Add TLS config to gRPC server #183

Merged
merged 1 commit into from
Sep 19, 2023
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
9 changes: 9 additions & 0 deletions yellowstone-grpc-geyser/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct ConfigGrpc {
/// Limits for possible filters
#[serde(default)]
pub filters: ConfigGrpcFilters,
/// TLS config
pub tls_config: Option<ConfigGrpcServerTls>,
}

impl ConfigGrpc {
Expand Down Expand Up @@ -264,6 +266,13 @@ impl Default for ConfigGrpcFiltersEntry {
}
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConfigGrpcServerTls {
pub cert_path: String,
pub key_path: String,
}

#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConfigPrometheus {
Expand Down
18 changes: 15 additions & 3 deletions yellowstone-grpc-geyser/src/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use tonic::{
codec::CompressionEncoding,
transport::{Identity, ServerTlsConfig},
};
use {
crate::{
config::{ConfigBlockFailAction, ConfigGrpc},
Expand Down Expand Up @@ -42,7 +46,6 @@ use {
},
tokio_stream::wrappers::ReceiverStream,
tonic::{
codec::CompressionEncoding,
transport::server::{Server, TcpIncoming},
Request, Response, Result as TonicResult, Status, Streaming,
},
Expand Down Expand Up @@ -707,7 +710,7 @@ impl GrpcService {

// Create Server
let service = GeyserServer::new(Self {
config,
config: config.clone(),
blocks_meta,
subscribe_id: AtomicUsize::new(0),
broadcast_tx: broadcast_tx.clone(),
Expand All @@ -727,12 +730,21 @@ impl GrpcService {
// Run Server
let shutdown = Arc::new(Notify::new());
let shutdown_grpc = Arc::clone(&shutdown);

let mut server_builder = Server::builder();

if let Some(tls_config) = config.tls_config {
let cert = std::fs::read_to_string(tls_config.cert_path)?;
let key = std::fs::read_to_string(tls_config.key_path)?;
server_builder = server_builder
.tls_config(ServerTlsConfig::new().identity(Identity::from_pem(&cert, &key)))?;
}
tokio::spawn(async move {
// gRPC Health check service
let (mut health_reporter, health_service) = health_reporter();
health_reporter.set_serving::<GeyserServer<Self>>().await;

Server::builder()
server_builder
.http2_keepalive_interval(Some(Duration::from_secs(5)))
.add_service(health_service)
.add_service(service)
Expand Down
Loading