Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Mar 4, 2025
1 parent c7d2315 commit 3fdf2a3
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 95 deletions.
6 changes: 3 additions & 3 deletions src/block_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{
use anyhow::{anyhow, bail};
use cost_model::Context;
use graphql::{
graphql_parser::query::{OperationDefinition, Selection, SelectionSet, Text, Value},
IntoStaticValue as _, StaticValue,
graphql_parser::query::{OperationDefinition, Selection, SelectionSet, Text, Value},
};
use itertools::Itertools as _;
use serde_json::{self, json};
Expand Down Expand Up @@ -100,14 +100,14 @@ fn block_constraints(context: &Context) -> Result<BTreeSet<BlockConstraint>, Err
OperationDefinition::Query(_)
| OperationDefinition::Mutation(_)
| OperationDefinition::Subscription(_) => {
return Err(Error::BadQuery(anyhow!("unsupported GraphQL features")))
return Err(Error::BadQuery(anyhow!("unsupported GraphQL features")));
}
};
for selection in &selection_set.items {
let selection_field = match selection {
Selection::Field(field) => field,
Selection::FragmentSpread(_) | Selection::InlineFragment(_) => {
return Err(Error::BadQuery(anyhow!("unsupported GraphQL features")))
return Err(Error::BadQuery(anyhow!("unsupported GraphQL features")));
}
};
let constraint = match selection_field
Expand Down
2 changes: 1 addition & 1 deletion src/budgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ordered_float::NotNan;
use tokio::{
select, spawn,
sync::{mpsc, watch},
time::{interval, MissedTickBehavior},
time::{MissedTickBehavior, interval},
};

use crate::metrics::METRICS;
Expand Down
6 changes: 3 additions & 3 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
iter,
};

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

use crate::blocks::Block;

Expand Down Expand Up @@ -108,10 +108,10 @@ impl Chain {
#[cfg(test)]
mod tests {
use itertools::Itertools;
use rand::{rngs::SmallRng, seq::IndexedRandom as _, Rng as _, RngCore as _, SeedableRng};
use rand::{Rng as _, RngCore as _, SeedableRng, rngs::SmallRng, seq::IndexedRandom as _};
use thegraph_core::{
alloy::primitives::{Address, BlockHash, U256},
IndexerId,
alloy::primitives::{Address, BlockHash, U256},
};

use super::{Block, Chain, MAX_LEN};
Expand Down
2 changes: 1 addition & 1 deletion src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use thegraph_core::IndexerId;
use tokio::{
select, spawn,
sync::mpsc,
time::{interval, MissedTickBehavior},
time::{MissedTickBehavior, interval},
};

use crate::{blocks::Block, chain::Chain, metrics::METRICS};
Expand Down
27 changes: 12 additions & 15 deletions src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{

use anyhow::anyhow;
use axum::{
Extension,
body::Bytes,
extract::{Path, State},
http::{Response, StatusCode},
Extension,
};
use cost_model::Context as AgoraContext;
use custom_debug::CustomDebug;
Expand All @@ -20,21 +20,21 @@ use prost::bytes::Buf;
use rand::Rng as _;
use serde::Deserialize;
use serde_json::value::RawValue;
use thegraph_core::{alloy::primitives::BlockNumber, AllocationId, DeploymentId, IndexerId};
use thegraph_headers::{graph_attestation::GraphAttestation, HttpBuilderExt as _};
use thegraph_core::{AllocationId, DeploymentId, IndexerId, alloy::primitives::BlockNumber};
use thegraph_headers::{HttpBuilderExt as _, graph_attestation::GraphAttestation};
use tokio::sync::mpsc;
use tracing::{info_span, Instrument as _};
use tracing::{Instrument as _, info_span};
use url::Url;

use self::{context::Context, query_selector::QuerySelector};
use crate::{
auth::AuthSettings,
block_constraints::{resolve_block_requirements, rewrite_query, BlockRequirements},
block_constraints::{BlockRequirements, resolve_block_requirements, rewrite_query},
budgets::USD,
errors::{Error, IndexerError, IndexerErrors, MissingBlockError, UnavailableReason},
indexer_client::{IndexerAuth, IndexerResponse},
indexing_performance,
metrics::{with_metric, METRICS},
metrics::{METRICS, with_metric},
middleware::RequestId,
network::{DeploymentError, Indexing, IndexingId, ResolvedSubgraphInfo, SubgraphError},
reports,
Expand Down Expand Up @@ -801,11 +801,11 @@ mod tests {

use assert_matches::assert_matches;
use axum::{
Extension, Router,
body::Body,
http::{Method, Request, StatusCode},
middleware,
routing::post,
Extension, Router,
};
use headers::{Authorization, ContentType, HeaderMapExt};
use http_body_util::BodyExt;
Expand All @@ -814,7 +814,7 @@ mod tests {

use crate::{
auth::{ApiKey, AuthContext, AuthSettings},
middleware::{legacy_auth_adapter, RequireAuthorizationLayer},
middleware::{RequireAuthorizationLayer, legacy_auth_adapter},
};

/// Create a test authorization context.
Expand All @@ -825,13 +825,10 @@ mod tests {
special_api_keys: Default::default(),
};
if let Some(key) = key {
ctx.api_keys = watch::channel(HashMap::from([(
key.into(),
ApiKey {
key: key.into(),
..Default::default()
},
)]))
ctx.api_keys = watch::channel(HashMap::from([(key.into(), ApiKey {
key: key.into(),
..Default::default()
})]))
.1;
}
ctx
Expand Down
2 changes: 1 addition & 1 deletion src/client_query/query_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ where
mod tests {
use assert_matches::assert_matches;
use axum::{
Router,
body::Body,
http::{Method, Request},
Router,
};
use http_body_util::BodyExt;
use thegraph_core::{deployment_id, subgraph_id};
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use ipnetwork::IpNetwork;
use ordered_float::NotNan;
use semver::Version;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use serde_with::{DisplayFromStr, serde_as};
use thegraph_core::{
alloy::primitives::{Address, BlockNumber, B256, U256},
DeploymentId,
alloy::primitives::{Address, B256, BlockNumber, U256},
};
use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use axum::response::{IntoResponse, Response};
use itertools::Itertools as _;
use thegraph_core::{alloy::primitives::BlockNumber, IndexerId};
use thegraph_core::{IndexerId, alloy::primitives::BlockNumber};

use crate::graphql;

Expand Down
4 changes: 2 additions & 2 deletions src/exchange_rate.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{sync::Arc, time::Duration};

use ChainlinkPriceFeed::ChainlinkPriceFeedInstance;
use anyhow::ensure;
use ordered_float::NotNan;
use thegraph_core::alloy::{
primitives::Address, providers::ProviderBuilder, sol, transports::http::Http,
};
use tokio::{
sync::watch,
time::{interval, MissedTickBehavior},
time::{MissedTickBehavior, interval},
};
use url::Url;
use ChainlinkPriceFeed::ChainlinkPriceFeedInstance;

sol!(
#[sol(rpc)]
Expand Down
24 changes: 15 additions & 9 deletions src/indexer_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use http::{header::CONTENT_TYPE, StatusCode};
use http::{StatusCode, header::CONTENT_TYPE};
use reqwest::header::AUTHORIZATION;
use serde::{Deserialize, Serialize};
use thegraph_core::{
Expand Down Expand Up @@ -235,14 +235,20 @@ mod tests {
fn check_block_error() {
let tests = [
("", Ok(())),
("Failed to decode `block.number` value: `subgraph QmQqLJVgZLcRduoszARzRi12qGheUTWAHFf3ixMeGm2xML has only indexed up to block number 133239690 and data for block number 133239697 is therefore not yet available", Err(MissingBlockError {
missing: Some(133239697),
latest: Some(133239690),
})),
("Failed to decode `block.hash` value", Err(MissingBlockError {
missing: None,
latest: None,
})),
(
"Failed to decode `block.number` value: `subgraph QmQqLJVgZLcRduoszARzRi12qGheUTWAHFf3ixMeGm2xML has only indexed up to block number 133239690 and data for block number 133239697 is therefore not yet available",
Err(MissingBlockError {
missing: Some(133239697),
latest: Some(133239690),
}),
),
(
"Failed to decode `block.hash` value",
Err(MissingBlockError {
missing: None,
latest: None,
}),
),
];
for (input, expected) in tests {
assert_eq!(super::check_block_error(input), expected);
Expand Down
2 changes: 1 addition & 1 deletion src/indexing_performance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, ops::Deref, time::Duration};

use parking_lot::RwLock;
use thegraph_core::{alloy::primitives::BlockNumber, DeploymentId, IndexerId};
use thegraph_core::{DeploymentId, IndexerId, alloy::primitives::BlockNumber};
use tokio::{self, sync::mpsc, time::MissedTickBehavior};

use crate::network::NetworkService;
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ use std::{

use auth::AuthContext;
use axum::{
Router,
http::{self, status::StatusCode},
routing,
serve::ListenerExt,
Router,
};
use budgets::{Budgeter, USD};
use chains::Chains;
use client_query::context::Context;
use config::{ApiKeys, BlocklistEntry, ExchangeRateProvider};
use indexer_client::IndexerClient;
use indexing_performance::IndexingPerformance;
use middleware::{legacy_auth_adapter, RequestTracingLayer, RequireAuthorizationLayer};
use middleware::{RequestTracingLayer, RequireAuthorizationLayer, legacy_auth_adapter};
use network::{indexer_blocklist, subgraph_client::Client as SubgraphClient};
use prometheus::{self, Encoder as _};
use receipts::ReceiptSigner;
Expand All @@ -54,7 +54,7 @@ use thegraph_core::{
};
use tokio::{net::TcpListener, signal::unix::SignalKind, sync::watch};
use tower_http::cors::{self, CorsLayer};
use tracing_subscriber::{prelude::*, EnvFilter};
use tracing_subscriber::{EnvFilter, prelude::*};

#[global_allocator]
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
Expand Down
13 changes: 6 additions & 7 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use lazy_static::lazy_static;
use prometheus::{
Gauge, Histogram, HistogramVec, IntCounter, IntCounterVec, IntGaugeVec,
core::{MetricVec, MetricVecBuilder},
register_gauge, register_histogram, register_histogram_vec, register_int_counter,
register_int_counter_vec, register_int_gauge_vec, Gauge, Histogram, HistogramVec, IntCounter,
IntCounterVec, IntGaugeVec,
register_int_counter_vec, register_int_gauge_vec,
};

lazy_static! {
Expand All @@ -26,11 +26,10 @@ impl Metrics {
"average indexer fees per query, in USD"
)
.unwrap(),
indexer_query: ResponseMetricVecs::new(
"gw_indexer_query",
"indexer query",
&["deployment", "indexer"],
),
indexer_query: ResponseMetricVecs::new("gw_indexer_query", "indexer query", &[
"deployment",
"indexer",
]),
blocks_per_minute: register_int_gauge_vec!(
"gw_blocks_per_minute",
"chain blocks per minute",
Expand Down
8 changes: 4 additions & 4 deletions src/middleware/legacy_auth.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::BTreeMap;

use axum::{
RequestPartsExt,
body::Body,
extract::{Path, Request},
http::{header, Response},
http::{Response, header},
middleware::Next,
RequestPartsExt,
};
use headers::{Authorization, HeaderMapExt};

Expand Down Expand Up @@ -40,11 +40,11 @@ pub async fn legacy_auth_adapter(mut request: Request, next: Next) -> Response<B
#[cfg(test)]
mod tests {
use axum::{
Router,
body::Body,
http::{header::AUTHORIZATION, HeaderMap, Method, Request, StatusCode},
http::{HeaderMap, Method, Request, StatusCode, header::AUTHORIZATION},
middleware,
routing::{get, post},
Router,
};
use http_body_util::BodyExt;
use tower::ServiceExt;
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/request_tracing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
sync::{
atomic::{self, AtomicU64},
Arc,
atomic::{self, AtomicU64},
},
task::{Context, Poll},
};
Expand Down
13 changes: 5 additions & 8 deletions src/middleware/require_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use axum::http::Request;
use headers::{authorization::Bearer, Authorization, HeaderMapExt, Origin};
use headers::{Authorization, HeaderMapExt, Origin, authorization::Bearer};
use tower::Service;

use crate::{
Expand Down Expand Up @@ -184,13 +184,10 @@ mod tests {
special_api_keys: Default::default(),
};
if let Some(key) = key {
ctx.api_keys = watch::channel(HashMap::from([(
key.into(),
ApiKey {
key: key.into(),
..Default::default()
},
)]))
ctx.api_keys = watch::channel(HashMap::from([(key.into(), ApiKey {
key: key.into(),
..Default::default()
})]))
.1;
}
ctx
Expand Down
6 changes: 3 additions & 3 deletions src/network/indexer_blocklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::{
time::Duration,
};

use anyhow::{anyhow, Context as _};
use anyhow::{Context as _, anyhow};
use futures::StreamExt as _;
use rand::RngCore as _;
use rdkafka::{
consumer::{Consumer as _, StreamConsumer},
Message, TopicPartitionList,
consumer::{Consumer as _, StreamConsumer},
};
use thegraph_core::{alloy::primitives::Address, DeploymentId, ProofOfIndexing};
use thegraph_core::{DeploymentId, ProofOfIndexing, alloy::primitives::Address};
use tokio::sync::watch;

use crate::config::BlocklistEntry;
Expand Down
2 changes: 1 addition & 1 deletion src/network/indexer_processing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};

use custom_debug::CustomDebug;
use thegraph_core::{alloy::primitives::BlockNumber, AllocationId, DeploymentId, IndexerId};
use thegraph_core::{AllocationId, DeploymentId, IndexerId, alloy::primitives::BlockNumber};
use tracing::Instrument;
use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion src/network/indexing_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use parking_lot::{Mutex, RwLock};
use serde_with::serde_as;
use thegraph_core::{alloy::primitives::BlockNumber, DeploymentId};
use thegraph_core::{DeploymentId, alloy::primitives::BlockNumber};
use thegraph_graphql_http::http_client::ReqwestExt;
use url::Url;

Expand Down
Loading

0 comments on commit 3fdf2a3

Please sign in to comment.