Skip to content

Commit ecc0c56

Browse files
committed
Hide tonic internals in GrpcServer.
1 parent 7167716 commit ecc0c56

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

timeboost/src/api/internal.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1+
use std::{io, net::SocketAddr};
2+
13
use proto::internal::internal_api_server::InternalApi;
24
use timeboost_builder::{CertifierDown, Handle};
35
use timeboost_types::Block;
46
use tonic::{Request, Response, Status};
57

6-
use timeboost_proto as proto;
8+
use timeboost_proto::{self as proto, internal::internal_api_server::InternalApiServer};
79

8-
pub struct InternalApiService {
9-
block_handler: Handle,
10+
pub struct GrpcServer {
11+
service: InternalApiService,
1012
}
1113

12-
impl InternalApiService {
14+
impl GrpcServer {
1315
pub fn new(block_handler: Handle) -> Self {
14-
Self { block_handler }
16+
Self {
17+
service: InternalApiService { block_handler },
18+
}
19+
}
20+
21+
pub async fn serve(self, addr: SocketAddr) -> io::Result<()> {
22+
tonic::transport::Server::builder()
23+
.add_service(InternalApiServer::new(self.service))
24+
.serve(addr)
25+
.await
26+
.map_err(io::Error::other)
1527
}
1628
}
1729

30+
struct InternalApiService {
31+
block_handler: Handle,
32+
}
33+
1834
#[tonic::async_trait]
1935
impl InternalApi for InternalApiService {
2036
async fn submit_block(&self, r: Request<proto::block::Block>) -> Result<Response<()>, Status> {

timeboost/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use anyhow::Result;
77
use metrics::TimeboostMetrics;
88
use multisig::PublicKey;
99
use timeboost_builder::{Certifier, CertifierDown, Submitter};
10-
use timeboost_proto::internal::internal_api_server::InternalApiServer;
1110
use timeboost_sequencer::{Output, Sequencer};
1211
use timeboost_types::BundleVariant;
1312
use timeboost_utils::types::prometheus::PrometheusMetrics;
@@ -23,7 +22,7 @@ pub use timeboost_sequencer as sequencer;
2322
pub use timeboost_types as types;
2423

2524
use crate::api::ApiServer;
26-
use crate::api::internal::InternalApiService;
25+
use crate::api::internal::GrpcServer;
2726
use crate::forwarder::nitro_forwarder::NitroForwarder;
2827

2928
pub mod api;
@@ -82,9 +81,8 @@ impl Timeboost {
8281
.build()
8382
}
8483

85-
pub fn internal_grpc_api(&self) -> tonic::transport::server::Router {
86-
let svc = InternalApiService::new(self.certifier.handle());
87-
tonic::transport::Server::builder().add_service(InternalApiServer::new(svc))
84+
pub fn internal_grpc_api(&self) -> GrpcServer {
85+
GrpcServer::new(self.certifier.handle())
8886
}
8987

9088
pub async fn go(mut self) -> Result<()> {

0 commit comments

Comments
 (0)