Files
lighthouse/boot_node/src/lib.rs
Eitan Seri-Levi df983a83e1 upgrade clap to v4.5 (#5273)
* upgrade clap to v4.5

* cli fixes

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* value parser for mnemonic

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* merge unstable

* default --format val

* fix eth sim

* fix eth sim

* merge conflicts

* resolve beta compiler issue

* add num args, version

* add custom flag parser, make rate limiter flags clap friendly

* remove unneeded check

* fmt

* update

* alphabetic order

* resolve merge conflict

* fix test

* resolve conflicts

* fix test

* revert removed if statement

* fmt got me again

* fix broken flag

* make cli

* make cli

* update

* remove -e files

* update

* cli help updates

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* cli help updates

* md files

* merge conflict

* merge conflicts

* md

* help text, text width, and a few flag fixes

* fmt

* merge

* revert

* revert

* resolve merge conflicts

* merge conflicts

* revert simulator changes

* require at least one arg

* fix eth sim cli

* resolve merge conflicts

* book changes

* md changes

* cli check

* cli check

* retry cli check

* retry cli check

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli

* cli

* Merge remote-tracking branch 'origin/unstable' into upgrade-clap-cli

* Update CLI docs for Goerli removal

* Fix cargo lock
2024-05-28 05:46:39 +00:00

91 lines
2.8 KiB
Rust

//! Creates a simple DISCV5 server which can be used to bootstrap an Eth2 network.
use clap::ArgMatches;
use slog::{o, Drain, Level, Logger};
use eth2_network_config::Eth2NetworkConfig;
mod cli;
pub mod config;
mod server;
pub use cli::cli_app;
use config::BootNodeConfig;
use types::{EthSpec, EthSpecId};
const LOG_CHANNEL_SIZE: usize = 2048;
/// Run the bootnode given the CLI configuration.
pub fn run(
lh_matches: &ArgMatches,
bn_matches: &ArgMatches,
eth_spec_id: EthSpecId,
eth2_network_config: &Eth2NetworkConfig,
debug_level: String,
) {
let debug_level = match debug_level.as_str() {
"trace" => log::Level::Trace,
"debug" => log::Level::Debug,
"info" => log::Level::Info,
"warn" => log::Level::Warn,
"error" => log::Level::Error,
"crit" => log::Level::Error,
_ => unreachable!(),
};
// Setting up the initial logger format and building it.
let drain = {
let decorator = slog_term::TermDecorator::new().build();
let decorator = logging::AlignedTermDecorator::new(decorator, logging::MAX_MESSAGE_WIDTH);
let drain = slog_term::FullFormat::new(decorator).build().fuse();
slog_async::Async::new(drain)
.chan_size(LOG_CHANNEL_SIZE)
.build()
};
let drain = match debug_level {
log::Level::Info => drain.filter_level(Level::Info),
log::Level::Debug => drain.filter_level(Level::Debug),
log::Level::Trace => drain.filter_level(Level::Trace),
log::Level::Warn => drain.filter_level(Level::Warning),
log::Level::Error => drain.filter_level(Level::Error),
};
let log = Logger::root(drain.fuse(), o!());
// Run the main function emitting any errors
if let Err(e) = match eth_spec_id {
EthSpecId::Minimal => {
main::<types::MinimalEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
}
EthSpecId::Mainnet => {
main::<types::MainnetEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
}
EthSpecId::Gnosis => {
main::<types::GnosisEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
}
} {
slog::crit!(slog_scope::logger(), "{}", e);
}
}
fn main<E: EthSpec>(
lh_matches: &ArgMatches,
bn_matches: &ArgMatches,
eth2_network_config: &Eth2NetworkConfig,
log: slog::Logger,
) -> Result<(), String> {
// Builds a custom executor for the bootnode
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.map_err(|e| format!("Failed to build runtime: {}", e))?;
// Run the boot node
runtime.block_on(server::run::<E>(
lh_matches,
bn_matches,
eth2_network_config,
log,
))?;
Ok(())
}