gatewayd/
gatewayd.rs

1#![warn(missing_docs)]
2//! This crate provides `gatewayd`, the Fedimint gateway binary.
3//!
4//! The binary contains logic for sending/receiving Lightning payments on behalf
5//! of Fedimint clients in one or more connected Federations.
6//!
7//! It runs a webserver with a REST API that can be used by Fedimint
8//! clients to request routing of payments through the Lightning Network.
9//! The API also has endpoints for managing the gateway.
10
11use std::sync::Arc;
12
13use fedimint_core::fedimint_build_code_version_env;
14use fedimint_core::util::handle_version_hash_command;
15use fedimint_gateway_server::Gateway;
16use fedimint_logging::TracingSetup;
17#[cfg(not(target_env = "msvc"))]
18use tikv_jemallocator::Jemalloc;
19use tracing::info;
20
21#[cfg(not(target_env = "msvc"))]
22#[global_allocator]
23// rocksdb suffers from memory fragmentation when using standard allocator
24static GLOBAL: Jemalloc = Jemalloc;
25
26fn main() -> Result<(), anyhow::Error> {
27    let runtime = Arc::new(tokio::runtime::Runtime::new()?);
28    runtime.block_on(async {
29        handle_version_hash_command(fedimint_build_code_version_env!());
30        TracingSetup::default().init()?;
31        let gatewayd = Gateway::new_with_default_modules().await?;
32        let shutdown_receiver = gatewayd.clone().run(runtime.clone()).await?;
33        shutdown_receiver.await;
34        gatewayd.unannounce_from_all_federations().await;
35        info!("Gatewayd exiting...");
36        Ok(())
37    })
38}