Skip to content
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

refactor: merge resolvers and blocklists #1003

Merged
merged 11 commits into from
Dec 9, 2024
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ thegraph-core = { version = "0.9.0", features = [
"attestation",
"serde",
] }
thegraph-graphql-http = { version = "0.2.1", features = [
"http-client-reqwest",
] }
thegraph-graphql-http = { version = "0.3.2", features = ["reqwest"] }
thiserror = "2.0.2"
tokio = { version = "1.38.0", features = [
"macros",
Expand Down
35 changes: 4 additions & 31 deletions src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
indexing_performance,
metrics::{with_metric, METRICS},
middleware::RequestId,
network::{self, DeploymentError, Indexing, IndexingId, ResolvedSubgraphInfo, SubgraphError},
network::{DeploymentError, Indexing, IndexingId, ResolvedSubgraphInfo, SubgraphError},
reports,
};

Expand Down Expand Up @@ -464,7 +464,7 @@ fn build_candidates_list(
blocks_per_minute: u64,
block_requirements: &BlockRequirements,
subgraph_versions: &[DeploymentId],
indexings: HashMap<IndexingId, Result<Indexing, network::ResolutionError>>,
indexings: HashMap<IndexingId, Result<Indexing, UnavailableReason>>,
) -> (
Vec<Candidate<IndexerId, CandidateMetadata>>,
BTreeMap<IndexerId, IndexerError>,
Expand Down Expand Up @@ -492,7 +492,7 @@ fn build_candidates_list(
let indexing = match indexing {
Ok(indexing) => indexing,
Err(err) => {
candidates_errors.insert(indexing_id.indexer, err.into());
candidates_errors.insert(indexing_id.indexer, IndexerError::Unavailable(err));
continue;
}
};
Expand Down Expand Up @@ -630,33 +630,6 @@ fn blocks_behind(seconds_behind: u32, blocks_per_minute: u64) -> u64 {
((seconds_behind as f64 / 60.0) * blocks_per_minute as f64) as u64
}

impl From<network::ResolutionError> for IndexerError {
fn from(err: network::ResolutionError) -> Self {
match err {
network::ResolutionError::Unavailable(reason) => {
let reason = match reason {
network::UnavailableReason::Blocked(reason) => {
UnavailableReason::Blocked(reason)
}
reason @ network::UnavailableReason::IndexerServiceVersionBelowMin
| reason @ network::UnavailableReason::GraphNodeVersionBelowMin => {
UnavailableReason::NotSupported(reason.to_string())
}
reason @ network::UnavailableReason::IndexerResolutionError { .. }
| reason @ network::UnavailableReason::IndexingProgressNotFound => {
UnavailableReason::NoStatus(reason.to_string())
}
};
IndexerError::Unavailable(reason)
}
network::ResolutionError::Internal(err) => {
tracing::error!(error = ?err, "internal error");
IndexerError::Unavailable(UnavailableReason::Internal(err))
}
}
}
}

pub async fn handle_indexer_query(
State(ctx): State<Context>,
Extension(auth): Extension<AuthSettings>,
Expand All @@ -680,7 +653,7 @@ pub async fn handle_indexer_query(
.get(&indexing_id)
.ok_or_else(|| Error::NoIndexers)?
.as_ref()
.map_err(|err| bad_indexers(err.clone().into()))?;
.map_err(|err| bad_indexers(IndexerError::Unavailable(err.clone())))?;

let (latest_block, blocks_per_minute) = {
let chain = ctx.chains.chain(&subgraph.chain);
Expand Down
6 changes: 6 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ pub enum UnavailableReason {
Internal(&'static str),
}

impl UnavailableReason {
pub fn invalid_url() -> Self {
UnavailableReason::NoStatus("invalid URL".to_string())
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MissingBlockError {
pub missing: Option<BlockNumber>,
Expand Down
7 changes: 0 additions & 7 deletions src/indexers.rs

This file was deleted.

112 changes: 0 additions & 112 deletions src/indexers/cost_models.rs

This file was deleted.

Loading
Loading