pub mod callback;
pub mod config;
pub mod control;
pub mod dashboard;
pub mod db;
pub mod error;
pub mod logging;
pub mod pool;
pub mod queue;
pub mod schema;
pub mod server;
pub mod stats;
pub mod time_bending;
pub use config::Config;
pub use error::{Error, Result};
pub use server::AggregatorServer;
pub use stats::{Stats, StatsSnapshot};
pub use callback::{
get_aggregator_callback, set_aggregator_callback, with_callback, AcceptedInfo,
AggregatorCallback, AggregatorStartedInfo, BlockUpdate, ForwardedInfo, NoOpCallback,
RejectedInfo, SubmissionInfo,
};
pub use control::{clear_stop_request, is_stop_requested, request_stop};
pub async fn run_aggregator_safe(config: Config) -> Result<()> {
clear_stop_request();
let result = std::panic::AssertUnwindSafe(async {
let server = AggregatorServer::new(config).await?;
server.run().await
});
match futures::FutureExt::catch_unwind(result).await {
Ok(Ok(())) => Ok(()),
Ok(Err(e)) => {
callback::with_callback(|cb| cb.on_error(&e.to_string()));
Err(e)
}
Err(panic) => {
let msg = panic
.downcast_ref::<&str>()
.map(|s| s.to_string())
.or_else(|| panic.downcast_ref::<String>().cloned())
.unwrap_or_else(|| "unknown panic".to_string());
callback::with_callback(|cb| cb.on_error(&format!("Aggregator panicked: {}", msg)));
Err(Error::Server(format!("Aggregator panicked: {}", msg)))
}
}
}