Skip to content

Commit 91b4b80

Browse files
author
Gilad Chase
committed
chore(apollo_l1_endpoint_monitor): add client with minimal boilerplate
1 parent f1a50b9 commit 91b4b80

File tree

6 files changed

+98
-8
lines changed

6 files changed

+98
-8
lines changed

Cargo.lock

+21
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

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ license.workspace = true
77

88
[dependencies]
99
alloy.workspace = true
10+
apollo_config.workspace = true
11+
apollo_infra.workspace = true
12+
apollo_l1_endpoint_monitor_types.workspace = true
13+
async-trait.workspace = true
1014
serde.workspace = true
1115
thiserror.workspace = true
1216
tracing.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,42 @@
1+
use std::sync::Arc;
2+
3+
use apollo_infra::component_client::ClientError;
4+
use async_trait::async_trait;
5+
use serde::{Deserialize, Serialize};
6+
use strum_macros::AsRefStr;
7+
use thiserror::Error;
8+
use url::Url;
9+
10+
pub type L1EndpointMonitorResult<T> = Result<T, L1EndpointMonitorError>;
11+
pub type L1EndpointMonitorClientResult<T> = Result<T, L1EndpointMonitorClientError>;
12+
pub type SharedL1EndpointMonitorClient = Arc<dyn L1EndpointMonitorClient>;
13+
14+
#[cfg_attr(any(feature = "testing", test), mockall::automock)]
15+
#[async_trait]
16+
pub trait L1EndpointMonitorClient: Send + Sync {
17+
async fn get_active_l1_endpoint(&self) -> L1EndpointMonitorClientResult<Url>;
18+
}
19+
20+
#[derive(Clone, Serialize, Deserialize, AsRefStr)]
21+
pub enum L1EndpointMonitorRequest {
22+
GetActiveL1Endpoint(),
23+
}
24+
25+
#[derive(Clone, Serialize, Deserialize, AsRefStr)]
26+
pub enum L1EndpointMonitorResponse {
27+
GetActiveL1Endpoint(L1EndpointMonitorResult<Url>),
28+
}
29+
30+
#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)]
31+
pub enum L1EndpointMonitorError {
32+
#[error("All L1 endpoints are non-operational")]
33+
NoActiveL1Endpoint,
34+
}
35+
36+
#[derive(Clone, Debug, Error)]
37+
pub enum L1EndpointMonitorClientError {
38+
#[error(transparent)]
39+
ClientError(#[from] ClientError),
40+
#[error(transparent)]
41+
L1EndpointMonitorError(#[from] L1EndpointMonitorError),
42+
}

0 commit comments

Comments
 (0)