mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 03:31:45 +00:00
Lighthouse bootnode (#1265)
* Initial bootnode structure * Add boot_node subcommand * Add bootnode subcommand * fmt corrections * Extend help message * Move boot_node crate * Update discv5 dep * Improve logging and boot-node logging Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
65
boot_node/src/lib.rs
Normal file
65
boot_node/src/lib.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
//! Creates a simple DISCV5 server which can be used to bootstrap an Eth2 network.
|
||||
use clap::ArgMatches;
|
||||
use slog;
|
||||
use slog::{o, Drain, Level, Logger};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
mod cli;
|
||||
mod config;
|
||||
mod server;
|
||||
pub use cli::cli_app;
|
||||
use config::BootNodeConfig;
|
||||
|
||||
/// Run the bootnode given the CLI configuration.
|
||||
pub fn run(matches: &ArgMatches<'_>, 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).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 logger = Logger::root(drain.fuse(), o!());
|
||||
let _scope_guard = slog_scope::set_global_logger(logger);
|
||||
let _log_guard = slog_stdlog::init_with_level(debug_level).unwrap();
|
||||
|
||||
// Run the main function emitting any errors
|
||||
if let Err(e) = main(matches, slog_scope::logger()) {
|
||||
slog::crit!(slog_scope::logger(), "{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn main(matches: &ArgMatches<'_>, log: slog::Logger) -> Result<(), String> {
|
||||
// Builds a custom executor for the bootnode
|
||||
let mut runtime = tokio::runtime::Builder::new()
|
||||
.threaded_scheduler()
|
||||
.enable_all()
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to build runtime: {}", e))?;
|
||||
|
||||
// parse the CLI args into a useable config
|
||||
let config = BootNodeConfig::try_from(matches)?;
|
||||
|
||||
// Run the boot node
|
||||
runtime.block_on(server::run(config, log));
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user