Skip to main content

confium_signerd/
main.rs

1//! `confium-signerd` — distributed threshold signing daemon.
2//!
3//! Connects to a coordinator and responds to signing requests.
4
5#![forbid(unsafe_code)]
6#![allow(dead_code)]
7#![allow(missing_docs)]
8
9mod config;
10mod daemon;
11
12use clap::Parser;
13use config::DaemonConfig;
14use daemon::SignerDaemon;
15use std::path::PathBuf;
16
17/// Command-line arguments.
18#[derive(Parser, Debug)]
19#[command(
20    name = "confium-signerd",
21    version,
22    about = "Distributed threshold signing daemon"
23)]
24pub struct Args {
25    /// Path to the TOML configuration file.
26    #[arg(short, long)]
27    config: PathBuf,
28
29    /// Run in verbose mode (more tracing output).
30    #[arg(short, long)]
31    verbose: bool,
32}
33
34fn main() {
35    let args = Args::parse();
36
37    let filter = tracing_subscriber::EnvFilter::new(if args.verbose { "debug" } else { "info" });
38
39    let subscriber = tracing_subscriber::fmt()
40        .with_env_filter(filter)
41        .with_target(false);
42
43    #[cfg(test)]
44    let _ = subscriber.try_init();
45    #[cfg(not(test))]
46    subscriber.init();
47
48    let config = match DaemonConfig::load(&args.config) {
49        Ok(c) => c,
50        Err(e) => {
51            eprintln!("Configuration error: {e}");
52            std::process::exit(1);
53        }
54    };
55
56    tracing::info!(
57        addr = %config.coordinator_addr,
58        signer = %config.signer_id,
59        quorum = %config.quorum_id,
60        scheme = %config.scheme,
61        "starting signer daemon"
62    );
63
64    let daemon = SignerDaemon::new(config);
65    let result = daemon.run();
66    match result {
67        daemon::RunResult::Disconnected => {
68            tracing::info!("disconnected, shutting down");
69        }
70        daemon::RunResult::MaxRetriesExhausted => {
71            tracing::error!("all reconnect attempts exhausted");
72            std::process::exit(1);
73        }
74    }
75}