Skip to content

Commit

Permalink
fix: remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Nov 12, 2024
1 parent 1d9a91b commit 0841243
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 1,216 deletions.
10 changes: 2 additions & 8 deletions src/block_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ use itertools::Itertools as _;
use serde_json::{self, json};
use thegraph_core::{BlockHash, BlockNumber};

use crate::{
blocks::{BlockConstraint, UnresolvedBlock},
chain::Chain,
errors::Error,
};
use crate::{blocks::BlockConstraint, chain::Chain, errors::Error};

#[derive(Debug)]
pub struct BlockRequirements {
Expand Down Expand Up @@ -54,9 +50,7 @@ pub fn resolve_block_requirements(
BlockConstraint::Unconstrained | BlockConstraint::NumberGTE(_) => None,
BlockConstraint::Number(number) => Some(*number),
// resolving block hashes is not guaranteed
BlockConstraint::Hash(hash) => chain
.find(&UnresolvedBlock::WithHash(*hash))
.map(|b| b.number),
BlockConstraint::Hash(hash) => chain.find(hash).map(|b| b.number),
})
.collect();
let min_block = exact_constraints.iter().min().cloned();
Expand Down
36 changes: 0 additions & 36 deletions src/blocks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::fmt;

use serde::Deserialize;
use thegraph_core::{BlockHash, BlockNumber, BlockTimestamp};

Expand All @@ -10,44 +8,10 @@ pub struct Block {
pub timestamp: BlockTimestamp,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum UnresolvedBlock {
WithHash(BlockHash),
WithNumber(BlockNumber),
}

impl UnresolvedBlock {
pub fn matches(&self, block: &Block) -> bool {
match self {
Self::WithHash(hash) => hash == &block.hash,
Self::WithNumber(number) => number == &block.number,
}
}
}

impl fmt::Display for UnresolvedBlock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::WithHash(hash) => write!(f, "{hash}"),
Self::WithNumber(number) => write!(f, "{number}"),
}
}
}

#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum BlockConstraint {
Unconstrained,
Hash(BlockHash),
Number(BlockNumber),
NumberGTE(BlockNumber),
}

impl BlockConstraint {
pub fn into_unresolved(self) -> Option<UnresolvedBlock> {
match self {
Self::Unconstrained => None,
Self::Hash(h) => Some(UnresolvedBlock::WithHash(h)),
Self::Number(n) | Self::NumberGTE(n) => Some(UnresolvedBlock::WithNumber(n)),
}
}
}
8 changes: 4 additions & 4 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::{
iter,
};

use thegraph_core::IndexerId;
use thegraph_core::{BlockHash, IndexerId};

use crate::blocks::{Block, UnresolvedBlock};
use crate::blocks::Block;

#[derive(Default)]
pub struct Chain(BTreeMap<Block, BTreeSet<IndexerId>>);
Expand All @@ -18,8 +18,8 @@ impl Chain {
self.consensus_blocks().next()
}

pub fn find(&self, unresolved: &UnresolvedBlock) -> Option<&Block> {
self.consensus_blocks().find(|b| unresolved.matches(b))
pub fn find(&self, unresolved: &BlockHash) -> Option<&Block> {
self.consensus_blocks().find(|b| &b.hash == unresolved)
}

/// Return the average block production rate, based on the consensus blocks. The result will
Expand Down
2 changes: 0 additions & 2 deletions src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ async fn run_indexer_queries(
response_time_ms,
result,
api_key: auth.key,
user_address: auth.user,
grt_per_usd,
indexer_requests,
request_bytes: client_request_bytes,
Expand Down Expand Up @@ -864,7 +863,6 @@ pub async fn handle_indexer_query(
response_time_ms,
result: report_result,
api_key: auth.key,
user_address: auth.user,
grt_per_usd,
request_bytes: indexer_request.request.len() as u32,
response_bytes: result.as_ref().map(|r| r.client_response.len() as u32).ok(),
Expand Down
12 changes: 1 addition & 11 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::response::{IntoResponse, Response};
use itertools::Itertools as _;
use thegraph_core::{BlockNumber, IndexerId};

use crate::{blocks::UnresolvedBlock, graphql};
use crate::graphql;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -17,9 +17,6 @@ pub enum Error {
/// Failed to authenticate or authorize the client request.
#[error("auth error: {0:#}")]
Auth(anyhow::Error),
/// A block required by the query is not found.
#[error("block not found: {0}")]
BlockNotFound(UnresolvedBlock),
/// The requested subgraph or deployment is not found or invalid.
#[error("subgraph not found: {0:#}")]
SubgraphNotFound(anyhow::Error),
Expand Down Expand Up @@ -67,9 +64,6 @@ impl fmt::Display for IndexerErrors {

#[derive(thiserror::Error, Clone, Debug)]
pub enum IndexerError {
/// Errors that should only occur in exceptional conditions.
#[error("InternalError({0})")]
Internal(&'static str),
/// The indexer is considered unavailable.
#[error("Unavailable({0})")]
Unavailable(UnavailableReason),
Expand Down Expand Up @@ -98,10 +92,6 @@ pub enum UnavailableReason {
#[error("no status: {0}")]
NoStatus(String),

/// The indexer has zero stake.
#[error("no stake")]
NoStake,

/// The indexer's cost model did not produce a fee for the GraphQL document.
#[error("no fee")]
NoFee,
Expand Down
3 changes: 0 additions & 3 deletions src/indexers/indexing_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ pub struct IndexingStatusResponse {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChainStatus {
pub network: String,
pub latest_block: Option<BlockStatus>,
pub earliest_block: Option<BlockStatus>,
}
Expand Down Expand Up @@ -188,7 +187,6 @@ mod tests {
"QmZTy9EJHu8rfY9QbEk3z1epmmvh5XHhT2Wqhkfbyt8k9Z"
);
assert_eq!(status1.chains.len(), 1);
assert_eq!(status1.chains[0].network, "rinkeby");
assert!(status1.chains[0].latest_block.is_some());
assert!(status1.chains[0].earliest_block.is_some());

Expand All @@ -198,7 +196,6 @@ mod tests {
"QmSLQfPFcz2pKRJZUH16Sk26EFpRgdxTYGnMiKvWgKRM2a"
);
assert_eq!(status2.chains.len(), 1);
assert_eq!(status2.chains[0].network, "rinkeby");
assert!(status2.chains[0].latest_block.is_none());
assert!(status2.chains[0].earliest_block.is_none());
}
Expand Down
5 changes: 0 additions & 5 deletions src/indexers/public_poi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ pub struct ProofOfIndexingInfo {
}

impl ProofOfIndexingInfo {
/// Get the POI bytes.
pub fn poi(&self) -> ProofOfIndexing {
self.proof_of_indexing
}

/// Get the POI metadata.
pub fn meta(&self) -> (DeploymentId, BlockNumber) {
(self.deployment_id, self.block_number)
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod receipts;
mod reports;
mod subgraph_studio;
mod time;
#[allow(dead_code)]
mod ttl_hash_map;
mod unattestable_errors;
mod vouchers;
Expand Down Expand Up @@ -162,7 +163,6 @@ async fn main() {
let reporter = reports::Reporter::create(
tap_signer,
conf.graph_env_id,
conf.query_fees_target,
reports::Topics {
queries: "gateway_queries",
attestations: "gateway_attestations",
Expand Down
8 changes: 2 additions & 6 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use lazy_static::lazy_static;
use prometheus::{
core::{MetricVec, MetricVecBuilder},
register_gauge, register_histogram, register_histogram_vec, register_int_counter,
register_int_counter_vec, register_int_gauge_vec, Gauge, Histogram, HistogramTimer,
HistogramVec, IntCounter, IntCounterVec, IntGaugeVec,
register_int_counter_vec, register_int_gauge_vec, Gauge, Histogram, HistogramVec, IntCounter,
IntCounterVec, IntGaugeVec,
};

lazy_static! {
Expand Down Expand Up @@ -113,10 +113,6 @@ impl ResponseMetricVecs {
}
}

pub fn start_timer(&self, label_values: &[&str]) -> Option<HistogramTimer> {
with_metric(&self.duration, label_values, |h| h.start_timer())
}

pub fn check<T, E>(&self, label_values: &[&str], result: &Result<T, E>) {
match &result {
Ok(_) => with_metric(&self.ok, label_values, |c| c.inc()),
Expand Down
6 changes: 3 additions & 3 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ mod request_tracing;
mod require_auth;

pub use legacy_auth::legacy_auth_adapter;
pub use request_id::{RequestId, SetRequestId, SetRequestIdLayer};
pub use request_tracing::{RequestTracing, RequestTracingLayer};
pub use require_auth::{RequireAuthorization, RequireAuthorizationLayer};
pub use request_id::{RequestId, SetRequestIdLayer};
pub use request_tracing::RequestTracingLayer;
pub use require_auth::RequireAuthorizationLayer;
6 changes: 2 additions & 4 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
//! provides information about the subgraphs (and subgraph deployments) registered in the network
//! smart contract, as well as the indexers that are indexing them.
pub use errors::{
DeploymentError, IndexingError, ResolutionError, SubgraphError, UnavailableReason,
};
pub use internal::{Indexer, Indexing, IndexingId};
pub use errors::{DeploymentError, ResolutionError, SubgraphError, UnavailableReason};
pub use internal::{Indexing, IndexingId};
pub use service::{NetworkService, ResolvedSubgraphInfo};

mod config;
Expand Down
3 changes: 0 additions & 3 deletions src/network/indexer_indexing_progress_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub enum ResolutionError {
/// The indexing progress information of a deployment on a chain.
#[derive(Debug, Clone)]
pub struct IndexingProgressInfo {
/// The chain the deployment is associated with.
pub chain: String,
/// The latest block number indexed by the indexer.
pub latest_block: BlockNumber,
/// The earliest block number indexed by the indexer.
Expand Down Expand Up @@ -115,7 +113,6 @@ impl IndexingProgressResolver {
let status = result.ok().and_then(|chains| {
let chain = chains.first()?;
Some(IndexingProgressInfo {
chain: chain.network.clone(),
latest_block: chain.latest_block.as_ref().map(|block| block.number)?,
min_block: chain.earliest_block.as_ref().map(|block| block.number),
})
Expand Down
12 changes: 2 additions & 10 deletions src/network/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use thegraph_core::{DeploymentId, IndexerId, SubgraphId};

use self::indexer_processing::IndexerRawInfo;
pub use self::{
snapshot::{Indexer, Indexing, IndexingId, IndexingProgress, NetworkTopologySnapshot},
snapshot::{Indexing, IndexingId, NetworkTopologySnapshot},
state::InternalState,
subgraph_processing::{AllocationInfo, DeploymentInfo, SubgraphInfo, SubgraphVersionInfo},
subgraph_processing::{AllocationInfo, DeploymentInfo, SubgraphInfo},
};
use super::{subgraph_client::Client as SubgraphClient, DeploymentError, SubgraphError};

Expand Down Expand Up @@ -67,11 +67,3 @@ pub async fn fetch_and_preprocess_subgraph_info(
indexers,
})
}

#[cfg(test)]
mod tests {
use super::*;

mod tests_pre_processing;
mod tests_subgraph_processing;
}
3 changes: 0 additions & 3 deletions src/network/internal/pre_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fn into_subgraph_version_raw_info(
.allocations
.into_iter()
.map(|allocation| AllocationInfo {
id: allocation.id,
indexer: allocation.indexer.id,
})
.collect::<Vec<_>>();
Expand All @@ -200,7 +199,6 @@ fn into_subgraph_version_raw_info(
.network
.ok_or_else(|| anyhow!("manifest missing network"))?;

let version_number = version.version;
let version_deployment = DeploymentRawInfo {
id: deployment.id,
allocations: deployment_allocations,
Expand All @@ -210,7 +208,6 @@ fn into_subgraph_version_raw_info(
};

Ok(SubgraphVersionRawInfo {
version: version_number,
deployment: version_deployment,
})
}
Expand Down
18 changes: 2 additions & 16 deletions src/network/internal/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ pub struct IndexingId {
pub struct Indexing {
/// The indexing unique identifier.
pub id: IndexingId,
/// The indexing chain.
pub chain: String,
/// The largest allocation address.
///
/// This is, among all allocations associated with the indexer and deployment, the address
Expand Down Expand Up @@ -132,11 +130,6 @@ pub struct Subgraph {

#[derive(Debug, Clone)]
pub struct Deployment {
/// Deployment ID.
///
/// The IPFS content ID of the subgraph manifest.
pub id: DeploymentId,

/// The deployment chain name.
///
/// This field is extracted from the deployment manifest.
Expand Down Expand Up @@ -278,11 +271,7 @@ fn construct_subgraphs_table_row(
indexer: alloc.indexer,
deployment: deployment.id,
};
construct_indexings_table_row(
indexing_id,
&deployment.manifest_network,
indexers,
)
construct_indexings_table_row(indexing_id, indexers)
})
.collect::<Vec<_>>()
})
Expand Down Expand Up @@ -323,7 +312,7 @@ fn construct_deployments_table_row(
deployment: deployment_id,
};

construct_indexings_table_row(indexing_id, &deployment_manifest_chain, indexers)
construct_indexings_table_row(indexing_id, indexers)
})
.collect::<HashMap<_, _>>();
if deployment_indexings.is_empty() {
Expand All @@ -333,7 +322,6 @@ fn construct_deployments_table_row(
let deployment_subgraphs = deployment_info.subgraphs;

Ok(Deployment {
id: deployment_id,
chain: deployment_manifest_chain,
start_block: deployment_manifest_start_block,
subgraphs: deployment_subgraphs,
Expand All @@ -346,7 +334,6 @@ fn construct_deployments_table_row(
/// If the indexer reported an error for the indexing, the row is constructed with the error.
fn construct_indexings_table_row(
indexing_id: IndexingId,
indexing_deployment_chain: &str,
indexers: &HashMap<
IndexerId,
Result<(ResolvedIndexerInfo, Arc<Indexer>), IndexerInfoResolutionError>,
Expand Down Expand Up @@ -398,7 +385,6 @@ fn construct_indexings_table_row(

let indexing = Indexing {
id: indexing_id,
chain: indexing_deployment_chain.to_owned(),
largest_allocation: indexing_largest_allocation_addr,
total_allocated_tokens: indexing_total_allocated_tokens,
indexer: Arc::clone(indexer),
Expand Down
Loading

0 comments on commit 0841243

Please sign in to comment.