Skip to content

Commit

Permalink
sui-node: use sui-http for rpc http service
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jan 2, 2025
1 parent b19b7af commit a8ffd5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sui-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ telemetry-subscribers.workspace = true
fastcrypto.workspace = true
fastcrypto-zkp.workspace = true
move-vm-profiler.workspace = true
sui-http.workspace = true

[target.'cfg(msim)'.dependencies]
sui-simulator.workspace = true
35 changes: 16 additions & 19 deletions crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use mysten_network::server::SUI_TLS_SERVER_NAME;
use prometheus::Registry;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
#[cfg(msim)]
Expand Down Expand Up @@ -229,7 +228,7 @@ pub struct SuiNode {
config: NodeConfig,
validator_components: Mutex<Option<ValidatorComponents>>,
/// The http server responsible for serving JSON-RPC as well as the experimental rest service
_http_server: Option<tokio::task::JoinHandle<()>>,
_http_server: Option<sui_http::ServerHandle>,
state: Arc<AuthorityState>,
transaction_orchestrator: Option<Arc<TransactiondOrchestrator<NetworkAuthorityClient>>>,
registry_service: RegistryService,
Expand Down Expand Up @@ -2020,7 +2019,7 @@ pub async fn build_http_server(
prometheus_registry: &Registry,
_custom_runtime: Option<Handle>,
software_version: &'static str,
) -> Result<Option<tokio::task::JoinHandle<()>>> {
) -> Result<Option<sui_http::ServerHandle>> {
// Validators do not expose these APIs
if config.consensus_config().is_some() {
return Ok(None);
Expand Down Expand Up @@ -2125,25 +2124,23 @@ pub async fn build_http_server(
rpc_service.into_router().await
};

router = router.merge(rpc_router);

let listener = tokio::net::TcpListener::bind(&config.json_rpc_address)
.await
.unwrap();
let addr = listener.local_addr().unwrap();
let layers = ServiceBuilder::new()
.map_request(|mut request: axum::http::Request<_>| {
if let Some(connect_info) = request.extensions().get::<sui_http::ConnectInfo>() {
let axum_connect_info = axum::extract::ConnectInfo(connect_info.remote_addr);
request.extensions_mut().insert(axum_connect_info);
}
request
})
.layer(axum::middleware::from_fn(server_timing_middleware));

router = router.layer(axum::middleware::from_fn(server_timing_middleware));
router = router.merge(rpc_router).layer(layers);

let handle = tokio::spawn(async move {
axum::serve(
listener,
router.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap()
});
let handle = sui_http::Builder::new()
.serve(&config.json_rpc_address, router)
.map_err(|e| anyhow::anyhow!("{e}"))?;

info!(local_addr =? addr, "Sui JSON-RPC server listening on {addr}");
info!(local_addr =? handle.local_addr(), "Sui JSON-RPC server listening on {}", handle.local_addr());

Ok(Some(handle))
}
Expand Down

0 comments on commit a8ffd5a

Please sign in to comment.