diff --git a/Cargo.lock b/Cargo.lock index 98fba149364..f95e4ed31f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1395,6 +1395,10 @@ name = "apollo_l1_endpoint_monitor" version = "0.0.0" dependencies = [ "alloy", + "apollo_config", + "apollo_infra", + "apollo_l1_endpoint_monitor_types", + "async-trait", "mockito 1.6.1", "papyrus_base_layer", "serde", @@ -1404,6 +1408,23 @@ dependencies = [ "url", ] +[[package]] +name = "apollo_l1_endpoint_monitor_types" +version = "0.0.0" +dependencies = [ + "alloy", + "apollo_config", + "apollo_infra", + "apollo_proc_macros", + "async-trait", + "mockall", + "serde", + "strum_macros 0.25.3", + "thiserror 1.0.69", + "tokio", + "url", +] + [[package]] name = "apollo_l1_gas_price" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 3d41a522cdf..b3d9332743b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ members = [ "crates/apollo_infra_utils", "crates/apollo_integration_tests", "crates/apollo_l1_endpoint_monitor", + "crates/apollo_l1_endpoint_monitor_types", "crates/apollo_l1_gas_price", "crates/apollo_l1_gas_price_types", "crates/apollo_l1_provider", @@ -106,6 +107,7 @@ apollo_infra.path = "crates/apollo_infra" apollo_infra_utils = { path = "crates/apollo_infra_utils", version = "0.0.0" } apollo_integration_tests.path = "crates/apollo_integration_tests" apollo_l1_endpoint_monitor.path = "crates/apollo_l1_endpoint_monitor" +apollo_l1_endpoint_monitor_types.path = "crates/apollo_l1_endpoint_monitor_types" apollo_l1_gas_price.path = "crates/apollo_l1_gas_price" apollo_l1_gas_price_types.path = "crates/apollo_l1_gas_price_types" apollo_l1_provider.path = "crates/apollo_l1_provider" diff --git a/crates/apollo_l1_endpoint_monitor/Cargo.toml b/crates/apollo_l1_endpoint_monitor/Cargo.toml index 62fb631de2b..90814ad5ff3 100644 --- a/crates/apollo_l1_endpoint_monitor/Cargo.toml +++ b/crates/apollo_l1_endpoint_monitor/Cargo.toml @@ -7,6 +7,10 @@ license.workspace = true [dependencies] alloy.workspace = true +apollo_config.workspace = true +apollo_infra.workspace = true +apollo_l1_endpoint_monitor_types.workspace = true +async-trait.workspace = true serde.workspace = true thiserror.workspace = true tracing.workspace = true diff --git a/crates/apollo_l1_endpoint_monitor/src/monitor.rs b/crates/apollo_l1_endpoint_monitor/src/monitor.rs index 290c5309d26..3704b8266dd 100644 --- a/crates/apollo_l1_endpoint_monitor/src/monitor.rs +++ b/crates/apollo_l1_endpoint_monitor/src/monitor.rs @@ -1,7 +1,7 @@ use alloy::primitives::U64; use alloy::providers::{Provider, ProviderBuilder}; +use apollo_l1_endpoint_monitor_types::{L1EndpointMonitorError, L1EndpointMonitorResult}; use serde::{Deserialize, Serialize}; -use thiserror::Error; use tracing::{error, warn}; use url::Url; @@ -72,9 +72,3 @@ impl L1EndpointMonitor { pub struct L1EndpointMonitorConfig { pub ordered_l1_endpoint_urls: Vec, } - -#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)] -pub enum L1EndpointMonitorError { - #[error("All L1 endpoints are non-operational")] - NoActiveL1Endpoint, -} diff --git a/crates/apollo_l1_endpoint_monitor_types/Cargo.toml b/crates/apollo_l1_endpoint_monitor_types/Cargo.toml new file mode 100644 index 00000000000..5c15fac8a0b --- /dev/null +++ b/crates/apollo_l1_endpoint_monitor_types/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "apollo_l1_endpoint_monitor_types" +version.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true + +[features] +testing = ["mockall"] + +[dependencies] +alloy.workspace = true +apollo_config.workspace = true +apollo_infra.workspace = true +apollo_proc_macros.workspace = true +async-trait.workspace = true +mockall = { workspace = true, optional = true } +serde.workspace = true +strum_macros.workspace = true +thiserror.workspace = true +tokio.workspace = true +url = { workspace = true, features = ["serde"] } + +[dev-dependencies] +mockall.workspace = true + +[lints] +workspace = true diff --git a/crates/apollo_l1_endpoint_monitor_types/src/lib.rs b/crates/apollo_l1_endpoint_monitor_types/src/lib.rs new file mode 100644 index 00000000000..ab1b0180e83 --- /dev/null +++ b/crates/apollo_l1_endpoint_monitor_types/src/lib.rs @@ -0,0 +1,42 @@ +use std::sync::Arc; + +use apollo_infra::component_client::ClientError; +use async_trait::async_trait; +use serde::{Deserialize, Serialize}; +use strum_macros::AsRefStr; +use thiserror::Error; +use url::Url; + +pub type L1EndpointMonitorResult = Result; +pub type L1EndpointMonitorClientResult = Result; +pub type SharedL1EndpointMonitorClient = Arc; + +#[cfg_attr(any(feature = "testing", test), mockall::automock)] +#[async_trait] +pub trait L1EndpointMonitorClient: Send + Sync { + async fn get_active_l1_endpoint(&self) -> L1EndpointMonitorClientResult; +} + +#[derive(Clone, Serialize, Deserialize, AsRefStr)] +pub enum L1EndpointMonitorRequest { + GetActiveL1Endpoint(), +} + +#[derive(Clone, Serialize, Deserialize, AsRefStr)] +pub enum L1EndpointMonitorResponse { + GetActiveL1Endpoint(L1EndpointMonitorResult), +} + +#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)] +pub enum L1EndpointMonitorError { + #[error("All L1 endpoints are non-operational")] + NoActiveL1Endpoint, +} + +#[derive(Clone, Debug, Error)] +pub enum L1EndpointMonitorClientError { + #[error(transparent)] + ClientError(#[from] ClientError), + #[error(transparent)] + L1EndpointMonitorError(#[from] L1EndpointMonitorError), +}