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::{LOG_GATEWAY, TracingSetup};
17#[cfg(not(any(target_env = "msvc", target_os = "ios", target_os = "android")))]
18use tikv_jemallocator::Jemalloc;
19use tracing::info;
20
21#[cfg(not(any(target_env = "msvc", target_os = "ios", target_os = "android")))]
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 (mnemonic_sender, mnemonic_receiver) = tokio::sync::broadcast::channel::<()>(4);
32        let gatewayd = Gateway::new_with_default_modules(mnemonic_sender).await?;
33        let shutdown_receiver = gatewayd
34            .clone()
35            .run(runtime.clone(), mnemonic_receiver)
36            .await?;
37        shutdown_receiver.await;
38        gatewayd.unannounce_from_all_federations().await;
39        info!(target: LOG_GATEWAY, "Gatewayd exiting...");
40        Ok(())
41    })
42}