diff --git a/Cargo.lock b/Cargo.lock index 1992e79a94a..51b391b5633 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1408,15 +1408,28 @@ name = "apollo_l1_endpoint_monitor" version = "0.15.0-rc.2" dependencies = [ "alloy", + "apollo_l1_endpoint_monitor_types", "mockito 1.6.1", "papyrus_base_layer", "serde", - "thiserror 1.0.69", "tokio", "tracing", "url", ] +[[package]] +name = "apollo_l1_endpoint_monitor_types" +version = "0.15.0-rc.2" +dependencies = [ + "apollo_infra", + "async-trait", + "mockall", + "serde", + "strum_macros 0.25.3", + "thiserror 1.0.69", + "url", +] + [[package]] name = "apollo_l1_gas_price" version = "0.15.0-rc.2" diff --git a/Cargo.toml b/Cargo.toml index 84595ac3568..e79eba80b23 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", @@ -109,6 +110,7 @@ apollo_infra.path = "crates/apollo_infra" apollo_infra_utils = { path = "crates/apollo_infra_utils", version = "0.15.0-rc.2" } 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..6679b3cf912 100644 --- a/crates/apollo_l1_endpoint_monitor/Cargo.toml +++ b/crates/apollo_l1_endpoint_monitor/Cargo.toml @@ -7,8 +7,8 @@ license.workspace = true [dependencies] alloy.workspace = true +apollo_l1_endpoint_monitor_types.workspace = true serde.workspace = true -thiserror.workspace = true tracing.workspace = true url = { workspace = true, features = ["serde"] } diff --git a/crates/apollo_l1_endpoint_monitor/src/monitor.rs b/crates/apollo_l1_endpoint_monitor/src/monitor.rs index 290c5309d26..a6025ad05e1 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; @@ -9,8 +9,6 @@ use url::Url; #[path = "l1_endpoint_monitor_tests.rs"] pub mod l1_endpoint_monitor_tests; -type L1EndpointMonitorResult = Result; - /// The JSON-RPC method used to check L1 endpoint health. // Note: is this fast enough? Alternatively, we can just check connectivity, but we already hit // a bug in infura where the connectivity was fine, but get_block_number() failed. @@ -72,9 +70,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/tests/happy_flow.rs b/crates/apollo_l1_endpoint_monitor/tests/happy_flow.rs index 222aa5d70ad..c9786e2db63 100644 --- a/crates/apollo_l1_endpoint_monitor/tests/happy_flow.rs +++ b/crates/apollo_l1_endpoint_monitor/tests/happy_flow.rs @@ -1,8 +1,5 @@ -use apollo_l1_endpoint_monitor::monitor::{ - L1EndpointMonitor, - L1EndpointMonitorConfig, - L1EndpointMonitorError, -}; +use apollo_l1_endpoint_monitor::monitor::{L1EndpointMonitor, L1EndpointMonitorConfig}; +use apollo_l1_endpoint_monitor_types::L1EndpointMonitorError; use papyrus_base_layer::test_utils::anvil; use url::Url; 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..a86f25411c4 --- /dev/null +++ b/crates/apollo_l1_endpoint_monitor_types/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "apollo_l1_endpoint_monitor_types" +version.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true + +[features] +testing = ["mockall"] + +[dependencies] +apollo_infra.workspace = true +async-trait.workspace = true +mockall = { workspace = true, optional = true } +serde.workspace = true +strum_macros.workspace = true +thiserror.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), +}