-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathcommit-boost.rs
More file actions
114 lines (95 loc) · 3.28 KB
/
commit-boost.rs
File metadata and controls
114 lines (95 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use std::path::PathBuf;
use cb_cli::docker_init::handle_docker_init;
use cb_common::{
config::{
LogsSettings, PBS_SERVICE_NAME, SIGNER_SERVICE_NAME, StartSignerConfig, load_pbs_config,
},
utils::{initialize_tracing_log, print_logo, wait_for_signal},
};
use cb_pbs::{DefaultBuilderApi, PbsService, PbsState};
use cb_signer::service::SigningService;
use clap::{Parser, Subcommand};
use eyre::Result;
use tracing::{error, info};
/// Version string with a leading 'v'
const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
/// Long about string for the CLI
const LONG_ABOUT: &str = "Commit-Boost allows Ethereum validators to safely run MEV-Boost and community-built commitment protocols";
/// Subcommands and global arguments for the module
#[derive(Parser, Debug)]
#[command(name = "Commit-Boost", version = VERSION, about, long_about = LONG_ABOUT)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
/// Run the PBS service
Pbs,
/// Run the Signer service
Signer,
/// Generate the starting docker-compose files and environment files
Init {
/// Path to config file
#[arg(long("config"))]
config_path: PathBuf,
/// Path to output files
#[arg(short, long("output"), default_value = "./")]
output_path: PathBuf,
},
}
#[tokio::main]
async fn main() -> Result<()> {
// Parse the CLI arguments (currently only used for version info, more can be
// added later)
let _cli = Cli::parse();
color_eyre::install()?;
match _cli.command {
Commands::Pbs => run_pbs_service().await?,
Commands::Signer => run_signer_service().await?,
Commands::Init { config_path, output_path } => run_init(config_path, output_path).await?,
}
Ok(())
}
/// Run the PBS service
async fn run_pbs_service() -> Result<()> {
let _guard = initialize_tracing_log(PBS_SERVICE_NAME, LogsSettings::from_env_config()?);
let pbs_config = load_pbs_config().await?;
PbsService::init_metrics(pbs_config.chain)?;
let state = PbsState::new(pbs_config);
let server = PbsService::run::<_, DefaultBuilderApi>(state);
tokio::select! {
maybe_err = server => {
if let Err(err) = maybe_err {
error!(%err, "PBS service unexpectedly stopped");
eprintln!("PBS service unexpectedly stopped: {err}");
}
},
_ = wait_for_signal() => {
info!("shutting down");
}
}
Ok(())
}
/// Run the Signer service
async fn run_signer_service() -> Result<()> {
let _guard = initialize_tracing_log(SIGNER_SERVICE_NAME, LogsSettings::from_env_config()?);
let config = StartSignerConfig::load_from_env()?;
let server = SigningService::run(config);
tokio::select! {
maybe_err = server => {
if let Err(err) = maybe_err {
error!(%err, "signing server unexpectedly stopped");
eprintln!("signing server unexpectedly stopped: {err}");
}
},
_ = wait_for_signal() => {
info!("shutting down");
}
}
Ok(())
}
async fn run_init(config_path: PathBuf, output_path: PathBuf) -> Result<()> {
print_logo();
handle_docker_init(config_path, output_path).await
}