|
1 |
| -use std::net::SocketAddr; |
| 1 | +use std::process::Stdio; |
2 | 2 |
|
3 |
| -use cb_common::{config::BuilderConfig, pbs::RelayEntry, types::Chain, utils::eth_to_wei}; |
| 3 | +use cb_common::{ |
| 4 | + config::{CommitBoostConfig, CONFIG_PATH_ENV, MODULE_ID_ENV}, |
| 5 | + utils::print_logo, |
| 6 | +}; |
| 7 | +use cb_crypto::service::SigningService; |
| 8 | +use cb_pbs::{BuilderState, DefaultBuilderApi, PbsService}; |
4 | 9 | use clap::{Parser, Subcommand};
|
5 | 10 |
|
6 |
| -pub mod runner; |
7 |
| - |
8 | 11 | #[derive(Parser, Debug)]
|
9 | 12 | #[command(version, about)]
|
10 | 13 | pub struct Args {
|
11 | 14 | #[command(subcommand)]
|
12 | 15 | pub cmd: Command,
|
13 |
| - |
14 |
| - /// Start with Holesky spec |
15 |
| - #[arg(long, global = true)] |
16 |
| - pub holesky: bool, |
| 16 | + // /// Start with Holesky spec |
| 17 | + // #[arg(long, global = true)] |
| 18 | + // pub holesky: bool, |
17 | 19 | }
|
18 | 20 |
|
19 | 21 | #[derive(Debug, Subcommand)]
|
20 | 22 | pub enum Command {
|
21 |
| - /// Pbs module configs, try to keep compatibility with MEV boost cli configs |
22 |
| - Boost { |
23 |
| - /// Address to start for boost server on |
24 |
| - #[arg(short, long, default_value = "127.0.0.1:18550", env = "BOOST_LISTEN_ADDR")] |
25 |
| - listen_address: SocketAddr, |
26 |
| - /// Add a single relay (can be repeated or comma separated). Format is scheme://pubkey@host |
27 |
| - #[arg(short, long, visible_alias = "relays", env = "RELAYS", num_args = 1.., required = true, value_delimiter = ',')] |
28 |
| - relay: Vec<String>, |
29 |
| - /// Check relay status on startup and getStatus calls |
30 |
| - #[arg(long, env = "RELAY_STARTUP_CHECK")] |
31 |
| - relay_check: bool, |
32 |
| - /// Timeout in ms for calling getHeader to relays |
33 |
| - #[arg(long, default_value_t = 950, env = "RELAY_TIMEOUT_MS_GETHEADER")] |
34 |
| - timeout_get_header_ms: u64, |
35 |
| - /// Timeout in ms for calling getPayload to relays |
36 |
| - #[arg(long, default_value_t = 4000, env = "RELAY_TIMEOUT_MS_GETPAYLOAD")] |
37 |
| - timeout_get_payload_ms: u64, |
38 |
| - /// Timeout in ms for calling registerValidator to relays |
39 |
| - #[arg(long, default_value_t = 3000, env = "RELAY_TIMEOUT_MS_REGVAL")] |
40 |
| - timeout_register_validator_ms: u64, |
41 |
| - /// Skip signature verification for relay headers |
42 |
| - #[arg(long)] |
43 |
| - skip_sigverify: bool, |
44 |
| - /// Minimum bid to accept from relays in ETH |
45 |
| - #[arg(long, default_value_t = 0.0, env = "MIN_BID_ETH")] |
46 |
| - min_bid_eth: f64, |
| 23 | + // /// Start pbs module, signing server and commit modules |
| 24 | + // Start { |
| 25 | + // /// Address to start for boost server on |
| 26 | + // #[arg(short, long, default_value = "127.0.0.1:18550", env = "BOOST_LISTEN_ADDR")] |
| 27 | + // pbs_address: SocketAddr, |
| 28 | + // /// Add a single relay (can be repeated or comma separated). Format is |
| 29 | + // scheme://pubkey@host #[arg(short, long, visible_alias = "relays", env = "RELAYS", |
| 30 | + // num_args = 1.., required = true, value_delimiter = ',')] relay: Vec<String>, |
| 31 | + // #[arg(long)] |
| 32 | + // pbs: Option<String>, |
| 33 | + // /// Check relay status on startup and getStatus calls |
| 34 | + // #[arg(long, env = "RELAY_STARTUP_CHECK")] |
| 35 | + // relay_check: bool, |
| 36 | + // /// Timeout in ms for calling getHeader to relays |
| 37 | + // #[arg(long, default_value_t = 950, env = "RELAY_TIMEOUT_MS_GETHEADER")] |
| 38 | + // timeout_get_header_ms: u64, |
| 39 | + // /// Timeout in ms for calling getPayload to relays |
| 40 | + // #[arg(long, default_value_t = 4000, env = "RELAY_TIMEOUT_MS_GETPAYLOAD")] |
| 41 | + // timeout_get_payload_ms: u64, |
| 42 | + // /// Timeout in ms for calling registerValidator to relays |
| 43 | + // #[arg(long, default_value_t = 3000, env = "RELAY_TIMEOUT_MS_REGVAL")] |
| 44 | + // timeout_register_validator_ms: u64, |
| 45 | + // /// Skip signature verification for relay headers |
| 46 | + // #[arg(long)] |
| 47 | + // skip_sigverify: bool, |
| 48 | + // /// Minimum bid to accept from relays in ETH |
| 49 | + // #[arg(long, default_value_t = 0.0, env = "MIN_BID_ETH")] |
| 50 | + // min_bid_eth: f64, |
| 51 | + // /// Address where to start the service on |
| 52 | + // #[arg(long, default_value = "127.0.0.1:33950", env = SIGNER_LISTEN_ADDR)] |
| 53 | + // sign_address: SocketAddr, |
| 54 | + // /// Path to executable |
| 55 | + // #[arg(short, long, num_args = 1.., required = true, value_delimiter = ',')] |
| 56 | + // module: Vec<String>, |
| 57 | + // }, |
| 58 | + Start { |
| 59 | + /// Path to config file |
| 60 | + config: String, |
47 | 61 | },
|
48 | 62 | }
|
49 | 63 |
|
50 | 64 | impl Args {
|
51 |
| - pub fn to_config(self) -> (Chain, BuilderConfig) { |
52 |
| - let chain = if self.holesky { Chain::Holesky } else { Chain::Mainnet }; |
| 65 | + pub async fn run(self) -> eyre::Result<()> { |
| 66 | + print_logo(); |
53 | 67 |
|
54 | 68 | match self.cmd {
|
55 |
| - Command::Boost { |
56 |
| - listen_address: address, |
57 |
| - relay, |
58 |
| - relay_check, |
59 |
| - timeout_get_header_ms, |
60 |
| - timeout_get_payload_ms, |
61 |
| - timeout_register_validator_ms, |
62 |
| - skip_sigverify, |
63 |
| - min_bid_eth, |
64 |
| - } => { |
65 |
| - let config = BuilderConfig { |
66 |
| - address, |
67 |
| - relays: deser_relay_vec(relay), |
68 |
| - relay_check, |
69 |
| - timeout_get_header_ms, |
70 |
| - timeout_get_payload_ms, |
71 |
| - timeout_register_validator_ms, |
72 |
| - skip_sigverify, |
73 |
| - min_bid_wei: eth_to_wei(min_bid_eth), |
74 |
| - }; |
75 |
| - println!("{}", serde_json::to_string_pretty(&config).unwrap()); |
76 |
| - (chain, config) |
| 69 | + Command::Start { config: config_path } => { |
| 70 | + let config = CommitBoostConfig::from_file(&config_path); |
| 71 | + |
| 72 | + // this mocks the commit boost client starting containers, processes etc |
| 73 | + let mut child_handles = Vec::with_capacity(config.modules.len()); |
| 74 | + |
| 75 | + for module in config.modules { |
| 76 | + let child = std::process::Command::new(module.path) |
| 77 | + .env(MODULE_ID_ENV, module.id) |
| 78 | + .env(CONFIG_PATH_ENV, &config_path) |
| 79 | + .spawn() |
| 80 | + .expect("failed to start process"); |
| 81 | + |
| 82 | + child_handles.push(child); |
| 83 | + } |
| 84 | + |
| 85 | + // start signing server |
| 86 | + tokio::spawn(SigningService::run(config.chain, config.signer)); |
| 87 | + |
| 88 | + // start pbs server |
| 89 | + if let Some(pbs_path) = config.pbs.path { |
| 90 | + let cmd = std::process::Command::new(pbs_path) |
| 91 | + .env(CONFIG_PATH_ENV, &config_path) |
| 92 | + .stdout(Stdio::inherit()) |
| 93 | + .stderr(Stdio::inherit()) |
| 94 | + .output() |
| 95 | + .expect("failed to start pbs module"); |
| 96 | + |
| 97 | + if !cmd.status.success() { |
| 98 | + eprintln!("Process failed with status: {}", cmd.status); |
| 99 | + } |
| 100 | + } else { |
| 101 | + let state = BuilderState::<()>::new(config.chain, config.pbs); |
| 102 | + PbsService::run::<(), DefaultBuilderApi>(state).await; |
| 103 | + } |
77 | 104 | }
|
78 | 105 | }
|
| 106 | + |
| 107 | + Ok(()) |
79 | 108 | }
|
80 | 109 | }
|
81 | 110 |
|
82 |
| -fn deser_relay_vec(relays: Vec<String>) -> Vec<RelayEntry> { |
83 |
| - relays |
84 |
| - .into_iter() |
85 |
| - .map(|s| { |
86 |
| - serde_json::from_str::<RelayEntry>(&format!("\"{}\"", s.trim())) |
87 |
| - .expect("invalid relay format, should be scheme://pubkey@host") |
88 |
| - }) |
89 |
| - .collect() |
90 |
| -} |
| 111 | +// fn deser_relay_vec(relays: Vec<String>) -> Vec<RelayEntry> { |
| 112 | +// relays |
| 113 | +// .into_iter() |
| 114 | +// .map(|s| { |
| 115 | +// serde_json::from_str::<RelayEntry>(&format!("\"{}\"", s.trim())) |
| 116 | +// .expect("invalid relay format, should be scheme://pubkey@host") |
| 117 | +// }) |
| 118 | +// .collect() |
| 119 | +// } |
0 commit comments