use std::{
panic::{self, PanicHookInfo},
process,
};
use backtrace::Backtrace;
use structopt::StructOpt;
use tokio::runtime::Builder;
use tracing::info;
use casper_node::{cli::Cli, MAX_THREAD_COUNT};
fn panic_hook(info: &PanicHookInfo<'_>) {
let backtrace = Backtrace::new();
eprintln!("{:?}", backtrace);
if let Some(s) = info.payload().downcast_ref::<&str>() {
eprintln!("node panicked: {s}");
} else {
eprintln!("{info}");
}
process::abort()
}
fn main() -> anyhow::Result<()> {
let exit_code = {
let num_cpus = num_cpus::get();
let runtime = Builder::new_multi_thread()
.enable_all()
.worker_threads(num_cpus)
.max_blocking_threads(MAX_THREAD_COUNT - num_cpus)
.build()
.unwrap();
panic::set_hook(Box::new(panic_hook));
let opts = Cli::from_args();
runtime.block_on(opts.run())?
};
info!(%exit_code, "exiting casper-node");
process::exit(exit_code)
}