Skip to content

chore(apollo_l1_endpoint_monitor): add client with minimal boilerplate #6329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gilad/05-06-chore_apollo_l1_endpoint_monitor_add_integration_test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions crates/apollo_l1_endpoint_monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions crates/apollo_l1_endpoint_monitor/src/monitor.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -72,9 +72,3 @@ impl L1EndpointMonitor {
pub struct L1EndpointMonitorConfig {
pub ordered_l1_endpoint_urls: Vec<Url>,
}

#[derive(Debug, Clone, Error, Serialize, Deserialize, PartialEq, Eq)]
pub enum L1EndpointMonitorError {
#[error("All L1 endpoints are non-operational")]
NoActiveL1Endpoint,
}
28 changes: 28 additions & 0 deletions crates/apollo_l1_endpoint_monitor_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions crates/apollo_l1_endpoint_monitor_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<T> = Result<T, L1EndpointMonitorError>;
pub type L1EndpointMonitorClientResult<T> = Result<T, L1EndpointMonitorClientError>;
pub type SharedL1EndpointMonitorClient = Arc<dyn L1EndpointMonitorClient>;

#[cfg_attr(any(feature = "testing", test), mockall::automock)]
#[async_trait]
pub trait L1EndpointMonitorClient: Send + Sync {
async fn get_active_l1_endpoint(&self) -> L1EndpointMonitorClientResult<Url>;
}

#[derive(Clone, Serialize, Deserialize, AsRefStr)]
pub enum L1EndpointMonitorRequest {
GetActiveL1Endpoint(),
}

#[derive(Clone, Serialize, Deserialize, AsRefStr)]
pub enum L1EndpointMonitorResponse {
GetActiveL1Endpoint(L1EndpointMonitorResult<Url>),
}

#[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),
}
Loading