Skip to content

Commit 80195c7

Browse files
author
Gilad Chase
committed
chore(apollo_l1_endpoint_monitor): add client with minimal boilerplate
1 parent 1669365 commit 80195c7

File tree

6 files changed

+95
-8
lines changed

6 files changed

+95
-8
lines changed

Cargo.lock

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ members = [
2626
"crates/apollo_infra_utils",
2727
"crates/apollo_integration_tests",
2828
"crates/apollo_l1_endpoint_monitor",
29+
"crates/apollo_l1_endpoint_monitor_types",
2930
"crates/apollo_l1_gas_price",
3031
"crates/apollo_l1_gas_price_types",
3132
"crates/apollo_l1_provider",
@@ -106,6 +107,7 @@ apollo_infra.path = "crates/apollo_infra"
106107
apollo_infra_utils = { path = "crates/apollo_infra_utils", version = "0.0.0" }
107108
apollo_integration_tests.path = "crates/apollo_integration_tests"
108109
apollo_l1_endpoint_monitor.path = "crates/apollo_l1_endpoint_monitor"
110+
apollo_l1_endpoint_monitor_types.path = "crates/apollo_l1_endpoint_monitor_types"
109111
apollo_l1_gas_price.path = "crates/apollo_l1_gas_price"
110112
apollo_l1_gas_price_types.path = "crates/apollo_l1_gas_price_types"
111113
apollo_l1_provider.path = "crates/apollo_l1_provider"

crates/apollo_l1_endpoint_monitor/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ license.workspace = true
99
alloy.workspace = true
1010
apollo_config.workspace = true
1111
apollo_infra.workspace = true
12+
apollo_l1_endpoint_monitor_types.workspace = true
1213
async-trait.workspace = true
1314
serde.workspace = true
1415
thiserror.workspace = true

crates/apollo_l1_endpoint_monitor/src/monitor.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use alloy::providers::{Provider, ProviderBuilder};
2+
use apollo_l1_endpoint_monitor_types::{L1EndpointMonitorError, L1EndpointMonitorResult};
23
use serde::{Deserialize, Serialize};
3-
use thiserror::Error;
44
use tracing::{error, warn};
55
use url::Url;
66

7-
type L1EndpointMonitorResult<T> = Result<T, L1EndpointMonitorError>;
87
#[derive(Debug, Clone)]
98
pub struct L1EndpointMonitor {
109
pub current_l1_endpoint_index: usize,
@@ -60,9 +59,3 @@ impl L1EndpointMonitor {
6059
pub struct L1EndpointMonitorConfig {
6160
pub ordered_l1_endpoint_urls: Vec<Url>,
6261
}
63-
64-
#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)]
65-
pub enum L1EndpointMonitorError {
66-
#[error("All L1 endpoints are non-operational")]
67-
NoActiveL1Endpoint,
68-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "apollo_l1_endpoint_monitor_types"
3+
version.workspace = true
4+
edition.workspace = true
5+
repository.workspace = true
6+
license.workspace = true
7+
8+
[features]
9+
testing = ["mockall"]
10+
11+
[dependencies]
12+
alloy.workspace = true
13+
apollo_config.workspace = true
14+
apollo_infra.workspace = true
15+
apollo_proc_macros.workspace = true
16+
async-trait.workspace = true
17+
mockall = { workspace = true, optional = true }
18+
serde.workspace = true
19+
strum_macros.workspace = true
20+
thiserror.workspace = true
21+
tokio.workspace = true
22+
url = { workspace = true, features = ["serde"] }
23+
24+
[dev-dependencies]
25+
mockall.workspace = true
26+
27+
[lints]
28+
workspace = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use std::sync::Arc;
2+
3+
use apollo_infra::component_client::ClientError;
4+
use apollo_infra::component_definitions::ComponentClient;
5+
use apollo_infra::impl_debug_for_infra_requests_and_responses;
6+
use apollo_proc_macros::handle_all_response_variants;
7+
use async_trait::async_trait;
8+
use serde::{Deserialize, Serialize};
9+
use strum_macros::AsRefStr;
10+
use thiserror::Error;
11+
use url::Url;
12+
13+
pub type L1EndpointMonitorResult<T> = Result<T, L1EndpointMonitorError>;
14+
pub type L1EndpointMonitorClientResult<T> = Result<T, L1EndpointMonitorClientError>;
15+
pub type SharedL1EndpointMonitorClient = Arc<dyn L1EndpointMonitorClient>;
16+
17+
#[cfg_attr(any(feature = "testing", test), mockall::automock)]
18+
#[async_trait]
19+
pub trait L1EndpointMonitorClient: Send + Sync {
20+
async fn get_active_l1_endpoint(&self) -> L1EndpointMonitorClientResult<Url>;
21+
}
22+
23+
#[derive(Clone, Serialize, Deserialize, AsRefStr)]
24+
pub enum L1EndpointMonitorRequest {
25+
GetActiveL1Endpoint(),
26+
}
27+
28+
#[derive(Clone, Serialize, Deserialize, AsRefStr)]
29+
pub enum L1EndpointMonitorResponse {
30+
GetActiveL1Endpoint(L1EndpointMonitorResult<Url>),
31+
}
32+
33+
#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)]
34+
pub enum L1EndpointMonitorError {
35+
#[error("All L1 endpoints are non-operational")]
36+
NoActiveL1Endpoint,
37+
}
38+
39+
#[derive(Clone, Debug, Error)]
40+
pub enum L1EndpointMonitorClientError {
41+
#[error(transparent)]
42+
ClientError(#[from] ClientError),
43+
#[error(transparent)]
44+
L1EndpointMonitorError(#[from] L1EndpointMonitorError),
45+
}

0 commit comments

Comments
 (0)