From 6cbf1f55eaa246aa7f7ca50bfd894f80992aaa8e Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 4 Dec 2023 14:26:44 +0100 Subject: [PATCH 01/34] Adjust log levels Signed-off-by: Filippo Costa --- backend/crates/common/src/queries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/crates/common/src/queries.rs b/backend/crates/common/src/queries.rs index acaf42d..b2f18b8 100644 --- a/backend/crates/common/src/queries.rs +++ b/backend/crates/common/src/queries.rs @@ -57,7 +57,7 @@ pub async fn query_indexing_statuses( .unwrap() .inc(); - warn!( + debug!( indexer_id = %indexer.id(), %error, "Failed to query indexing statuses" From ad362d5ea11c26a86425c472909be5cc3d6f29cc Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 4 Dec 2023 14:27:09 +0100 Subject: [PATCH 02/34] Adjust log levels Signed-off-by: Filippo Costa --- backend/crates/common/src/indexer/real_indexer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index f58151d..75ad9b3 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -189,7 +189,7 @@ impl Indexer for RealIndexer { .unwrap() .inc(); - warn!( + debug!( id = %self.id(), %error, "Failed to query POIs batch from indexer" ); @@ -198,7 +198,7 @@ impl Indexer for RealIndexer { .to_string() .contains(r#"Cannot query field "publicProofsOfIndexing" on type "Query""#) { - warn!( + debug!( id = %self.id(), "Indexer doesn't seem to support 'publicProofsOfIndexing', skipping it" ); From 791ed74b22f5d814ffc0de80fd92f50bf5a0c073 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 11:06:28 +0100 Subject: [PATCH 03/34] Add support for graph-node version --- .../indexer/queries/indexer-version.gql | 6 ++ .../indexer/queries/subgraph-api-versions.gql | 5 ++ .../down.sql | 3 + .../2023-12-04-133234_indexing_status/up.sql | 20 +++++++ backend/crates/common/src/db/schema.rs | 25 ++++++++ .../crates/common/src/indexer/interceptor.rs | 13 ++++- backend/crates/common/src/indexer/mod.rs | 9 ++- .../crates/common/src/indexer/real_indexer.rs | 54 +++++++++++++++++- backend/crates/common/src/queries.rs | 49 +++++++++++++++- .../crates/common/src/store/diesel_queries.rs | 34 ++++++++++- backend/crates/common/src/store/mod.rs | 35 ++++++++---- .../src/store/{models/mod.rs => models.rs} | 9 +++ backend/crates/common/src/store/schema.rs | 25 ++++++++ backend/crates/common/src/store/tests.rs | 17 +++--- backend/crates/common/src/test_utils/mocks.rs | 18 +++++- backend/crates/common/src/types.rs | 6 ++ .../common/tests/it_indexing_statuses.rs | 3 +- .../common/tests/it_proofs_of_indexing.rs | 3 +- backend/crates/cross-checker/src/main.rs | 4 ++ ops/compose/grafana/data/grafana.db | Bin 1347584 -> 1347584 bytes 20 files changed, 309 insertions(+), 29 deletions(-) create mode 100644 backend/crates/common/graphql/indexer/queries/indexer-version.gql create mode 100644 backend/crates/common/graphql/indexer/queries/subgraph-api-versions.gql create mode 100644 backend/crates/common/migrations/2023-12-04-133234_indexing_status/down.sql create mode 100644 backend/crates/common/migrations/2023-12-04-133234_indexing_status/up.sql rename backend/crates/common/src/store/{models/mod.rs => models.rs} (94%) diff --git a/backend/crates/common/graphql/indexer/queries/indexer-version.gql b/backend/crates/common/graphql/indexer/queries/indexer-version.gql new file mode 100644 index 0000000..4020655 --- /dev/null +++ b/backend/crates/common/graphql/indexer/queries/indexer-version.gql @@ -0,0 +1,6 @@ +query IndexerVersion { + version { + version + commit + } +} diff --git a/backend/crates/common/graphql/indexer/queries/subgraph-api-versions.gql b/backend/crates/common/graphql/indexer/queries/subgraph-api-versions.gql new file mode 100644 index 0000000..fb14073 --- /dev/null +++ b/backend/crates/common/graphql/indexer/queries/subgraph-api-versions.gql @@ -0,0 +1,5 @@ +query SubgraphApiVersions($subgraphId: String!) { + apiVersions(subgraphId: $subgraphId) { + version + } +} diff --git a/backend/crates/common/migrations/2023-12-04-133234_indexing_status/down.sql b/backend/crates/common/migrations/2023-12-04-133234_indexing_status/down.sql new file mode 100644 index 0000000..2b990c5 --- /dev/null +++ b/backend/crates/common/migrations/2023-12-04-133234_indexing_status/down.sql @@ -0,0 +1,3 @@ +DROP TABLE indexer_versions; + +DROP TABLE sg_deployment_api_versions; diff --git a/backend/crates/common/migrations/2023-12-04-133234_indexing_status/up.sql b/backend/crates/common/migrations/2023-12-04-133234_indexing_status/up.sql new file mode 100644 index 0000000..c164328 --- /dev/null +++ b/backend/crates/common/migrations/2023-12-04-133234_indexing_status/up.sql @@ -0,0 +1,20 @@ +CREATE TABLE indexer_versions ( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + indexer_id INTEGER NOT NULL REFERENCES indexers(id) ON DELETE CASCADE, + error TEXT, + version_string TEXT, + version_commit TEXT, + created_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +CREATE INDEX indexer_versions_indexer_id_idx ON indexer_versions(indexer_id); + +CREATE TABLE sg_deployment_api_versions ( + id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + sg_deployment_id INTEGER NOT NULL REFERENCES sg_deployments(id) ON DELETE CASCADE, + api_versions TEXT[] DEFAULT '{}', + error TEXT, + created_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +CREATE INDEX sg_deployment_api_versions_sg_deployment_id_idx ON sg_deployment_api_versions(sg_deployment_id); diff --git a/backend/crates/common/src/db/schema.rs b/backend/crates/common/src/db/schema.rs index 5a9dad0..9e6c0cf 100644 --- a/backend/crates/common/src/db/schema.rs +++ b/backend/crates/common/src/db/schema.rs @@ -17,6 +17,17 @@ diesel::table! { } } +diesel::table! { + indexer_versions (id) { + id -> Int4, + indexer_id -> Int4, + error -> Nullable, + version_string -> Nullable, + version_commit -> Nullable, + created_at -> Timestamp, + } +} + diesel::table! { indexers (id) { id -> Int4, @@ -63,6 +74,16 @@ diesel::table! { } } +diesel::table! { + sg_deployment_api_versions (id) { + id -> Int4, + sg_deployment_id -> Int4, + api_versions -> Nullable>>, + error -> Nullable, + created_at -> Timestamp, + } +} + diesel::table! { sg_deployments (id) { id -> Int4, @@ -82,23 +103,27 @@ diesel::table! { } diesel::joinable!(blocks -> networks (network_id)); +diesel::joinable!(indexer_versions -> indexers (indexer_id)); diesel::joinable!(live_pois -> indexers (indexer_id)); diesel::joinable!(live_pois -> pois (poi_id)); diesel::joinable!(live_pois -> sg_deployments (sg_deployment_id)); diesel::joinable!(pois -> blocks (block_id)); diesel::joinable!(pois -> indexers (indexer_id)); diesel::joinable!(pois -> sg_deployments (sg_deployment_id)); +diesel::joinable!(sg_deployment_api_versions -> sg_deployments (sg_deployment_id)); diesel::joinable!(sg_deployments -> networks (network)); diesel::joinable!(sg_names -> sg_deployments (sg_deployment_id)); diesel::allow_tables_to_appear_in_same_query!( blocks, divergence_investigation_reports, + indexer_versions, indexers, live_pois, networks, pending_divergence_investigation_requests, pois, + sg_deployment_api_versions, sg_deployments, sg_names, ); diff --git a/backend/crates/common/src/indexer/interceptor.rs b/backend/crates/common/src/indexer/interceptor.rs index c76e101..13105fa 100644 --- a/backend/crates/common/src/indexer/interceptor.rs +++ b/backend/crates/common/src/indexer/interceptor.rs @@ -7,7 +7,7 @@ use async_trait::async_trait; use super::{CachedEthereumCall, EntityChanges}; use crate::indexer::Indexer; use crate::prelude::Bytes32; -use crate::types::{IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; /// Pretends to be an indexer by routing requests a /// [`RealIndexer`](crate::indexer::RealIndexer) and then intercepting the @@ -60,6 +60,10 @@ impl Indexer for IndexerInterceptor { Ok(hijacked_statuses) } + async fn version(self: Arc) -> anyhow::Result { + self.target.clone().version().await + } + async fn proofs_of_indexing( self: Arc, requests: Vec, @@ -79,6 +83,13 @@ impl Indexer for IndexerInterceptor { .collect() } + async fn subgraph_api_versions( + self: Arc, + subgraph_id: &str, + ) -> anyhow::Result> { + self.target.clone().subgraph_api_versions(subgraph_id).await + } + async fn cached_eth_calls( self: Arc, network: &str, diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs index 7760219..71a3774 100644 --- a/backend/crates/common/src/indexer/mod.rs +++ b/backend/crates/common/src/indexer/mod.rs @@ -11,7 +11,7 @@ use async_trait::async_trait; pub use interceptor::IndexerInterceptor; pub use real_indexer::RealIndexer; -use crate::types::{IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; #[async_trait] pub trait Indexer: Send + Sync + Debug { @@ -28,6 +28,13 @@ pub trait Indexer: Send + Sync + Debug { async fn proofs_of_indexing(self: Arc, requests: Vec) -> Vec; + async fn version(self: Arc) -> anyhow::Result; + + async fn subgraph_api_versions( + self: Arc, + subgraph_id: &str, + ) -> anyhow::Result>; + /// Convenience wrapper around calling [`Indexer::proofs_of_indexing`] for a /// single POI. async fn proof_of_indexing( diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index 75ad9b3..3bda447 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -13,7 +13,9 @@ use super::{CachedEthereumCall, EntityChanges, Indexer}; use crate::config::IndexerUrls; use crate::prelude::{IndexerConfig, WithIndexer}; use crate::prometheus_metrics::metrics; -use crate::types::{BlockPointer, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment}; +use crate::types::{ + BlockPointer, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, +}; const REQUEST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); @@ -211,6 +213,38 @@ impl Indexer for RealIndexer { pois } + async fn subgraph_api_versions( + self: Arc, + subgraph_id: &str, + ) -> anyhow::Result> { + let request = gql_types::SubgraphApiVersions::build_query( + gql_types::subgraph_api_versions::Variables { + subgraph_id: subgraph_id.to_string(), + }, + ); + + let response: gql_types::subgraph_api_versions::ResponseData = + self.graphql_query(request).await?; + + Ok(response + .api_versions + .into_iter() + .map(|v| v.version) + .collect()) + } + + async fn version(self: Arc) -> anyhow::Result { + let request = gql_types::IndexerVersion::build_query(gql_types::indexer_version::Variables); + + let response: gql_types::indexer_version::ResponseData = + self.graphql_query(request).await?; + + Ok(IndexerVersion { + version: response.version.version, + commit: response.version.commit, + }) + } + async fn cached_eth_calls( self: Arc, network: &str, @@ -397,6 +431,24 @@ mod gql_types { } } + #[derive(GraphQLQuery)] + #[graphql( + schema_path = "graphql/indexer/schema.gql", + query_path = "graphql/indexer/queries/indexer-version.gql", + response_derives = "Debug", + variables_derives = "Debug" + )] + pub struct IndexerVersion; + + #[derive(GraphQLQuery)] + #[graphql( + schema_path = "graphql/indexer/schema.gql", + query_path = "graphql/indexer/queries/subgraph-api-versions.gql", + response_derives = "Debug", + variables_derives = "Debug" + )] + pub struct SubgraphApiVersions; + #[derive(GraphQLQuery)] #[graphql( schema_path = "graphql/indexer/schema.gql", diff --git a/backend/crates/common/src/queries.rs b/backend/crates/common/src/queries.rs index b2f18b8..e27fda6 100644 --- a/backend/crates/common/src/queries.rs +++ b/backend/crates/common/src/queries.rs @@ -7,7 +7,9 @@ use tracing::*; use crate::block_choice::BlockChoicePolicy; use crate::indexer::Indexer; -use crate::prelude::{IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment}; +use crate::prelude::{ + IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, +}; use crate::PrometheusMetrics; /// Queries all `indexingStatuses` for all the given indexers. @@ -79,6 +81,51 @@ pub async fn query_indexing_statuses( indexing_statuses } +/// Queries all `indexers` for their `graph-node` versions. +pub async fn query_graph_node_versions( + indexers: &[Arc], + _metrics: &PrometheusMetrics, +) -> HashMap, anyhow::Result> { + let span = span!(Level::TRACE, "query_graph_node_versions"); + let _enter_span = span.enter(); + + info!("Querying graph-node versions..."); + + let mut futures = FuturesUnordered::new(); + for indexer in indexers { + futures.push(async move { (indexer.clone(), indexer.clone().version().await) }); + } + + let mut versions = HashMap::new(); + while let Some((indexer, version_result)) = futures.next().await { + match &version_result { + Ok(version) => { + trace!( + indexer_id = %indexer.id(), + version = %version.version, + commit = %version.commit, + "Successfully queried graph-node version" + ); + } + Err(error) => { + trace!( + indexer_id = %indexer.id(), + %error, + "Failed to query graph-node version" + ); + } + } + versions.insert(indexer, version_result); + } + + info!( + indexers = versions.len(), + "Finished querying graph-node versions for all indexers" + ); + + versions +} + pub async fn query_proofs_of_indexing( indexing_statuses: Vec, block_choice_policy: BlockChoicePolicy, diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index 24343c4..dadb5b5 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -8,7 +8,8 @@ use tracing::info; use super::models::WritablePoi; use super::PoiLiveness; use crate::graphql_api::types::BlockRangeInput; -use crate::prelude::BlockPointer; +use crate::indexer::Indexer; +use crate::prelude::{BlockPointer, IndexerVersion}; use crate::store::models::{ self, IndexerRow, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, }; @@ -256,6 +257,37 @@ fn get_or_insert_block(conn: &mut PgConnection, block: BlockPointer) -> anyhow:: } } +pub fn write_graph_node_version( + conn: &mut PgConnection, + indexer: &dyn Indexer, + version: anyhow::Result, +) -> anyhow::Result<()> { + use schema::indexer_versions; + + let indexer_id = get_or_insert_indexer(conn, indexer.id(), indexer.address())?; + + let new_version = match version { + Ok(v) => models::NewIndexerVersion { + indexer_id, + error: None, + version_string: Some(v.version), + version_commit: Some(v.commit), + }, + Err(err) => models::NewIndexerVersion { + indexer_id, + error: Some(err.to_string()), + version_string: None, + version_commit: None, + }, + }; + + diesel::insert_into(indexer_versions::table) + .values(&new_version) + .execute(conn)?; + + Ok(()) +} + fn get_or_insert_indexer( conn: &mut PgConnection, id: &str, diff --git a/backend/crates/common/src/store/mod.rs b/backend/crates/common/src/store/mod.rs index 50c73a8..f038a5f 100644 --- a/backend/crates/common/src/store/mod.rs +++ b/backend/crates/common/src/store/mod.rs @@ -1,6 +1,16 @@ //! Database access (read and write) abstractions for all Graphix backend //! services. +// Provides the diesel queries, callers should handle connection pooling and transactions. +mod diesel_queries; +#[cfg(tests)] +pub use diesel_queries; +pub mod models; +mod schema; + +use std::collections::HashMap; +use std::sync::Arc; + use anyhow::Error; use diesel::prelude::*; use diesel::r2d2::{self, ConnectionManager, Pool, PooledConnection}; @@ -8,19 +18,12 @@ use diesel::{Connection, PgConnection}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use tracing::info; +use self::models::{QueriedSgDeployment, WritablePoi}; use crate::graphql_api::types::{BlockRangeInput, IndexersQuery, SgDeploymentsQuery}; +use crate::indexer::Indexer; +use crate::prelude::IndexerVersion; use crate::store::models::{IndexerRow, Poi}; -// Provides the diesel queries, callers should handle connection pooling and transactions. -mod diesel_queries; -#[cfg(tests)] -pub use diesel_queries; - -use self::models::{QueriedSgDeployment, WritablePoi}; - -pub mod models; -mod schema; - #[cfg(test)] mod tests; @@ -193,6 +196,18 @@ impl Store { .transaction::<_, Error, _>(|conn| diesel_queries::write_pois(conn, pois, live)) } + pub fn write_graph_node_versions( + &self, + versions: HashMap, anyhow::Result>, + ) -> anyhow::Result<()> { + for (indexer, version) in versions { + let mut conn = self.conn()?; + diesel_queries::write_graph_node_version(&mut conn, &*indexer, version)?; + } + + Ok(()) + } + pub fn get_first_pending_divergence_investigation_request( &self, ) -> anyhow::Result> { diff --git a/backend/crates/common/src/store/models/mod.rs b/backend/crates/common/src/store/models.rs similarity index 94% rename from backend/crates/common/src/store/models/mod.rs rename to backend/crates/common/src/store/models.rs index cc78482..a918474 100644 --- a/backend/crates/common/src/store/models/mod.rs +++ b/backend/crates/common/src/store/models.rs @@ -37,6 +37,15 @@ pub enum IndexerRef<'a> { Address(&'a [u8]), } +#[derive(Insertable, Debug)] +#[diesel(table_name = indexer_versions)] +pub struct NewIndexerVersion { + pub indexer_id: IntId, + pub error: Option, + pub version_string: Option, + pub version_commit: Option, +} + #[derive(Insertable, Debug)] #[diesel(table_name = pois)] pub struct NewPoi { diff --git a/backend/crates/common/src/store/schema.rs b/backend/crates/common/src/store/schema.rs index 5a9dad0..9e6c0cf 100644 --- a/backend/crates/common/src/store/schema.rs +++ b/backend/crates/common/src/store/schema.rs @@ -17,6 +17,17 @@ diesel::table! { } } +diesel::table! { + indexer_versions (id) { + id -> Int4, + indexer_id -> Int4, + error -> Nullable, + version_string -> Nullable, + version_commit -> Nullable, + created_at -> Timestamp, + } +} + diesel::table! { indexers (id) { id -> Int4, @@ -63,6 +74,16 @@ diesel::table! { } } +diesel::table! { + sg_deployment_api_versions (id) { + id -> Int4, + sg_deployment_id -> Int4, + api_versions -> Nullable>>, + error -> Nullable, + created_at -> Timestamp, + } +} + diesel::table! { sg_deployments (id) { id -> Int4, @@ -82,23 +103,27 @@ diesel::table! { } diesel::joinable!(blocks -> networks (network_id)); +diesel::joinable!(indexer_versions -> indexers (indexer_id)); diesel::joinable!(live_pois -> indexers (indexer_id)); diesel::joinable!(live_pois -> pois (poi_id)); diesel::joinable!(live_pois -> sg_deployments (sg_deployment_id)); diesel::joinable!(pois -> blocks (block_id)); diesel::joinable!(pois -> indexers (indexer_id)); diesel::joinable!(pois -> sg_deployments (sg_deployment_id)); +diesel::joinable!(sg_deployment_api_versions -> sg_deployments (sg_deployment_id)); diesel::joinable!(sg_deployments -> networks (network)); diesel::joinable!(sg_names -> sg_deployments (sg_deployment_id)); diesel::allow_tables_to_appear_in_same_query!( blocks, divergence_investigation_reports, + indexer_versions, indexers, live_pois, networks, pending_divergence_investigation_requests, pois, + sg_deployment_api_versions, sg_deployments, sg_names, ); diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index edcde0f..93fd2c3 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -1,15 +1,16 @@ +use std::collections::BTreeSet; +use std::sync::{Mutex, OnceLock}; + +use diesel::Connection; + use crate::block_choice::BlockChoicePolicy; use crate::graphql_api::types::SgDeploymentsQuery; use crate::prelude::ProofOfIndexing; use crate::prometheus_metrics::metrics; -use crate::test_utils::{fast_rng, gen::gen_bytes32, gen::gen_indexers}; -use crate::{ - queries, - store::{diesel_queries, PoiLiveness, Store}, -}; -use diesel::Connection; -use std::collections::BTreeSet; -use std::sync::{Mutex, OnceLock}; +use crate::queries; +use crate::store::{diesel_queries, PoiLiveness, Store}; +use crate::test_utils::fast_rng; +use crate::test_utils::gen::{gen_bytes32, gen_indexers}; static TEST_LOCK: OnceLock> = OnceLock::new(); diff --git a/backend/crates/common/src/test_utils/mocks.rs b/backend/crates/common/src/test_utils/mocks.rs index 4e4dbe0..b9c2d4e 100644 --- a/backend/crates/common/src/test_utils/mocks.rs +++ b/backend/crates/common/src/test_utils/mocks.rs @@ -4,8 +4,8 @@ use anyhow::anyhow; use async_trait::async_trait; use crate::prelude::{ - BlockPointer, Bytes32, CachedEthereumCall, EntityChanges, Indexer, IndexingStatus, PoiRequest, - ProofOfIndexing, SubgraphDeployment, + BlockPointer, Bytes32, CachedEthereumCall, EntityChanges, Indexer, IndexerVersion, + IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, }; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -86,6 +86,20 @@ impl Indexer for MockIndexer { .collect::>() } + async fn version(self: Arc) -> anyhow::Result { + Ok(IndexerVersion { + version: "0.0.0".to_string(), + commit: "no-commit-hash".to_string(), + }) + } + + async fn subgraph_api_versions( + self: Arc, + _subgraph_id: &str, + ) -> anyhow::Result> { + Ok(vec![]) + } + async fn cached_eth_calls( self: Arc, _network: &str, diff --git a/backend/crates/common/src/types.rs b/backend/crates/common/src/types.rs index e2dbcfc..2121255 100644 --- a/backend/crates/common/src/types.rs +++ b/backend/crates/common/src/types.rs @@ -7,6 +7,12 @@ use serde::Serialize; use crate::indexer::Indexer; use crate::store::models::WritablePoi; +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] +pub struct IndexerVersion { + pub version: String, + pub commit: String, +} + #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] pub struct BlockPointer { pub number: u64, diff --git a/backend/crates/common/tests/it_indexing_statuses.rs b/backend/crates/common/tests/it_indexing_statuses.rs index 8b5e2c9..545cd35 100644 --- a/backend/crates/common/tests/it_indexing_statuses.rs +++ b/backend/crates/common/tests/it_indexing_statuses.rs @@ -1,10 +1,9 @@ use std::sync::Arc; use std::time::Duration; -use reqwest::Url; - use graphix_common::config::{IndexerConfig, IndexerUrls}; use graphix_common::prelude::{Indexer, RealIndexer, SubgraphDeployment}; +use reqwest::Url; /// Test utility function to create a valid `Indexer` from an arbitrary base url. fn test_indexer_from_url(url: impl Into) -> Arc { diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/backend/crates/common/tests/it_proofs_of_indexing.rs index bd0db73..a49d810 100644 --- a/backend/crates/common/tests/it_proofs_of_indexing.rs +++ b/backend/crates/common/tests/it_proofs_of_indexing.rs @@ -1,12 +1,11 @@ use std::sync::Arc; use std::time::Duration; -use reqwest::Url; - use graphix_common::config::IndexerUrls; use graphix_common::prelude::{ Indexer, IndexerConfig, PoiRequest, RealIndexer, SubgraphDeployment, }; +use reqwest::Url; /// Test utility function to create a valid `Indexer` from an arbitrary base url. fn test_indexer_from_url(url: impl Into) -> Arc { diff --git a/backend/crates/cross-checker/src/main.rs b/backend/crates/cross-checker/src/main.rs index 4d78b97..3c29476 100644 --- a/backend/crates/cross-checker/src/main.rs +++ b/backend/crates/cross-checker/src/main.rs @@ -63,6 +63,10 @@ async fn main() -> anyhow::Result<()> { tx_indexers.send(indexers.clone())?; + let graph_node_versions = + graphix_common::queries::query_graph_node_versions(&indexers, metrics()).await; + store.write_graph_node_versions(graph_node_versions)?; + let indexing_statuses = query_indexing_statuses(indexers, metrics()).await; info!("Monitor proofs of indexing"); diff --git a/ops/compose/grafana/data/grafana.db b/ops/compose/grafana/data/grafana.db index f656a10a6b298e7dc919326b9fc5b755ac15bbbc..b1f47870caa6b7ca0b201e946791153b32abd79c 100644 GIT binary patch delta 2572 zcmdT`eQXrh5#P7pcfQ@(-E(a#lzK5vZ47s}A9s7VM*!Q2nh+7<&=RR7Dqi2N!Afj{ z&m}}jYn!&Aq(n*7)URI%i=a>?s5MY|k*Wd_txBazMoMcH`Vk}-l~T2ksE{gDy1rdX zr~P(anZ#7X9oY`5MK-JOx+ak1!AKgvvO&2zA7VLmZoskTCN+qI=}GiPa?v-hw~F zCAbkP7tkM|kyx=TlR!ce&XN7S3{1gZxD?7)Q9rOm*MxW0klzYRQ1=u1+95yK88mVU zF^BFQ@wROp*s0&+Rk!vHdn3N^0~#q11%xUEZ^AzKDO5v6p*KRBXiLZsg1m3Ier6e) z*og4NuTd)!@V;hxK%8XYyD$ltLs_Rs2<~sG2K=QQ{YX-J7Zs1^=!O}C{*AOWSo+pe zu2piaN?)nq_xHI$KHu*Y@@C$3^99>+tYTPOMRRCru;~ku;|9f|Wd~l-H$5Zp0?YB8 zpcwQSCEs;?+_r{3e=}{u&R^j#@D8b8>7-wW3`x6A;24AiK3Z8eS{Wu{Yh6o$ZZRVCwMeS&YfUGF@^%TESxB=H;6Kp!Bc49ib zNb_lF1zOTYwp%)r@MEeK(mZ?>z6@jV1XN)Vwtz?M?}k}8PFnN=Zc+H<=h=7)VyU%GSVNI~ok4+Ab<8>tXLPq!6O+s_jC2b#!E4 zXiF+bWj-*te!J*Y+p|wQ}+P`0?>cMEBOJKje8-XD^VL+(C4CKCZ7N_c!sU2m}0 zDEb;H^D^BeeM@B06l!Zb+L5qrln^C?vr&}8#4)wP@%;mjjRqt5$ct({c7LQcg!_)G z6YN5DNYr}}hUd~3XfuyrdjmD#AD&b-FwKl*=w_juH_L`u!`sEW)|pc(*U2&KC}tgj z?`B%RX?E3-SB!{kBpqGONb;@HjC@R@MZB@ssGSHe98>qc2lzkAC%g)pa(1#aox~5_ zsVxrME@&6|)*}Pm@1o8x5?JnEQLT`m9$><|d7ed+fmYYvev^x`{^aME=}+nd{v$*B zP%!%V@W`XqzwJhF$9(@!~Ur&#Q`n-A%jg_t1MLgYHpNig1D__2Rcy>5lhfiM7 zB*io`hO3)a**3}rt5%CY6(+aUb0MdsZ#)+P;jZgyW7wu^rug5WX(5_UbG__gia$&m zcYtp^x>g`#lgrKD5seM{=h$#z*K6wID4h1Rb@cz7yLGrn*J1+A8NFWU3X@2&q;?jJ#i!-D_- delta 2312 zcmd5-Yiu0V6`ngg&wb3<*>Rc{lX|>yNesK*nVo&j0%mIpQIJBMs74Bp+B>^5j%n;T z-ZhFH6D!HWfSdDO^wo)Cb!bvDmp$(-?35jTn8c47quCC7c&i&5)&fI$^Y8xkN8+SE_6pBJ?iLIe1%D;Pc7AZgM+Yv`|d)|$& zLxr!K9j@7dj&G1IQw*G?;61niXW@M}Jb~VZ0LzFW#FI=`oY{rwZs|jUI#0nx_%ob` z58Uuu=p9(j_{2Jh@x$vRUiCo@c0$#a7LfzYa#j@Z_9awqTh)rX#?-Y#WqZ3l!Ym{H zxVWxZsoEoIxmek3Z7q(Je?+4&z!X`=rr@veH2eZ=HyoyWfNf{Q9)utM4Qd0gBuPx) zvFWa!uI_ujjGu0y2ZRY99E80v;Yun!0?aaB0^x5Y==;@`*RU$Sk8{pw^lw8e%O^{| zoMmW6$n?k?R*vxp$A4@-_wE+=g>YnfKIm@C;%(adHo z!?X?Ea*}w}ZS)%e7sx({sDFdMz(3%u8!phVLY(y>#B-jgtT$yCZ}j=Rk){1`oa7v# z;E!;c$b7^NchfHdp6{il5J?H4GGQ9sQe`Jk_tM0C#2EK3z&A_ra2{aBjt~g@Nz=4n~H)$!MEX?Fb-o-fkEhpBEjDd3or{c+!p3; z@+qLW-C^$Yz`@Tck?~>N!u4d}1B%t^wI>LhNRxr|evpbv^AtGnCAbIfhC87XGSC4x z01rpWA2EU3RPIJbnwRF?Zk1aB0!&i@ju8kcmgNXJPV#Q~twdaR@>a)kxZ`HV& z8owjq<99xSA6wvC*+rWV9>Rwg_$b?Kb4!ooH$1Ot^E)y#C-_GI&AE^Mj^AEb79=GG zr>Ni*d=E6j*%zD&P7x)>g1p1C{f>{pFLVlV{Ii&lq0s=o91{{KjsF=FV&mymk5T25 zWrL#VX9%!3v~?(6u`88!;@z8=`Q%P+k~vC;tw z9)wpQCmn#Nzyz!pnEi*AbWg4Kr}~1O6udx=$92*nsgwMSG0FcRD^NnbC2efL zYv%l)?bOV;p8cY3v=t!Pi7k~52jv)br`ylO67E8^0_%b zu>i54``lb;<1zfoxWxIBMn0L$8(NgZZ;ne*yn0;v)PF@7{F8C%I^il34}Tm&*OMn_ z$0cGwEbPvX%Xe$cMT)*iwsW3l_62;3d+De0ORRfnR(^=V(k)7}n}1n;6ye00rtjki zj>>EBd+Q@IUf8N|_{dQ?0$MJvW!0qa?KzcN!rO#E+srYUEwI#XirT$LE=;!V-x3H= z2nom#LoctS1+gJRCa&qKPNd4^Q<|&)UfzRn_dew-xcfrnb9ix|asa>inWlrd@EUpu zpLiX;i>EIsRaZSLe}Tr~%@H2yxTPg>22V4}3hbPdCAwY3g|{Nj_{noJXzgl3t&9$; z*4XNS#=F(7Hf94u{k@fHu{v6{E4?H3wo$uMt+eCCbMmdI3vc*SL>U??4%*Rt^p5Sr zBaPc58jDuPhCN?zuT8wYy~Hy*P`=jj)mYRET}jAC+qwv5^FWzoImIm%I~EKZOym~MM;@pD-NWz9*pc^rjgBp=DG7#LYl#`P Yi7&7snYQ9!UsE%>*k From b1c9b21d1f99f83e2d1fef5cf10ad135ec567ec3 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 11:20:29 +0100 Subject: [PATCH 04/34] Use containerized store tests --- Cargo.lock | 103 ++++++++++++++++++++++- backend/crates/common/Cargo.toml | 2 + backend/crates/common/src/store/mod.rs | 4 +- backend/crates/common/src/store/tests.rs | 52 +++++++++--- 4 files changed, 143 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9ca274..7fd9f17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,7 +172,7 @@ checksum = "cebcf27112b969c4ff2a003b318ab5efde96055f9d0ee3344a3b3831fa2932ba" dependencies = [ "Inflector", "async-graphql-parser", - "darling", + "darling 0.14.4", "proc-macro-crate 1.3.1", "proc-macro2", "quote", @@ -297,6 +297,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bollard-stubs" +version = "1.42.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864" +dependencies = [ + "serde", + "serde_with", +] + [[package]] name = "bumpalo" version = "3.12.0" @@ -541,14 +551,38 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + [[package]] name = "darling" version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.14.4", + "darling_macro 0.14.4", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", ] [[package]] @@ -565,13 +599,24 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core 0.13.4", + "quote", + "syn 1.0.109", +] + [[package]] name = "darling_macro" version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ - "darling_core", + "darling_core 0.14.4", "quote", "syn 1.0.109", ] @@ -967,6 +1012,8 @@ dependencies = [ "serde_json", "serde_yaml", "sqlx", + "testcontainers", + "testcontainers-modules", "tiny-cid", "tokio", "tracing", @@ -2224,6 +2271,28 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling 0.13.4", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "serde_yaml" version = "0.9.21" @@ -2494,6 +2563,32 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "testcontainers" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d2931d7f521af5bae989f716c3fa43a6af9af7ec7a5e21b59ae40878cec00" +dependencies = [ + "bollard-stubs", + "futures", + "hex", + "hmac", + "log", + "rand", + "serde", + "serde_json", + "sha2", +] + +[[package]] +name = "testcontainers-modules" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd4f62dbab24872d1ba3bf8c495c6674fe73035ba1489df319620bf5fd4d3857" +dependencies = [ + "testcontainers", +] + [[package]] name = "thiserror" version = "1.0.40" diff --git a/backend/crates/common/Cargo.toml b/backend/crates/common/Cargo.toml index 7ea18df..1d66a08 100644 --- a/backend/crates/common/Cargo.toml +++ b/backend/crates/common/Cargo.toml @@ -24,6 +24,8 @@ serde_derive = "1.0.130" serde_json = "1.0.78" serde_yaml = "0.9" tiny-cid = "0.3.0" +testcontainers = "0.15" +testcontainers-modules = { version = "0.2", features = ["postgres"] } tokio = { version = "1.14.0", features = ["full"] } tracing = "0.1.29" rand = { version = "0.8.4", features = ["small_rng"], optional = true } diff --git a/backend/crates/common/src/store/mod.rs b/backend/crates/common/src/store/mod.rs index f038a5f..6fd697b 100644 --- a/backend/crates/common/src/store/mod.rs +++ b/backend/crates/common/src/store/mod.rs @@ -37,7 +37,7 @@ pub struct Store { } impl Store { - /// Connects to the database and runs migrations. + /// Connects to the database and runs all pending migrations. pub async fn new(db_url: &str) -> anyhow::Result { info!("Initializing database connection pool"); let manager = r2d2::ConnectionManager::::new(db_url); @@ -51,6 +51,8 @@ impl Store { let mut conn = self.pool.get()?; // Get a lock for running migrations. Blocks until we get the lock. + // We need this because different Graphix instances may attempt + // to run migrations concurrently (that's a big no-no). diesel::sql_query("select pg_advisory_lock(1)").execute(&mut conn)?; info!("Run database migrations"); conn.run_pending_migrations(MIGRATIONS) diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index 93fd2c3..848b642 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -1,7 +1,9 @@ use std::collections::BTreeSet; -use std::sync::{Mutex, OnceLock}; +use std::ops::Deref; use diesel::Connection; +use testcontainers::clients::Cli; +use testcontainers::Container; use crate::block_choice::BlockChoicePolicy; use crate::graphql_api::types::SgDeploymentsQuery; @@ -12,20 +14,41 @@ use crate::store::{diesel_queries, PoiLiveness, Store}; use crate::test_utils::fast_rng; use crate::test_utils::gen::{gen_bytes32, gen_indexers}; -static TEST_LOCK: OnceLock> = OnceLock::new(); +pub struct EmptyStoreForTesting<'a> { + _container: Container<'a, testcontainers_modules::postgres::Postgres>, + store: Store, +} + +impl<'a> EmptyStoreForTesting<'a> { + pub async fn new(docker_client: &'a Cli) -> anyhow::Result> { + use testcontainers_modules::postgres::Postgres; -fn test_lock() -> &'static Mutex<()> { - TEST_LOCK.get_or_init(|| Mutex::new(())) + let container = docker_client.run(Postgres::default()); + let connection_string = &format!( + "postgres://postgres:postgres@127.0.0.1:{}/postgres", + container.get_host_port_ipv4(5432) + ); + let store = Store::new(connection_string).await?; + Ok(Self { + _container: container, + store, + }) + } } -fn test_db_url() -> String { - std::env::var("GRAPHIX_TEST_DB_URL").expect("GRAPHIX_TEST_DB_URL must be set to run tests") +impl<'a> Deref for EmptyStoreForTesting<'a> { + type Target = Store; + + fn deref(&self) -> &Self::Target { + &self.store + } } #[tokio::test] #[ignore] // FIXME: Race condition with other tests async fn no_deployments_at_first() { - let store = Store::new(&test_db_url()).await.unwrap(); + let docker_cli = Cli::default(); + let store = EmptyStoreForTesting::new(&docker_cli).await.unwrap(); let initial_deployments = store.sg_deployments(SgDeploymentsQuery::default()).unwrap(); assert!(initial_deployments.is_empty()); } @@ -33,7 +56,8 @@ async fn no_deployments_at_first() { #[tokio::test] #[should_panic] // FIXME async fn deployments_with_name() { - let store = Store::new(&test_db_url()).await.unwrap(); + let docker_cli = Cli::default(); + let store = EmptyStoreForTesting::new(&docker_cli).await.unwrap(); let ipfs_cid1 = "QmNY7gDNXHECV8SXoEY7hbfg4BX1aDMxTBDiFuG4huaSGA"; let ipfs_cid2 = "QmYzsCjrVwwXtdsNm3PZVNziLGmb9o513GUzkq5wwhgXDT"; @@ -54,7 +78,9 @@ async fn deployments_with_name() { #[tokio::test] async fn create_divergence_investigation_request() { - let store = Store::new(&test_db_url()).await.unwrap(); + let docker_cli = Cli::default(); + let store = EmptyStoreForTesting::new(&docker_cli).await.unwrap(); + let uuid = store .create_divergence_investigation_request(serde_json::json!({})) .unwrap(); @@ -68,7 +94,8 @@ async fn create_divergence_investigation_request() { #[tokio::test] async fn poi_db_roundtrip() { - let _lock = test_lock().lock().unwrap(); + let docker_cli = Cli::default(); + let store = EmptyStoreForTesting::new(&docker_cli).await.unwrap(); let mut rng = fast_rng(0); let indexers = gen_indexers(&mut rng, 100); @@ -77,7 +104,6 @@ async fn poi_db_roundtrip() { let pois = queries::query_proofs_of_indexing(indexing_statuses, BlockChoicePolicy::Earliest).await; - let store = Store::new(&test_db_url()).await.unwrap(); let mut conn = store.conn().unwrap(); conn.test_transaction(|conn| test_pois(conn, &pois, PoiLiveness::NotLive, false)); conn.test_transaction(|conn| test_pois(conn, &pois, PoiLiveness::Live, true)); @@ -85,7 +111,8 @@ async fn poi_db_roundtrip() { #[tokio::test] async fn test_additional_pois() { - let _lock = test_lock().lock().unwrap(); + let docker_cli = Cli::default(); + let store = EmptyStoreForTesting::new(&docker_cli).await.unwrap(); let mut rng = fast_rng(0); let indexers = gen_indexers(&mut rng, 100); @@ -94,7 +121,6 @@ async fn test_additional_pois() { let pois = queries::query_proofs_of_indexing(indexing_statuses, BlockChoicePolicy::Earliest).await; - let store = Store::new(&test_db_url()).await.unwrap(); let mut conn = store.conn().unwrap(); conn.test_transaction(|conn| -> Result<(), anyhow::Error> { From a39d75798860fedfe0be0a81fd0dcd82462e0fe0 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 11:23:26 +0100 Subject: [PATCH 05/34] Add previously removed test --- backend/crates/common/src/store/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index 848b642..3bb89af 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -14,6 +14,8 @@ use crate::store::{diesel_queries, PoiLiveness, Store}; use crate::test_utils::fast_rng; use crate::test_utils::gen::{gen_bytes32, gen_indexers}; +/// A wrapper around a [`Store`] that is backed by a containerized Postgres +/// database. pub struct EmptyStoreForTesting<'a> { _container: Container<'a, testcontainers_modules::postgres::Postgres>, store: Store, @@ -45,7 +47,6 @@ impl<'a> Deref for EmptyStoreForTesting<'a> { } #[tokio::test] -#[ignore] // FIXME: Race condition with other tests async fn no_deployments_at_first() { let docker_cli = Cli::default(); let store = EmptyStoreForTesting::new(&docker_cli).await.unwrap(); From 85daa56785d9ebdf8e2c90231681f67995d2d05c Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 11:24:27 +0100 Subject: [PATCH 06/34] Rename `NetworkSubgraphClient` --- backend/crates/common/src/config.rs | 6 +++--- backend/crates/common/src/network_subgraph/mod.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index d57935d..8ac9093 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -8,7 +8,7 @@ use tracing::{info, warn}; use crate::block_choice::BlockChoicePolicy; use crate::indexer::{Indexer, IndexerInterceptor, RealIndexer}; -use crate::network_subgraph::NetworkSubgraph; +use crate::network_subgraph::NetworkSubgraphClient; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] @@ -180,7 +180,7 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result network_subgraph.indexers_by_allocations().await, NetworkSubgraphQuery::ByStakedTokens => { @@ -213,7 +213,7 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result Self { const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); @@ -240,7 +240,7 @@ pub struct Indexer { pub url: Option, } -impl NetworkSubgraph {} +impl NetworkSubgraphClient {} mod util { use tiny_cid::Cid; @@ -309,8 +309,8 @@ mod queries { mod tests { use super::*; - fn mainnet_network_subgraph() -> NetworkSubgraph { - NetworkSubgraph::new( + fn mainnet_network_subgraph() -> NetworkSubgraphClient { + NetworkSubgraphClient::new( "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet" .to_string(), ) From cd3a1ac4539116f9fa00c6c87fc0a1df0c87e842 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 11:27:22 +0100 Subject: [PATCH 07/34] Rename network subgraph directory, remove dead code --- backend/crates/common/src/config.rs | 2 +- backend/crates/common/src/lib.rs | 2 +- .../mod.rs | 62 +------------------ .../queries/deployments.graphql | 0 .../queries/indexer_by_address.graphql | 0 .../queries/indexers_by_staked_tokens.graphql | 0 6 files changed, 5 insertions(+), 61 deletions(-) rename backend/crates/common/src/{network_subgraph => network_subgraph_client}/mod.rs (84%) rename backend/crates/common/src/{network_subgraph => network_subgraph_client}/queries/deployments.graphql (100%) rename backend/crates/common/src/{network_subgraph => network_subgraph_client}/queries/indexer_by_address.graphql (100%) rename backend/crates/common/src/{network_subgraph => network_subgraph_client}/queries/indexers_by_staked_tokens.graphql (100%) diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index 8ac9093..b8d86fd 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -8,7 +8,7 @@ use tracing::{info, warn}; use crate::block_choice::BlockChoicePolicy; use crate::indexer::{Indexer, IndexerInterceptor, RealIndexer}; -use crate::network_subgraph::NetworkSubgraphClient; +use crate::network_subgraph_client::NetworkSubgraphClient; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] diff --git a/backend/crates/common/src/lib.rs b/backend/crates/common/src/lib.rs index 9a73d86..c926633 100644 --- a/backend/crates/common/src/lib.rs +++ b/backend/crates/common/src/lib.rs @@ -2,7 +2,7 @@ pub mod block_choice; pub mod config; pub mod graphql_api; mod indexer; -pub mod network_subgraph; +pub mod network_subgraph_client; mod prometheus_metrics; pub mod queries; pub mod store; diff --git a/backend/crates/common/src/network_subgraph/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs similarity index 84% rename from backend/crates/common/src/network_subgraph/mod.rs rename to backend/crates/common/src/network_subgraph_client/mod.rs index 7ac396a..640f3aa 100644 --- a/backend/crates/common/src/network_subgraph/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -13,6 +13,8 @@ use tracing::warn; use crate::config::{IndexerConfig, IndexerUrls}; use crate::prelude::{Indexer as IndexerTrait, RealIndexer}; +/// A GraphQL client that can query the network subgraph and extract useful +/// data. #[derive(Debug, Clone)] pub struct NetworkSubgraphClient { endpoint: String, @@ -21,7 +23,7 @@ pub struct NetworkSubgraphClient { } impl NetworkSubgraphClient { - /// Creates a new [`NetworkSubgraph`] with the given endpoint. + /// Creates a new [`NetworkSubgraphClient`] with the given endpoint. pub fn new(endpoint: String) -> Self { const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); @@ -240,64 +242,6 @@ pub struct Indexer { pub url: Option, } -impl NetworkSubgraphClient {} - -mod util { - use tiny_cid::Cid; - - pub fn bytes32_to_cid_v0(bytes32: [u8; 32]) -> Cid { - let mut cidv0: [u8; 34] = [0; 34]; - - // The start of any CIDv0. - cidv0[0] = 0x12; - cidv0[1] = 0x20; - - cidv0[2..].copy_from_slice(&bytes32); - - // Unwrap: We've constructed a valid CIDv0. - Cid::read_bytes(cidv0.as_ref()).unwrap() - } - - /// # Panics - /// - /// Panics if `cid` version is not `v0`. - pub fn cid_v0_to_bytes32(cid: &Cid) -> [u8; 32] { - assert!(cid.version() == tiny_cid::Version::V0); - let cid_bytes = cid.to_bytes(); - - // A CIDv0 in byte form is 34 bytes long, starting with 0x1220. - assert_eq!(cid_bytes.len(), 34); - - let mut bytes: [u8; 32] = [0; 32]; - bytes.copy_from_slice(&cid_bytes[2..]); - bytes - } - - #[cfg(test)] - mod tests { - use quickcheck::{Arbitrary, Gen}; - use quickcheck_macros::quickcheck; - - #[derive(Debug, Clone)] - struct Bytes([u8; 32]); - - impl Arbitrary for Bytes { - fn arbitrary(g: &mut Gen) -> Self { - let mut bytes = [0; 32]; - bytes.fill_with(|| Arbitrary::arbitrary(g)); - Self(bytes) - } - } - - #[quickcheck] - fn convert_to_cid_v0_and_back(bytes32: Bytes) { - let cid = super::bytes32_to_cid_v0(bytes32.0); - let bytes32_back = super::cid_v0_to_bytes32(&cid); - assert_eq!(bytes32.0, bytes32_back); - } - } -} - mod queries { pub const INDEXERS_BY_STAKED_TOKENS_QUERY: &str = include_str!("queries/indexers_by_staked_tokens.graphql"); diff --git a/backend/crates/common/src/network_subgraph/queries/deployments.graphql b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph/queries/deployments.graphql rename to backend/crates/common/src/network_subgraph_client/queries/deployments.graphql diff --git a/backend/crates/common/src/network_subgraph/queries/indexer_by_address.graphql b/backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph/queries/indexer_by_address.graphql rename to backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql diff --git a/backend/crates/common/src/network_subgraph/queries/indexers_by_staked_tokens.graphql b/backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph/queries/indexers_by_staked_tokens.graphql rename to backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql From aa9622ca53b3baa9770751a891f5a6f532d90739 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 11:55:37 +0100 Subject: [PATCH 08/34] Add network subgraph client test --- .../common/src/network_subgraph_client/mod.rs | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index 640f3aa..56d84fa 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -24,11 +24,11 @@ pub struct NetworkSubgraphClient { impl NetworkSubgraphClient { /// Creates a new [`NetworkSubgraphClient`] with the given endpoint. - pub fn new(endpoint: String) -> Self { + pub fn new(endpoint: impl ToString) -> Self { const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); Self { - endpoint, + endpoint: endpoint.to_string(), timeout: DEFAULT_TIMEOUT, client: reqwest::Client::new(), } @@ -86,6 +86,8 @@ impl NetworkSubgraphClient { Ok(indexers) } + /// Instantiates a [`RealIndexer`] from the indexer with the given address, + /// querying the necessary information from the network subgraph. pub async fn indexer_by_address( &self, address: &[u8], @@ -127,8 +129,10 @@ impl NetworkSubgraphClient { Ok(indexer) } - // The `curation_threshold` is denominated in GRT. - pub async fn subgraph_deployments(&self) -> anyhow::Result> { + /// Returns all subgraph deployments. + pub async fn subgraph_deployments( + &self, + ) -> anyhow::Result> { let response_data: GraphqlResponseSgDeployments = self .graphql_query_no_errors( queries::DEPLOYMENTS_QUERY, @@ -140,6 +144,9 @@ impl NetworkSubgraphClient { Ok(response_data.subgraph_deployments) } + /// A wrapper around [`NetworkSubgraphClient::graphql_query`] that requires + /// no errors in the response, and deserializes the response data into the + /// given type. async fn graphql_query_no_errors( &self, query: impl ToString, @@ -159,7 +166,8 @@ impl NetworkSubgraphClient { Ok(serde_json::from_value(response_data)?) } - async fn graphql_query( + /// Sends a generic GraphQL query to the network subgraph. + pub async fn graphql_query( &self, query: impl ToString, variables: Vec<(String, serde_json::Value)>, @@ -206,16 +214,19 @@ struct GraphqlRequest { variables: BTreeMap, } +/// A generic GraphQL response. #[derive(Deserialize)] -struct GraphqlResponse { - data: Option, - errors: Option>, +pub struct GraphqlResponse { + /// The response data. + pub data: Option, + /// The response error data. + pub errors: Option>, } #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct GraphqlResponseSgDeployments { - subgraph_deployments: Vec, + subgraph_deployments: Vec, } #[derive(Deserialize)] @@ -226,7 +237,7 @@ struct GraphqlResponseTopIndexers { #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] -pub struct SubgraphDeployment { +pub struct SubgraphDeploymentWithAllocations { pub ipfs_hash: String, pub indexer_allocations: Vec, } @@ -255,11 +266,21 @@ mod tests { fn mainnet_network_subgraph() -> NetworkSubgraphClient { NetworkSubgraphClient::new( - "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet" - .to_string(), + "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet", ) } + #[tokio::test] + async fn short_timeout_always_fails() { + // We should never be able to get a response back under 1ms. If we do, + // it means the timeout logic is broken. + let network_sg = mainnet_network_subgraph().with_timeout(Duration::from_millis(1)); + assert!(matches!( + network_sg.indexers_by_staked_tokens().await, + Err(_) + )); + } + #[tokio::test] async fn mainnet_indexers_by_staked_tokens_no_panic() { let network_sg = mainnet_network_subgraph(); From 9780a4b7e53fddd1c83e8c7223f23780f820c5fc Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 12:52:56 +0100 Subject: [PATCH 09/34] Fix query variable --- .../common/src/network_subgraph_client/mod.rs | 40 +++++++++---------- .../queries/deployments.graphql | 2 +- .../queries/indexer_by_address.graphql | 2 +- .../queries/indexers_by_staked_tokens.graphql | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index 56d84fa..d307165 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -94,6 +94,7 @@ impl NetworkSubgraphClient { ) -> anyhow::Result> { let hex_encoded_addr_json = serde_json::to_value(format!("0x{}", hex::encode(address))) .expect("Unable to hex encode address"); + println!("hex_encoded_addr_json: {:?}", hex_encoded_addr_json); let response_data: ResponseData = self .graphql_query_no_errors( queries::INDEXER_BY_ADDRESS_QUERY, @@ -264,7 +265,7 @@ mod queries { mod tests { use super::*; - fn mainnet_network_subgraph() -> NetworkSubgraphClient { + fn network_sg_client_on_ethereum() -> NetworkSubgraphClient { NetworkSubgraphClient::new( "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet", ) @@ -274,42 +275,39 @@ mod tests { async fn short_timeout_always_fails() { // We should never be able to get a response back under 1ms. If we do, // it means the timeout logic is broken. - let network_sg = mainnet_network_subgraph().with_timeout(Duration::from_millis(1)); - assert!(matches!( - network_sg.indexers_by_staked_tokens().await, - Err(_) - )); + let client = network_sg_client_on_ethereum().with_timeout(Duration::from_millis(1)); + assert!(matches!(client.indexers_by_staked_tokens().await, Err(_))); } #[tokio::test] async fn mainnet_indexers_by_staked_tokens_no_panic() { - let network_sg = mainnet_network_subgraph(); - let indexers = network_sg.indexers_by_staked_tokens().await.unwrap(); + let client = network_sg_client_on_ethereum(); + let indexers = client.indexers_by_staked_tokens().await.unwrap(); assert!(indexers.len() > 0); } #[tokio::test] async fn mainnet_indexers_by_allocations_no_panic() { - let network_sg = mainnet_network_subgraph(); - let indexers = network_sg.indexers_by_allocations().await.unwrap(); + let client = network_sg_client_on_ethereum(); + let indexers = client.indexers_by_allocations().await.unwrap(); assert!(indexers.len() > 0); } #[tokio::test] - async fn mainnet_deployments_no_panic() { - let network_sg = mainnet_network_subgraph(); - let deployments = network_sg.subgraph_deployments().await.unwrap(); - assert!(deployments.len() > 0); + async fn at_least_100_subgraph_deployments() { + let client = network_sg_client_on_ethereum(); + let deployments = client.subgraph_deployments().await.unwrap(); + println!("n. of deployments: {:?}", deployments.len()); + assert!(deployments.len() >= 100); } #[tokio::test] - #[should_panic] // FIXME - async fn mainnet_fetch_indexer() { - let network_sg = mainnet_network_subgraph(); + async fn mainnet_fetch_ellipfra() { + let client = network_sg_client_on_ethereum(); // ellipfra.eth: - // https://thegraph.com/explorer/profile/0x62a0bd1d110ff4e5b793119e95fc07c9d1fc8c4a?view=Indexing&chain=mainnet - let addr = hex::decode("62a0bd1d110ff4e5b793119e95fc07c9d1fc8c4a").unwrap(); - let indexer = network_sg.indexer_by_address(&addr).await.unwrap(); - assert_eq!(indexer.address(), Some(&addr[..])); + // htps://thegraph.com/explorer/profile/0x62a0bd1d110ff4e5b793119e95fc07c9d1fc8c4a?view=Indexing&chain=mainnet + let address = hex::decode("62a0bd1d110ff4e5b793119e95fc07c9d1fc8c4a").unwrap(); + let indexer = client.indexer_by_address(&address).await.unwrap(); + assert_eq!(indexer.address(), Some(&address[..])); } } diff --git a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql index 71a006f..db09ef7 100644 --- a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql +++ b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql @@ -1,4 +1,4 @@ -{ +query subgraphDeployments { subgraphDeployments( where: { indexerAllocations_: { status_in: [Active] } } orderBy: stakedTokens diff --git a/backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql b/backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql index 570b8f4..ebf3487 100644 --- a/backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql +++ b/backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql @@ -1,4 +1,4 @@ -{ +query IndexerByAddress($id: String) { indexers(where: { id: $id }) { url defaultDisplayName diff --git a/backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql b/backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql index d668c40..c515b62 100644 --- a/backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql +++ b/backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql @@ -1,4 +1,4 @@ -{ +query IndexersByStakedTokens { indexers(orderBy: stakedTokens) { id url From 62313bde72fa7a2b3a1c7581871e0f9089ec4a72 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 13:57:40 +0100 Subject: [PATCH 10/34] Much more effective network subgraph queries --- backend/crates/common/src/config.rs | 4 +- .../crates/common/src/indexer/real_indexer.rs | 4 + .../common/src/network_subgraph_client/mod.rs | 133 ++++++++++++++---- .../queries/deployments.graphql | 18 ++- .../queries/indexers_by_allocations.graphql | 13 ++ 5 files changed, 138 insertions(+), 34 deletions(-) create mode 100644 backend/crates/common/src/network_subgraph_client/queries/indexers_by_allocations.graphql diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index b8d86fd..ffad9f1 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -182,7 +182,9 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result network_subgraph.indexers_by_allocations().await, + NetworkSubgraphQuery::ByAllocations => { + network_subgraph.indexers_by_allocations(Some(100)).await + } NetworkSubgraphQuery::ByStakedTokens => { network_subgraph.indexers_by_staked_tokens().await } diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index 3bda447..f2fd307 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -38,6 +38,10 @@ impl RealIndexer { } } + pub fn set_address(&mut self, address: Vec) { + self.address = Some(address); + } + #[instrument(skip_all)] pub fn with_address(address: &[u8], status_url: impl IntoUrl) -> Self { Self { diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index d307165..db96252 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -15,6 +15,10 @@ use crate::prelude::{Indexer as IndexerTrait, RealIndexer}; /// A GraphQL client that can query the network subgraph and extract useful /// data. +/// +/// The queries available for this client are oriented towards the needs of +/// Graphix, namely to find high-quality and important indexers and subgraph +/// deployments. #[derive(Debug, Clone)] pub struct NetworkSubgraphClient { endpoint: String, @@ -68,17 +72,49 @@ impl NetworkSubgraphClient { Ok(indexers) } - pub async fn indexers_by_allocations(&self) -> anyhow::Result>> { - let sg_deployments = self.subgraph_deployments().await?; + pub async fn indexers_by_allocations( + &self, + limit: Option, + ) -> anyhow::Result>> { + let page_size = 100; + + let mut indexers = Vec::>::new(); + loop { + let response_data: GraphqlResponseTopIndexers = self + .graphql_query_no_errors( + queries::INDEXERS_BY_ALLOCATIONS_QUERY, + vec![ + ("first".to_string(), page_size.into()), + ("skip".to_string(), indexers.len().into()), + ], + "error(s) querying indexers by allocations from the network subgraph", + ) + .await?; + + // If we got less than the page size, we're done. + let no_more_results = response_data.indexers.len() < page_size; + + for indexer in response_data.indexers { + if let Some(url) = indexer.url { + let address = hex::decode(indexer.id.trim_start_matches("0x"))?; + let mut real_indexer = RealIndexer::new(IndexerConfig { + name: indexer.id, + urls: IndexerUrls { + status: Url::parse(&format!("{}/status", url))?, + }, + }); + real_indexer.set_address(address); + indexers.push(Arc::new(real_indexer)); + } + } - let mut indexers: Vec> = vec![]; - for deployment in sg_deployments { - for indexer_allocation in deployment.indexer_allocations { - let url = indexer_allocation.indexer.url.clone(); - if let Ok(indexer) = indexer_allocation_data_to_real_indexer(indexer_allocation) { - indexers.push(Arc::new(indexer)); - } else { - warn!(url, "Failed to create indexer from allocation data"); + if no_more_results { + break; + } + if let Some(limit) = limit { + if indexers.len() > limit as usize { + indexers.truncate(limit as usize); + break; } } } @@ -94,7 +130,6 @@ impl NetworkSubgraphClient { ) -> anyhow::Result> { let hex_encoded_addr_json = serde_json::to_value(format!("0x{}", hex::encode(address))) .expect("Unable to hex encode address"); - println!("hex_encoded_addr_json: {:?}", hex_encoded_addr_json); let response_data: ResponseData = self .graphql_query_no_errors( queries::INDEXER_BY_ADDRESS_QUERY, @@ -120,29 +155,54 @@ impl NetworkSubgraphClient { anyhow::anyhow!("No indexer found for address 0x{}", hex::encode(address)) })?; - let indexer = Arc::new(RealIndexer::new(IndexerConfig { + let mut indexer = RealIndexer::new(IndexerConfig { name: indexer_data.default_display_name.clone(), urls: IndexerUrls { status: Url::parse(&format!("{}/status", indexer_data.url))?, }, - })); + }); + indexer.set_address(address.to_vec()); - Ok(indexer) + Ok(Arc::new(indexer)) } - /// Returns all subgraph deployments. - pub async fn subgraph_deployments( + /// Returns all subgraph deployments, ordered by curation signal amounts. + pub async fn subgraph_deployments_by_signal( &self, + limit: Option, ) -> anyhow::Result> { - let response_data: GraphqlResponseSgDeployments = self - .graphql_query_no_errors( - queries::DEPLOYMENTS_QUERY, - vec![], - "error(s) querying deployments from the network subgraph", - ) - .await?; + let page_size = 100; + + let mut subgraph_deployments = vec![]; + loop { + let response_data: GraphqlResponseSgDeployments = self + .graphql_query_no_errors( + queries::DEPLOYMENTS_QUERY, + vec![ + ("first".to_string(), page_size.into()), + ("skip".to_string(), subgraph_deployments.len().into()), + ], + "error(s) querying deployments from the network subgraph", + ) + .await?; + + // If we got less than the page size, we're done. + let no_more_results = response_data.subgraph_deployments.len() < page_size; + + subgraph_deployments.extend(response_data.subgraph_deployments); + + if no_more_results { + break; + } + if let Some(limit) = limit { + if subgraph_deployments.len() > limit as usize { + subgraph_deployments.truncate(limit as usize); + break; + } + } + } - Ok(response_data.subgraph_deployments) + Ok(subgraph_deployments) } /// A wrapper around [`NetworkSubgraphClient::graphql_query`] that requires @@ -257,6 +317,8 @@ pub struct Indexer { mod queries { pub const INDEXERS_BY_STAKED_TOKENS_QUERY: &str = include_str!("queries/indexers_by_staked_tokens.graphql"); + pub const INDEXERS_BY_ALLOCATIONS_QUERY: &str = + include_str!("queries/indexers_by_allocations.graphql"); pub const DEPLOYMENTS_QUERY: &str = include_str!("queries/deployments.graphql"); pub const INDEXER_BY_ADDRESS_QUERY: &str = include_str!("queries/indexer_by_address.graphql"); } @@ -289,16 +351,27 @@ mod tests { #[tokio::test] async fn mainnet_indexers_by_allocations_no_panic() { let client = network_sg_client_on_ethereum(); - let indexers = client.indexers_by_allocations().await.unwrap(); - assert!(indexers.len() > 0); + let indexers = client.indexers_by_allocations(Some(10)).await.unwrap(); + assert_eq!(indexers.len(), 10); } #[tokio::test] - async fn at_least_100_subgraph_deployments() { + async fn subgraph_deployments_limits() { let client = network_sg_client_on_ethereum(); - let deployments = client.subgraph_deployments().await.unwrap(); - println!("n. of deployments: {:?}", deployments.len()); - assert!(deployments.len() >= 100); + + // Single page. + let deployments = client + .subgraph_deployments_by_signal(Some(5)) + .await + .unwrap(); + assert_eq!(deployments.len(), 5); + + // Muliple pages. + let deployments = client + .subgraph_deployments_by_signal(Some(150)) + .await + .unwrap(); + assert_eq!(deployments.len(), 150); } #[tokio::test] diff --git a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql index db09ef7..da9e42a 100644 --- a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql +++ b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql @@ -1,11 +1,23 @@ -query subgraphDeployments { +query subgraphDeployments($first: Int!, $skip: Int!) { subgraphDeployments( where: { indexerAllocations_: { status_in: [Active] } } - orderBy: stakedTokens + first: $first + skip: $skip + orderBy: signalAmount + orderDirection: desc ) { ipfsHash - indexerAllocations(orderBy: allocatedTokens) { + signalAmount + indexerAllocations( + # Only the 5 indexers with the largest allocations, otherwise + # the query response becomes massive. + first: 5 + orderBy: allocatedTokens + orderDirection: desc + ) { indexer { + defaultDisplayName + stakedTokens id url } diff --git a/backend/crates/common/src/network_subgraph_client/queries/indexers_by_allocations.graphql b/backend/crates/common/src/network_subgraph_client/queries/indexers_by_allocations.graphql new file mode 100644 index 0000000..b2f5b48 --- /dev/null +++ b/backend/crates/common/src/network_subgraph_client/queries/indexers_by_allocations.graphql @@ -0,0 +1,13 @@ +query IndexersByAllocations($first: Int, $skip: Int) { + indexers( + orderBy: allocatedTokens + orderDirection: desc + first: $first + skip: $skip + ) { + id + defaultDisplayName + url + allocatedTokens + } +} From 8836c5857fa64d3d890165aa98f9bcc4a199fd1f Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 14:59:48 +0100 Subject: [PATCH 11/34] Add indexer and network info on Grafana --- .../down.sql | 0 .../up.sql | 0 backend/crates/common/src/config.rs | 2 +- .../crates/common/src/graphql_api/server.rs | 7 + .../crates/common/src/indexer/real_indexer.rs | 5 +- backend/crates/common/src/store/mod.rs | 18 +- .../crates/schema/graphql/api_schema.graphql | 1 + .../grafana/dashboards/Graphix_Dashboard.json | 372 +++++++++++++++--- ops/compose/grafana/data/grafana.db | Bin 1347584 -> 1351680 bytes ops/compose/network.yml | 2 + 10 files changed, 340 insertions(+), 67 deletions(-) rename backend/crates/common/migrations/{2023-12-04-133234_indexing_status => 2023-12-04-133234_versions}/down.sql (100%) rename backend/crates/common/migrations/{2023-12-04-133234_indexing_status => 2023-12-04-133234_versions}/up.sql (100%) diff --git a/backend/crates/common/migrations/2023-12-04-133234_indexing_status/down.sql b/backend/crates/common/migrations/2023-12-04-133234_versions/down.sql similarity index 100% rename from backend/crates/common/migrations/2023-12-04-133234_indexing_status/down.sql rename to backend/crates/common/migrations/2023-12-04-133234_versions/down.sql diff --git a/backend/crates/common/migrations/2023-12-04-133234_indexing_status/up.sql b/backend/crates/common/migrations/2023-12-04-133234_versions/up.sql similarity index 100% rename from backend/crates/common/migrations/2023-12-04-133234_indexing_status/up.sql rename to backend/crates/common/migrations/2023-12-04-133234_versions/up.sql diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index ffad9f1..57f9874 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -183,7 +183,7 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result { - network_subgraph.indexers_by_allocations(Some(100)).await + network_subgraph.indexers_by_allocations(config.limit).await } NetworkSubgraphQuery::ByStakedTokens => { network_subgraph.indexers_by_staked_tokens().await diff --git a/backend/crates/common/src/graphql_api/server.rs b/backend/crates/common/src/graphql_api/server.rs index d1e1543..4e57deb 100644 --- a/backend/crates/common/src/graphql_api/server.rs +++ b/backend/crates/common/src/graphql_api/server.rs @@ -183,6 +183,13 @@ impl QueryRoot { Ok(None) } } + + async fn networks(&self, ctx: &Context<'_>) -> Result> { + let api_ctx = ctx.data::()?; + + let networks = api_ctx.store.networks()?; + Ok(networks) + } } pub struct MutationRoot; diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index f2fd307..0d8dfa4 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::sync::Arc; -use anyhow::anyhow; +use anyhow::{anyhow, Context}; use async_trait::async_trait; use graphql_client::{GraphQLQuery, Response}; use reqwest::IntoUrl; @@ -82,8 +82,7 @@ impl RealIndexer { return Err(anyhow::anyhow!("Indexer returned errors: {}", errors)); } - // Unwrap: `data` is always present if there are no errors. - Ok(response.data.unwrap()) + Ok(response.data.context("Indexer returned no data")?) } async fn proofs_of_indexing_batch( diff --git a/backend/crates/common/src/store/mod.rs b/backend/crates/common/src/store/mod.rs index 6fd697b..98a3302 100644 --- a/backend/crates/common/src/store/mod.rs +++ b/backend/crates/common/src/store/mod.rs @@ -19,7 +19,7 @@ use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use tracing::info; use self::models::{QueriedSgDeployment, WritablePoi}; -use crate::graphql_api::types::{BlockRangeInput, IndexersQuery, SgDeploymentsQuery}; +use crate::graphql_api::types::{BlockRangeInput, IndexersQuery, Network, SgDeploymentsQuery}; use crate::indexer::Indexer; use crate::prelude::IndexerVersion; use crate::store::models::{IndexerRow, Poi}; @@ -137,6 +137,22 @@ impl Store { diesel_queries::delete_network(&mut conn, network_name) } + pub fn networks(&self) -> anyhow::Result> { + use schema::networks; + + let mut conn = self.conn()?; + let rows = networks::table + .select((networks::name, networks::caip2)) + .load::<(String, Option)>(&mut conn)?; + + let networks = rows + .into_iter() + .map(|(name, caip2)| Network { name, caip2 }) + .collect(); + + Ok(networks) + } + /// Returns all indexers stored in the database. pub fn indexers(&self, filter: IndexersQuery) -> anyhow::Result> { use schema::indexers; diff --git a/backend/crates/schema/graphql/api_schema.graphql b/backend/crates/schema/graphql/api_schema.graphql index 2e3d5ee..15a2af1 100644 --- a/backend/crates/schema/graphql/api_schema.graphql +++ b/backend/crates/schema/graphql/api_schema.graphql @@ -373,6 +373,7 @@ type QueryRoot { liveProofsOfIndexing(filter: PoisQuery!): [ProofOfIndexing!]! poiAgreementRatios(indexerName: String!): [PoiAgreementRatio!]! divergenceInvestigationReport(uuid: String!): DivergenceInvestigationReport + networks: [Network!]! } """ diff --git a/ops/compose/grafana/dashboards/Graphix_Dashboard.json b/ops/compose/grafana/dashboards/Graphix_Dashboard.json index 8e0f168..33fbfde 100644 --- a/ops/compose/grafana/dashboards/Graphix_Dashboard.json +++ b/ops/compose/grafana/dashboards/Graphix_Dashboard.json @@ -82,7 +82,7 @@ }, "showHeader": true }, - "pluginVersion": "9.5.1", + "pluginVersion": "9.4.7", "targets": [ { "aliasBy": "", @@ -293,6 +293,101 @@ "transformations": [], "type": "timeseries" }, + { + "datasource": { + "type": "prometheus", + "uid": "c19gyBP4z" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "hertz" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 15, + "x": 9, + "y": 17 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "c19gyBP4z" + }, + "editorMode": "code", + "expr": "sum (rate(public_proofs_of_indexing_requests[$__rate_interval]))", + "hide": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "RPS: \"publicProofsOfIndexing\"", + "transformations": [], + "type": "timeseries" + }, { "datasource": { "type": "fifemon-graphql-datasource", @@ -321,10 +416,10 @@ "overrides": [] }, "gridPos": { - "h": 7, - "w": 9, - "x": 0, - "y": 16 + "h": 4, + "w": 5, + "x": 9, + "y": 25 }, "id": 3, "options": { @@ -341,7 +436,7 @@ }, "textMode": "auto" }, - "pluginVersion": "9.5.1", + "pluginVersion": "9.4.7", "targets": [ { "aliasBy": "", @@ -380,43 +475,154 @@ }, { "datasource": { - "type": "prometheus", - "uid": "c19gyBP4z" + "type": "fifemon-graphql-datasource", + "uid": "gYhzyBE4k" }, + "description": "List of indexers monitored by Graphix", "fieldConfig": { "defaults": { "color": { - "mode": "palette-classic" + "mode": "thresholds" }, "custom": { - "axisCenteredZero": false, - "axisColorMode": "text", - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "drawStyle": "line", - "fillOpacity": 0, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false + "align": "auto", + "cellOptions": { + "type": "auto" }, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "id" }, - "showPoints": "auto", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" + "properties": [ + { + "id": "displayName", + "value": "Indexer ID" + }, + { + "id": "custom.filterable", + "value": true + }, + { + "id": "links", + "value": [ + { + "targetBlank": true, + "title": "Indexer page on the Network Explorer", + "url": "https://thegraph.com/explorer/profile/${__value.text}?view=Overview&chain=mainnet" + } + ] + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "allocatedTokens" }, - "thresholdsStyle": { - "mode": "off" - } + "properties": [ + { + "id": "noValue", + "value": "-" + }, + { + "id": "displayName", + "value": "Total allocated tokens" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Indexer ID" + }, + "properties": [ + { + "id": "custom.width", + "value": 473 + } + ] + } + ] + }, + "gridPos": { + "h": 14, + "w": 10, + "x": 14, + "y": 25 + }, + "id": 9, + "options": { + "footer": { + "countRows": false, + "enablePagination": true, + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true, + "sortBy": [] + }, + "pluginVersion": "9.4.7", + "targets": [ + { + "aliasBy": "", + "annotationTags": "", + "annotationText": "", + "annotationTitle": "", + "constant": 6.5, + "dataPath": "indexers", + "datasource": { + "type": "fifemon-graphql-datasource", + "uid": "gYhzyBE4k" + }, + "endTimePath": "endTime", + "groupBy": "", + "queryText": "query {\n indexers(filter: {}) {\n id\n allocatedTokens\n }\n}", + "refId": "A", + "timePath": "" + } + ], + "title": "Monitored indexers", + "type": "table" + }, + { + "datasource": { + "type": "fifemon-graphql-datasource", + "uid": "gYhzyBE4k" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false }, "mappings": [], "thresholds": { @@ -431,47 +637,89 @@ "value": 80 } ] - }, - "unit": "hertz" + } }, - "overrides": [] + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "name" + }, + "properties": [ + { + "id": "displayName", + "value": "Name" + }, + { + "id": "custom.filterable", + "value": true + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "caip2" + }, + "properties": [ + { + "id": "displayName", + "value": "CAIP-2 ID" + }, + { + "id": "noValue", + "value": "-" + } + ] + } + ] }, "gridPos": { - "h": 8, - "w": 15, + "h": 10, + "w": 5, "x": 9, - "y": 17 + "y": 29 }, - "id": 7, + "id": 11, "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom", - "showLegend": true + "footer": { + "countRows": false, + "fields": "", + "reducer": [ + "sum" + ], + "show": false }, - "tooltip": { - "mode": "single", - "sort": "none" - } + "showHeader": true, + "sortBy": [ + { + "desc": false, + "displayName": "CAIP2 network ID (if known)" + } + ] }, + "pluginVersion": "9.4.7", "targets": [ { + "aliasBy": "", + "annotationTags": "", + "annotationText": "", + "annotationTitle": "", + "constant": 6.5, + "dataPath": "networks", "datasource": { - "type": "prometheus", - "uid": "c19gyBP4z" + "type": "fifemon-graphql-datasource", + "uid": "gYhzyBE4k" }, - "editorMode": "code", - "expr": "sum (rate(public_proofs_of_indexing_requests[$__rate_interval]))", - "hide": false, - "legendFormat": "__auto", - "range": true, - "refId": "A" + "endTimePath": "endTime", + "groupBy": "", + "queryText": "query {\n networks {\n name\n caip2\n }\n}", + "refId": "A", + "timePath": "" } ], - "title": "RPS: \"publicProofsOfIndexing\"", - "transformations": [], - "type": "timeseries" + "title": "Networks with known subgraphs", + "type": "table" } ], "refresh": "", @@ -490,6 +738,6 @@ "timezone": "", "title": "Graphix Dashboard", "uid": "dee4d09d-0dbc-4af2-b4a2-2fcb9ecf35cc", - "version": 5, + "version": 6, "weekStart": "" } diff --git a/ops/compose/grafana/data/grafana.db b/ops/compose/grafana/data/grafana.db index b1f47870caa6b7ca0b201e946791153b32abd79c..976aac7df10551c2d3bf6e56204ef5c141cdb084 100644 GIT binary patch delta 6060 zcmeHLe{9s&9lv+KZ0>UQ*}gz1q!_muA-%hteZR;JLLiAqSVL1pM?2`icjqK-F81~8 za6#deWUWG5sVb}`Z{i=)!l*P&+ErCCQYA(!RYm+!TD7axPD_Wzv`w7^Y~B7Cli0KG zl1n|A>^1@sUm0h$u?gY*G*glF>vaCM7q;;zFcNNKCie zr`sLV?ap)UF6Z0$dU78U4cHTP?yZi4<0 z#Qg4^J|BsZfMn2xPBh{)LAx9PVBOZe%er?$W}W+{V*^o!7>mYSB+e6M;u7(id7?49 zi3ZFG&>+0K^2E9-Pj~0hOJTQhDU7{6>nPT1@cAp)de`5jB0UFRzk>C+HcLhPrE~9N z&ye7<@$6^Vct@Sn*JAU%<7*)$;fjdJ5h+$sC6rZ%|E6MI4df z&5caMj;yTZbK>D$sDle~hs4~d#HBc^SqhGGau&5RqnfUcga_oDE)~RdZV^&1j7p`) zOF?*b6SKh~=LJjZmOD%B+}7J464>4@Zb7u7{?JlcQyt>q^>?VX_r-(U7?)}ba)-H; z5HAI-sqlP|Q}a6Fp~j`g;Z-mFSa*=q)PlYp!S;=FSxL)qsR1#kNkMM$EK;1QU0@YS zFRF!MGzqp@9$<$RwWw_5O7H{1-3U*WC>5(B;LA@@3cUC^y%P5SgmSf1yES%vzrt1z z(~Y%OMnv|bCR9HL!kUU6jV;RhP(=-^jiv_+Vtxp2`zzf7^KxCpTo>Yd56YU(sspU7 zWTi2wps^#WBI{~F%ChOh><)8?JjTJ}9=Z?q|AlUw}S`MFBY--Jyy%m8=JpOfy zIlt&RSsB)9lt8}K#loPZZ_kO!FqbkHKFH~^j@XdmCgwHe#X*Tx6;>aT*j-gucaP0$KhDXVj5asfudN7gWSFsrCNx0|zWVhIMI7FKs;}OT{e@ z9g+&>kNu;Oh>*w(iL$a~M3lV>S{@D&u}Z}zQq1MljHpZ5J?gNeXqK0D-HB}rRJ^kb z_o%vSp}FuP#xQF;|re#K0|>(?pDiFUaL)0BsGm{wxE=e#=KUA;1$_8bW)`U_O2cV6GEVa(-TIy@FN`a1%T0azC4Bg@syccq%C zM}&vJUmaNOySoY(1Lf>D9k9GE@Sqvc`yD2y*G>DG8Gpd#@}9JLPrgWX9H}Rdpttqb zTTiTrMo}#Ja2$UGcN^Q@qKeB*{%+OfcQcdw91WNDVgZw?Q!m68a}}>})j(PIL%YfG zd(W`}dxstDtQF_~y_+?j%?DVkLjRzR{^xRqzWkc{Eq_g2uFw}g;N4XpxxT7G{|}t_ B$qoPj delta 2447 zcmbVOZEPIH8Q$4%pYL|PyO$VnlUpta@kjQ&-*>x>&L&d%3|9CE1e`!`@Ai@txwB)( z1{bJ}qS}NuB?;yx2muy}fFG&ifSQe32|^H(f00C@K~V%wgsP%e)J^}<{77fdv7Mx} zg5Kzv*`0Z3=6z+k0p`)4zodXqUiq7HKUlZR zNl!Rw5IAZ45Wi~GKc92-tfLpatW_*|j&GVJ+cGuNaZJmwZ9S78&*9@aVmwD4%TeS> zHo^O7UC{Yzlrnx@;Jl%OvWDQ*TbGMY2P&6lGbDrn9_Tr*$6ngLC8pq2+T-i}%Z z&}|blX*!rmGbg8r;d6)Jo>R=N)Fr?2r*ZhfDdukKr~dHS7ml4~UgW_i!R}e++3qM2 zYsX@r#@cy5)*dv;?EPG1_}pPciz*Q$T-(Jea5Bx>6v&3})$l#6xYc_wpNTw<4&Zb+ zFopU+9{Qc^0crT`?g)1fBe)$HPjfrC&-rZ7q_Q16mPCwB!KE{rZH5?m@Y|E`x z&4)F^)ooYRAJDp!J!Xh zn@&Vj$JHIz$Rug_)hL&Qt)tven5&)ezEN%kyI=wP(a@4TUbmk(KFT5R!ST_iyZ=#Z z5-EzD#K=i>`!A8HTA6CZ0APX95c}N<948hWHZ)n&T~l{8C(!;PZUpf7NkN8F2ZUPi z)50AblRMJoRBS|;; zfRgt-)wk`uq81!aK~ZQZSv~J4TGlI;vL#Q=Yo4OQ>E`&#CyHpcJ2>Q3%5_N%whj&Y z1McQzDr`3=+n(KAl^1^xmn;6f@y_t^+M#lByDtw6RjcLdR=Lnu>EG_}^o#JsYw<*_ z5WN}xU5PWfU2ASxVEe1SVj-hjx?WP8tfeVtsZ>gSV+8e_11%K#NZ414m z2MQ<1>-Aunu4exTJ$%+G9)M%7#bco;_Q9TmLNnCA0Ez3A&?zntsJ+5vzAjGc8;tq} ziSsKeHMxvgbmrY5oTP4W#&$L924_ZK|4xB}8`j15!;iicn7T>>q|*DCaP@$i7A_|u zu`t_$O&HjOHtGSXH*RAWH~PaeoTBG9vK19Yf#xFChIZ{n7akFF!Cqe+!Fn!5%VLjQ?&Gh36BcGq(qb7Vc2&lC(NbZBqK|NAHo^-2Er)Y8b9QIzKtyK zxytsY?`Jzd`aM+t&pYg`b&K@xY4KlIYW)HkY?zX!d3dT%YJ?vh5jb8|R42@~hU!}S zl`HUt^B`557N`lTNuub(7=0Ms``dK$`}Z&s`by~h`j!U6KuJ5svg}5d3hww=cp3!L zd2u}s*S{wX!_()$Z)?8T82sk6u$3f{*tKJF9Ph3o-D4Py-sP(~_h!_#Agn}4AcXy$ z2pYmFgxe8rLr5XCA*@E|Kxjo!5ZV#K@1ib*Gy?iZu0PwTy(2gyi?6cv_zzJ0$3f6^ sUYH=EoQ^-Sq;FhT;m5OJIh;8UBrdC{nK0&b%e9=PqX?+}_~pdE0a!=0J^%m! diff --git a/ops/compose/network.yml b/ops/compose/network.yml index 8dafc4b..d2b474c 100644 --- a/ops/compose/network.yml +++ b/ops/compose/network.yml @@ -30,6 +30,8 @@ services: - --web.console.templates=/usr/share/prometheus/consoles ports: - "9090:9090" + logging: + driver: none volumes: - ./prometheus/:/etc/prometheus/ From a7329e6c6746827663512b0c0c14ad322191a31a Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 15:00:07 +0100 Subject: [PATCH 12/34] Removed dead file --- backend/crates/common/src/db/schema.rs | 129 ------------------------- 1 file changed, 129 deletions(-) delete mode 100644 backend/crates/common/src/db/schema.rs diff --git a/backend/crates/common/src/db/schema.rs b/backend/crates/common/src/db/schema.rs deleted file mode 100644 index 9e6c0cf..0000000 --- a/backend/crates/common/src/db/schema.rs +++ /dev/null @@ -1,129 +0,0 @@ -// @generated automatically by Diesel CLI. - -diesel::table! { - blocks (id) { - id -> Int8, - network_id -> Int4, - number -> Int8, - hash -> Bytea, - } -} - -diesel::table! { - divergence_investigation_reports (uuid) { - uuid -> Text, - report -> Jsonb, - created_at -> Timestamp, - } -} - -diesel::table! { - indexer_versions (id) { - id -> Int4, - indexer_id -> Int4, - error -> Nullable, - version_string -> Nullable, - version_commit -> Nullable, - created_at -> Timestamp, - } -} - -diesel::table! { - indexers (id) { - id -> Int4, - name -> Nullable, - address -> Nullable, - created_at -> Timestamp, - } -} - -diesel::table! { - live_pois (id) { - id -> Int4, - sg_deployment_id -> Int4, - indexer_id -> Int4, - poi_id -> Int4, - } -} - -diesel::table! { - networks (id) { - id -> Int4, - name -> Text, - created_at -> Timestamp, - caip2 -> Nullable, - } -} - -diesel::table! { - pending_divergence_investigation_requests (uuid) { - uuid -> Text, - request -> Jsonb, - created_at -> Timestamp, - } -} - -diesel::table! { - pois (id) { - id -> Int4, - poi -> Bytea, - sg_deployment_id -> Int4, - indexer_id -> Int4, - block_id -> Int8, - created_at -> Timestamp, - } -} - -diesel::table! { - sg_deployment_api_versions (id) { - id -> Int4, - sg_deployment_id -> Int4, - api_versions -> Nullable>>, - error -> Nullable, - created_at -> Timestamp, - } -} - -diesel::table! { - sg_deployments (id) { - id -> Int4, - ipfs_cid -> Text, - network -> Int4, - created_at -> Timestamp, - } -} - -diesel::table! { - sg_names (id) { - id -> Int4, - sg_deployment_id -> Int4, - name -> Text, - created_at -> Timestamp, - } -} - -diesel::joinable!(blocks -> networks (network_id)); -diesel::joinable!(indexer_versions -> indexers (indexer_id)); -diesel::joinable!(live_pois -> indexers (indexer_id)); -diesel::joinable!(live_pois -> pois (poi_id)); -diesel::joinable!(live_pois -> sg_deployments (sg_deployment_id)); -diesel::joinable!(pois -> blocks (block_id)); -diesel::joinable!(pois -> indexers (indexer_id)); -diesel::joinable!(pois -> sg_deployments (sg_deployment_id)); -diesel::joinable!(sg_deployment_api_versions -> sg_deployments (sg_deployment_id)); -diesel::joinable!(sg_deployments -> networks (network)); -diesel::joinable!(sg_names -> sg_deployments (sg_deployment_id)); - -diesel::allow_tables_to_appear_in_same_query!( - blocks, - divergence_investigation_reports, - indexer_versions, - indexers, - live_pois, - networks, - pending_divergence_investigation_requests, - pois, - sg_deployment_api_versions, - sg_deployments, - sg_names, -); From 560deac041a5770e8f22f3fe0f93f991f24bd0b1 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 11 Dec 2023 19:00:18 +0100 Subject: [PATCH 13/34] More clearly separate indexer name and ID --- backend/crates/common/src/config.rs | 18 ++- .../crates/common/src/graphql_api/types.rs | 19 +++- .../crates/common/src/indexer/interceptor.rs | 16 ++- backend/crates/common/src/indexer/mod.rs | 45 ++++++-- .../crates/common/src/indexer/real_indexer.rs | 33 ++---- .../common/src/network_subgraph_client/mod.rs | 17 ++- backend/crates/common/src/queries.rs | 4 +- .../crates/common/src/store/diesel_queries.rs | 61 ++++++---- backend/crates/common/src/store/mod.rs | 7 ++ backend/crates/common/src/store/models.rs | 16 ++- backend/crates/common/src/test_utils/gen.rs | 2 +- backend/crates/common/src/test_utils/mocks.rs | 8 +- backend/crates/common/src/types.rs | 20 +++- .../common/tests/it_indexing_statuses.rs | 3 +- .../common/tests/it_proofs_of_indexing.rs | 3 +- backend/crates/cross-checker/src/bisect.rs | 4 +- backend/crates/cross-checker/src/main.rs | 4 +- .../crates/schema/graphql/api_schema.graphql | 6 +- .../grafana/dashboards/Graphix_Dashboard.json | 106 ++++++++++++++++-- ops/compose/grafana/data/grafana.db | Bin 1351680 -> 1372160 bytes ops/compose/graphix/network.yml | 10 +- 21 files changed, 298 insertions(+), 104 deletions(-) diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index 57f9874..80ca751 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::fs::File; use std::path::Path; use std::sync::Arc; @@ -9,6 +10,7 @@ use tracing::{info, warn}; use crate::block_choice::BlockChoicePolicy; use crate::indexer::{Indexer, IndexerInterceptor, RealIndexer}; use crate::network_subgraph_client::NetworkSubgraphClient; +use crate::prelude::IndexerId; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] @@ -95,10 +97,21 @@ pub struct IndexerUrls { #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct IndexerConfig { - pub name: String, + pub name: Option, + pub address: Option>, pub urls: IndexerUrls, } +impl IndexerId for IndexerConfig { + fn address(&self) -> Option<&[u8]> { + self.address.as_deref() + } + + fn name(&self) -> Option> { + self.name.as_ref().map(Cow::Borrowed) + } +} + #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct IndexerByAddressConfig { @@ -172,7 +185,7 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result anyhow::Result, + pub address: Option, /// The number of tokens allocated to the indexer, if known. pub allocated_tokens: Option, } impl From for Indexer { fn from(indexer: models::Indexer) -> Self { + let address = indexer + .address + .map(|addr| format!("0x{}", hex::encode(addr))); Self { - id: indexer.name.unwrap_or_default(), + id: if let Some(name) = &indexer.name { + name.clone() + } else if let Some(address) = &address { + address.clone() + } else { + panic!("Indexer has neither name nor address"); + }, + name: indexer.name, + address, allocated_tokens: None, // TODO: we don't store this in the db yet } } diff --git a/backend/crates/common/src/indexer/interceptor.rs b/backend/crates/common/src/indexer/interceptor.rs index 13105fa..0b4a463 100644 --- a/backend/crates/common/src/indexer/interceptor.rs +++ b/backend/crates/common/src/indexer/interceptor.rs @@ -1,5 +1,6 @@ //! A indexer interceptor, for test configs only. +use std::borrow::Cow; use std::sync::Arc; use async_trait::async_trait; @@ -16,25 +17,22 @@ use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; #[derive(Debug)] pub struct IndexerInterceptor { target: Arc, - id: String, poi_byte: u8, } impl IndexerInterceptor { - pub fn new(id: String, target: Arc, poi_byte: u8) -> Self { - Self { - id, - target, - poi_byte, - } + pub fn new(target: Arc, poi_byte: u8) -> Self { + Self { target, poi_byte } } } #[async_trait] impl Indexer for IndexerInterceptor { - fn id(&self) -> &str { - &self.id + fn name(&self) -> Option> { + self.target + .name() + .map(|name| Cow::Owned(format!("interceptor-{}", name))) } fn address(&self) -> Option<&[u8]> { diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs index 71a3774..0ddefa5 100644 --- a/backend/crates/common/src/indexer/mod.rs +++ b/backend/crates/common/src/indexer/mod.rs @@ -1,26 +1,42 @@ mod interceptor; mod real_indexer; -use std::collections::HashMap; use std::fmt::Debug; use std::hash::Hash; use std::sync::Arc; +use std::{borrow::Cow, collections::HashMap}; use anyhow::anyhow; use async_trait::async_trait; pub use interceptor::IndexerInterceptor; pub use real_indexer::RealIndexer; -use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::types::{self, IndexerId, IndexingStatus, PoiRequest, ProofOfIndexing}; +/// An indexer is a `graph-node` instance that may or may not also be a network +/// participant. #[async_trait] pub trait Indexer: Send + Sync + Debug { - /// Uniquely identifies the indexer. This is relied on for the [`Hash`] and - /// [`Eq`] impls. - fn id(&self) -> &str; - + /// The indexer's address. This can be [`None`] if the indexer is not a + /// network participant but e.g. a local `graph-node` instance. fn address(&self) -> Option<&[u8]>; + /// Human-readable name of the indexer. + fn name(&self) -> Option>; + + /// Within Graphix, an indexer is uniquely identified by its hex-encoded + /// address (if it is a network participant), or its name (if it's not). + /// This is known as the indexer's "global ID" or "GID". + fn id(&self) -> String { + if let Some(address) = self.address() { + hex::encode(address) + } else { + self.name() + .expect("indexer has neither address nor name; this is a bug") + .to_string() + } + } + async fn ping(self: Arc) -> anyhow::Result<()>; async fn indexing_statuses(self: Arc) -> anyhow::Result>; @@ -71,6 +87,19 @@ pub trait Indexer: Send + Sync + Debug { ) -> anyhow::Result; } +impl IndexerId for T +where + T: Indexer, +{ + fn address(&self) -> Option<&[u8]> { + Indexer::address(self) + } + + fn name(&self) -> Option> { + Indexer::name(self) + } +} + impl PartialEq for dyn Indexer { fn eq(&self, other: &Self) -> bool { self.id() == other.id() @@ -87,13 +116,13 @@ impl Hash for dyn Indexer { impl PartialOrd for dyn Indexer { fn partial_cmp(&self, other: &Self) -> Option { - self.id().partial_cmp(other.id()) + self.id().partial_cmp(&other.id()) } } impl Ord for dyn Indexer { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id().cmp(other.id()) + self.id().cmp(&other.id()) } } diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index 0d8dfa4..3c557d1 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -1,10 +1,10 @@ +use std::borrow::Cow; use std::collections::HashMap; use std::sync::Arc; use anyhow::{anyhow, Context}; use async_trait::async_trait; use graphql_client::{GraphQLQuery, Response}; -use reqwest::IntoUrl; use serde::de::DeserializeOwned; use serde::Serialize; use tracing::*; @@ -21,18 +21,19 @@ const REQUEST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); #[derive(Debug)] pub struct RealIndexer { - id: String, // Assumed to be unique accross all indexers address: Option>, + name: Option, urls: IndexerUrls, client: reqwest::Client, } impl RealIndexer { + // FIXME: this logic is bug-prone and should be replaced with proper sum types. #[instrument(skip_all)] pub fn new(config: IndexerConfig) -> Self { Self { - id: config.name, - address: None, + name: config.name, + address: config.address, urls: config.urls, client: reqwest::Client::new(), } @@ -42,18 +43,6 @@ impl RealIndexer { self.address = Some(address); } - #[instrument(skip_all)] - pub fn with_address(address: &[u8], status_url: impl IntoUrl) -> Self { - Self { - id: hex::encode(address), - address: Some(address.to_vec()), - urls: IndexerUrls { - status: status_url.into_url().unwrap(), - }, - client: reqwest::Client::new(), - } - } - /// Internal utility method to make a GraphQL query to the indexer. `error` /// and `data` fields are treated as mutually exclusive (which is generally /// a good assumption, but some callers may want more control over error @@ -115,14 +104,14 @@ impl RealIndexer { #[async_trait] impl Indexer for RealIndexer { - fn id(&self) -> &str { - &self.id - } - fn address(&self) -> Option<&[u8]> { self.address.as_deref() } + fn name(&self) -> Option> { + self.name.as_ref().map(Cow::Borrowed) + } + async fn ping(self: Arc) -> anyhow::Result<()> { let request = gql_types::Typename::build_query(gql_types::typename::Variables); self.graphql_query(request).await?; @@ -181,7 +170,7 @@ impl Indexer for RealIndexer { Ok(batch_pois) => { metrics() .public_proofs_of_indexing_requests - .get_metric_with_label_values(&[self.id(), "1"]) + .get_metric_with_label_values(&[&self.id(), "1"]) .unwrap() .inc(); @@ -190,7 +179,7 @@ impl Indexer for RealIndexer { Err(error) => { metrics() .public_proofs_of_indexing_requests - .get_metric_with_label_values(&[self.id(), "0"]) + .get_metric_with_label_values(&[&self.id(), "0"]) .unwrap() .inc(); diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index db96252..c28d969 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -97,13 +97,13 @@ impl NetworkSubgraphClient { for indexer in response_data.indexers { if let Some(url) = indexer.url { let address = hex::decode(indexer.id.trim_start_matches("0x"))?; - let mut real_indexer = RealIndexer::new(IndexerConfig { - name: indexer.id, + let real_indexer = RealIndexer::new(IndexerConfig { + name: indexer.default_display_name, + address: Some(address), urls: IndexerUrls { status: Url::parse(&format!("{}/status", url))?, }, }); - real_indexer.set_address(address); indexers.push(Arc::new(real_indexer)); } } @@ -156,7 +156,8 @@ impl NetworkSubgraphClient { })?; let mut indexer = RealIndexer::new(IndexerConfig { - name: indexer_data.default_display_name.clone(), + name: Some(indexer_data.default_display_name.clone()), + address: Some(address.to_vec()), urls: IndexerUrls { status: Url::parse(&format!("{}/status", indexer_data.url))?, }, @@ -256,14 +257,17 @@ impl NetworkSubgraphClient { fn indexer_allocation_data_to_real_indexer( indexer_allocation: IndexerAllocation, ) -> anyhow::Result { + let name = indexer_allocation.indexer.default_display_name.clone(); let indexer = indexer_allocation.indexer; + let address = hex::decode(indexer.id.trim_start_matches("0x"))?; let mut url: Url = indexer .url .ok_or_else(|| anyhow!("Indexer without URL"))? .parse()?; url.set_path("/status"); let config = IndexerConfig { - name: indexer.id, + name, + address: Some(address), urls: IndexerUrls { status: url }, }; Ok(RealIndexer::new(config)) @@ -304,13 +308,16 @@ pub struct SubgraphDeploymentWithAllocations { } #[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct IndexerAllocation { pub indexer: Indexer, } #[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct Indexer { pub id: String, + pub default_display_name: Option, pub url: Option, } diff --git a/backend/crates/common/src/queries.rs b/backend/crates/common/src/queries.rs index e27fda6..5e1bdb9 100644 --- a/backend/crates/common/src/queries.rs +++ b/backend/crates/common/src/queries.rs @@ -39,7 +39,7 @@ pub async fn query_indexing_statuses( query_successes += 1; metrics .indexing_statuses_requests - .get_metric_with_label_values(&[indexer.id(), "1"]) + .get_metric_with_label_values(&[&indexer.id(), "1"]) .unwrap() .inc(); @@ -55,7 +55,7 @@ pub async fn query_indexing_statuses( query_failures += 1; metrics .indexing_statuses_requests - .get_metric_with_label_values(&[indexer.id(), "0"]) + .get_metric_with_label_values(&[&indexer.id(), "0"]) .unwrap() .inc(); diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index dadb5b5..8d3de14 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::collections::BTreeMap; use chrono::Utc; @@ -117,6 +118,31 @@ pub(super) fn pois( } } +pub fn write_indexers( + conn: &mut PgConnection, + indexers: &[impl AsRef], +) -> anyhow::Result<()> { + use schema::indexers; + + let insertable_indexers = indexers + .iter() + .map(|indexer| { + let indexer = indexer.as_ref(); + NewIndexer { + address: indexer.address().map(ToOwned::to_owned), + name: indexer.name().map(|s| s.to_string()), + } + }) + .collect::>(); + + diesel::insert_into(indexers::table) + .values(insertable_indexers) + .on_conflict_do_nothing() + .execute(conn)?; + + Ok(()) +} + pub fn set_deployment_name( conn: &mut PgConnection, sg_deployment_id: &str, @@ -186,8 +212,7 @@ pub(super) fn write_pois( let new_pois: Vec<_> = poi_group .iter() .map(|poi| { - let indexer_id = - get_or_insert_indexer(conn, poi.indexer_id(), poi.indexer_address())?; + let indexer_id = get_indexer_id(conn, poi.indexer_name(), poi.indexer_address())?; Ok(NewPoi { sg_deployment_id, @@ -264,7 +289,7 @@ pub fn write_graph_node_version( ) -> anyhow::Result<()> { use schema::indexer_versions; - let indexer_id = get_or_insert_indexer(conn, indexer.id(), indexer.address())?; + let indexer_id = get_indexer_id(conn, indexer.name(), indexer.address())?; let new_version = match version { Ok(v) => models::NewIndexerVersion { @@ -288,32 +313,28 @@ pub fn write_graph_node_version( Ok(()) } -fn get_or_insert_indexer( +fn get_indexer_id( conn: &mut PgConnection, - id: &str, + name: Option>, address: Option<&[u8]>, -) -> Result { +) -> anyhow::Result { use schema::indexers; let existing_indexer: Option = indexers::table - .filter(indexers::name.is_not_distinct_from(id)) + .filter(indexers::name.is_not_distinct_from(&name)) .filter(indexers::address.is_not_distinct_from(address)) .get_result(conn) .optional()?; - Ok(if let Some(existing_indexer) = existing_indexer { - // If the indexer exists, use its id - existing_indexer.id + + if let Some(i) = existing_indexer { + Ok(i.id) } else { - // If the indexer doesn't exist, insert a new one and return its id - let new_indexer = NewIndexer { - address: address.map(ToOwned::to_owned), - name: Some(id.to_string()), - }; - diesel::insert_into(indexers::table) - .values(&new_indexer) - .returning(indexers::id) - .get_result(conn)? - }) + Err(anyhow::anyhow!( + "Indexer with name {:?} and/or address {:?} not found", + &name, + address + )) + } } fn get_or_insert_deployment( diff --git a/backend/crates/common/src/store/mod.rs b/backend/crates/common/src/store/mod.rs index 98a3302..fb11aed 100644 --- a/backend/crates/common/src/store/mod.rs +++ b/backend/crates/common/src/store/mod.rs @@ -159,6 +159,7 @@ impl Store { let mut query = indexers::table.into_boxed(); + // FIXME if let Some(address) = filter.address { query = query.filter(indexers::name.eq(address)); } @@ -214,6 +215,12 @@ impl Store { .transaction::<_, Error, _>(|conn| diesel_queries::write_pois(conn, pois, live)) } + pub fn write_indexers(&self, indexers: &[impl AsRef]) -> anyhow::Result<()> { + let mut conn = self.conn()?; + diesel_queries::write_indexers(&mut conn, indexers)?; + Ok(()) + } + pub fn write_graph_node_versions( &self, versions: HashMap, anyhow::Result>, diff --git a/backend/crates/common/src/store/models.rs b/backend/crates/common/src/store/models.rs index a918474..aa486f1 100644 --- a/backend/crates/common/src/store/models.rs +++ b/backend/crates/common/src/store/models.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use async_graphql::SimpleObject; use chrono::NaiveDateTime; use diesel::deserialize::FromSql; @@ -58,7 +60,7 @@ pub struct NewPoi { pub trait WritablePoi { fn deployment_cid(&self) -> &str; - fn indexer_id(&self) -> &str; + fn indexer_name(&self) -> Option>; fn indexer_address(&self) -> Option<&[u8]>; fn block(&self) -> BlockPointer; fn proof_of_indexing(&self) -> &[u8]; @@ -108,6 +110,18 @@ pub struct IndexerRow { pub created_at: NaiveDateTime, } +impl IndexerRow { + pub fn indexer_id(&self) -> String { + if let Some(address) = &self.address { + hex::encode(address) + } else { + self.name + .clone() + .expect("indexer has neither address nor name; this is a bug") + } + } +} + #[derive(Debug, Insertable)] #[diesel(table_name = indexers)] pub struct NewIndexer { diff --git a/backend/crates/common/src/test_utils/gen.rs b/backend/crates/common/src/test_utils/gen.rs index 868396d..19f9baa 100644 --- a/backend/crates/common/src/test_utils/gen.rs +++ b/backend/crates/common/src/test_utils/gen.rs @@ -95,7 +95,7 @@ where .collect(); Arc::new(MockIndexer { - id, + name: id, deployment_details, fail_indexing_statuses: rng.gen_bool(0.1), }) as Arc diff --git a/backend/crates/common/src/test_utils/mocks.rs b/backend/crates/common/src/test_utils/mocks.rs index b9c2d4e..f21592f 100644 --- a/backend/crates/common/src/test_utils/mocks.rs +++ b/backend/crates/common/src/test_utils/mocks.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{borrow::Cow, sync::Arc}; use anyhow::anyhow; use async_trait::async_trait; @@ -19,15 +19,15 @@ pub struct DeploymentDetails { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct MockIndexer { - pub id: String, + pub name: String, pub deployment_details: Vec, pub fail_indexing_statuses: bool, } #[async_trait] impl Indexer for MockIndexer { - fn id(&self) -> &str { - &self.id + fn name(&self) -> Option> { + Some(Cow::Borrowed(&self.name)) } fn address(&self) -> Option<&[u8]> { diff --git a/backend/crates/common/src/types.rs b/backend/crates/common/src/types.rs index 2121255..518fb18 100644 --- a/backend/crates/common/src/types.rs +++ b/backend/crates/common/src/types.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::fmt; use std::ops::Deref; use std::sync::Arc; @@ -114,8 +115,8 @@ impl WritablePoi for ProofOfIndexing { self.deployment.as_str() } - fn indexer_id(&self) -> &str { - self.indexer.id() + fn indexer_name(&self) -> Option> { + self.indexer.name() } fn indexer_address(&self) -> Option<&[u8]> { @@ -131,6 +132,21 @@ impl WritablePoi for ProofOfIndexing { } } +pub trait IndexerId { + fn address(&self) -> Option<&[u8]>; + fn name(&self) -> Option>; + + fn id(&self) -> String { + if let Some(address) = self.address() { + format!("0x{}", hex::encode(address)) + } else if let Some(name) = self.name() { + name.to_string() + } else { + panic!("Indexer has neither name nor address") + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] pub struct DivergingBlock { pub block: BlockPointer, diff --git a/backend/crates/common/tests/it_indexing_statuses.rs b/backend/crates/common/tests/it_indexing_statuses.rs index 545cd35..e8c89bb 100644 --- a/backend/crates/common/tests/it_indexing_statuses.rs +++ b/backend/crates/common/tests/it_indexing_statuses.rs @@ -9,7 +9,8 @@ use reqwest::Url; fn test_indexer_from_url(url: impl Into) -> Arc { let url: Url = url.into().parse().expect("Invalid status url"); let conf = IndexerConfig { - name: url.host().unwrap().to_string(), + name: Some(url.host().unwrap().to_string()), + address: None, urls: IndexerUrls { status: url.join("status").unwrap(), }, diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/backend/crates/common/tests/it_proofs_of_indexing.rs index a49d810..68f2083 100644 --- a/backend/crates/common/tests/it_proofs_of_indexing.rs +++ b/backend/crates/common/tests/it_proofs_of_indexing.rs @@ -11,7 +11,8 @@ use reqwest::Url; fn test_indexer_from_url(url: impl Into) -> Arc { let url: Url = url.into().parse().expect("Invalid status url"); let conf = IndexerConfig { - name: url.host().unwrap().to_string(), + name: Some(url.host().unwrap().to_string()), + address: None, urls: IndexerUrls { status: url.join("status").unwrap(), }, diff --git a/backend/crates/cross-checker/src/bisect.rs b/backend/crates/cross-checker/src/bisect.rs index c72ead0..755f670 100644 --- a/backend/crates/cross-checker/src/bisect.rs +++ b/backend/crates/cross-checker/src/bisect.rs @@ -311,7 +311,7 @@ async fn handle_divergence_investigation_request_pair( debug!(req_uuid = req_uuid_str, poi1 = %poi1_s, poi2 = %poi2_s, "Fetching indexers"); let indexer1 = match indexers .iter() - .find(|indexer| Some(indexer.id()) == poi1.indexer.name.as_deref()) + .find(|indexer| indexer.id() == poi1.indexer.indexer_id()) .cloned() .ok_or(DivergenceInvestigationError::IndexerNotFound { poi: poi1_s.to_string(), @@ -324,7 +324,7 @@ async fn handle_divergence_investigation_request_pair( }; let indexer2 = match indexers .iter() - .find(|indexer| Some(indexer.id()) == poi2.indexer.name.as_deref()) + .find(|indexer| indexer.id() == poi2.indexer.indexer_id()) .cloned() .ok_or(DivergenceInvestigationError::IndexerNotFound { poi: poi2_s.to_string(), diff --git a/backend/crates/cross-checker/src/main.rs b/backend/crates/cross-checker/src/main.rs index 3c29476..8c87b54 100644 --- a/backend/crates/cross-checker/src/main.rs +++ b/backend/crates/cross-checker/src/main.rs @@ -61,6 +61,8 @@ async fn main() -> anyhow::Result<()> { // duplicate indexers. indexers = deduplicate_indexers(&indexers); + store.write_indexers(&indexers)?; + tx_indexers.send(indexers.clone())?; let graph_node_versions = @@ -96,7 +98,7 @@ fn deduplicate_indexers(indexers: &[Arc]) -> Vec> let mut seen = HashSet::new(); let mut deduplicated = vec![]; for indexer in indexers { - if !seen.contains(indexer.id()) { + if !seen.contains(&indexer.id()) { deduplicated.push(indexer.clone()); seen.insert(indexer.id().to_string()); } diff --git a/backend/crates/schema/graphql/api_schema.graphql b/backend/crates/schema/graphql/api_schema.graphql index 15a2af1..de7cc19 100644 --- a/backend/crates/schema/graphql/api_schema.graphql +++ b/backend/crates/schema/graphql/api_schema.graphql @@ -186,11 +186,9 @@ enum DivergenceInvestigationStatus { An indexer that is known to Graphix. """ type Indexer { - """ - The indexer's ID, which is equal to its hex-encoded address with a '0x' - prefix. - """ id: String! + name: String + address: String """ The number of tokens allocated to the indexer, if known. """ diff --git a/ops/compose/grafana/dashboards/Graphix_Dashboard.json b/ops/compose/grafana/dashboards/Graphix_Dashboard.json index 33fbfde..b4a38a8 100644 --- a/ops/compose/grafana/dashboards/Graphix_Dashboard.json +++ b/ops/compose/grafana/dashboards/Graphix_Dashboard.json @@ -61,7 +61,72 @@ ] } }, - "overrides": [] + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "id" + }, + "properties": [ + { + "id": "displayName", + "value": "Deployment ID" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "networkName" + }, + "properties": [ + { + "id": "displayName", + "value": "Network" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "name" + }, + "properties": [ + { + "id": "displayName", + "value": "Sg. name" + }, + { + "id": "noValue", + "value": "-" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Deployment ID" + }, + "properties": [ + { + "id": "custom.width", + "value": 470 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Network" + }, + "properties": [ + { + "id": "custom.width", + "value": 98 + } + ] + } + ] }, "gridPos": { "h": 16, @@ -74,13 +139,15 @@ "cellHeight": "sm", "footer": { "countRows": false, + "enablePagination": true, "fields": "", "reducer": [ "sum" ], "show": false }, - "showHeader": true + "showHeader": true, + "sortBy": [] }, "pluginVersion": "9.4.7", "targets": [ @@ -102,7 +169,7 @@ "timePath": "" } ], - "title": "Deployments", + "title": "Monitored deployments", "type": "table" }, { @@ -510,12 +577,12 @@ { "matcher": { "id": "byName", - "options": "id" + "options": "address" }, "properties": [ { "id": "displayName", - "value": "Indexer ID" + "value": "Indexer ID (address)" }, { "id": "custom.filterable", @@ -528,6 +595,11 @@ "targetBlank": true, "title": "Indexer page on the Network Explorer", "url": "https://thegraph.com/explorer/profile/${__value.text}?view=Overview&chain=mainnet" + }, + { + "targetBlank": true, + "title": "Etherscan", + "url": "https://etherscan.io/address/${__value.text}" } ] } @@ -552,12 +624,28 @@ { "matcher": { "id": "byName", - "options": "Indexer ID" + "options": "name" + }, + "properties": [ + { + "id": "displayName", + "value": "Default display name" + }, + { + "id": "noValue", + "value": "-" + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Indexer ID (address)" }, "properties": [ { "id": "custom.width", - "value": 473 + "value": 425 } ] } @@ -598,7 +686,7 @@ }, "endTimePath": "endTime", "groupBy": "", - "queryText": "query {\n indexers(filter: {}) {\n id\n allocatedTokens\n }\n}", + "queryText": "query {\n indexers(filter: {}) {\n address\n name\n allocatedTokens\n }\n}", "refId": "A", "timePath": "" } @@ -738,6 +826,6 @@ "timezone": "", "title": "Graphix Dashboard", "uid": "dee4d09d-0dbc-4af2-b4a2-2fcb9ecf35cc", - "version": 6, + "version": 9, "weekStart": "" } diff --git a/ops/compose/grafana/data/grafana.db b/ops/compose/grafana/data/grafana.db index 976aac7df10551c2d3bf6e56204ef5c141cdb084..83ebb52804c499b94c604c3bb398f90bb5b32006 100644 GIT binary patch delta 1809 zcmds1Ur1YL6u;k1?w`bXe-v+&8XpYz%>zYAuZsd&s&{G zzLC9zc>ERBJ|F3-?(_#bE4^Knq`ISnc$5w~(vb|&$&eu#GR}n<<5#@X+D2vaPFdIk zw6*OruAQQ_-)VNh!su?P9$vGupBYMpyTIkKM|t6)aMy~gNXLO-VGIay4O?fuhF)L| zNJplClh_vSl8_Q+g;^bVK!CK1WzFUW&WQ8}ruqr}uBBbv^%ULo7rejB?O`^_aMc1_ zUgi!l`^j+QOLHsSTUNBHy}ic$9HtvxTDyxkAi8M-h?_r0H$6LN=5scrne+pxr*rKgHZ!0vw?LTc6XupB6Hvbbolmji3;`eiDOiMIHY0D{`Fmg&H z5+{R$aHrJnfV?4`4~tWx*({Z82TI}N1l|X=qPT#{VDUUI485XullWk#(&sF5CgM?N z(All3{ewZbn>>!VdSdSF1n#|W96vs!L=(iNl9TEPv|qqqLvI3m#X8cZB%-Pm=^5;g zDyO7A( z0&qKq#f!#uoM$%B*QlHa+y;G3yVEUxOBa79)LSToc;rL5<7YcL-sF|NzH*PZ+~biv zRY7m1J`_#aWt%m^dn@>$QQxkDiH-YMH=DL`-;Ny&UqkUVXL0SDS~5?Z;~dL=PNb0A zJwDTK^7-`SxjfGw@c|SBkvYui!{FVb=T8Gy=dOa2AH+`kPJ5%dujIVWAdJ(1J$6Dmk&!t zVjFzK+HbTnZ%7=w7@NWGV^H&5t{>@DozmE1! sr!m9uGZa6g|Gj7U;-zB^JIb6H;7sPHm6>_FrOZF*|GSvNneiX_7n_h!(EtDd delta 553 zcmXYuO=uHA9L0BLvpW+v+0AS=SSYqh5bC9y%}0|alvo8pDyG^}A{3;lU9YWp$fY3( z;-(7XN40}J6^e=;G^Mc9n;)mrOH#B45t?}LqJjql1)6Q@$5PorjUJu;tdZSy`lp@KRCnom1DzL!%p!hlH_?Iuw%DB(+R4GdJe$%n4`84~%?N%9<)md`%Wzx9G0TuF z!($m<+mQEj?s&$CXQHXFNO#L}n4T)jC&Z&4y-=2W(9xZwbB^&poD9Q%;o3%7c2FFA zY@TRAiSBWXvZQ}A_h&r6~2X*M>7yjdHwoSHC zt+PiQRMy$^lP*D8=A`9CGCa>LpJpSrfc;nbuFX8sI1q_c?v Date: Mon, 11 Dec 2023 19:16:08 +0100 Subject: [PATCH 14/34] Remove unused struct IndexerRow --- .../crates/common/src/graphql_api/types.rs | 3 ++ backend/crates/common/src/indexer/mod.rs | 3 +- .../queries/deployments.graphql | 2 + .../crates/common/src/store/diesel_queries.rs | 4 +- backend/crates/common/src/store/mod.rs | 4 +- backend/crates/common/src/store/models.rs | 39 ++++-------------- backend/crates/common/src/test_utils/mocks.rs | 3 +- backend/crates/common/src/types.rs | 3 +- backend/crates/cross-checker/src/bisect.rs | 8 ++-- .../crates/schema/graphql/api_schema.graphql | 6 +++ ops/compose/grafana/data/grafana.db | Bin 1372160 -> 1372160 bytes 11 files changed, 34 insertions(+), 41 deletions(-) diff --git a/backend/crates/common/src/graphql_api/types.rs b/backend/crates/common/src/graphql_api/types.rs index 12b17eb..c9e2396 100644 --- a/backend/crates/common/src/graphql_api/types.rs +++ b/backend/crates/common/src/graphql_api/types.rs @@ -7,6 +7,7 @@ use async_graphql::*; use diesel::deserialize::FromSqlRow; use serde::{Deserialize, Serialize}; +use crate::prelude::IndexerVersion; use crate::store::models::{self}; type HexBytesWith0xPrefix = String; @@ -266,6 +267,7 @@ pub struct Indexer { pub id: String, pub name: Option, pub address: Option, + pub version: Option, /// The number of tokens allocated to the indexer, if known. pub allocated_tokens: Option, } @@ -284,6 +286,7 @@ impl From for Indexer { panic!("Indexer has neither name nor address"); }, name: indexer.name, + version: None, // TODO address, allocated_tokens: None, // TODO: we don't store this in the db yet } diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs index 0ddefa5..e0fd01b 100644 --- a/backend/crates/common/src/indexer/mod.rs +++ b/backend/crates/common/src/indexer/mod.rs @@ -1,10 +1,11 @@ mod interceptor; mod real_indexer; +use std::borrow::Cow; +use std::collections::HashMap; use std::fmt::Debug; use std::hash::Hash; use std::sync::Arc; -use std::{borrow::Cow, collections::HashMap}; use anyhow::anyhow; use async_trait::async_trait; diff --git a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql index da9e42a..600401f 100644 --- a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql +++ b/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql @@ -7,6 +7,8 @@ query subgraphDeployments($first: Int!, $skip: Int!) { orderDirection: desc ) { ipfsHash + id + manifest signalAmount indexerAllocations( # Only the 5 indexers with the largest allocations, otherwise diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index 8d3de14..6fd30a5 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -12,7 +12,7 @@ use crate::graphql_api::types::BlockRangeInput; use crate::indexer::Indexer; use crate::prelude::{BlockPointer, IndexerVersion}; use crate::store::models::{ - self, IndexerRow, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, + self, Indexer as IndexerModel, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, }; use crate::store::schema::{self, live_pois}; @@ -320,7 +320,7 @@ fn get_indexer_id( ) -> anyhow::Result { use schema::indexers; - let existing_indexer: Option = indexers::table + let existing_indexer: Option = indexers::table .filter(indexers::name.is_not_distinct_from(&name)) .filter(indexers::address.is_not_distinct_from(address)) .get_result(conn) diff --git a/backend/crates/common/src/store/mod.rs b/backend/crates/common/src/store/mod.rs index fb11aed..f4cac57 100644 --- a/backend/crates/common/src/store/mod.rs +++ b/backend/crates/common/src/store/mod.rs @@ -22,7 +22,7 @@ use self::models::{QueriedSgDeployment, WritablePoi}; use crate::graphql_api::types::{BlockRangeInput, IndexersQuery, Network, SgDeploymentsQuery}; use crate::indexer::Indexer; use crate::prelude::IndexerVersion; -use crate::store::models::{IndexerRow, Poi}; +use crate::store::models::{Indexer as IndexerModel, Poi}; #[cfg(test)] mod tests; @@ -167,7 +167,7 @@ impl Store { query = query.limit(limit.into()); } - let rows = query.load::(&mut self.conn()?)?; + let rows = query.load::(&mut self.conn()?)?; Ok(rows.into_iter().map(Into::into).collect()) } diff --git a/backend/crates/common/src/store/models.rs b/backend/crates/common/src/store/models.rs index aa486f1..224fd4d 100644 --- a/backend/crates/common/src/store/models.rs +++ b/backend/crates/common/src/store/models.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use types::BlockPointer; use super::schema::*; -use crate::types; +use crate::types::{self, IndexerId}; pub type IntId = i32; pub type BigIntId = i64; @@ -23,7 +23,7 @@ pub struct Poi { #[serde(skip)] pub created_at: NaiveDateTime, pub sg_deployment: SgDeployment, - pub indexer: IndexerRow, + pub indexer: Indexer, pub block: Block, } @@ -82,43 +82,22 @@ pub struct NewBlock { pub hash: Vec, } -#[derive(Debug, Queryable)] +#[derive(Debug, Queryable, Serialize)] pub struct Indexer { pub id: IntId, pub name: Option, pub address: Option>, + #[serde(skip)] pub created_at: NaiveDateTime, } -impl From for Indexer { - fn from(row: IndexerRow) -> Self { - Self { - id: row.id, - name: row.name, - address: row.address, - created_at: row.created_at, - } +impl IndexerId for Indexer { + fn address(&self) -> Option<&[u8]> { + self.address.as_deref() } -} - -#[derive(Debug, Queryable, Serialize)] -pub struct IndexerRow { - pub id: IntId, - pub name: Option, - pub address: Option>, - #[serde(skip)] - pub created_at: NaiveDateTime, -} -impl IndexerRow { - pub fn indexer_id(&self) -> String { - if let Some(address) = &self.address { - hex::encode(address) - } else { - self.name - .clone() - .expect("indexer has neither address nor name; this is a bug") - } + fn name(&self) -> Option> { + self.name.as_ref().map(Cow::Borrowed) } } diff --git a/backend/crates/common/src/test_utils/mocks.rs b/backend/crates/common/src/test_utils/mocks.rs index f21592f..aa12f99 100644 --- a/backend/crates/common/src/test_utils/mocks.rs +++ b/backend/crates/common/src/test_utils/mocks.rs @@ -1,4 +1,5 @@ -use std::{borrow::Cow, sync::Arc}; +use std::borrow::Cow; +use std::sync::Arc; use anyhow::anyhow; use async_trait::async_trait; diff --git a/backend/crates/common/src/types.rs b/backend/crates/common/src/types.rs index 518fb18..b5e044b 100644 --- a/backend/crates/common/src/types.rs +++ b/backend/crates/common/src/types.rs @@ -3,12 +3,13 @@ use std::fmt; use std::ops::Deref; use std::sync::Arc; +use async_graphql::SimpleObject; use serde::Serialize; use crate::indexer::Indexer; use crate::store::models::WritablePoi; -#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd, SimpleObject)] pub struct IndexerVersion { pub version: String, pub commit: String, diff --git a/backend/crates/cross-checker/src/bisect.rs b/backend/crates/cross-checker/src/bisect.rs index 755f670..edada1a 100644 --- a/backend/crates/cross-checker/src/bisect.rs +++ b/backend/crates/cross-checker/src/bisect.rs @@ -6,8 +6,8 @@ use graphix_common::graphql_api::types::{ DivergenceInvestigationRequest, DivergenceInvestigationStatus, PartialBlock, }; use graphix_common::prelude::{ - BlockPointer, DivergingBlock as DivergentBlock, Indexer, PoiRequest, ProofOfIndexing, - SubgraphDeployment, + BlockPointer, DivergingBlock as DivergentBlock, Indexer, IndexerId, PoiRequest, + ProofOfIndexing, SubgraphDeployment, }; use graphix_common::store::Store; use thiserror::Error; @@ -311,7 +311,7 @@ async fn handle_divergence_investigation_request_pair( debug!(req_uuid = req_uuid_str, poi1 = %poi1_s, poi2 = %poi2_s, "Fetching indexers"); let indexer1 = match indexers .iter() - .find(|indexer| indexer.id() == poi1.indexer.indexer_id()) + .find(|indexer| indexer.id() == poi1.indexer.id()) .cloned() .ok_or(DivergenceInvestigationError::IndexerNotFound { poi: poi1_s.to_string(), @@ -324,7 +324,7 @@ async fn handle_divergence_investigation_request_pair( }; let indexer2 = match indexers .iter() - .find(|indexer| indexer.id() == poi2.indexer.indexer_id()) + .find(|indexer| indexer.id() == poi2.indexer.id()) .cloned() .ok_or(DivergenceInvestigationError::IndexerNotFound { poi: poi2_s.to_string(), diff --git a/backend/crates/schema/graphql/api_schema.graphql b/backend/crates/schema/graphql/api_schema.graphql index de7cc19..2107be6 100644 --- a/backend/crates/schema/graphql/api_schema.graphql +++ b/backend/crates/schema/graphql/api_schema.graphql @@ -189,12 +189,18 @@ type Indexer { id: String! name: String address: String + version: IndexerVersion """ The number of tokens allocated to the indexer, if known. """ allocatedTokens: Int } +type IndexerVersion { + version: String! + commit: String! +} + """ A filter for indexers. """ diff --git a/ops/compose/grafana/data/grafana.db b/ops/compose/grafana/data/grafana.db index 83ebb52804c499b94c604c3bb398f90bb5b32006..72050aa875cc96be8849b7551e51219a1c5cee68 100644 GIT binary patch delta 137 zcmZp85Zv$}c!D(Jj)^kPj5{_abm=nQZho!X{#ut2h?#(x8Hibcm=%cGw!hY8U$BrV z@W}Sw^X$L*8E+|;B^X$L*8E Date: Mon, 11 Dec 2023 22:10:08 +0100 Subject: [PATCH 15/34] Add IndexerId trait, indexer_network_subgraph_entry --- .../2023-12-11-181933_new_columns/down.sql | 1 + .../2023-12-11-181933_new_columns/up.sql | 9 ++++++ backend/crates/common/src/config.rs | 3 +- backend/crates/common/src/indexer/mod.rs | 30 +++++++++++++++++- .../crates/common/src/store/diesel_queries.rs | 5 +-- backend/crates/common/src/store/models.rs | 14 +++----- backend/crates/common/src/types.rs | 26 +++------------ ops/compose/grafana/data/grafana.db | Bin 1372160 -> 1372160 bytes ops/compose/network.yml | 2 +- 9 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql create mode 100644 backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql diff --git a/backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql b/backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql new file mode 100644 index 0000000..291a2c5 --- /dev/null +++ b/backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql @@ -0,0 +1 @@ +DELETE TABLE indexer_network_subgraph_entry IF EXISTS; diff --git a/backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql b/backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql new file mode 100644 index 0000000..46421be --- /dev/null +++ b/backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql @@ -0,0 +1,9 @@ +CREATE TABLE indexer_network_subgraph_entry ( + indexer_id TEXT NOT NULL, + staked_tokens BIGINT NOT NULL, + allocated_tokens BIGINT NOT NULL, + locked_tokens BIGINT NOT NULL, + query_fees_collected BIGINT NOT NULL, + delegated_capacity BIGINT NOT NULL, + available_stake BIGINT NOT NULL +); diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index 80ca751..f69f92f 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -8,9 +8,8 @@ use serde::{Deserialize, Deserializer}; use tracing::{info, warn}; use crate::block_choice::BlockChoicePolicy; -use crate::indexer::{Indexer, IndexerInterceptor, RealIndexer}; +use crate::indexer::{Indexer, IndexerId, IndexerInterceptor, RealIndexer}; use crate::network_subgraph_client::NetworkSubgraphClient; -use crate::prelude::IndexerId; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs index e0fd01b..fb22da4 100644 --- a/backend/crates/common/src/indexer/mod.rs +++ b/backend/crates/common/src/indexer/mod.rs @@ -12,7 +12,7 @@ use async_trait::async_trait; pub use interceptor::IndexerInterceptor; pub use real_indexer::RealIndexer; -use crate::types::{self, IndexerId, IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; /// An indexer is a `graph-node` instance that may or may not also be a network /// participant. @@ -88,6 +88,24 @@ pub trait Indexer: Send + Sync + Debug { ) -> anyhow::Result; } +/// Graphix defines an indexer's ID as either its Ethereum address (if it has +/// one) or its name (if it doesn't have an address i.e. it's not a network +/// participant), strictly in this order. +pub trait IndexerId { + fn address(&self) -> Option<&[u8]>; + fn name(&self) -> Option>; + + fn id(&self) -> String { + if let Some(address) = self.address() { + format!("0x{}", hex::encode(address)) + } else if let Some(name) = self.name() { + name.to_string() + } else { + panic!("Indexer has neither name nor address") + } + } +} + impl IndexerId for T where T: Indexer, @@ -101,6 +119,16 @@ where } } +impl IndexerId for Arc { + fn address(&self) -> Option<&[u8]> { + Indexer::address(&**self) + } + + fn name(&self) -> Option> { + Indexer::name(&**self) + } +} + impl PartialEq for dyn Indexer { fn eq(&self, other: &Self) -> bool { self.id() == other.id() diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index 6fd30a5..31fe8ac 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -9,7 +9,7 @@ use tracing::info; use super::models::WritablePoi; use super::PoiLiveness; use crate::graphql_api::types::BlockRangeInput; -use crate::indexer::Indexer; +use crate::indexer::{Indexer, IndexerId}; use crate::prelude::{BlockPointer, IndexerVersion}; use crate::store::models::{ self, Indexer as IndexerModel, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, @@ -212,7 +212,8 @@ pub(super) fn write_pois( let new_pois: Vec<_> = poi_group .iter() .map(|poi| { - let indexer_id = get_indexer_id(conn, poi.indexer_name(), poi.indexer_address())?; + let indexer_id = + get_indexer_id(conn, poi.indexer_id().name(), poi.indexer_id().address())?; Ok(NewPoi { sg_deployment_id, diff --git a/backend/crates/common/src/store/models.rs b/backend/crates/common/src/store/models.rs index 224fd4d..010e5c5 100644 --- a/backend/crates/common/src/store/models.rs +++ b/backend/crates/common/src/store/models.rs @@ -10,7 +10,8 @@ use serde::{Deserialize, Serialize}; use types::BlockPointer; use super::schema::*; -use crate::types::{self, IndexerId}; +use crate::indexer::IndexerId; +use crate::types::{self}; pub type IntId = i32; pub type BigIntId = i64; @@ -33,12 +34,6 @@ impl Poi { } } -#[derive(Debug, Copy, Clone)] -pub enum IndexerRef<'a> { - Id(IntId), - Address(&'a [u8]), -} - #[derive(Insertable, Debug)] #[diesel(table_name = indexer_versions)] pub struct NewIndexerVersion { @@ -59,9 +54,10 @@ pub struct NewPoi { } pub trait WritablePoi { + type IndexerId: IndexerId; + fn deployment_cid(&self) -> &str; - fn indexer_name(&self) -> Option>; - fn indexer_address(&self) -> Option<&[u8]>; + fn indexer_id(&self) -> Self::IndexerId; fn block(&self) -> BlockPointer; fn proof_of_indexing(&self) -> &[u8]; } diff --git a/backend/crates/common/src/types.rs b/backend/crates/common/src/types.rs index b5e044b..30f77f4 100644 --- a/backend/crates/common/src/types.rs +++ b/backend/crates/common/src/types.rs @@ -1,4 +1,3 @@ -use std::borrow::Cow; use std::fmt; use std::ops::Deref; use std::sync::Arc; @@ -112,16 +111,14 @@ impl PartialEq for ProofOfIndexing { } impl WritablePoi for ProofOfIndexing { + type IndexerId = Arc; + fn deployment_cid(&self) -> &str { self.deployment.as_str() } - fn indexer_name(&self) -> Option> { - self.indexer.name() - } - - fn indexer_address(&self) -> Option<&[u8]> { - self.indexer.address().map(AsRef::as_ref) + fn indexer_id(&self) -> Self::IndexerId { + self.indexer.clone() } fn block(&self) -> BlockPointer { @@ -133,21 +130,6 @@ impl WritablePoi for ProofOfIndexing { } } -pub trait IndexerId { - fn address(&self) -> Option<&[u8]>; - fn name(&self) -> Option>; - - fn id(&self) -> String { - if let Some(address) = self.address() { - format!("0x{}", hex::encode(address)) - } else if let Some(name) = self.name() { - name.to_string() - } else { - panic!("Indexer has neither name nor address") - } - } -} - #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] pub struct DivergingBlock { pub block: BlockPointer, diff --git a/ops/compose/grafana/data/grafana.db b/ops/compose/grafana/data/grafana.db index 72050aa875cc96be8849b7551e51219a1c5cee68..7ba5b8d71cd2568973c9180f1f21a592e5d96f7a 100644 GIT binary patch delta 189 zcmZp85Zv$}c!D(J(TOt7j7K*nbm=nQZGNrW{#ut2h?#(x8Hibcm=%cGw!hY8U$BrV z^8fVS^Xz%74yongueV)b@8D;=yS?*1`&B=t@Xy;5^f;IqnW7k`r|NUeWQyWwGXNsa zHUq9U1MW5ho;CyCZ3cXQ{a7rlObn+p*7LbQSf2HK3J_Kf0``cknab-rjki{i+{R;Mwg7dK}D*Oo1n-r|NUeWb*pmX28*A zz}aTN)n>rmX28>Cz`M Date: Mon, 11 Dec 2023 22:10:31 +0100 Subject: [PATCH 16/34] Simplify API of `graphql_api` module --- backend/crates/common/src/graphql_api/mod.rs | 19 ++++++++++++++++++- .../crates/common/src/graphql_api/server.rs | 10 +--------- backend/crates/schema/build.rs | 6 ++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/backend/crates/common/src/graphql_api/mod.rs b/backend/crates/common/src/graphql_api/mod.rs index e63d76b..181d298 100644 --- a/backend/crates/common/src/graphql_api/mod.rs +++ b/backend/crates/common/src/graphql_api/mod.rs @@ -1,4 +1,21 @@ mod server; pub mod types; -pub use server::*; +use async_graphql::{EmptySubscription, Schema, SchemaBuilder}; + +use self::server::{MutationRoot, QueryRoot}; +use crate::store::Store; + +pub type ApiSchema = Schema; + +pub struct ApiSchemaContext { + pub store: Store, +} + +pub fn api_schema_builder() -> SchemaBuilder { + Schema::build(QueryRoot, MutationRoot, EmptySubscription) +} + +pub fn api_schema(ctx: ApiSchemaContext) -> ApiSchema { + api_schema_builder().data(ctx).finish() +} diff --git a/backend/crates/common/src/graphql_api/server.rs b/backend/crates/common/src/graphql_api/server.rs index 4e57deb..1922641 100644 --- a/backend/crates/common/src/graphql_api/server.rs +++ b/backend/crates/common/src/graphql_api/server.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use anyhow::Context as _; -use async_graphql::{Context, EmptySubscription, Object, Result, Schema}; +use async_graphql::{Context, Object, Result}; use super::types::*; use crate::store::models::QueriedSgDeployment; @@ -243,14 +243,6 @@ impl MutationRoot { } } -pub type ApiSchema = Schema; - pub struct ApiSchemaContext { pub store: Store, } - -pub fn api_schema(ctx: ApiSchemaContext) -> ApiSchema { - Schema::build(QueryRoot, MutationRoot, EmptySubscription) - .data(ctx) - .finish() -} diff --git a/backend/crates/schema/build.rs b/backend/crates/schema/build.rs index b218046..0283cf7 100644 --- a/backend/crates/schema/build.rs +++ b/backend/crates/schema/build.rs @@ -2,8 +2,7 @@ use std::env; use std::fs::File; use std::io::*; -use async_graphql::{EmptySubscription, Schema}; -use graphix_common::graphql_api::{MutationRoot, QueryRoot}; +use graphix_common::graphql_api::api_schema_builder; fn main() -> std::io::Result<()> { // We're only interested in re-generating the API schema if build @@ -11,13 +10,12 @@ fn main() -> std::io::Result<()> { // See . println!("cargo:rerun-if-changed=build.rs"); - let api_schema = Schema::build(QueryRoot, MutationRoot, EmptySubscription).finish(); let path = env::current_dir()?.join("graphql/api_schema.graphql"); let mut f = File::create(&path)?; f.write_all(b"# AUTOGENERATED. DO NOT MODIFY. ALL CHANGES WILL BE LOST.\n\n")?; - f.write_all(api_schema.sdl().as_bytes())?; + f.write_all(api_schema_builder().finish().sdl().as_bytes())?; println!("Updated: {}", path.display()); Ok(()) From 3f58d9deaa701089d1805ad34fa94c6cf6e8d67a Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 11:41:50 +0100 Subject: [PATCH 17/34] Update to Rust 1.75 --- Cargo.toml | 1 + rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2af26e4..2512a78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "backend/crates/*", #"frontend" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 469a750..de3b853 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.70.0" +channel = "1.75.0" targets = ["wasm32-unknown-unknown"] profile = "default" From 68dbb87fe65800005deb5e699db853415d2c54da Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 11:42:28 +0100 Subject: [PATCH 18/34] Delete frontend code --- Cargo.toml | 5 +- frontend/Cargo.toml | 24 -- frontend/build.rs | 32 -- frontend/graphql/queries/deployments.graphql | 3 - .../queries/launch_cross_check_report.graphql | 4 - .../queries/poi_cross_check_reports.graphql | 14 - .../queries/proofs_of_indexing.graphql | 12 - frontend/index.html | 20 -- frontend/src/components/mod.rs | 9 - frontend/src/components/navigation.rs | 40 --- .../src/components/navigation_menu_item.rs | 28 -- frontend/src/components/page.rs | 23 -- frontend/src/components/page_header.rs | 22 -- frontend/src/contexts/mod.rs | 3 - frontend/src/contexts/theme.rs | 106 ------ frontend/src/main.rs | 45 --- frontend/src/pages/mod.rs | 2 - frontend/src/pages/poi_explorer/deployment.rs | 311 ------------------ frontend/src/pages/poi_explorer/index.rs | 120 ------- frontend/src/pages/poi_explorer/mod.rs | 5 - frontend/src/pages/poi_reports/index.rs | 275 ---------------- frontend/src/pages/poi_reports/indexers.rs | 300 ----------------- frontend/src/pages/poi_reports/mod.rs | 5 - frontend/src/routes.rs | 58 ---- 24 files changed, 1 insertion(+), 1465 deletions(-) delete mode 100644 frontend/Cargo.toml delete mode 100644 frontend/build.rs delete mode 100644 frontend/graphql/queries/deployments.graphql delete mode 100644 frontend/graphql/queries/launch_cross_check_report.graphql delete mode 100644 frontend/graphql/queries/poi_cross_check_reports.graphql delete mode 100644 frontend/graphql/queries/proofs_of_indexing.graphql delete mode 100644 frontend/index.html delete mode 100644 frontend/src/components/mod.rs delete mode 100644 frontend/src/components/navigation.rs delete mode 100644 frontend/src/components/navigation_menu_item.rs delete mode 100644 frontend/src/components/page.rs delete mode 100644 frontend/src/components/page_header.rs delete mode 100644 frontend/src/contexts/mod.rs delete mode 100644 frontend/src/contexts/theme.rs delete mode 100644 frontend/src/main.rs delete mode 100644 frontend/src/pages/mod.rs delete mode 100644 frontend/src/pages/poi_explorer/deployment.rs delete mode 100644 frontend/src/pages/poi_explorer/index.rs delete mode 100644 frontend/src/pages/poi_explorer/mod.rs delete mode 100644 frontend/src/pages/poi_reports/index.rs delete mode 100644 frontend/src/pages/poi_reports/indexers.rs delete mode 100644 frontend/src/pages/poi_reports/mod.rs delete mode 100644 frontend/src/routes.rs diff --git a/Cargo.toml b/Cargo.toml index 2512a78..45ddcc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,3 @@ [workspace] resolver = "2" -members = [ - "backend/crates/*", - #"frontend" -] +members = ["backend/crates/*"] diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml deleted file mode 100644 index 8763f93..0000000 --- a/frontend/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "graphix-frontend" -version = "0.1.0" -edition = "2021" - -[dependencies] -anyhow = "1.0.53" -css-colors = "1.0.1" -gloo = "0.6.0" -graphql_client = "0.10.0" -log = "0.4.14" -once_cell = "1.9.0" -reqwasm = "0.4.0" -serde = "1.0.136" -serde_json = "1.0.78" -stylist = { version = "0.10.0", features = ["yew_integration"] } -wasm-bindgen-futures = "0.4.29" -wasm-logger = "0.2.0" -yew = "0.19.3" -yew-router = "0.16.0" - -[build-dependencies] -async-graphql = "3.0.22" -graphix-common = { path = "../backend/crates/common" } diff --git a/frontend/build.rs b/frontend/build.rs deleted file mode 100644 index a67b96e..0000000 --- a/frontend/build.rs +++ /dev/null @@ -1,32 +0,0 @@ -use async_graphql::*; -use graphix_common::api_types::QueryRoot; -use std::env; -use std::fs::File; -use std::io::*; - -struct Query; - -#[Object] -impl Query { - async fn howdy(&self) -> &'static str { - "partner" - } -} - -fn main() -> std::io::Result<()> { - // We're only interested in re-generating the API schema if build - // dependencies change or the build script itself does. - // See . - println!("cargo:rerun-if-changed=build.rs"); - - let api_schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription).finish(); - let path = env::current_dir()?.join("graphql/api_schema.graphql"); - - let mut f = File::create(&path)?; - - f.write_all(b"# AUTOGENERATED. DO NOT MODIFY. ALL CHANGES WILL BE LOST.\n\n")?; - f.write_all(api_schema.sdl().as_bytes())?; - - println!("Updated: {}", path.display()); - Ok(()) -} diff --git a/frontend/graphql/queries/deployments.graphql b/frontend/graphql/queries/deployments.graphql deleted file mode 100644 index dc5e461..0000000 --- a/frontend/graphql/queries/deployments.graphql +++ /dev/null @@ -1,3 +0,0 @@ -query Deployments { - deployments -} diff --git a/frontend/graphql/queries/launch_cross_check_report.graphql b/frontend/graphql/queries/launch_cross_check_report.graphql deleted file mode 100644 index 93f3945..0000000 --- a/frontend/graphql/queries/launch_cross_check_report.graphql +++ /dev/null @@ -1,4 +0,0 @@ -mutation LaunchCrossCheckReport() { - # FIXME, TODO - deployments -} diff --git a/frontend/graphql/queries/poi_cross_check_reports.graphql b/frontend/graphql/queries/poi_cross_check_reports.graphql deleted file mode 100644 index b74de43..0000000 --- a/frontend/graphql/queries/poi_cross_check_reports.graphql +++ /dev/null @@ -1,14 +0,0 @@ -query POICrossCheckReports($request: POICrossCheckReportRequest!) { - poiCrossCheckReports(request: $request) { - timestamp - indexer1 - indexer2 - deployment - block { - number - hash - } - proofOfIndexing1 - proofOfIndexing2 - } -} diff --git a/frontend/graphql/queries/proofs_of_indexing.graphql b/frontend/graphql/queries/proofs_of_indexing.graphql deleted file mode 100644 index d31a688..0000000 --- a/frontend/graphql/queries/proofs_of_indexing.graphql +++ /dev/null @@ -1,12 +0,0 @@ -query ProofsOfIndexing($request: ProofOfIndexingRequest!) { - proofsOfIndexing(request: $request) { - timestamp - deployment - indexer - block { - number - hash - } - proofOfIndexing - } -} diff --git a/frontend/index.html b/frontend/index.html deleted file mode 100644 index e567cb1..0000000 --- a/frontend/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - Graphix - - - - - - - - - - diff --git a/frontend/src/components/mod.rs b/frontend/src/components/mod.rs deleted file mode 100644 index 99a67a6..0000000 --- a/frontend/src/components/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod navigation; -mod navigation_menu_item; -mod page; -mod page_header; - -pub use self::navigation::*; -pub use self::navigation_menu_item::*; -pub use self::page::*; -pub use self::page_header::*; diff --git a/frontend/src/components/navigation.rs b/frontend/src/components/navigation.rs deleted file mode 100644 index a29ad9f..0000000 --- a/frontend/src/components/navigation.rs +++ /dev/null @@ -1,40 +0,0 @@ -use stylist::yew::*; -use yew::prelude::*; -use yew_router::prelude::*; - -use super::NavigationMenuItem; -use crate::contexts::use_theme; -use crate::routes::*; - -#[styled_component(Navigation)] -pub fn navigation() -> Html { - let _theme = use_theme(); - - html! { -
- - - - -
- } -} diff --git a/frontend/src/components/navigation_menu_item.rs b/frontend/src/components/navigation_menu_item.rs deleted file mode 100644 index 57b271a..0000000 --- a/frontend/src/components/navigation_menu_item.rs +++ /dev/null @@ -1,28 +0,0 @@ -use stylist::yew::*; -use yew::prelude::*; - -#[derive(Clone, Properties, PartialEq)] -pub struct NavigationMenuItemProps { - pub name: String, - pub fontawesome_icon: String, - pub is_active: bool, -} - -#[styled_component(NavigationMenuItem)] -pub fn navigation_menu_item(props: &NavigationMenuItemProps) -> Html { - let fontawesome_attrs = format!("fa mr-4 fa-{}", props.fontawesome_icon); - let item_attrs = if props.is_active { - "mb-2 bg-gray-800 rounded shadow" - } else { - "mb-2 rounded hover:shadow hover:bg-gray-800" - }; - - html! { -
  • - - - {props.name.as_str()} - -
  • - } -} diff --git a/frontend/src/components/page.rs b/frontend/src/components/page.rs deleted file mode 100644 index 9f5b61a..0000000 --- a/frontend/src/components/page.rs +++ /dev/null @@ -1,23 +0,0 @@ -use stylist::yew::*; -use yew::prelude::*; - -use crate::components::PageHeader; - -#[derive(Properties, PartialEq)] -pub struct PageProps { - pub title: String, - #[prop_or_default] - pub children: Children, -} - -#[styled_component(Page)] -pub fn page(props: &PageProps) -> Html { - html! { -
    - - <> - { for props.children.iter() } - -
    - } -} diff --git a/frontend/src/components/page_header.rs b/frontend/src/components/page_header.rs deleted file mode 100644 index dae37de..0000000 --- a/frontend/src/components/page_header.rs +++ /dev/null @@ -1,22 +0,0 @@ -use stylist::yew::*; -use yew::prelude::*; - -#[derive(Properties, PartialEq)] -pub struct PageHeaderProps { - pub title: String, -} - -#[styled_component(PageHeader)] -pub fn page_header(props: &PageHeaderProps) -> Html { - html! { -
    -

    {&props.title}

    -
    - } -} diff --git a/frontend/src/contexts/mod.rs b/frontend/src/contexts/mod.rs deleted file mode 100644 index 687df2a..0000000 --- a/frontend/src/contexts/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod theme; - -pub use theme::*; diff --git a/frontend/src/contexts/theme.rs b/frontend/src/contexts/theme.rs deleted file mode 100644 index 283f7dc..0000000 --- a/frontend/src/contexts/theme.rs +++ /dev/null @@ -1,106 +0,0 @@ -use std::ops::Deref; - -use css_colors::{rgba, Color, Ratio}; -use stylist::yew::styled_component; -use yew::html::ImplicitClone; -use yew::prelude::*; - -#[derive(Debug, Clone, PartialEq)] -pub struct ThemeColors { - pub background: String, - pub text: String, - pub one: String, - pub two: String, - pub three: String, - pub four: String, - pub five: String, - pub link: String, - pub link_hover: String, - pub ok: String, - pub error: String, -} - -#[derive(Debug, Clone, PartialEq)] -pub struct Theme { - pub colors: ThemeColors, -} - -impl Default for Theme { - fn default() -> Self { - Self { - colors: ThemeColors { - background: "white".into(), - text: "black".into(), - one: "#1f2041ff".into(), - two: "#4b3f72ff".into(), - three: "#ffc857ff".into(), - four: "#119da4ff".into(), - five: "#19647eff".into(), - link: "black".into(), - link_hover: "#19647eff".into(), - ok: rgba(0, 255, 0, 1.0) - .lighten(Ratio::from_percentage(20)) - .to_css(), - error: rgba(255, 0, 0, 1.0) - .lighten(Ratio::from_percentage(20)) - .to_css(), - }, - } - } -} - -impl ImplicitClone for Theme {} - -#[derive(Debug, Clone)] -pub struct ThemeContext { - inner: UseStateHandle, -} - -impl ThemeContext { - pub fn new(inner: UseStateHandle) -> Self { - Self { inner } - } - - pub fn _set(&self, theme: Theme) { - self.inner.set(theme) - } - - pub fn _get(&self) -> Theme { - (*self.inner).clone() - } -} - -impl Deref for ThemeContext { - type Target = Theme; - - fn deref(&self) -> &Self::Target { - &*self.inner - } -} - -impl PartialEq for ThemeContext { - fn eq(&self, rhs: &Self) -> bool { - *self.inner == *rhs.inner - } -} - -#[derive(Debug, PartialEq, Properties)] -pub struct ThemeProviderProps { - pub children: Children, -} - -#[styled_component(ThemeProvider)] -pub fn theme_provider(props: &ThemeProviderProps) -> Html { - let theme = use_state(Theme::default); - let theme_ctx = ThemeContext::new(theme); - - html! { - context={theme_ctx}> - {props.children.clone()} - > - } -} - -pub fn use_theme() -> ThemeContext { - use_context::().unwrap() -} diff --git a/frontend/src/main.rs b/frontend/src/main.rs deleted file mode 100644 index 90d4ff3..0000000 --- a/frontend/src/main.rs +++ /dev/null @@ -1,45 +0,0 @@ -pub mod components; -mod contexts; -pub mod pages; -mod routes; - -use stylist::yew::*; -use yew::prelude::*; -use yew_router::prelude::*; - -use components::*; -use contexts::*; -use routes::*; - -#[styled_component(App)] -fn app() -> Html { - html! { - -
    -
    - -
    - render={Switch::render(switch)} /> -
    -
    -
    -
    - } -} - -#[styled_component(Root)] -fn root() -> Html { - html! { - - - - } -} - -fn main() { - wasm_logger::init(wasm_logger::Config::default()); - - log::info!("Starting up"); - - yew::start_app::(); -} diff --git a/frontend/src/pages/mod.rs b/frontend/src/pages/mod.rs deleted file mode 100644 index 33e49b5..0000000 --- a/frontend/src/pages/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod poi_explorer; -pub mod poi_reports; diff --git a/frontend/src/pages/poi_explorer/deployment.rs b/frontend/src/pages/poi_explorer/deployment.rs deleted file mode 100644 index a847684..0000000 --- a/frontend/src/pages/poi_explorer/deployment.rs +++ /dev/null @@ -1,311 +0,0 @@ -use std::collections::BTreeMap; - -use css_colors::{rgba, Color, Ratio, RGBA}; -use gloo::timers::callback::Interval; -use graphql_client::{GraphQLQuery, Response as GraphQLResponse}; -use log::warn; -use reqwasm::http::*; -use stylist::css; -use wasm_bindgen_futures::spawn_local; -use yew::{html::Scope, prelude::*}; - -#[derive(GraphQLQuery)] -#[graphql( - schema_path = "./graphql/api_schema.graphql", - query_path = "./graphql/queries/proofs_of_indexing.graphql", - response_derives = "Debug" -)] -struct ProofsOfIndexing; - -type POI = proofs_of_indexing::ProofsOfIndexingProofsOfIndexing; -type POISGroupedByBlock = BTreeMap>; - -async fn fetch_proofs_of_indexing(deployment: String) -> Result { - let query = ProofsOfIndexing::build_query(proofs_of_indexing::Variables { - request: proofs_of_indexing::ProofOfIndexingRequest { - deployments: vec![deployment.clone()], - blockRange: None, - limit: None, - }, - }); - let query = serde_json::json!(query); - - let request = Request::new("http://localhost:3030/graphql") - .body(query.to_string()) - .header("content-type", "application/json") - .method(Method::POST) - .mode(RequestMode::Cors); - - let response: GraphQLResponse = - request.send().await?.json().await?; - - let pois = match (response.data, response.errors) { - (Some(data), _) => data.proofs_of_indexing, - (_, Some(errors)) => { - warn!( - "Errors fetching proofs of indexing for deployment {}: {:?}", - deployment, errors - ); - vec![] - } - (_, _) => vec![], - }; - - // Group POIs by block number (using a BTreeMap to order the numbers) - let mut grouped_by_block = POISGroupedByBlock::new(); - - for poi in pois { - grouped_by_block - .entry(poi.block.number) - .or_insert_with(Vec::new) - .push(poi); - } - - // For each block number, sort POIs by indexer - for (_, pois) in grouped_by_block.iter_mut() { - pois.sort_by(|a, b| a.indexer.cmp(&b.indexer)); - } - - Ok(grouped_by_block) -} - -fn poll_proofs_of_indexing(deployment: String, link: Scope) { - spawn_local(async move { - let pois = match fetch_proofs_of_indexing(deployment).await { - Ok(pois) => pois, - Err(error) => { - warn!("Failed to fetch proofs of indexing: {}", error); - return; - } - }; - - let layout = Layout::from(pois); - - link.send_message(Msg::Update(layout)); - }); -} - -#[derive(Debug)] -pub enum Cell { - POI(POI, RGBA), - Placeholder, -} - -impl Cell { - fn render(&self) -> Html { - match self { - Cell::POI(poi, color) => html! { - - {&poi.proof_of_indexing[..7]} - - }, - Cell::Placeholder => html! { - {"-"} - }, - } - } -} - -#[derive(Debug)] -pub enum Row { - Block(i64, Vec), - Placeholder, -} - -impl Row { - fn render(&self) -> Html { - match self { - Row::Block(number, cells) => html! { - - {number} - { - for cells.iter().map(Cell::render) - } - - }, - Row::Placeholder => html! { - - {"..."} - - }, - } - } -} - -#[derive(Debug, Default)] -pub struct Layout { - pub indexers: Vec, - pub rows: Vec, -} - -impl Layout { - fn from(data: POISGroupedByBlock) -> Self { - let mut rows = vec![]; - - // Assign a column to each indexer - let mut indexer_columns = BTreeMap::new(); - let mut indexers = vec![]; - for group in data.values() { - for poi in group { - match indexer_columns.get(&poi.indexer) { - Some(_) => {} - None => { - indexer_columns.insert(poi.indexer.clone(), indexers.len()); - indexers.push(poi.indexer.clone()); - } - } - } - } - - let mut groups = data.into_iter().rev().peekable(); - while let Some((block_number, group)) = groups.next() { - // Create a new row for the block number - let mut cells = vec![]; - let mut color = rgba(17, 157, 164, 1.0).lighten(Ratio::from_percentage(40)); - let mut last_poi = None; - - // Add indexer POIs or placeholders - for poi in group { - // Identify the indexer column - let indexer_column = indexer_columns.get(&poi.indexer).unwrap(); - - // If the indexer is supposed to be at a later column, insert placeholders - // for every column (indexer) for which we don't have data - let current_column = cells.len(); - if *indexer_column > current_column { - for _ in current_column..*indexer_column { - cells.push(Cell::Placeholder); - } - } - - // Use a different color if the POI is different from the one in the previous column - if last_poi.is_none() || poi.proof_of_indexing.ne(last_poi.as_ref().unwrap()) { - last_poi = Some(poi.proof_of_indexing.clone()); - color = color.darken(Ratio::from_percentage(15)); - } - - cells.push(Cell::POI(poi, color)); - } - - // Add the row to the layout - rows.push(Row::Block(block_number, cells)); - - // If the next block number is not one block before, add a placeholder - if let Some((next_block_number, _)) = groups.peek() { - if next_block_number < &(block_number - 1) { - rows.push(Row::Placeholder); - } - } - } - - Self { indexers, rows } - } - - fn render(&self) -> Html { - html! { -
    - - - - - { - for self.indexers.iter().map(|i| html! { - - }) - } - <> - - - - - { - for self.rows.iter().map(Row::render) - } - -
    {"Block"}{i}
    -
    - } - } -} - -#[derive(Properties, PartialEq)] -pub struct ViewProps { - pub id: String, -} - -pub struct View { - layout: Layout, - _proofs_of_indexing_interval: Interval, -} - -pub enum Msg { - Update(Layout), -} - -impl Component for View { - type Message = Msg; - type Properties = ViewProps; - - fn create(ctx: &Context) -> Self { - let id = ctx.props().id.clone(); - let link = ctx.link().clone(); - - // Fetch deployments immediately - poll_proofs_of_indexing(id.clone(), link.clone()); - - Self { - layout: Layout::default(), - - // Refetch deployments every 5s - _proofs_of_indexing_interval: Interval::new(5000, move || { - poll_proofs_of_indexing(id.clone(), link.clone()) - }), - } - } - - fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { - match msg { - Msg::Update(layout) => { - self.layout = layout; - } - } - true - } - - fn view(&self, _ctx: &Context) -> Html { - html! { -
    - {self.layout.render()} -
    - } - } -} diff --git a/frontend/src/pages/poi_explorer/index.rs b/frontend/src/pages/poi_explorer/index.rs deleted file mode 100644 index edfde78..0000000 --- a/frontend/src/pages/poi_explorer/index.rs +++ /dev/null @@ -1,120 +0,0 @@ -use anyhow; -use gloo::timers::callback::Interval; -use graphql_client::{GraphQLQuery, Response as GraphQLResponse}; -use log::warn; -use reqwasm::http::*; -use stylist::yew::*; -use wasm_bindgen_futures::spawn_local; -use yew::{html::Scope, prelude::*}; -use yew_router::prelude::*; - -use crate::routes::*; - -#[derive(GraphQLQuery)] -#[graphql( - schema_path = "./graphql/api_schema.graphql", - query_path = "./graphql/queries/deployments.graphql", - response_derives = "Debug" -)] -struct Deployments; - -async fn fetch_deployments() -> Result, anyhow::Error> { - let query = Deployments::build_query(deployments::Variables {}); - let query = serde_json::json!(query); - - let request = Request::new("http://localhost:3030/graphql") - .body(query.to_string()) - .header("content-type", "application/json") - .method(Method::POST) - .mode(RequestMode::Cors); - - let response: GraphQLResponse = request.send().await?.json().await?; - - match (response.data, response.errors) { - (Some(data), _) => Ok(data.deployments), - (_, Some(errors)) => { - warn!("Errors fetching deployments: {:?}", errors); - Ok(vec![]) - } - (_, _) => unreachable!(), - } -} - -fn poll_deployments(link: Scope) { - spawn_local(async move { - match fetch_deployments().await { - Ok(deployments) => link.send_message(Msg::UpdateDeployments(deployments)), - Err(error) => warn!("Failed to fetch deployments: {}", error), - } - }); -} - -#[derive(Properties, PartialEq)] -pub struct DeploymentLinkProps { - pub deployment: String, -} - -#[styled_component(DeploymentLink)] -pub fn deployment_link(props: &DeploymentLinkProps) -> Html { - html! { - to={Route::POIExplorerDeployment { id: props.deployment.clone() }}> - {&props.deployment} - > - } -} - -pub struct View { - deployments: Vec, - _deployments_interval: Interval, -} - -pub enum Msg { - UpdateDeployments(Vec), -} - -impl Component for View { - type Message = Msg; - type Properties = (); - - fn create(ctx: &Context) -> Self { - let link = ctx.link().clone(); - - // Fetch deployments immediately - poll_deployments(link.clone()); - - Self { - deployments: vec![], - - // Refetch deployments every 5s - _deployments_interval: Interval::new(5000, move || poll_deployments(link.clone())), - } - } - - fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { - match msg { - Msg::UpdateDeployments(deployments) => { - self.deployments = deployments; - } - } - true - } - - fn view(&self, _ctx: &Context) -> Html { - html! { - <> -

    {"Deployments"}

    -
      - { - for self.deployments.iter().map(|d| { - html!{ -
    • - -
    • - } - }) - } -
    - - } - } -} diff --git a/frontend/src/pages/poi_explorer/mod.rs b/frontend/src/pages/poi_explorer/mod.rs deleted file mode 100644 index b8c5817..0000000 --- a/frontend/src/pages/poi_explorer/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod index; -pub use index::View as Index; - -mod deployment; -pub use deployment::View as Deployment; diff --git a/frontend/src/pages/poi_reports/index.rs b/frontend/src/pages/poi_reports/index.rs deleted file mode 100644 index 994aa3a..0000000 --- a/frontend/src/pages/poi_reports/index.rs +++ /dev/null @@ -1,275 +0,0 @@ -use std::collections::{BTreeMap, BTreeSet}; - -use gloo::timers::callback::Interval; -use graphql_client::{GraphQLQuery, Response as GraphQLResponse}; -use log::warn; -use reqwasm::http::{Method, Request, RequestMode}; -use stylist::css; -use wasm_bindgen_futures::spawn_local; -use yew::{html::Scope, prelude::*}; -use yew_router::prelude::*; - -use crate::contexts::{Theme, ThemeContext}; -use crate::routes::Route; - -#[derive(GraphQLQuery)] -#[graphql( - schema_path = "./graphql/api_schema.graphql", - query_path = "./graphql/queries/poi_cross_check_reports.graphql", - response_derives = "Debug, Clone" -)] -struct POICrossCheckReports; - -type POICrossCheckReport = poi_cross_check_reports::PoiCrossCheckReportsPoiCrossCheckReports; - -async fn fetch_cross_check_reports() -> Result, anyhow::Error> { - let query = POICrossCheckReports::build_query(poi_cross_check_reports::Variables { - request: poi_cross_check_reports::POICrossCheckReportRequest { - deployments: vec![], - indexer1: None, - indexer2: None, - }, - }); - let query = serde_json::json!(query); - - let request = Request::new("http://localhost:3030/graphql") - .body(query.to_string()) - .header("content-type", "application/json") - .method(Method::POST) - .mode(RequestMode::Cors); - - let response: GraphQLResponse = - request.send().await?.json().await?; - - let reports = match (response.data, response.errors) { - (Some(data), _) => data.poi_cross_check_reports, - (_, Some(errors)) => { - warn!("Errors fetching POI cross-check reports: {:?}", errors); - vec![] - } - (_, _) => vec![], - }; - - Ok(reports) -} - -fn poll_cross_check_reports(link: Scope) { - spawn_local(async move { - let reports = match fetch_cross_check_reports().await { - Ok(reports) => reports, - Err(error) => { - warn!("Failed to fetch POI cross-check reports: {}", error); - return; - } - }; - - let layout = Layout::from(reports); - - link.send_message(Msg::Update(layout)); - }); -} - -#[derive(Clone, Debug, Default)] -pub struct Cell { - pub reports: Vec, -} - -impl Cell { - fn render(&self, theme: &Theme) -> Html { - match self.reports.is_empty() { - true => html! { {"-"} }, - false => { - let conflicts = self - .reports - .iter() - .filter(|report| report.proof_of_indexing1.ne(&report.proof_of_indexing2)) - .collect::>(); - - match conflicts.is_empty() { - true => html! { - {"\u{00a0}"} - }, - false => { - let conflict = conflicts.iter().next().unwrap(); - - html! { - - to={Route::POIReportsForIndexers { indexer1: conflict.indexer1.clone(), indexer2: conflict.indexer2.clone() }}> - { - format!( - "{} {}", - conflicts.len(), - match conflicts.len() { - 1 => "conflict", - _ => "conflicts" - } - ) - } - > - - } - } - } - } - } - } -} - -#[derive(Clone, Debug)] -pub struct Row { - pub indexer: String, - pub cells: Vec, -} - -impl Row { - fn new(indexer: String, columns: usize) -> Self { - let mut cells = vec![]; - cells.resize(columns, Default::default()); - Self { indexer, cells } - } - - fn render(&self, theme: &Theme) -> Html { - html! { - - {&self.indexer} - { - for self.cells.iter().map(|cell| cell.render(theme)) - } - - } - } -} - -#[derive(Debug, Default)] -pub struct Layout { - pub indexer_indices: BTreeMap, - pub rows: Vec, -} - -impl From> for Layout { - fn from(reports: Vec) -> Self { - let indexer_indices = reports - .iter() - .map(|report| report.indexer1.clone()) - .chain(reports.iter().map(|report| report.indexer2.clone())) - .collect::>() - .into_iter() - .enumerate() - .map(|(i, indexer)| (indexer, i)) - .collect::>(); - - let mut rows = vec![]; - for indexer in indexer_indices.keys() { - rows.push(Row::new(indexer.clone(), indexer_indices.len())); - } - - for report in reports { - let indexer1_index = indexer_indices.get(&report.indexer1).unwrap(); - let indexer2_index = indexer_indices.get(&report.indexer2).unwrap(); - - rows[*indexer1_index].cells[*indexer2_index] - .reports - .push(report.clone()); - rows[*indexer2_index].cells[*indexer1_index] - .reports - .push(report); - } - - Self { - indexer_indices, - rows, - } - } -} - -impl Layout { - fn render(&self, theme: &Theme) -> Html { - html! { -
    - - - - { - for self.indexer_indices.keys().map(|indexer| { - html! { - - } - }) - } - - - { - for self.rows.iter().map(|row| row.render(theme)) - } - -
    {&indexer}
    -
    - } - } -} - -pub struct View { - layout: Layout, - _poll_interval: Interval, -} - -pub enum Msg { - Update(Layout), -} - -impl Component for View { - type Message = Msg; - type Properties = (); - - fn create(ctx: &Context) -> Self { - let link = ctx.link().clone(); - - poll_cross_check_reports(link.clone()); - - Self { - layout: Layout::default(), - - // Refetch reports every few seconds - _poll_interval: Interval::new(5000, move || poll_cross_check_reports(link.clone())), - } - } - - fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { - match msg { - Msg::Update(layout) => { - self.layout = layout; - } - } - true - } - - fn view(&self, ctx: &Context) -> Html { - let (theme, _) = ctx - .link() - .context::(Callback::noop()) - .expect("theme context to be set"); - - html! { -
    - {self.layout.render(&theme)} -
    - } - } -} diff --git a/frontend/src/pages/poi_reports/indexers.rs b/frontend/src/pages/poi_reports/indexers.rs deleted file mode 100644 index 5a75dd6..0000000 --- a/frontend/src/pages/poi_reports/indexers.rs +++ /dev/null @@ -1,300 +0,0 @@ -use std::collections::BTreeMap; - -use gloo::timers::callback::Interval; -use graphql_client::{GraphQLQuery, Response as GraphQLResponse}; -use log::warn; -use reqwasm::http::{Method, Request, RequestMode}; -use stylist::css; -use wasm_bindgen_futures::spawn_local; -use yew::{html::Scope, prelude::*}; -use yew_router::prelude::*; - -use crate::contexts::{Theme, ThemeContext}; -use crate::routes::Route; - -#[derive(GraphQLQuery)] -#[graphql( - schema_path = "./graphql/api_schema.graphql", - query_path = "./graphql/queries/poi_cross_check_reports.graphql", - response_derives = "Debug, Clone" -)] -struct POICrossCheckReports; - -type POICrossCheckReport = poi_cross_check_reports::PoiCrossCheckReportsPoiCrossCheckReports; - -async fn fetch_indexer_cross_check_reports( - indexer1: String, - indexer2: String, -) -> Result, anyhow::Error> { - let query = POICrossCheckReports::build_query(poi_cross_check_reports::Variables { - request: poi_cross_check_reports::POICrossCheckReportRequest { - deployments: vec![], - indexer1: Some(indexer1), - indexer2: Some(indexer2), - }, - }); - let query = serde_json::json!(query); - - let request = Request::new("http://localhost:3030/graphql") - .body(query.to_string()) - .header("content-type", "application/json") - .method(Method::POST) - .mode(RequestMode::Cors); - - let response: GraphQLResponse = - request.send().await?.json().await?; - - let reports = match (response.data, response.errors) { - (Some(data), _) => data.poi_cross_check_reports, - (_, Some(errors)) => { - warn!("Errors fetching POI cross-check reports: {:?}", errors); - vec![] - } - (_, _) => vec![], - }; - - Ok(reports) -} - -fn poll_indexer_cross_check_reports(indexer1: String, indexer2: String, link: Scope) { - spawn_local(async move { - let reports = match fetch_indexer_cross_check_reports(indexer1, indexer2).await { - Ok(reports) => reports, - Err(error) => { - warn!("Failed to fetch POI cross-check reports: {}", error); - return; - } - }; - - let layout = Layout::from(reports); - - link.send_message(Msg::Update(layout)); - }); -} - -#[derive(Clone, Debug, Default)] -pub struct Cell { - pub reports: Vec, -} - -impl Cell { - fn render(&self, theme: &Theme) -> Html { - match self.reports.is_empty() { - true => html! { {"-"} }, - false => { - let conflicts = self - .reports - .iter() - .filter(|report| report.proof_of_indexing1.ne(&report.proof_of_indexing2)) - .collect::>(); - - match conflicts.is_empty() { - true => html! { - {"\u{00a0}"} - }, - false => { - let conflict = conflicts.iter().next().unwrap(); - - html! { - - to={Route::POIReportsForIndexers { indexer1: conflict.indexer1.clone(), indexer2: conflict.indexer2.clone() }}> - { - format!( - "{} {}", - conflicts.len(), - match conflicts.len() { - 1 => "conflict", - _ => "conflicts" - } - ) - } - > - - } - } - } - } - } - } -} - -#[derive(Clone, Debug)] -pub struct Row { - pub indexer: String, - pub cells: Vec, -} - -impl Row { - fn new(indexer: String, columns: usize) -> Self { - let mut cells = vec![]; - cells.resize(columns, Default::default()); - Self { indexer, cells } - } - - fn render(&self, theme: &Theme) -> Html { - html! { - - {&self.indexer} - { - for self.cells.iter().map(|cell| cell.render(theme)) - } - - } - } -} - -#[derive(Debug, Default)] -pub struct Layout { - pub deployments: BTreeMap>, -} - -impl From> for Layout { - fn from(reports: Vec) -> Self { - let mut deployments = BTreeMap::>::new(); - - for report in reports { - deployments - .entry(report.deployment.clone()) - .or_default() - .push(report); - } - - Self { deployments } - } -} - -impl Layout { - fn render(&self, theme: &Theme) -> Html { - html! { -
    - { - match self.deployments.is_empty() { - true => html! {

    {"No reports generated yet."}

    }, - false => html! { - <> - { - for self.deployments.iter().map(|(deployment, reports)| { - html! { -
    -

    {"Deployment "}{&deployment}

    - - - - - - - - - - - <> - { - for reports.iter().map(|report| { - html! { - - - - - - - } - }) - } - - -
    {"Block"}{"POI 1"}{"POI 2"}{"Diverging Block"}
    {report.block.number}{" ("}{report.block.hash.clone().unwrap_or(String::from("-"))}{")"}{&report.proof_of_indexing1[0..7]}{&report.proof_of_indexing2[0..7]} - //
    {report.diverging_block.clone().map_or(String::from("-"), |diverging_block| format!("{:#?}", diverging_block))}
    -
    -
    - } - }) - } - - } - } - } -
    - } - } -} - -pub struct View { - layout: Layout, - _poll_interval: Interval, -} - -pub enum Msg { - Update(Layout), -} - -#[derive(PartialEq, Properties)] -pub struct ViewProperties { - pub indexer1: String, - pub indexer2: String, -} - -impl Component for View { - type Message = Msg; - type Properties = ViewProperties; - - fn create(ctx: &Context) -> Self { - let indexer1 = ctx.props().indexer1.clone(); - let indexer2 = ctx.props().indexer2.clone(); - - let link = ctx.link().clone(); - - poll_indexer_cross_check_reports(indexer1.clone(), indexer2.clone(), link.clone()); - - Self { - layout: Layout::default(), - - // Refetch reports every few seconds - _poll_interval: Interval::new(5000, move || { - poll_indexer_cross_check_reports(indexer1.clone(), indexer2.clone(), link.clone()) - }), - } - } - - fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { - match msg { - Msg::Update(layout) => { - self.layout = layout; - } - } - true - } - - fn view(&self, ctx: &Context) -> Html { - let (theme, _) = ctx - .link() - .context::(Callback::noop()) - .expect("theme context to be set"); - - html! { -
    - {self.layout.render(&theme)} -
    - } - } -} diff --git a/frontend/src/pages/poi_reports/mod.rs b/frontend/src/pages/poi_reports/mod.rs deleted file mode 100644 index 4bab4f2..0000000 --- a/frontend/src/pages/poi_reports/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod index; -pub use index::View as Index; - -mod indexers; -pub use indexers::View as Indexers; diff --git a/frontend/src/routes.rs b/frontend/src/routes.rs deleted file mode 100644 index 7f3ad8c..0000000 --- a/frontend/src/routes.rs +++ /dev/null @@ -1,58 +0,0 @@ -use yew::prelude::*; -use yew_router::prelude::*; - -use crate::components::*; -use crate::pages::*; - -#[derive(Clone, Routable, PartialEq)] -pub enum Route { - #[at("/")] - Overview, - #[at("/poi-explorer")] - POIExplorer, - #[at("/poi-reports/deployment/:id")] - POIExplorerDeployment { id: String }, - #[at("/poi-reports")] - POIReports, - #[at("/poi-reports/indexers/:indexer1/:indexer2")] - POIReportsForIndexers { indexer1: String, indexer2: String }, - #[not_found] - #[at("/404")] - NotFound, -} - -pub fn switch(routes: &Route) -> Html { - match routes.clone() { - Route::Overview | Route::POIExplorer => { - html! { - - - - } - } - Route::POIExplorerDeployment { id } => { - html! { - - - - } - } - Route::POIReports => { - html! { - - - - } - } - Route::POIReportsForIndexers { indexer1, indexer2 } => { - html! { - - - - } - } - Route::NotFound => { - html! {
    {"404 Not Found"}
    } - } - } -} From aa3c5188bb62955b76f1587723e944d00fe6a5de Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 11:45:00 +0100 Subject: [PATCH 19/34] Remove useless .clone() --- backend/crates/common/src/store/tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index 3bb89af..a2c58de 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -170,7 +170,6 @@ fn test_pois( // Common logic to create poi_triples let poi_triples: BTreeSet<(String, String, Vec)> = pois - .clone() .into_iter() .map(|poi| { ( From 18f2374296fd82cedf47d7651e2fcd1a806ab5ed Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 11:54:43 +0100 Subject: [PATCH 20/34] Fix all Clippy warnings --- backend/crates/api-server/src/main.rs | 5 +++-- backend/crates/common/src/block_choice.rs | 9 ++------- backend/crates/common/src/config.rs | 15 +++++---------- backend/crates/common/src/graphql_api/server.rs | 2 +- backend/crates/common/src/graphql_api/types.rs | 2 +- backend/crates/common/src/indexer/mod.rs | 2 +- backend/crates/common/src/indexer/real_indexer.rs | 8 ++++---- .../common/src/network_subgraph_client/mod.rs | 4 ++-- backend/crates/common/src/queries.rs | 10 ++++------ backend/crates/common/src/store/diesel_queries.rs | 6 +++--- backend/crates/common/src/store/tests.rs | 8 +++++--- backend/crates/common/src/test_utils/gen.rs | 4 ++-- backend/crates/common/src/test_utils/mocks.rs | 4 ++-- backend/crates/common/src/types.rs | 8 ++++---- .../crates/common/tests/it_proofs_of_indexing.rs | 6 +++--- backend/crates/cross-checker/src/bisect.rs | 4 ++-- backend/crates/cross-checker/src/main.rs | 3 ++- backend/crates/cross-checker/src/utils.rs | 2 +- 18 files changed, 47 insertions(+), 55 deletions(-) diff --git a/backend/crates/api-server/src/main.rs b/backend/crates/api-server/src/main.rs index 524d5d5..f546445 100644 --- a/backend/crates/api-server/src/main.rs +++ b/backend/crates/api-server/src/main.rs @@ -31,14 +31,15 @@ async fn main() -> anyhow::Result<()> { let server_fut = create_server(cli_options); // Listen to requests forever. - Ok(server_fut.await?.await) + server_fut.await?.await; + Ok(()) } async fn create_server(cli_options: CliOptions) -> anyhow::Result> { let store = Store::new(cli_options.database_url.as_str()).await?; // GET / -> 200 OK - let health_check_route = warp::path::end().map(|| format!("Ready to roll!")); + let health_check_route = warp::path::end().map(|| "Ready to roll!".to_string()); // GraphQL API let api_context = graphql_api::ApiSchemaContext { store }; diff --git a/backend/crates/common/src/block_choice.rs b/backend/crates/common/src/block_choice.rs index bbc49ce..99405d0 100644 --- a/backend/crates/common/src/block_choice.rs +++ b/backend/crates/common/src/block_choice.rs @@ -2,21 +2,16 @@ use serde::Deserialize; use crate::prelude::IndexingStatus; -#[derive(Copy, Clone, Debug, Deserialize)] +#[derive(Copy, Clone, Debug, Default, Deserialize)] #[serde(rename_all = "camelCase")] pub enum BlockChoicePolicy { // Use the earliest block that all indexers have in common Earliest, // Use the block that maximizes the total number of blocks synced across all indexers + #[default] MaxSyncedBlocks, } -impl Default for BlockChoicePolicy { - fn default() -> Self { - BlockChoicePolicy::MaxSyncedBlocks - } -} - impl BlockChoicePolicy { pub fn choose_block<'a>( &self, diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index f69f92f..6a28e9a 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -3,6 +3,7 @@ use std::fs::File; use std::path::Path; use std::sync::Arc; +use anyhow::Context; use reqwest::Url; use serde::{Deserialize, Deserializer}; use tracing::{info, warn}; @@ -29,8 +30,7 @@ pub struct Config { impl Config { pub fn read(path: &Path) -> anyhow::Result { let file = File::open(path)?; - Ok(serde_yaml::from_reader(file) - .map_err(|e| anyhow::Error::new(e).context("invalid config file"))?) + serde_yaml::from_reader(file).context("invalid config file") } pub fn indexers(&self) -> Vec { @@ -130,19 +130,14 @@ pub struct NetworkSubgraphConfig { pub limit: Option, } -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Default, Deserialize)] #[serde(rename_all = "camelCase")] pub enum NetworkSubgraphQuery { + #[default] ByAllocations, ByStakedTokens, } -impl Default for NetworkSubgraphQuery { - fn default() -> Self { - NetworkSubgraphQuery::ByAllocations - } -} - #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct InterceptorConfig { @@ -230,7 +225,7 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result for ProofOfIndexing { number: poi.block.number as u64, hash: hex::encode(poi.block.hash), }, - indexer: Indexer::from(models::Indexer::from(poi.indexer)), + indexer: Indexer::from(poi.indexer), } } } diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs index fb22da4..9625080 100644 --- a/backend/crates/common/src/indexer/mod.rs +++ b/backend/crates/common/src/indexer/mod.rs @@ -145,7 +145,7 @@ impl Hash for dyn Indexer { impl PartialOrd for dyn Indexer { fn partial_cmp(&self, other: &Self) -> Option { - self.id().partial_cmp(&other.id()) + Some(self.cmp(other)) } } diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index 3c557d1..561b10e 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -71,7 +71,7 @@ impl RealIndexer { return Err(anyhow::anyhow!("Indexer returned errors: {}", errors)); } - Ok(response.data.context("Indexer returned no data")?) + response.data.context("Indexer returned no data") } async fn proofs_of_indexing_batch( @@ -83,7 +83,7 @@ impl RealIndexer { }; let request = gql_types::ProofsOfIndexing::build_query(Variables { requests: requests - .into_iter() + .iter() .map(|query| PublicProofOfIndexingRequest { deployment: query.deployment.to_string(), block_number: query.block_number.to_string(), @@ -254,7 +254,7 @@ impl Indexer for RealIndexer { let eth_calls = response .cached_ethereum_calls - .unwrap_or(vec![]) + .unwrap_or_default() .into_iter() .map(|eth_call| { Ok(CachedEthereumCall { @@ -359,7 +359,7 @@ mod gql_types { let chain = self .inner .chains - .get(0) + .first() .ok_or_else(|| anyhow!("chain status missing"))?; let (latest_block, earliest_block_num) = match &chain.on { diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index c28d969..2633e7c 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -345,14 +345,14 @@ mod tests { // We should never be able to get a response back under 1ms. If we do, // it means the timeout logic is broken. let client = network_sg_client_on_ethereum().with_timeout(Duration::from_millis(1)); - assert!(matches!(client.indexers_by_staked_tokens().await, Err(_))); + assert!(client.indexers_by_staked_tokens().await.is_err()) } #[tokio::test] async fn mainnet_indexers_by_staked_tokens_no_panic() { let client = network_sg_client_on_ethereum(); let indexers = client.indexers_by_staked_tokens().await.unwrap(); - assert!(indexers.len() > 0); + assert!(!indexers.is_empty()); } #[tokio::test] diff --git a/backend/crates/common/src/queries.rs b/backend/crates/common/src/queries.rs index 5e1bdb9..d18919d 100644 --- a/backend/crates/common/src/queries.rs +++ b/backend/crates/common/src/queries.rs @@ -166,13 +166,13 @@ pub async fn query_proofs_of_indexing( ( deployment.clone(), statuses_by_deployment.get(deployment).and_then(|statuses| { - block_choice_policy.choose_block(statuses.iter().map(|&s| s)) + block_choice_policy.choose_block(statuses.iter().copied()) }), ) })); // Fetch POIs for the most recent common blocks - let pois = indexers + indexers .iter() .map(|indexer| async { let poi_requests = latest_blocks @@ -190,7 +190,7 @@ pub async fn query_proofs_of_indexing( .filter_map(|(deployment, block_number)| { block_number.map(|block_number| PoiRequest { deployment: deployment.clone(), - block_number: block_number, + block_number, }) }) .collect::>(); @@ -209,7 +209,5 @@ pub async fn query_proofs_of_indexing( .await .into_iter() .flatten() - .collect::>(); - - pois + .collect::>() } diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index 31fe8ac..7b668ed 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -84,7 +84,7 @@ pub(super) fn pois( }; let order_by = (blocks::number.desc(), schema::pois::created_at.desc()); - let limit = limit.map(|l| l as i64).unwrap_or(i64::MAX) as i64; + let limit = limit.map(|l| l as i64).unwrap_or(i64::MAX); match live_only { false => { @@ -98,7 +98,7 @@ pub(super) fn pois( .filter(blocks_filter) .filter(indexer_filter) .limit(limit); - return Ok(query.load::(conn)?); + Ok(query.load::(conn)?) } // This will additionally join with `live_pois` to filter out any Pois that are not live. true => { @@ -113,7 +113,7 @@ pub(super) fn pois( .filter(blocks_filter) .filter(indexer_filter) .limit(limit); - return Ok(query.load::(conn)?); + Ok(query.load::(conn)?) } } } diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index a2c58de..bcc6030 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -68,8 +68,10 @@ async fn deployments_with_name() { store.set_deployment_name(ipfs_cid2, "foo").unwrap(); let deployments = { - let mut filter = SgDeploymentsQuery::default(); - filter.name = Some("foo".to_string()); + let filter = SgDeploymentsQuery { + name: Some("foo".to_string()), + ..Default::default() + }; store.sg_deployments(filter).unwrap() }; assert!(deployments.len() == 1); @@ -170,7 +172,7 @@ fn test_pois( // Common logic to create poi_triples let poi_triples: BTreeSet<(String, String, Vec)> = pois - .into_iter() + .iter() .map(|poi| { ( poi.deployment.0.clone(), diff --git a/backend/crates/common/src/test_utils/gen.rs b/backend/crates/common/src/test_utils/gen.rs index 19f9baa..f908be0 100644 --- a/backend/crates/common/src/test_utils/gen.rs +++ b/backend/crates/common/src/test_utils/gen.rs @@ -24,7 +24,7 @@ pub fn gen_blocks() -> Vec { let block_hash = |n: u64| -> Bytes32 { let mut buf = [0u8; 32]; buf[24..32].clone_from_slice(&n.to_be_bytes()); - Bytes32(buf.into()) + Bytes32(buf) }; (0..10) .map(|number| BlockPointer { @@ -88,7 +88,7 @@ where .map(|deployment| DeploymentDetails { deployment, network: "mainnet".into(), - latest_block: blocks.iter().choose(&mut rng).unwrap().clone(), + latest_block: *blocks.iter().choose(&mut rng).unwrap(), canonical_pois: gen_pois(blocks.clone(), &mut rng), earliest_block_num: blocks[0].number, }) diff --git a/backend/crates/common/src/test_utils/mocks.rs b/backend/crates/common/src/test_utils/mocks.rs index aa12f99..bbdf4bc 100644 --- a/backend/crates/common/src/test_utils/mocks.rs +++ b/backend/crates/common/src/test_utils/mocks.rs @@ -81,8 +81,8 @@ impl Indexer for MockIndexer { .map(|(deployment_detail, poi)| ProofOfIndexing { indexer: self.clone(), deployment: deployment_detail.deployment.clone(), - block: poi.block.clone(), - proof_of_indexing: poi.proof_of_indexing.clone(), + block: poi.block, + proof_of_indexing: poi.proof_of_indexing, }) .collect::>() } diff --git a/backend/crates/common/src/types.rs b/backend/crates/common/src/types.rs index 30f77f4..6b3d316 100644 --- a/backend/crates/common/src/types.rs +++ b/backend/crates/common/src/types.rs @@ -55,7 +55,7 @@ pub struct IndexingStatus { impl PartialEq for IndexingStatus { fn eq(&self, other: &Self) -> bool { - &*self.indexer == &*other.indexer + self.indexer.as_ref() == other.indexer.as_ref() && self.deployment == other.deployment && self.network == other.network && self.latest_block == other.latest_block @@ -89,7 +89,7 @@ impl TryFrom> for Bytes32 { impl fmt::Display for Bytes32 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", hex::encode(&self.0)) + write!(f, "{}", hex::encode(self.0)) } } @@ -103,7 +103,7 @@ pub struct ProofOfIndexing { impl PartialEq for ProofOfIndexing { fn eq(&self, other: &Self) -> bool { - &*self.indexer == &*other.indexer + self.indexer.as_ref() == other.indexer.as_ref() && self.deployment == other.deployment && self.block == other.block && self.proof_of_indexing == other.proof_of_indexing @@ -122,7 +122,7 @@ impl WritablePoi for ProofOfIndexing { } fn block(&self) -> BlockPointer { - self.block.clone() + self.block } fn proof_of_indexing(&self) -> &[u8] { diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/backend/crates/common/tests/it_proofs_of_indexing.rs index 68f2083..c2c8b00 100644 --- a/backend/crates/common/tests/it_proofs_of_indexing.rs +++ b/backend/crates/common/tests/it_proofs_of_indexing.rs @@ -108,7 +108,7 @@ async fn send_single_query_of_unknown_block_number_and_handle_error() { #[tokio::test] async fn send_multiple_queries_and_process_results() { - //// Given + // Given // FIXME: This is temporarily set to 1 until we fix the error: 'Null value resolved for // non-null field `proofOfIndexing`' Which is probably a Graph Node bug. Setting it to 1 @@ -126,13 +126,13 @@ async fn send_multiple_queries_and_process_results() { }) .collect::>(); - //// When + // When let request_fut = Indexer::proofs_of_indexing(indexer, poi_requests); let response = tokio::time::timeout(Duration::from_secs(10), request_fut) .await .expect("Timeout"); - //// Then + // Then assert_eq!(response.len(), MAX_REQUESTS_PER_QUERY + 2); assert_eq!(response[0].deployment, deployment); diff --git a/backend/crates/cross-checker/src/bisect.rs b/backend/crates/cross-checker/src/bisect.rs index edada1a..b53d2ec 100644 --- a/backend/crates/cross-checker/src/bisect.rs +++ b/backend/crates/cross-checker/src/bisect.rs @@ -240,7 +240,7 @@ async fn handle_divergence_investigation_request_pair( debug!(req_uuid = req_uuid_str, poi1 = %poi1_s, poi2 = %poi2_s, "Fetching Pois"); let poi1 = match store - .poi(&poi1_s) + .poi(poi1_s) .map_err(DivergenceInvestigationError::Database) .and_then(|poi_opt| { if let Some(poi) = poi_opt { @@ -258,7 +258,7 @@ async fn handle_divergence_investigation_request_pair( } }; let poi2 = match store - .poi(&poi2_s) + .poi(poi2_s) .map_err(DivergenceInvestigationError::Database) .and_then(|poi_opt| { if let Some(poi) = poi_opt { diff --git a/backend/crates/cross-checker/src/main.rs b/backend/crates/cross-checker/src/main.rs index 8c87b54..ea57565 100644 --- a/backend/crates/cross-checker/src/main.rs +++ b/backend/crates/cross-checker/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::type_complexity)] + mod bisect; mod utils; @@ -13,7 +15,6 @@ use graphix_common::{config, metrics, store, PrometheusExporter}; use prometheus_exporter::prometheus; use tokio::sync::watch; use tracing::*; -use tracing_subscriber; use crate::bisect::handle_divergence_investigation_requests; diff --git a/backend/crates/cross-checker/src/utils.rs b/backend/crates/cross-checker/src/utils.rs index d7ad8b7..d1adab9 100644 --- a/backend/crates/cross-checker/src/utils.rs +++ b/backend/crates/cross-checker/src/utils.rs @@ -30,7 +30,7 @@ pub fn find_any_indexer_for_poi( poi_s: &str, indexers: &[Arc], ) -> anyhow::Result>> { - let poi = if let Some(poi) = store.poi(&poi_s)? { + let poi = if let Some(poi) = store.poi(poi_s)? { poi } else { return Ok(None); From 7b5ada3f8f539ecb1c98047bc4a3e9701a2d3f6f Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 12:00:49 +0100 Subject: [PATCH 21/34] Update async-graphql to v7.0.1 --- Cargo.lock | 239 ++++++++++++------ backend/crates/api-server/Cargo.toml | 4 +- backend/crates/api-server/src/main.rs | 3 +- backend/crates/common/Cargo.toml | 2 +- backend/crates/schema/Cargo.toml | 2 +- .../crates/schema/graphql/api_schema.graphql | 2 + 6 files changed, 167 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fd9f17..bae8a66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,13 +25,14 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -133,9 +134,9 @@ checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" [[package]] name = "async-graphql" -version = "5.0.7" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0ed623e2503b45d875461e5de88a1b3466cf2ed3e43cf189a102a641b93f19" +checksum = "b16926f97f683ff3b47b035cc79622f3d6a374730b07a5d9051e81e88b5f1904" dependencies = [ "async-graphql-derive", "async-graphql-parser", @@ -148,8 +149,8 @@ dependencies = [ "fnv", "futures-util", "handlebars", - "http", - "indexmap", + "http 1.0.0", + "indexmap 2.1.0", "mime", "multer", "num-traits", @@ -159,32 +160,33 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "static_assertions", + "static_assertions_next", "tempfile", "thiserror", ] [[package]] name = "async-graphql-derive" -version = "5.0.7" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cebcf27112b969c4ff2a003b318ab5efde96055f9d0ee3344a3b3831fa2932ba" +checksum = "a6a7349168b79030e3172a620f4f0e0062268a954604e41475eff082380fe505" dependencies = [ "Inflector", "async-graphql-parser", - "darling 0.14.4", + "darling 0.20.3", "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 1.0.109", + "strum", + "syn 2.0.48", "thiserror", ] [[package]] name = "async-graphql-parser" -version = "5.0.7" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631770464ad2492da9af6b70048e9e477ef7c1e55fdbfb0719f3330cfa87d8e9" +checksum = "58fdc0adf9f53c2b65bb0ff5170cba1912299f248d0e48266f444b6f005deb1d" dependencies = [ "async-graphql-value", "pest", @@ -194,24 +196,25 @@ dependencies = [ [[package]] name = "async-graphql-value" -version = "5.0.7" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b59633f68ae4b858e14ec761e02455c575327249cbefed3af067a0b26d76daa9" +checksum = "7cf4d4e86208f4f9b81a503943c07e6e7f29ad3505e6c9ce6431fe64dc241681" dependencies = [ "bytes", - "indexmap", + "indexmap 2.1.0", "serde", "serde_json", ] [[package]] name = "async-graphql-warp" -version = "5.0.7" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb6bf41fb7c140172034290b10c17eca6ebf37af148301f913dc95eb625083b" +checksum = "d906b817c1499c0a814ea62b2a9cc03726e50d694d7e8cad3fcc1b24e8b62883" dependencies = [ "async-graphql", "futures-util", + "http 0.2.9", "serde_json", "warp", ] @@ -235,7 +238,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -246,7 +249,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -400,7 +403,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -531,7 +534,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -548,7 +551,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -563,12 +566,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" dependencies = [ - "darling_core 0.14.4", - "darling_macro 0.14.4", + "darling_core 0.20.3", + "darling_macro 0.20.3", ] [[package]] @@ -587,16 +590,16 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -612,13 +615,13 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.14.4" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ - "darling_core 0.14.4", + "darling_core 0.20.3", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -748,6 +751,12 @@ dependencies = [ "regex", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.1" @@ -902,7 +911,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -1122,8 +1131,8 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", - "indexmap", + "http 0.2.9", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -1152,11 +1161,11 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.3", + "ahash 0.8.7", "allocator-api2", ] @@ -1166,7 +1175,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" dependencies = [ - "hashbrown 0.14.0", + "hashbrown 0.14.3", ] [[package]] @@ -1179,7 +1188,7 @@ dependencies = [ "bitflags", "bytes", "headers-core", - "http", + "http 0.2.9", "httpdate", "mime", "sha1", @@ -1191,7 +1200,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" dependencies = [ - "http", + "http 0.2.9", ] [[package]] @@ -1253,6 +1262,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.5" @@ -1260,7 +1280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.9", "pin-project-lite", ] @@ -1287,7 +1307,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.9", "http-body", "httparse", "httpdate", @@ -1361,6 +1381,16 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", "serde", ] @@ -1434,9 +1464,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.141" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "link-cplusplus" @@ -1553,14 +1583,14 @@ dependencies = [ [[package]] name = "multer" -version = "2.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01acbdc23469fd8fe07ab135923371d5f5a422fbf9c522158677c8eb15bc51c2" +checksum = "a15d522be0a9c3e46fd2632e272d178f56387bdb5c9fbb3a36c649062e9b5219" dependencies = [ "bytes", "encoding_rs", "futures-util", - "http", + "http 1.0.0", "httparse", "log", "memchr", @@ -1678,9 +1708,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" @@ -1705,7 +1735,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -1794,10 +1824,11 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.7" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1403e8401ad5dedea73c626b99758535b342502f8d1e361f4a2dd952749122" +checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" dependencies = [ + "memchr", "thiserror", "ucd-trie", ] @@ -1822,7 +1853,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -1934,9 +1965,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -2000,9 +2031,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2115,7 +2146,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.9", "http-body", "hyper", "hyper-tls", @@ -2163,6 +2194,12 @@ dependencies = [ "base64 0.21.0", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.13" @@ -2230,22 +2267,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.160" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -2299,7 +2336,7 @@ version = "0.9.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9d684e3ec7de3bf5466b32bd75303ac16f0736426e5a4e0d6e489559ce1249c" dependencies = [ - "indexmap", + "indexmap 1.9.3", "itoa", "ryu", "serde", @@ -2424,7 +2461,7 @@ dependencies = [ "hex", "hkdf", "hmac", - "indexmap", + "indexmap 1.9.3", "itoa", "libc", "log", @@ -2480,10 +2517,10 @@ dependencies = [ ] [[package]] -name = "static_assertions" -version = "1.1.0" +name = "static_assertions_next" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" [[package]] name = "stringprep" @@ -2501,6 +2538,28 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.48", +] + [[package]] name = "subtle" version = "2.4.1" @@ -2520,9 +2579,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.15" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -2606,7 +2665,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -2748,7 +2807,7 @@ checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.48", ] [[package]] @@ -2763,9 +2822,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", "pin-project-lite", @@ -2819,7 +2878,7 @@ version = "0.19.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" dependencies = [ - "indexmap", + "indexmap 1.9.3", "toml_datetime", "winnow", ] @@ -2931,7 +2990,7 @@ dependencies = [ "base64 0.13.1", "byteorder", "bytes", - "http", + "http 0.2.9", "httparse", "log", "rand", @@ -3114,7 +3173,7 @@ dependencies = [ "futures-channel", "futures-util", "headers", - "http", + "http 0.2.9", "hyper", "log", "mime", @@ -3437,3 +3496,23 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] diff --git a/backend/crates/api-server/Cargo.toml b/backend/crates/api-server/Cargo.toml index 8ccb422..539767f 100644 --- a/backend/crates/api-server/Cargo.toml +++ b/backend/crates/api-server/Cargo.toml @@ -11,8 +11,8 @@ path = "src/main.rs" [dependencies] anyhow = "1.0.52" -async-graphql = "5" -async-graphql-warp = "5" +async-graphql = "7" +async-graphql-warp = "7" clap = { version = "4", features = ["derive", "env"] } graphix-common = { path = "../common" } serde_json = "1" diff --git a/backend/crates/api-server/src/main.rs b/backend/crates/api-server/src/main.rs index f546445..371e752 100644 --- a/backend/crates/api-server/src/main.rs +++ b/backend/crates/api-server/src/main.rs @@ -1,5 +1,6 @@ use std::convert::Infallible; use std::future::Future; +use std::net::Ipv4Addr; use async_graphql::http::{playground_source, GraphQLPlaygroundConfig}; use async_graphql::Request; @@ -73,7 +74,7 @@ async fn create_server(cli_options: CliOptions) -> anyhow::Result Date: Mon, 22 Jan 2024 12:16:30 +0100 Subject: [PATCH 22/34] Switch `api-server` from Warp to Axum --- Cargo.lock | 360 +++++++++++++++--------- backend/crates/api-server/Cargo.toml | 4 +- backend/crates/api-server/src/main.rs | 73 ++--- backend/crates/cross-checker/Cargo.toml | 1 - ops/compose/grafana/data/grafana.db | Bin 1372160 -> 1372160 bytes 5 files changed, 254 insertions(+), 184 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bae8a66..7c0f983 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,6 +165,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "async-graphql-axum" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3415c9dbaf54397292da0bb81a907e2b989661ce068e4ccfebac33dc9e245e" +dependencies = [ + "async-graphql", + "async-trait", + "axum", + "bytes", + "futures-util", + "serde_json", + "tokio", + "tokio-stream", + "tokio-util", + "tower-service", +] + [[package]] name = "async-graphql-derive" version = "7.0.1" @@ -206,19 +224,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "async-graphql-warp" -version = "7.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d906b817c1499c0a814ea62b2a9cc03726e50d694d7e8cad3fcc1b24e8b62883" -dependencies = [ - "async-graphql", - "futures-util", - "http 0.2.9", - "serde_json", - "warp", -] - [[package]] name = "async-stream" version = "0.3.5" @@ -267,6 +272,64 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" +dependencies = [ + "async-trait", + "axum-core", + "base64 0.21.0", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.1.0", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sha1", + "sync_wrapper", + "tokio", + "tokio-tungstenite", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "base-x" version = "0.2.11" @@ -982,14 +1045,14 @@ version = "0.1.0" dependencies = [ "anyhow", "async-graphql", - "async-graphql-warp", + "async-graphql-axum", + "axum", "clap", "graphix-common", "serde_json", "tokio", "tracing", "tracing-subscriber", - "warp", ] [[package]] @@ -1051,7 +1114,6 @@ dependencies = [ "tracing-subscriber", "tracing-test", "uuid 0.8.2", - "warp", ] [[package]] @@ -1139,6 +1201,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.0.0", + "indexmap 2.1.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "handlebars" version = "4.3.6" @@ -1178,31 +1259,6 @@ dependencies = [ "hashbrown 0.14.3", ] -[[package]] -name = "headers" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" -dependencies = [ - "base64 0.13.1", - "bitflags", - "bytes", - "headers-core", - "http 0.2.9", - "httpdate", - "mime", - "sha1", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http 0.2.9", -] - [[package]] name = "heck" version = "0.4.1" @@ -1284,6 +1340,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.0.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -1306,20 +1385,39 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.17", "http 0.2.9", - "http-body", + "http-body 0.4.5", "httparse", "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", "want", ] +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -1327,12 +1425,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.25", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.1.0", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.56" @@ -1511,6 +1627,12 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md-5" version = "0.10.5" @@ -1553,16 +1675,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1610,20 +1722,6 @@ dependencies = [ "data-encoding-macro", ] -[[package]] -name = "multiparty" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed1ec6589a6d4a1e0b33b4c0a3f6ee96dfba88ebdb3da51403fd7cf0a24a4b04" -dependencies = [ - "bytes", - "futures-core", - "httparse", - "memchr", - "pin-project-lite", - "try-lock", -] - [[package]] name = "nanoid" version = "0.4.0" @@ -2145,10 +2243,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", + "h2 0.3.17", "http 0.2.9", - "http-body", - "hyper", + "http-body 0.4.5", + "hyper 0.14.25", "hyper-tls", "ipnet", "js-sys", @@ -2185,15 +2283,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "rustls-pemfile" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" -dependencies = [ - "base64 0.21.0", -] - [[package]] name = "rustversion" version = "1.0.14" @@ -2224,12 +2313,6 @@ dependencies = [ "parking_lot 0.12.1", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" version = "1.1.0" @@ -2296,6 +2379,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2408,6 +2501,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "spin" version = "0.9.8" @@ -2588,6 +2691,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "synstructure" version = "0.12.6" @@ -2794,7 +2903,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.4.9", "tokio-macros", "windows-sys 0.45.0", ] @@ -2833,9 +2942,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.18.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" dependencies = [ "futures-util", "log", @@ -2851,6 +2960,7 @@ checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -2883,6 +2993,28 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -2983,14 +3115,14 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "tungstenite" -version = "0.18.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" dependencies = [ - "base64 0.13.1", "byteorder", "bytes", - "http 0.2.9", + "data-encoding", + "http 1.0.0", "httparse", "log", "rand", @@ -3012,15 +3144,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.13" @@ -3163,37 +3286,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "warp" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27e1a710288f0f91a98dd8a74f05b76a10768db245ce183edf64dc1afdc3016c" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "headers", - "http 0.2.9", - "hyper", - "log", - "mime", - "mime_guess", - "multiparty", - "percent-encoding", - "pin-project", - "rustls-pemfile", - "scoped-tls", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-stream", - "tokio-tungstenite", - "tokio-util", - "tower-service", - "tracing", -] - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" diff --git a/backend/crates/api-server/Cargo.toml b/backend/crates/api-server/Cargo.toml index 539767f..8117f62 100644 --- a/backend/crates/api-server/Cargo.toml +++ b/backend/crates/api-server/Cargo.toml @@ -12,11 +12,11 @@ path = "src/main.rs" [dependencies] anyhow = "1.0.52" async-graphql = "7" -async-graphql-warp = "7" +async-graphql-axum = "7" +axum = "0.7" clap = { version = "4", features = ["derive", "env"] } graphix-common = { path = "../common" } serde_json = "1" tokio = { version = "1.15.0", features = ["full"] } tracing = "0.1.29" tracing-subscriber = { version = "0.3.6", features = ["env-filter"] } -warp = "0.3.2" diff --git a/backend/crates/api-server/src/main.rs b/backend/crates/api-server/src/main.rs index 371e752..9bc055e 100644 --- a/backend/crates/api-server/src/main.rs +++ b/backend/crates/api-server/src/main.rs @@ -1,15 +1,13 @@ -use std::convert::Infallible; -use std::future::Future; use std::net::Ipv4Addr; -use async_graphql::http::{playground_source, GraphQLPlaygroundConfig}; -use async_graphql::Request; -use async_graphql_warp::{self, GraphQLResponse}; +use async_graphql::http::GraphiQLSource; +use async_graphql_axum::GraphQL; +use axum::response::IntoResponse; +use axum::Router; use clap::Parser; use graphix_common::graphql_api::{self}; use graphix_common::store::Store; -use warp::http::{self, Method}; -use warp::Filter; +use tokio::net::TcpListener; #[derive(Parser, Debug)] pub struct CliOptions { @@ -29,54 +27,35 @@ async fn main() -> anyhow::Result<()> { init_tracing(); let cli_options = CliOptions::parse(); - let server_fut = create_server(cli_options); // Listen to requests forever. - server_fut.await?.await; + axum::serve( + TcpListener::bind((Ipv4Addr::UNSPECIFIED, cli_options.port)).await?, + axum_server(cli_options).await?, + ) + .await?; + Ok(()) } -async fn create_server(cli_options: CliOptions) -> anyhow::Result> { - let store = Store::new(cli_options.database_url.as_str()).await?; - - // GET / -> 200 OK - let health_check_route = warp::path::end().map(|| "Ready to roll!".to_string()); - - // GraphQL API - let api_context = graphql_api::ApiSchemaContext { store }; - let api_schema = graphql_api::api_schema(api_context); - let api = async_graphql_warp::graphql(api_schema).and_then( - |(schema, request): (graphql_api::ApiSchema, Request)| async move { - Ok::<_, Infallible>(GraphQLResponse::from(schema.execute(request).await)) - }, - ); - let cors = warp::cors() - .allow_methods(&[Method::GET, Method::POST, Method::OPTIONS]) - .allow_header("content-type") - .allow_any_origin(); - let graphql_route = warp::any() - .and(warp::path("graphql").and(warp::path::end())) - .and(api) - .with(cors.clone()); - - // GraphQL playground - let graphql_playground = warp::get().map(|| { - http::Response::builder() - .header("content-type", "text/html") - .body(playground_source(GraphQLPlaygroundConfig::new("/graphql"))) - }); - let graphql_playground_route = warp::get() - .and(warp::path("graphql").and(warp::path::end())) - .and(graphql_playground); +async fn axum_server(cli_options: CliOptions) -> anyhow::Result> { + use axum::routing::get; - let routes = warp::get() - .and(health_check_route) - .or(graphql_playground_route) - .or(graphql_route); - - Ok(warp::serve(routes).run((Ipv4Addr::UNSPECIFIED, cli_options.port))) + let store = Store::new(cli_options.database_url.as_str()).await?; + let api_schema = graphql_api::api_schema(graphql_api::ApiSchemaContext { store }); + + Ok(axum::Router::new() + .route("/", get(|| async { "Ready to roll!" })) + .route( + "/graphql", + get(graphiql_route).post_service(GraphQL::new(api_schema)), + )) } fn init_tracing() { tracing_subscriber::fmt::init(); } + +async fn graphiql_route() -> impl IntoResponse { + axum::response::Html(GraphiQLSource::build().endpoint("/graphql").finish()) +} diff --git a/backend/crates/cross-checker/Cargo.toml b/backend/crates/cross-checker/Cargo.toml index e4d720f..8357828 100644 --- a/backend/crates/cross-checker/Cargo.toml +++ b/backend/crates/cross-checker/Cargo.toml @@ -24,7 +24,6 @@ tokio = { version = "1.14.0", features = ["full"] } tracing = "0.1.29" tracing-subscriber = { version = "0.3.2", features = ["env-filter"] } uuid = { version = "0.8.2", features = ["v4"] } -warp = "0.3.2" [dev-dependencies] graphix-common = { path = "../common", features = ["tests"] } diff --git a/ops/compose/grafana/data/grafana.db b/ops/compose/grafana/data/grafana.db index 7ba5b8d71cd2568973c9180f1f21a592e5d96f7a..8391fc359ff14d27d9c9c41319a18bf661264abe 100644 GIT binary patch delta 447 zcmZp85Zv$}c!D(J$%!(~j3+lHbm=nQYksZU{#ut2h?#(x8Hibcm=%cGw!hY8pTCfK zonOTC-t+7pta7P9=Js3X+1K$i-rL@JpS{{ah?S?Gf%hn{7Jn+=DV}~_Encn7f)15D zW{na8Z0U_2%q)p{`FXm&({1cI5{wL)(-}!}iNN%8_8ew3GQ0hpKL-$V0x=g5a|1CC5c2{t9}x2cu>cSY Q0R3ifm^VBr+G}AQ8#O+$T9JiQ+SojJV_|NgP@fGr2;hzJ7KzpM3rWe|AoMN0d zeStlP*z{UG4)N)k_8i7WKzmY9EJ-skGfy%!NKHz%OiDJlG%ztYG&eRkGD%9bG&D{% zPU4(?&Yr`J=C-t-^XC9!P9Ww2Vs0Sj0b*Vt<^y7WAQk{(K_C_aV&U!Q{6&lw006;V Bky-!% From 5eeaa2c3d9961d1a4f0ac81d39d19e59bacca019 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 12:19:05 +0100 Subject: [PATCH 23/34] Remove unused .gitkeep --- backend/crates/common/migrations/.gitkeep | 0 backend/crates/schema/Cargo.toml | 2 -- 2 files changed, 2 deletions(-) delete mode 100644 backend/crates/common/migrations/.gitkeep diff --git a/backend/crates/common/migrations/.gitkeep b/backend/crates/common/migrations/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/backend/crates/schema/Cargo.toml b/backend/crates/schema/Cargo.toml index ed52e1c..2e6f1f3 100644 --- a/backend/crates/schema/Cargo.toml +++ b/backend/crates/schema/Cargo.toml @@ -3,8 +3,6 @@ name = "graphix-schema" version = "0.1.0" edition = "2021" -[dependencies] - [build-dependencies] async-graphql = "7" graphix-common = { path = "../common" } From b9e5980bd476bb1f2fc35145bfbd4d17ff31b529 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 12:30:43 +0100 Subject: [PATCH 24/34] Remove prelude modue; explicit imports --- backend/crates/common/src/block_choice.rs | 2 +- backend/crates/common/src/graphql_api/types.rs | 2 +- backend/crates/common/src/indexer/interceptor.rs | 2 +- backend/crates/common/src/indexer/real_indexer.rs | 4 ++-- backend/crates/common/src/lib.rs | 13 ++----------- .../common/src/network_subgraph_client/mod.rs | 2 +- backend/crates/common/src/queries.rs | 2 +- backend/crates/common/src/store/diesel_queries.rs | 2 +- backend/crates/common/src/store/mod.rs | 2 +- backend/crates/common/src/store/tests.rs | 2 +- backend/crates/common/src/test_utils/gen.rs | 3 ++- backend/crates/common/src/test_utils/mocks.rs | 7 ++++--- backend/crates/common/tests/indexing_statuses.rs | 2 +- backend/crates/common/tests/it_indexing_statuses.rs | 3 ++- .../crates/common/tests/it_proofs_of_indexing.rs | 6 +++--- backend/crates/cross-checker/src/bisect.rs | 8 ++++---- backend/crates/cross-checker/src/main.rs | 3 ++- backend/crates/cross-checker/src/utils.rs | 2 +- 18 files changed, 31 insertions(+), 36 deletions(-) diff --git a/backend/crates/common/src/block_choice.rs b/backend/crates/common/src/block_choice.rs index 99405d0..ab68202 100644 --- a/backend/crates/common/src/block_choice.rs +++ b/backend/crates/common/src/block_choice.rs @@ -1,6 +1,6 @@ use serde::Deserialize; -use crate::prelude::IndexingStatus; +use crate::types::IndexingStatus; #[derive(Copy, Clone, Debug, Default, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/backend/crates/common/src/graphql_api/types.rs b/backend/crates/common/src/graphql_api/types.rs index f074963..f30e7ae 100644 --- a/backend/crates/common/src/graphql_api/types.rs +++ b/backend/crates/common/src/graphql_api/types.rs @@ -7,8 +7,8 @@ use async_graphql::*; use diesel::deserialize::FromSqlRow; use serde::{Deserialize, Serialize}; -use crate::prelude::IndexerVersion; use crate::store::models::{self}; +use crate::types::IndexerVersion; type HexBytesWith0xPrefix = String; type UuidString = String; diff --git a/backend/crates/common/src/indexer/interceptor.rs b/backend/crates/common/src/indexer/interceptor.rs index 0b4a463..d0b25fa 100644 --- a/backend/crates/common/src/indexer/interceptor.rs +++ b/backend/crates/common/src/indexer/interceptor.rs @@ -7,7 +7,7 @@ use async_trait::async_trait; use super::{CachedEthereumCall, EntityChanges}; use crate::indexer::Indexer; -use crate::prelude::Bytes32; +use crate::types::Bytes32; use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; /// Pretends to be an indexer by routing requests a diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index 561b10e..b7d18d5 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -10,8 +10,9 @@ use serde::Serialize; use tracing::*; use super::{CachedEthereumCall, EntityChanges, Indexer}; +use crate::config::IndexerConfig; use crate::config::IndexerUrls; -use crate::prelude::{IndexerConfig, WithIndexer}; +use crate::indexer::WithIndexer; use crate::prometheus_metrics::metrics; use crate::types::{ BlockPointer, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, @@ -318,7 +319,6 @@ impl Indexer for RealIndexer { mod gql_types { use super::*; - use crate::prelude::WithIndexer; pub type JSONObject = serde_json::Value; pub type BigInt = String; diff --git a/backend/crates/common/src/lib.rs b/backend/crates/common/src/lib.rs index c926633..435015a 100644 --- a/backend/crates/common/src/lib.rs +++ b/backend/crates/common/src/lib.rs @@ -1,23 +1,14 @@ pub mod block_choice; pub mod config; pub mod graphql_api; -mod indexer; +pub mod indexer; pub mod network_subgraph_client; mod prometheus_metrics; pub mod queries; pub mod store; -mod types; +pub mod types; #[cfg(feature = "tests")] pub mod test_utils; pub use prometheus_metrics::{metrics, PrometheusExporter, PrometheusMetrics}; - -pub mod prelude { - pub use super::config::*; - pub use super::indexer::*; - pub use super::queries::{query_indexing_statuses, query_proofs_of_indexing}; - pub use super::store; - pub use super::store::Store; - pub use super::types::*; -} diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index 2633e7c..32f236a 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -11,7 +11,7 @@ use serde_derive::{Deserialize, Serialize}; use tracing::warn; use crate::config::{IndexerConfig, IndexerUrls}; -use crate::prelude::{Indexer as IndexerTrait, RealIndexer}; +use crate::indexer::{Indexer as IndexerTrait, RealIndexer}; /// A GraphQL client that can query the network subgraph and extract useful /// data. diff --git a/backend/crates/common/src/queries.rs b/backend/crates/common/src/queries.rs index d18919d..00180b8 100644 --- a/backend/crates/common/src/queries.rs +++ b/backend/crates/common/src/queries.rs @@ -7,7 +7,7 @@ use tracing::*; use crate::block_choice::BlockChoicePolicy; use crate::indexer::Indexer; -use crate::prelude::{ +use crate::types::{ IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, }; use crate::PrometheusMetrics; diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index 7b668ed..031c5d7 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -10,11 +10,11 @@ use super::models::WritablePoi; use super::PoiLiveness; use crate::graphql_api::types::BlockRangeInput; use crate::indexer::{Indexer, IndexerId}; -use crate::prelude::{BlockPointer, IndexerVersion}; use crate::store::models::{ self, Indexer as IndexerModel, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, }; use crate::store::schema::{self, live_pois}; +use crate::types::{BlockPointer, IndexerVersion}; pub(super) fn poi(conn: &mut PgConnection, poi: &str) -> anyhow::Result> { use schema::{blocks, indexers, pois, sg_deployments}; diff --git a/backend/crates/common/src/store/mod.rs b/backend/crates/common/src/store/mod.rs index f4cac57..1bb267b 100644 --- a/backend/crates/common/src/store/mod.rs +++ b/backend/crates/common/src/store/mod.rs @@ -21,8 +21,8 @@ use tracing::info; use self::models::{QueriedSgDeployment, WritablePoi}; use crate::graphql_api::types::{BlockRangeInput, IndexersQuery, Network, SgDeploymentsQuery}; use crate::indexer::Indexer; -use crate::prelude::IndexerVersion; use crate::store::models::{Indexer as IndexerModel, Poi}; +use crate::types::IndexerVersion; #[cfg(test)] mod tests; diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index bcc6030..4ddfaa7 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -7,12 +7,12 @@ use testcontainers::Container; use crate::block_choice::BlockChoicePolicy; use crate::graphql_api::types::SgDeploymentsQuery; -use crate::prelude::ProofOfIndexing; use crate::prometheus_metrics::metrics; use crate::queries; use crate::store::{diesel_queries, PoiLiveness, Store}; use crate::test_utils::fast_rng; use crate::test_utils::gen::{gen_bytes32, gen_indexers}; +use crate::types::ProofOfIndexing; /// A wrapper around a [`Store`] that is backed by a containerized Postgres /// database. diff --git a/backend/crates/common/src/test_utils/gen.rs b/backend/crates/common/src/test_utils/gen.rs index f908be0..12ac741 100644 --- a/backend/crates/common/src/test_utils/gen.rs +++ b/backend/crates/common/src/test_utils/gen.rs @@ -6,7 +6,8 @@ use rand::seq::IteratorRandom; use rand::Rng; use super::mocks::{DeploymentDetails, MockIndexer, PartialProofOfIndexing}; -use crate::prelude::{BlockPointer, Bytes32, Indexer, SubgraphDeployment}; +use crate::indexer::Indexer; +use crate::types::{BlockPointer, Bytes32, SubgraphDeployment}; pub fn gen_deployments() -> Vec { vec![ diff --git a/backend/crates/common/src/test_utils/mocks.rs b/backend/crates/common/src/test_utils/mocks.rs index bbdf4bc..115394f 100644 --- a/backend/crates/common/src/test_utils/mocks.rs +++ b/backend/crates/common/src/test_utils/mocks.rs @@ -4,9 +4,10 @@ use std::sync::Arc; use anyhow::anyhow; use async_trait::async_trait; -use crate::prelude::{ - BlockPointer, Bytes32, CachedEthereumCall, EntityChanges, Indexer, IndexerVersion, - IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, +use crate::indexer::{CachedEthereumCall, EntityChanges, Indexer}; +use crate::types::{ + BlockPointer, Bytes32, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, + SubgraphDeployment, }; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/backend/crates/common/tests/indexing_statuses.rs b/backend/crates/common/tests/indexing_statuses.rs index 5a24e6d..5f8bd7f 100644 --- a/backend/crates/common/tests/indexing_statuses.rs +++ b/backend/crates/common/tests/indexing_statuses.rs @@ -1,10 +1,10 @@ use futures::stream::FuturesUnordered; use futures::{future, StreamExt}; use graphix_common::metrics; -use graphix_common::prelude::IndexingStatus; use graphix_common::queries::query_indexing_statuses; use graphix_common::test_utils::fast_rng; use graphix_common::test_utils::gen::*; +use graphix_common::types::IndexingStatus; #[tokio::test] async fn indexing_statuses() { diff --git a/backend/crates/common/tests/it_indexing_statuses.rs b/backend/crates/common/tests/it_indexing_statuses.rs index e8c89bb..7510fab 100644 --- a/backend/crates/common/tests/it_indexing_statuses.rs +++ b/backend/crates/common/tests/it_indexing_statuses.rs @@ -2,7 +2,8 @@ use std::sync::Arc; use std::time::Duration; use graphix_common::config::{IndexerConfig, IndexerUrls}; -use graphix_common::prelude::{Indexer, RealIndexer, SubgraphDeployment}; +use graphix_common::indexer::{Indexer, RealIndexer}; +use graphix_common::types::SubgraphDeployment; use reqwest::Url; /// Test utility function to create a valid `Indexer` from an arbitrary base url. diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/backend/crates/common/tests/it_proofs_of_indexing.rs index c2c8b00..8b2b066 100644 --- a/backend/crates/common/tests/it_proofs_of_indexing.rs +++ b/backend/crates/common/tests/it_proofs_of_indexing.rs @@ -1,10 +1,10 @@ use std::sync::Arc; use std::time::Duration; +use graphix_common::config::IndexerConfig; use graphix_common::config::IndexerUrls; -use graphix_common::prelude::{ - Indexer, IndexerConfig, PoiRequest, RealIndexer, SubgraphDeployment, -}; +use graphix_common::indexer::{Indexer, RealIndexer}; +use graphix_common::types::{PoiRequest, SubgraphDeployment}; use reqwest::Url; /// Test utility function to create a valid `Indexer` from an arbitrary base url. diff --git a/backend/crates/cross-checker/src/bisect.rs b/backend/crates/cross-checker/src/bisect.rs index b53d2ec..eeb65b7 100644 --- a/backend/crates/cross-checker/src/bisect.rs +++ b/backend/crates/cross-checker/src/bisect.rs @@ -5,11 +5,11 @@ use graphix_common::graphql_api::types::{ BisectionReport, BisectionRunReport, DivergenceBlockBounds, DivergenceInvestigationReport, DivergenceInvestigationRequest, DivergenceInvestigationStatus, PartialBlock, }; -use graphix_common::prelude::{ - BlockPointer, DivergingBlock as DivergentBlock, Indexer, IndexerId, PoiRequest, - ProofOfIndexing, SubgraphDeployment, -}; +use graphix_common::indexer::{Indexer, IndexerId}; use graphix_common::store::Store; +use graphix_common::types::{ + BlockPointer, DivergingBlock as DivergentBlock, PoiRequest, ProofOfIndexing, SubgraphDeployment, +}; use thiserror::Error; use tokio::sync::watch; use tracing::{debug, error, info}; diff --git a/backend/crates/cross-checker/src/main.rs b/backend/crates/cross-checker/src/main.rs index ea57565..b3fbc42 100644 --- a/backend/crates/cross-checker/src/main.rs +++ b/backend/crates/cross-checker/src/main.rs @@ -9,7 +9,8 @@ use std::sync::Arc; use std::time::Duration; use clap::Parser; -use graphix_common::prelude::{Config, Indexer}; +use graphix_common::config::Config; +use graphix_common::indexer::Indexer; use graphix_common::queries::{query_indexing_statuses, query_proofs_of_indexing}; use graphix_common::{config, metrics, store, PrometheusExporter}; use prometheus_exporter::prometheus; diff --git a/backend/crates/cross-checker/src/utils.rs b/backend/crates/cross-checker/src/utils.rs index d1adab9..8f066b5 100644 --- a/backend/crates/cross-checker/src/utils.rs +++ b/backend/crates/cross-checker/src/utils.rs @@ -4,7 +4,7 @@ use std::collections::HashSet; use std::hash::Hash; use std::sync::Arc; -use graphix_common::prelude::Indexer; +use graphix_common::indexer::Indexer; use graphix_common::store; use crate::bisect::DivergenceInvestigationError; From 58ef385a15ef64bd843bf0bfdf9096a7a7f2ebbf Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 12:31:07 +0100 Subject: [PATCH 25/34] cargo +nightly fmt --all Signed-off-by: Filippo Costa --- backend/crates/common/src/indexer/interceptor.rs | 3 +-- backend/crates/common/src/indexer/real_indexer.rs | 3 +-- backend/crates/common/tests/it_proofs_of_indexing.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/crates/common/src/indexer/interceptor.rs b/backend/crates/common/src/indexer/interceptor.rs index d0b25fa..5f1650a 100644 --- a/backend/crates/common/src/indexer/interceptor.rs +++ b/backend/crates/common/src/indexer/interceptor.rs @@ -7,8 +7,7 @@ use async_trait::async_trait; use super::{CachedEthereumCall, EntityChanges}; use crate::indexer::Indexer; -use crate::types::Bytes32; -use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::types::{self, Bytes32, IndexingStatus, PoiRequest, ProofOfIndexing}; /// Pretends to be an indexer by routing requests a /// [`RealIndexer`](crate::indexer::RealIndexer) and then intercepting the diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index b7d18d5..01d55ee 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -10,8 +10,7 @@ use serde::Serialize; use tracing::*; use super::{CachedEthereumCall, EntityChanges, Indexer}; -use crate::config::IndexerConfig; -use crate::config::IndexerUrls; +use crate::config::{IndexerConfig, IndexerUrls}; use crate::indexer::WithIndexer; use crate::prometheus_metrics::metrics; use crate::types::{ diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/backend/crates/common/tests/it_proofs_of_indexing.rs index 8b2b066..b480183 100644 --- a/backend/crates/common/tests/it_proofs_of_indexing.rs +++ b/backend/crates/common/tests/it_proofs_of_indexing.rs @@ -1,8 +1,7 @@ use std::sync::Arc; use std::time::Duration; -use graphix_common::config::IndexerConfig; -use graphix_common::config::IndexerUrls; +use graphix_common::config::{IndexerConfig, IndexerUrls}; use graphix_common::indexer::{Indexer, RealIndexer}; use graphix_common::types::{PoiRequest, SubgraphDeployment}; use reqwest::Url; From a01f63119bce29a1cd6ee0c03c554f30f5cb72b5 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 22 Jan 2024 13:59:24 +0100 Subject: [PATCH 26/34] Make indexer addresses non-optional --- .../2023-12-11-181933_new_columns/down.sql | 1 - .../2023-12-11-181933_new_columns/up.sql | 9 ---- .../down.sql | 5 ++ .../2024-01-22-122801_non_null_address/up.sql | 6 +++ backend/crates/common/src/config.rs | 13 ++--- .../crates/common/src/graphql_api/types.rs | 15 ++---- .../crates/common/src/indexer/interceptor.rs | 4 +- backend/crates/common/src/indexer/mod.rs | 50 +++++++------------ .../crates/common/src/indexer/real_indexer.rs | 24 ++++----- .../common/src/network_subgraph_client/mod.rs | 11 ++-- backend/crates/common/src/queries.rs | 16 +++--- .../crates/common/src/store/diesel_queries.rs | 4 +- backend/crates/common/src/store/models.rs | 8 +-- backend/crates/common/src/store/schema.rs | 2 +- backend/crates/common/src/store/tests.rs | 3 +- backend/crates/common/src/test_utils/mocks.rs | 4 +- backend/crates/common/src/types.rs | 37 +++++++++++++- .../common/tests/it_indexing_statuses.rs | 2 +- .../common/tests/it_proofs_of_indexing.rs | 2 +- backend/crates/cross-checker/src/bisect.rs | 8 +-- backend/crates/cross-checker/src/main.rs | 6 +-- backend/crates/cross-checker/src/utils.rs | 2 +- schema.rs | 1 + 23 files changed, 121 insertions(+), 112 deletions(-) delete mode 100644 backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql delete mode 100644 backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql create mode 100644 backend/crates/common/migrations/2024-01-22-122801_non_null_address/down.sql create mode 100644 backend/crates/common/migrations/2024-01-22-122801_non_null_address/up.sql create mode 100644 schema.rs diff --git a/backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql b/backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql deleted file mode 100644 index 291a2c5..0000000 --- a/backend/crates/common/migrations/2023-12-11-181933_new_columns/down.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE TABLE indexer_network_subgraph_entry IF EXISTS; diff --git a/backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql b/backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql deleted file mode 100644 index 46421be..0000000 --- a/backend/crates/common/migrations/2023-12-11-181933_new_columns/up.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE indexer_network_subgraph_entry ( - indexer_id TEXT NOT NULL, - staked_tokens BIGINT NOT NULL, - allocated_tokens BIGINT NOT NULL, - locked_tokens BIGINT NOT NULL, - query_fees_collected BIGINT NOT NULL, - delegated_capacity BIGINT NOT NULL, - available_stake BIGINT NOT NULL -); diff --git a/backend/crates/common/migrations/2024-01-22-122801_non_null_address/down.sql b/backend/crates/common/migrations/2024-01-22-122801_non_null_address/down.sql new file mode 100644 index 0000000..10effc8 --- /dev/null +++ b/backend/crates/common/migrations/2024-01-22-122801_non_null_address/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE + indexers +ALTER COLUMN + address DROP NOT NULL; diff --git a/backend/crates/common/migrations/2024-01-22-122801_non_null_address/up.sql b/backend/crates/common/migrations/2024-01-22-122801_non_null_address/up.sql new file mode 100644 index 0000000..e712116 --- /dev/null +++ b/backend/crates/common/migrations/2024-01-22-122801_non_null_address/up.sql @@ -0,0 +1,6 @@ +ALTER TABLE + indexers +ALTER COLUMN + address +SET + NOT NULL; diff --git a/backend/crates/common/src/config.rs b/backend/crates/common/src/config.rs index 6a28e9a..8795365 100644 --- a/backend/crates/common/src/config.rs +++ b/backend/crates/common/src/config.rs @@ -11,6 +11,7 @@ use tracing::{info, warn}; use crate::block_choice::BlockChoicePolicy; use crate::indexer::{Indexer, IndexerId, IndexerInterceptor, RealIndexer}; use crate::network_subgraph_client::NetworkSubgraphClient; +use crate::types::HexString; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] @@ -97,13 +98,13 @@ pub struct IndexerUrls { #[serde(rename_all = "camelCase")] pub struct IndexerConfig { pub name: Option, - pub address: Option>, + pub address: Vec, pub urls: IndexerUrls, } impl IndexerId for IndexerConfig { - fn address(&self) -> Option<&[u8]> { - self.address.as_deref() + fn address(&self) -> &[u8] { + self.address.as_slice() } fn name(&self) -> Option> { @@ -142,7 +143,7 @@ pub enum NetworkSubgraphQuery { #[serde(rename_all = "camelCase")] pub struct InterceptorConfig { pub name: String, - pub target: String, + pub target: HexString>, pub poi_byte: u8, } @@ -179,7 +180,7 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result anyhow::Result for Indexer { fn from(indexer: models::Indexer) -> Self { - let address = indexer - .address - .map(|addr| format!("0x{}", hex::encode(addr))); + let address_string = indexer.address_string(); Self { - id: if let Some(name) = &indexer.name { - name.clone() - } else if let Some(address) = &address { - address.clone() - } else { - panic!("Indexer has neither name nor address"); - }, + id: address_string.clone(), name: indexer.name, version: None, // TODO - address, + address: Some(address_string), allocated_tokens: None, // TODO: we don't store this in the db yet } } diff --git a/backend/crates/common/src/indexer/interceptor.rs b/backend/crates/common/src/indexer/interceptor.rs index 5f1650a..ff9a817 100644 --- a/backend/crates/common/src/indexer/interceptor.rs +++ b/backend/crates/common/src/indexer/interceptor.rs @@ -34,8 +34,8 @@ impl Indexer for IndexerInterceptor { .map(|name| Cow::Owned(format!("interceptor-{}", name))) } - fn address(&self) -> Option<&[u8]> { - None + fn address(&self) -> &[u8] { + self.target.address() } async fn ping(self: Arc) -> anyhow::Result<()> { diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs index 9625080..12b2cc9 100644 --- a/backend/crates/common/src/indexer/mod.rs +++ b/backend/crates/common/src/indexer/mod.rs @@ -12,32 +12,17 @@ use async_trait::async_trait; pub use interceptor::IndexerInterceptor; pub use real_indexer::RealIndexer; -use crate::types::{self, IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::types::{self, HexString, IndexingStatus, PoiRequest, ProofOfIndexing}; -/// An indexer is a `graph-node` instance that may or may not also be a network -/// participant. +/// An indexer is a `graph-node` instance that can be queried for information. #[async_trait] pub trait Indexer: Send + Sync + Debug { - /// The indexer's address. This can be [`None`] if the indexer is not a - /// network participant but e.g. a local `graph-node` instance. - fn address(&self) -> Option<&[u8]>; + /// The indexer's address. + fn address(&self) -> &[u8]; /// Human-readable name of the indexer. fn name(&self) -> Option>; - /// Within Graphix, an indexer is uniquely identified by its hex-encoded - /// address (if it is a network participant), or its name (if it's not). - /// This is known as the indexer's "global ID" or "GID". - fn id(&self) -> String { - if let Some(address) = self.address() { - hex::encode(address) - } else { - self.name() - .expect("indexer has neither address nor name; this is a bug") - .to_string() - } - } - async fn ping(self: Arc) -> anyhow::Result<()>; async fn indexing_statuses(self: Arc) -> anyhow::Result>; @@ -92,17 +77,13 @@ pub trait Indexer: Send + Sync + Debug { /// one) or its name (if it doesn't have an address i.e. it's not a network /// participant), strictly in this order. pub trait IndexerId { - fn address(&self) -> Option<&[u8]>; + fn address(&self) -> &[u8]; fn name(&self) -> Option>; - fn id(&self) -> String { - if let Some(address) = self.address() { - format!("0x{}", hex::encode(address)) - } else if let Some(name) = self.name() { - name.to_string() - } else { - panic!("Indexer has neither name nor address") - } + /// Returns the string representation of the indexer's address using + /// [`HexString`]. + fn address_string(&self) -> String { + HexString(self.address()).to_string() } } @@ -110,7 +91,7 @@ impl IndexerId for T where T: Indexer, { - fn address(&self) -> Option<&[u8]> { + fn address(&self) -> &[u8] { Indexer::address(self) } @@ -120,7 +101,7 @@ where } impl IndexerId for Arc { - fn address(&self) -> Option<&[u8]> { + fn address(&self) -> &[u8] { Indexer::address(&**self) } @@ -131,7 +112,7 @@ impl IndexerId for Arc { impl PartialEq for dyn Indexer { fn eq(&self, other: &Self) -> bool { - self.id() == other.id() + self.address() == other.address() } } @@ -139,7 +120,10 @@ impl Eq for dyn Indexer {} impl Hash for dyn Indexer { fn hash(&self, state: &mut H) { - self.id().hash(state) + // It's best to hash addresses even though entropy is typically already + // high, because some Graphix configurations may use human-readable + // strings as fake addresses. + self.address().hash(state) } } @@ -151,7 +135,7 @@ impl PartialOrd for dyn Indexer { impl Ord for dyn Indexer { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id().cmp(&other.id()) + self.address().cmp(other.address()) } } diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/backend/crates/common/src/indexer/real_indexer.rs index 01d55ee..5f53a0d 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/backend/crates/common/src/indexer/real_indexer.rs @@ -11,7 +11,7 @@ use tracing::*; use super::{CachedEthereumCall, EntityChanges, Indexer}; use crate::config::{IndexerConfig, IndexerUrls}; -use crate::indexer::WithIndexer; +use crate::indexer::{IndexerId, WithIndexer}; use crate::prometheus_metrics::metrics; use crate::types::{ BlockPointer, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, @@ -21,7 +21,7 @@ const REQUEST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); #[derive(Debug)] pub struct RealIndexer { - address: Option>, + address: Vec, name: Option, urls: IndexerUrls, client: reqwest::Client, @@ -39,10 +39,6 @@ impl RealIndexer { } } - pub fn set_address(&mut self, address: Vec) { - self.address = Some(address); - } - /// Internal utility method to make a GraphQL query to the indexer. `error` /// and `data` fields are treated as mutually exclusive (which is generally /// a good assumption, but some callers may want more control over error @@ -104,8 +100,8 @@ impl RealIndexer { #[async_trait] impl Indexer for RealIndexer { - fn address(&self) -> Option<&[u8]> { - self.address.as_deref() + fn address(&self) -> &[u8] { + self.address.as_slice() } fn name(&self) -> Option> { @@ -133,7 +129,7 @@ impl Indexer for RealIndexer { Ok(status) => statuses.push(status), Err(e) => { warn!( - id = %self.id(), + address = %self.address_string(), %e, %deployment, "Failed to parse indexing status, skipping deployment" @@ -159,7 +155,7 @@ impl Indexer for RealIndexer { // reduces the impact of this issue. for requests in requests.chunks(1) { trace!( - indexer = %self.id(), + indexer = %self.address_string(), batch_size = requests.len(), "Requesting public Pois batch" ); @@ -170,7 +166,7 @@ impl Indexer for RealIndexer { Ok(batch_pois) => { metrics() .public_proofs_of_indexing_requests - .get_metric_with_label_values(&[&self.id(), "1"]) + .get_metric_with_label_values(&[&self.address_string(), "1"]) .unwrap() .inc(); @@ -179,12 +175,12 @@ impl Indexer for RealIndexer { Err(error) => { metrics() .public_proofs_of_indexing_requests - .get_metric_with_label_values(&[&self.id(), "0"]) + .get_metric_with_label_values(&[&self.address_string(), "0"]) .unwrap() .inc(); debug!( - id = %self.id(), %error, + id = %self.address_string(), %error, "Failed to query POIs batch from indexer" ); @@ -193,7 +189,7 @@ impl Indexer for RealIndexer { .contains(r#"Cannot query field "publicProofsOfIndexing" on type "Query""#) { debug!( - id = %self.id(), + id = %self.address_string(), "Indexer doesn't seem to support 'publicProofsOfIndexing', skipping it" ); break; diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/backend/crates/common/src/network_subgraph_client/mod.rs index 32f236a..f131b43 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/backend/crates/common/src/network_subgraph_client/mod.rs @@ -99,7 +99,7 @@ impl NetworkSubgraphClient { let address = hex::decode(indexer.id.trim_start_matches("0x"))?; let real_indexer = RealIndexer::new(IndexerConfig { name: indexer.default_display_name, - address: Some(address), + address, urls: IndexerUrls { status: Url::parse(&format!("{}/status", url))?, }, @@ -155,14 +155,13 @@ impl NetworkSubgraphClient { anyhow::anyhow!("No indexer found for address 0x{}", hex::encode(address)) })?; - let mut indexer = RealIndexer::new(IndexerConfig { + let indexer = RealIndexer::new(IndexerConfig { name: Some(indexer_data.default_display_name.clone()), - address: Some(address.to_vec()), + address: address.to_vec(), urls: IndexerUrls { status: Url::parse(&format!("{}/status", indexer_data.url))?, }, }); - indexer.set_address(address.to_vec()); Ok(Arc::new(indexer)) } @@ -267,7 +266,7 @@ fn indexer_allocation_data_to_real_indexer( url.set_path("/status"); let config = IndexerConfig { name, - address: Some(address), + address, urls: IndexerUrls { status: url }, }; Ok(RealIndexer::new(config)) @@ -388,6 +387,6 @@ mod tests { // htps://thegraph.com/explorer/profile/0x62a0bd1d110ff4e5b793119e95fc07c9d1fc8c4a?view=Indexing&chain=mainnet let address = hex::decode("62a0bd1d110ff4e5b793119e95fc07c9d1fc8c4a").unwrap(); let indexer = client.indexer_by_address(&address).await.unwrap(); - assert_eq!(indexer.address(), Some(&address[..])); + assert_eq!(indexer.address(), address); } } diff --git a/backend/crates/common/src/queries.rs b/backend/crates/common/src/queries.rs index 00180b8..1912492 100644 --- a/backend/crates/common/src/queries.rs +++ b/backend/crates/common/src/queries.rs @@ -6,7 +6,7 @@ use futures::StreamExt; use tracing::*; use crate::block_choice::BlockChoicePolicy; -use crate::indexer::Indexer; +use crate::indexer::{Indexer, IndexerId}; use crate::types::{ IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, }; @@ -39,12 +39,12 @@ pub async fn query_indexing_statuses( query_successes += 1; metrics .indexing_statuses_requests - .get_metric_with_label_values(&[&indexer.id(), "1"]) + .get_metric_with_label_values(&[&indexer.address_string(), "1"]) .unwrap() .inc(); debug!( - indexer_id = %indexer.id(), + indexer_id = %indexer.address_string(), statuses = %statuses.len(), "Successfully queried indexing statuses" ); @@ -55,12 +55,12 @@ pub async fn query_indexing_statuses( query_failures += 1; metrics .indexing_statuses_requests - .get_metric_with_label_values(&[&indexer.id(), "0"]) + .get_metric_with_label_values(&[&indexer.address_string(), "0"]) .unwrap() .inc(); debug!( - indexer_id = %indexer.id(), + indexer_id = %indexer.address_string(), %error, "Failed to query indexing statuses" ); @@ -101,7 +101,7 @@ pub async fn query_graph_node_versions( match &version_result { Ok(version) => { trace!( - indexer_id = %indexer.id(), + indexer_id = %indexer.address_string(), version = %version.version, commit = %version.commit, "Successfully queried graph-node version" @@ -109,7 +109,7 @@ pub async fn query_graph_node_versions( } Err(error) => { trace!( - indexer_id = %indexer.id(), + indexer_id = %indexer.address_string(), %error, "Failed to query graph-node version" ); @@ -198,7 +198,7 @@ pub async fn query_proofs_of_indexing( let pois = indexer.clone().proofs_of_indexing(poi_requests).await; debug!( - id = %indexer.id(), pois = %pois.len(), + id = %indexer.address_string(), pois = %pois.len(), "Successfully queried POIs from indexer" ); diff --git a/backend/crates/common/src/store/diesel_queries.rs b/backend/crates/common/src/store/diesel_queries.rs index 031c5d7..41e1d5a 100644 --- a/backend/crates/common/src/store/diesel_queries.rs +++ b/backend/crates/common/src/store/diesel_queries.rs @@ -129,7 +129,7 @@ pub fn write_indexers( .map(|indexer| { let indexer = indexer.as_ref(); NewIndexer { - address: indexer.address().map(ToOwned::to_owned), + address: indexer.address().to_owned(), name: indexer.name().map(|s| s.to_string()), } }) @@ -317,7 +317,7 @@ pub fn write_graph_node_version( fn get_indexer_id( conn: &mut PgConnection, name: Option>, - address: Option<&[u8]>, + address: &[u8], ) -> anyhow::Result { use schema::indexers; diff --git a/backend/crates/common/src/store/models.rs b/backend/crates/common/src/store/models.rs index 010e5c5..20ae46c 100644 --- a/backend/crates/common/src/store/models.rs +++ b/backend/crates/common/src/store/models.rs @@ -82,14 +82,14 @@ pub struct NewBlock { pub struct Indexer { pub id: IntId, pub name: Option, - pub address: Option>, + pub address: Vec, #[serde(skip)] pub created_at: NaiveDateTime, } impl IndexerId for Indexer { - fn address(&self) -> Option<&[u8]> { - self.address.as_deref() + fn address(&self) -> &[u8] { + self.address.as_slice() } fn name(&self) -> Option> { @@ -100,7 +100,7 @@ impl IndexerId for Indexer { #[derive(Debug, Insertable)] #[diesel(table_name = indexers)] pub struct NewIndexer { - pub address: Option>, + pub address: Vec, pub name: Option, } diff --git a/backend/crates/common/src/store/schema.rs b/backend/crates/common/src/store/schema.rs index 9e6c0cf..5d4549b 100644 --- a/backend/crates/common/src/store/schema.rs +++ b/backend/crates/common/src/store/schema.rs @@ -32,7 +32,7 @@ diesel::table! { indexers (id) { id -> Int4, name -> Nullable, - address -> Nullable, + address -> Bytea, created_at -> Timestamp, } } diff --git a/backend/crates/common/src/store/tests.rs b/backend/crates/common/src/store/tests.rs index 4ddfaa7..8c61086 100644 --- a/backend/crates/common/src/store/tests.rs +++ b/backend/crates/common/src/store/tests.rs @@ -7,6 +7,7 @@ use testcontainers::Container; use crate::block_choice::BlockChoicePolicy; use crate::graphql_api::types::SgDeploymentsQuery; +use crate::indexer::IndexerId; use crate::prometheus_metrics::metrics; use crate::queries; use crate::store::{diesel_queries, PoiLiveness, Store}; @@ -176,7 +177,7 @@ fn test_pois( .map(|poi| { ( poi.deployment.0.clone(), - poi.indexer.id().to_owned(), + poi.indexer.address_string(), poi.proof_of_indexing.0.to_vec(), ) }) diff --git a/backend/crates/common/src/test_utils/mocks.rs b/backend/crates/common/src/test_utils/mocks.rs index 115394f..9c6b8ed 100644 --- a/backend/crates/common/src/test_utils/mocks.rs +++ b/backend/crates/common/src/test_utils/mocks.rs @@ -32,8 +32,8 @@ impl Indexer for MockIndexer { Some(Cow::Borrowed(&self.name)) } - fn address(&self) -> Option<&[u8]> { - None + fn address(&self) -> &[u8] { + self.name.as_bytes() } async fn indexing_statuses(self: Arc) -> Result, anyhow::Error> { diff --git a/backend/crates/common/src/types.rs b/backend/crates/common/src/types.rs index 6b3d316..3ccb179 100644 --- a/backend/crates/common/src/types.rs +++ b/backend/crates/common/src/types.rs @@ -1,13 +1,46 @@ -use std::fmt; +use std::fmt::{self, Display}; use std::ops::Deref; use std::sync::Arc; use async_graphql::SimpleObject; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use crate::indexer::Indexer; use crate::store::models::WritablePoi; +#[derive(Copy, Clone, Debug)] +pub struct HexString(pub T); + +impl> Display for HexString { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "0x{}", hex::encode(self.0.as_ref())) + } +} + +impl> Serialize for HexString { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.collect_str(&self) + } +} + +impl<'a> Deserialize<'a> for HexString> { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'a>, + { + let s = String::deserialize(deserializer)?; + if !s.starts_with("0x") { + return Err(serde::de::Error::custom("hexstring must start with 0x")); + } + hex::decode(&s[2..]) + .map(Self) + .map_err(serde::de::Error::custom) + } +} + #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd, SimpleObject)] pub struct IndexerVersion { pub version: String, diff --git a/backend/crates/common/tests/it_indexing_statuses.rs b/backend/crates/common/tests/it_indexing_statuses.rs index 7510fab..e3039fa 100644 --- a/backend/crates/common/tests/it_indexing_statuses.rs +++ b/backend/crates/common/tests/it_indexing_statuses.rs @@ -11,7 +11,7 @@ fn test_indexer_from_url(url: impl Into) -> Arc { let url: Url = url.into().parse().expect("Invalid status url"); let conf = IndexerConfig { name: Some(url.host().unwrap().to_string()), - address: None, + address: url.as_str().as_bytes().to_owned(), urls: IndexerUrls { status: url.join("status").unwrap(), }, diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/backend/crates/common/tests/it_proofs_of_indexing.rs index b480183..c5a30dc 100644 --- a/backend/crates/common/tests/it_proofs_of_indexing.rs +++ b/backend/crates/common/tests/it_proofs_of_indexing.rs @@ -11,7 +11,7 @@ fn test_indexer_from_url(url: impl Into) -> Arc { let url: Url = url.into().parse().expect("Invalid status url"); let conf = IndexerConfig { name: Some(url.host().unwrap().to_string()), - address: None, + address: url.as_str().as_bytes().to_owned(), urls: IndexerUrls { status: url.join("status").unwrap(), }, diff --git a/backend/crates/cross-checker/src/bisect.rs b/backend/crates/cross-checker/src/bisect.rs index eeb65b7..fcc2f62 100644 --- a/backend/crates/cross-checker/src/bisect.rs +++ b/backend/crates/cross-checker/src/bisect.rs @@ -311,7 +311,7 @@ async fn handle_divergence_investigation_request_pair( debug!(req_uuid = req_uuid_str, poi1 = %poi1_s, poi2 = %poi2_s, "Fetching indexers"); let indexer1 = match indexers .iter() - .find(|indexer| indexer.id() == poi1.indexer.id()) + .find(|indexer| indexer.address() == poi1.indexer.address()) .cloned() .ok_or(DivergenceInvestigationError::IndexerNotFound { poi: poi1_s.to_string(), @@ -324,7 +324,7 @@ async fn handle_divergence_investigation_request_pair( }; let indexer2 = match indexers .iter() - .find(|indexer| indexer.id() == poi2.indexer.id()) + .find(|indexer| indexer.address() == poi2.indexer.address()) .cloned() .ok_or(DivergenceInvestigationError::IndexerNotFound { poi: poi2_s.to_string(), @@ -337,10 +337,10 @@ async fn handle_divergence_investigation_request_pair( }; debug!(req_uuid = req_uuid_str, poi1 = %poi1_s, poi2 = %poi2_s, "Fetched indexers"); - if indexer1.id() == indexer2.id() { + if indexer1.address() == indexer2.address() { report.error = Some( DivergenceInvestigationError::SameIndexer { - indexer_id: indexer1.id().to_string(), + indexer_id: indexer1.address_string(), } .to_string(), ); diff --git a/backend/crates/cross-checker/src/main.rs b/backend/crates/cross-checker/src/main.rs index b3fbc42..43f6d62 100644 --- a/backend/crates/cross-checker/src/main.rs +++ b/backend/crates/cross-checker/src/main.rs @@ -10,7 +10,7 @@ use std::time::Duration; use clap::Parser; use graphix_common::config::Config; -use graphix_common::indexer::Indexer; +use graphix_common::indexer::{Indexer, IndexerId}; use graphix_common::queries::{query_indexing_statuses, query_proofs_of_indexing}; use graphix_common::{config, metrics, store, PrometheusExporter}; use prometheus_exporter::prometheus; @@ -100,9 +100,9 @@ fn deduplicate_indexers(indexers: &[Arc]) -> Vec> let mut seen = HashSet::new(); let mut deduplicated = vec![]; for indexer in indexers { - if !seen.contains(&indexer.id()) { + if !seen.contains(indexer.address()) { deduplicated.push(indexer.clone()); - seen.insert(indexer.id().to_string()); + seen.insert(indexer.address()); } } info!( diff --git a/backend/crates/cross-checker/src/utils.rs b/backend/crates/cross-checker/src/utils.rs index 8f066b5..65aaf1a 100644 --- a/backend/crates/cross-checker/src/utils.rs +++ b/backend/crates/cross-checker/src/utils.rs @@ -38,7 +38,7 @@ pub fn find_any_indexer_for_poi( let indexer_opt = indexers .iter() - .find(|indexer| indexer.address() == poi.indexer.address.as_deref()) + .find(|indexer| indexer.address() == poi.indexer.address) .cloned(); Ok(indexer_opt) diff --git a/schema.rs b/schema.rs new file mode 100644 index 0000000..363ebf0 --- /dev/null +++ b/schema.rs @@ -0,0 +1 @@ +The --database-url argument must be passed, or the DATABASE_URL environment variable must be set. From 928212ab50681f674b5074dfa0e5a8a86a70f128 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 09:11:40 +0100 Subject: [PATCH 27/34] wip refactor Signed-off-by: Filippo Costa --- Cargo.lock | 2672 +++-------------- Cargo.toml | 2 +- .../api-server => api-server}/Cargo.toml | 2 +- .../api-server => api-server}/src/main.rs | 0 .../Cargo.toml | 4 +- .../build.rs | 0 .../graphql/api_schema.graphql | 0 .../src/lib.rs | 0 backend/crates/common/Cargo.toml | 47 - backend/crates/common/src/indexer/mod.rs | 167 -- crates/indexer-client/Cargo.toml | 19 + .../common => crates/indexer-client}/build.rs | 0 .../graphql/indexer/queries/block-data.gql | 0 .../indexer/queries/cached-eth-calls.gql | 0 .../queries/entity-changes-in-block.gql | 0 .../indexer/queries/indexer-version.gql | 0 .../indexer/queries/indexing-statuses.gql | 0 .../graphql/indexer/queries/pois.gql | 0 .../indexer/queries/subgraph-api-versions.gql | 0 .../graphql/indexer/queries/typename.gql | 0 .../graphql/indexer/schema.gql | 0 .../graphql/touch-this-file-to-refetch-schema | 0 .../indexer-client/src}/interceptor.rs | 6 +- crates/indexer-client/src/lib.rs | 346 +++ .../indexer-client/src}/real_indexer.rs | 36 +- crates/network-sg-client/Cargo.toml | 17 + .../network-sg-client/src/lib.rs | 41 +- .../src}/queries/deployments.graphql | 0 .../src}/queries/indexer_by_address.graphql | 0 .../queries/indexers_by_allocations.graphql | 0 .../queries/indexers_by_staked_tokens.graphql | 0 .../Cargo.toml | 4 +- .../src/bisect.rs | 0 .../src/main.rs | 0 .../src/utils.rs | 0 graphix-lib/Cargo.toml | 17 + .../src/block_choice.rs | 0 .../common => graphix-lib}/src/config.rs | 0 .../src/graphql_api/mod.rs | 0 .../src/graphql_api/server.rs | 0 .../src/graphql_api/types.rs | 0 .../crates/common => graphix-lib}/src/lib.rs | 0 .../src/prometheus_metrics.rs | 0 .../common => graphix-lib}/src/queries.rs | 0 .../src/test_utils/gen.rs | 0 .../src/test_utils/mocks.rs | 0 .../src/test_utils/mod.rs | 0 .../common => graphix-lib}/src/types.rs | 0 .../tests/indexing_statuses.rs | 0 .../tests/it_indexing_statuses.rs | 0 .../tests/it_proofs_of_indexing.rs | 0 .../tests/proofs_of_indexing.rs | 0 store/Cargo.toml | 4 + {backend/crates/common => store}/diesel.toml | 0 .../down.sql | 0 .../up.sql | 0 .../2023-03-30-000000_initial_schema/down.sql | 0 .../2023-03-30-000000_initial_schema/up.sql | 0 .../2023-05-26-125000_caip2/down.sql | 0 .../migrations/2023-05-26-125000_caip2/up.sql | 0 .../2023-10-09-122825_cleanup/down.sql | 0 .../2023-10-09-122825_cleanup/up.sql | 0 .../2023-12-04-133234_versions/down.sql | 0 .../2023-12-04-133234_versions/up.sql | 0 .../down.sql | 0 .../2024-01-22-122801_non_null_address/up.sql | 0 .../src/store => store/src}/diesel_queries.rs | 0 .../src/store/mod.rs => store/src/lib.rs | 0 .../common/src/store => store/src}/models.rs | 0 .../common/src/store => store/src}/schema.rs | 0 .../common/src/store => store/src}/tests.rs | 0 71 files changed, 916 insertions(+), 2468 deletions(-) rename {backend/crates/api-server => api-server}/Cargo.toml (92%) rename {backend/crates/api-server => api-server}/src/main.rs (100%) rename {backend/crates/schema => autogen_graphql_schema}/Cargo.toml (51%) rename {backend/crates/schema => autogen_graphql_schema}/build.rs (100%) rename {backend/crates/schema => autogen_graphql_schema}/graphql/api_schema.graphql (100%) rename {backend/crates/schema => autogen_graphql_schema}/src/lib.rs (100%) delete mode 100644 backend/crates/common/Cargo.toml delete mode 100644 backend/crates/common/src/indexer/mod.rs create mode 100644 crates/indexer-client/Cargo.toml rename {backend/crates/common => crates/indexer-client}/build.rs (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/block-data.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/cached-eth-calls.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/entity-changes-in-block.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/indexer-version.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/indexing-statuses.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/pois.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/subgraph-api-versions.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/queries/typename.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/indexer/schema.gql (100%) rename {backend/crates/common => crates/indexer-client}/graphql/touch-this-file-to-refetch-schema (100%) rename {backend/crates/common/src/indexer => crates/indexer-client/src}/interceptor.rs (94%) create mode 100644 crates/indexer-client/src/lib.rs rename {backend/crates/common/src/indexer => crates/indexer-client/src}/real_indexer.rs (95%) create mode 100644 crates/network-sg-client/Cargo.toml rename backend/crates/common/src/network_subgraph_client/mod.rs => crates/network-sg-client/src/lib.rs (93%) rename {backend/crates/common/src/network_subgraph_client => crates/network-sg-client/src}/queries/deployments.graphql (100%) rename {backend/crates/common/src/network_subgraph_client => crates/network-sg-client/src}/queries/indexer_by_address.graphql (100%) rename {backend/crates/common/src/network_subgraph_client => crates/network-sg-client/src}/queries/indexers_by_allocations.graphql (100%) rename {backend/crates/common/src/network_subgraph_client => crates/network-sg-client/src}/queries/indexers_by_staked_tokens.graphql (100%) rename {backend/crates/cross-checker => cross-checker}/Cargo.toml (88%) rename {backend/crates/cross-checker => cross-checker}/src/bisect.rs (100%) rename {backend/crates/cross-checker => cross-checker}/src/main.rs (100%) rename {backend/crates/cross-checker => cross-checker}/src/utils.rs (100%) create mode 100644 graphix-lib/Cargo.toml rename {backend/crates/common => graphix-lib}/src/block_choice.rs (100%) rename {backend/crates/common => graphix-lib}/src/config.rs (100%) rename {backend/crates/common => graphix-lib}/src/graphql_api/mod.rs (100%) rename {backend/crates/common => graphix-lib}/src/graphql_api/server.rs (100%) rename {backend/crates/common => graphix-lib}/src/graphql_api/types.rs (100%) rename {backend/crates/common => graphix-lib}/src/lib.rs (100%) rename {backend/crates/common => graphix-lib}/src/prometheus_metrics.rs (100%) rename {backend/crates/common => graphix-lib}/src/queries.rs (100%) rename {backend/crates/common => graphix-lib}/src/test_utils/gen.rs (100%) rename {backend/crates/common => graphix-lib}/src/test_utils/mocks.rs (100%) rename {backend/crates/common => graphix-lib}/src/test_utils/mod.rs (100%) rename {backend/crates/common => graphix-lib}/src/types.rs (100%) rename {backend/crates/common => graphix-lib}/tests/indexing_statuses.rs (100%) rename {backend/crates/common => graphix-lib}/tests/it_indexing_statuses.rs (100%) rename {backend/crates/common => graphix-lib}/tests/it_proofs_of_indexing.rs (100%) rename {backend/crates/common => graphix-lib}/tests/proofs_of_indexing.rs (100%) create mode 100644 store/Cargo.toml rename {backend/crates/common => store}/diesel.toml (100%) rename {backend/crates/common => store}/migrations/00000000000000_diesel_initial_setup/down.sql (100%) rename {backend/crates/common => store}/migrations/00000000000000_diesel_initial_setup/up.sql (100%) rename {backend/crates/common => store}/migrations/2023-03-30-000000_initial_schema/down.sql (100%) rename {backend/crates/common => store}/migrations/2023-03-30-000000_initial_schema/up.sql (100%) rename {backend/crates/common => store}/migrations/2023-05-26-125000_caip2/down.sql (100%) rename {backend/crates/common => store}/migrations/2023-05-26-125000_caip2/up.sql (100%) rename {backend/crates/common => store}/migrations/2023-10-09-122825_cleanup/down.sql (100%) rename {backend/crates/common => store}/migrations/2023-10-09-122825_cleanup/up.sql (100%) rename {backend/crates/common => store}/migrations/2023-12-04-133234_versions/down.sql (100%) rename {backend/crates/common => store}/migrations/2023-12-04-133234_versions/up.sql (100%) rename {backend/crates/common => store}/migrations/2024-01-22-122801_non_null_address/down.sql (100%) rename {backend/crates/common => store}/migrations/2024-01-22-122801_non_null_address/up.sql (100%) rename {backend/crates/common/src/store => store/src}/diesel_queries.rs (100%) rename backend/crates/common/src/store/mod.rs => store/src/lib.rs (100%) rename {backend/crates/common/src/store => store/src}/models.rs (100%) rename {backend/crates/common/src/store => store/src}/schema.rs (100%) rename {backend/crates/common/src/store => store/src}/tests.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 7c0f983..abd8e9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,101 +13,29 @@ dependencies = [ ] [[package]] -name = "ahash" -version = "0.7.6" +name = "addr2line" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ - "getrandom", - "once_cell", - "version_check", + "gimli", ] [[package]] -name = "ahash" -version = "0.8.7" +name = "adler" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anstream" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is-terminal", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" - -[[package]] -name = "anstyle-parse" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys 0.48.0", -] - -[[package]] -name = "anstyle-wincon" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd" -dependencies = [ - "anstyle", - "windows-sys 0.48.0", -] - [[package]] name = "anyhow" version = "1.0.70" @@ -120,12 +48,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" -[[package]] -name = "ascii" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" - [[package]] name = "ascii_utils" version = "0.9.3" @@ -150,7 +72,7 @@ dependencies = [ "futures-util", "handlebars", "http 1.0.0", - "indexmap 2.1.0", + "indexmap", "mime", "multer", "num-traits", @@ -165,24 +87,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "async-graphql-axum" -version = "7.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3415c9dbaf54397292da0bb81a907e2b989661ce068e4ccfebac33dc9e245e" -dependencies = [ - "async-graphql", - "async-trait", - "axum", - "bytes", - "futures-util", - "serde_json", - "tokio", - "tokio-stream", - "tokio-util", - "tower-service", -] - [[package]] name = "async-graphql-derive" version = "7.0.1" @@ -191,8 +95,8 @@ checksum = "a6a7349168b79030e3172a620f4f0e0062268a954604e41475eff082380fe505" dependencies = [ "Inflector", "async-graphql-parser", - "darling 0.20.3", - "proc-macro-crate 1.3.1", + "darling", + "proc-macro-crate", "proc-macro2", "quote", "strum", @@ -219,7 +123,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cf4d4e86208f4f9b81a503943c07e6e7f29ad3505e6c9ce6431fe64dc241681" dependencies = [ "bytes", - "indexmap 2.1.0", + "indexmap", "serde", "serde_json", ] @@ -257,15 +161,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "atoi" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" -dependencies = [ - "num-traits", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -273,69 +168,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "axum" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" -dependencies = [ - "async-trait", - "axum-core", - "base64 0.21.0", - "bytes", - "futures-util", - "http 1.0.0", - "http-body 1.0.0", - "http-body-util", - "hyper 1.1.0", - "hyper-util", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "serde_json", - "serde_path_to_error", - "serde_urlencoded", - "sha1", - "sync_wrapper", - "tokio", - "tokio-tungstenite", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "axum-core" -version = "0.4.3" +name = "backtrace" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http 1.0.0", - "http-body 1.0.0", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", - "tracing", + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", ] -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.13.1" @@ -344,9 +190,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.0" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bitflags" @@ -354,6 +200,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + [[package]] name = "block-buffer" version = "0.10.4" @@ -363,27 +215,11 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bollard-stubs" -version = "1.42.0-rc.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864" -dependencies = [ - "serde", - "serde_with", -] - [[package]] name = "bumpalo" -version = "3.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" - -[[package]] -name = "by_address" -version = "1.1.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8dba2868114ed769a1f2590fc9ae5eb331175b44313b6c9b922f8f7ca813d0" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byteorder" @@ -393,18 +229,21 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" dependencies = [ "serde", ] [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -413,600 +252,224 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "chrono" -version = "0.4.24" +name = "combine" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" +checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" dependencies = [ - "iana-time-zone", - "js-sys", - "num-integer", - "num-traits", - "time 0.1.45", - "wasm-bindgen", - "winapi", + "ascii", + "byteorder", + "either", + "memchr", + "unreachable", ] [[package]] -name = "chunked_transfer" -version = "1.4.1" +name = "core-foundation" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cca491388666e04d7248af3f60f0c40cfb0991c72205595d7c396e3510207d1a" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] -name = "clap" -version = "4.2.2" +name = "core-foundation-sys" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b802d85aaf3a1cdb02b224ba472ebdea62014fccfcb269b95a4d76443b5ee5a" -dependencies = [ - "clap_builder", - "clap_derive", - "once_cell", -] +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] -name = "clap_builder" -version = "4.2.2" +name = "cpufeatures" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14a1a858f532119338887a4b8e1af9c60de8249cd7bafd68036a489e261e37b6" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ - "anstream", - "anstyle", - "bitflags", - "clap_lex", - "strsim", + "libc", ] [[package]] -name = "clap_derive" -version = "4.2.0" +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.48", + "generic-array", + "typenum", ] [[package]] -name = "clap_lex" -version = "0.4.1" +name = "darling" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] [[package]] -name = "codespan-reporting" -version = "0.11.1" +name = "darling_core" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" dependencies = [ - "termcolor", - "unicode-width", + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.48", ] [[package]] -name = "colorchoice" -version = "1.0.0" +name = "darling_macro" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.48", +] [[package]] -name = "combine" -version = "3.8.1" +name = "digest" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "ascii 0.9.3", - "byteorder", - "either", - "memchr", - "unreachable", + "block-buffer", + "crypto-common", ] [[package]] -name = "core-foundation" -version = "0.9.3" +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "encoding_rs" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ - "core-foundation-sys", - "libc", + "cfg-if", ] [[package]] -name = "core-foundation-sys" -version = "0.8.4" +name = "equivalent" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "cpufeatures" -version = "0.2.6" +name = "errno" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", + "windows-sys 0.52.0", ] [[package]] -name = "crc" -version = "3.0.1" +name = "fast_chemail" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "495a39d30d624c2caabe6312bfead73e7717692b44e0b32df168c275a2e8e9e4" dependencies = [ - "crc-catalog", + "ascii_utils", ] [[package]] -name = "crc-catalog" -version = "2.2.0" +name = "fastrand" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] -name = "crossbeam-queue" -version = "0.3.8" +name = "fnv" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] -name = "crossbeam-utils" -version = "0.8.16" +name = "foreign-types" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "cfg-if", + "foreign-types-shared", ] [[package]] -name = "crypto-common" -version = "0.1.6" +name = "foreign-types-shared" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] -name = "cxx" -version = "1.0.94" +name = "form_urlencoded" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", + "percent-encoding", ] [[package]] -name = "cxx-build" -version = "1.0.94" +name = "futures-channel" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn 2.0.48", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core 0.13.4", - "darling_macro 0.13.4", -] - -[[package]] -name = "darling" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" -dependencies = [ - "darling_core 0.20.3", - "darling_macro 0.20.3", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_core" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 2.0.48", -] - -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core 0.13.4", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" -dependencies = [ - "darling_core 0.20.3", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "data-encoding" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" - -[[package]] -name = "data-encoding-macro" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c904b33cc60130e1aeea4956ab803d08a3f4a0ca82d64ed757afac3891f2bb99" -dependencies = [ - "data-encoding", - "data-encoding-macro-internal", -] - -[[package]] -name = "data-encoding-macro-internal" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdf3fce3ce863539ec1d7fd1b6dcc3c645663376b43ed376bbf887733e4f772" -dependencies = [ - "data-encoding", - "syn 1.0.109", -] - -[[package]] -name = "diesel" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4391a22b19c916e50bec4d6140f29bdda3e3bb187223fe6e3ea0b6e4d1021c04" -dependencies = [ - "bitflags", - "byteorder", - "chrono", - "diesel_derives", - "itoa", - "pq-sys", - "r2d2", - "serde_json", -] - -[[package]] -name = "diesel_derives" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad74fdcf086be3d4fdd142f67937678fe60ed431c3b2f08599e7687269410c4" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "diesel_migrations" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9ae22beef5e9d6fab9225ddb073c1c6c1a7a6ded5019d5da11d1e5c5adc34e2" -dependencies = [ - "diesel", - "migrations_internals", - "migrations_macros", -] - -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", - "subtle", -] - -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "either" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" - -[[package]] -name = "encoding_rs" -version = "0.8.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "env_logger" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "eventuals" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0450e5c57135f799007162ff8beba7b2809d4a018cf9cdcbca2c319a73d9d8ee" -dependencies = [ - "by_address", - "futures", - "never", - "tokio", -] - -[[package]] -name = "fast_chemail" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "495a39d30d624c2caabe6312bfead73e7717692b44e0b32df168c275a2e8e9e4" -dependencies = [ - "ascii_utils", -] - -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", + "futures-core", ] [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-intrusive" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot 0.11.2", -] +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", "syn 2.0.48", ] -[[package]] -name = "futures-retry" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde5a672a61f96552aa5ed9fd9c81c3fbdae4be9b1e205d6eaf17c83705adc0f" -dependencies = [ - "futures", - "pin-project-lite", - "tokio", -] - [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ - "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -1029,99 +492,40 @@ dependencies = [ ] [[package]] -name = "getrandom" -version = "0.2.9" +name = "gimli" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] - -[[package]] -name = "graphix-api-server" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-graphql", - "async-graphql-axum", - "axum", - "clap", - "graphix-common", - "serde_json", - "tokio", - "tracing", - "tracing-subscriber", -] +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] -name = "graphix-common" +name = "graphix_indexer_client" version = "0.1.0" dependencies = [ "anyhow", "async-graphql", "async-trait", - "chrono", - "diesel", - "diesel_migrations", - "eventuals", - "futures", - "futures-retry", - "graphix-common", "graphql_client", "hex", - "itertools", - "once_cell", "prometheus", - "prometheus_exporter", - "quickcheck", - "quickcheck_macros", - "rand", "reqwest", "serde", - "serde_derive", "serde_json", - "serde_yaml", - "sqlx", - "testcontainers", - "testcontainers-modules", - "tiny-cid", - "tokio", "tracing", - "uuid 1.3.3", ] [[package]] -name = "graphix-cross-checker" +name = "graphix_network_sg_client" version = "0.1.0" dependencies = [ "anyhow", - "async-trait", - "clap", - "eventuals", - "futures", - "graphix-common", + "graphix_indexer_client", "hex", - "nanoid", - "once_cell", - "prometheus_exporter", - "rand", + "prometheus", + "reqwest", + "serde", "serde_json", - "thiserror", "tokio", "tracing", - "tracing-subscriber", - "tracing-test", - "uuid 0.8.2", -] - -[[package]] -name = "graphix-schema" -version = "0.1.0" -dependencies = [ - "async-graphql", - "graphix-common", ] [[package]] @@ -1145,9 +549,9 @@ dependencies = [ [[package]] name = "graphql_client" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa61bb9dc6d373a8b465a5da17b62809483e8527a34b0e9034dc0915b09e160a" +checksum = "09cdf7b487d864c2939b23902291a5041bc4a84418268f25fda1c8d4e15ad8fa" dependencies = [ "graphql_query_derive", "serde", @@ -1156,9 +560,9 @@ dependencies = [ [[package]] name = "graphql_client_codegen" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e55df64cc702c4ad6647f8df13a799ad11688a3781fadf5045f7ba12733fa9b" +checksum = "a40f793251171991c4eb75bd84bc640afa8b68ff6907bc89d3b712a22f700506" dependencies = [ "graphql-introspection-query", "graphql-parser", @@ -1173,9 +577,9 @@ dependencies = [ [[package]] name = "graphql_query_derive" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52fc9cde811f44b15ec0692b31e56a3067f6f431c5ace712f286e47c1dacc98" +checksum = "00bda454f3d313f909298f626115092d348bc231025699f557b27e248475f48c" dependencies = [ "graphql_client_codegen", "proc-macro2", @@ -1184,36 +588,17 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66b91535aa35fea1523ad1b86cb6b53c28e0ae566ba4a460f4457e936cad7c6f" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.9", - "indexmap 1.9.3", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "h2" -version = "0.4.2" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" dependencies = [ "bytes", "fnv", "futures-core", "futures-sink", "futures-util", - "http 1.0.0", - "indexmap 2.1.0", + "http 0.2.11", + "indexmap", "slab", "tokio", "tokio-util", @@ -1222,9 +607,9 @@ dependencies = [ [[package]] name = "handlebars" -version = "4.3.6" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "035ef95d03713f2c347a72547b7cd38cbc9af7cd51e6099fb62d586d4a6dee3a" +checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225" dependencies = [ "log", "pest", @@ -1234,54 +619,23 @@ dependencies = [ "thiserror", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash 0.8.7", - "allocator-api2", -] - -[[package]] -name = "hashlink" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" -dependencies = [ - "hashbrown 0.14.3", -] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "hex" @@ -1289,29 +643,11 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hkdf" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "http" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" dependencies = [ "bytes", "fnv", @@ -1331,35 +667,12 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http 0.2.9", - "pin-project-lite", -] - -[[package]] -name = "http-body" -version = "1.0.0" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http 1.0.0", -] - -[[package]] -name = "http-body-util" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" -dependencies = [ - "bytes", - "futures-util", - "http 1.0.0", - "http-body 1.0.0", + "http 0.2.11", "pin-project-lite", ] @@ -1371,53 +684,34 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.25" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", "futures-core", "futures-util", - "h2 0.3.17", - "http 0.2.9", - "http-body 0.4.5", + "h2", + "http 0.2.11", + "http-body", "httparse", "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2", "tokio", "tower-service", "tracing", "want", ] -[[package]] -name = "hyper" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2 0.4.2", - "http 1.0.0", - "http-body 1.0.0", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "tokio", -] - [[package]] name = "hyper-tls" version = "0.5.0" @@ -1425,138 +719,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.25", + "hyper", "native-tls", - "tokio", - "tokio-native-tls", -] - -[[package]] -name = "hyper-util" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http 1.0.0", - "http-body 1.0.0", - "hyper 1.1.0", - "pin-project-lite", - "socket2 0.5.5", - "tokio", - "tracing", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" -dependencies = [ - "cxx", - "cxx-build", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "idna" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "indexmap" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" -dependencies = [ - "equivalent", - "hashbrown 0.14.3", - "serde", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys 0.48.0", + "tokio", + "tokio-native-tls", ] [[package]] -name = "ipnet" -version = "2.7.2" +name = "ident_case" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] -name = "is-terminal" -version = "0.4.7" +name = "idna" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", - "rustix", - "windows-sys 0.48.0", + "unicode-bidi", + "unicode-normalization", ] [[package]] -name = "itertools" -version = "0.10.5" +name = "indexmap" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "433de089bd45971eecf4668ee0ee8f4cec17db4f8bd8f7bc3197a6ce37aa7d9b" dependencies = [ - "either", + "equivalent", + "hashbrown", + "serde", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "itoa" version = "1.0.6" @@ -1565,9 +766,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -1584,26 +785,17 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] - [[package]] name = "linux-raw-sys" -version = "0.3.1" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1611,36 +803,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata", -] - -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - -[[package]] -name = "md-5" -version = "0.10.5" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" -dependencies = [ - "digest", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" @@ -1648,27 +813,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "migrations_internals" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c493c09323068c01e54c685f7da41a9ccf9219735c3766fbfd6099806ea08fbc" -dependencies = [ - "serde", - "toml", -] - -[[package]] -name = "migrations_macros" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a8ff27a350511de30cdabb77147501c36ef02e0451d957abea2f30caffb2b58" -dependencies = [ - "migrations_internals", - "proc-macro2", - "quote", -] - [[package]] name = "mime" version = "0.3.17" @@ -1676,21 +820,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] -name = "minimal-lexical" -version = "0.2.1" +name = "miniz_oxide" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] [[package]] name = "mio" -version = "0.8.6" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", - "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.45.0", + "wasi", + "windows-sys 0.48.0", ] [[package]] @@ -1711,26 +857,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "multibase" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b78c60039650ff12e140ae867ef5299a58e19dded4d334c849dc7177083667e2" -dependencies = [ - "base-x", - "data-encoding", - "data-encoding-macro", -] - -[[package]] -name = "nanoid" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ffa00dec017b5b1a8b7cf5e2c008bfda1aa7e0697ac1508b491fdf2622fb4d8" -dependencies = [ - "rand", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -1750,58 +876,31 @@ dependencies = [ ] [[package]] -name = "never" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "num-integer" -version = "0.1.45" +name = "num-traits" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", - "num-traits", ] [[package]] -name = "num-traits" -version = "0.2.15" +name = "num_cpus" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "autocfg", + "hermit-abi", + "libc", ] [[package]] -name = "num_cpus" -version = "1.15.0" +name = "object" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ - "hermit-abi 0.2.6", - "libc", + "memchr", ] [[package]] @@ -1812,11 +911,11 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.50" +version = "0.10.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e30d8bc91859781f0a943411186324d580f2bbeb71b452fe91ae344806af3f1" +checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" dependencies = [ - "bitflags", + "bitflags 2.4.2", "cfg-if", "foreign-types", "libc", @@ -1844,9 +943,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.85" +version = "0.9.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d3d193fb1488ad46ffe3aaabc912cc931d02ee8518fe2959aea8ef52718b0c0" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" dependencies = [ "cc", "libc", @@ -1854,23 +953,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -1878,47 +960,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.7", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.2.16", + "redox_syscall", "smallvec", - "windows-sys 0.45.0", + "windows-targets 0.48.5", ] -[[package]] -name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" @@ -1933,9 +995,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.7" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be99c4c1d2fc2769b1d00239431d711d08f6efedcecb8b6e30707160aee99c15" +checksum = "bcd6ab1236bbdb3a49027e920e693192ebfe8913f6d60e294de57463a493cfde" dependencies = [ "pest", "pest_generator", @@ -1943,9 +1005,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.7" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e56094789873daa36164de2e822b3888c6ae4b4f9da555a1103587658c805b1e" +checksum = "2a31940305ffc96863a735bef7c7994a00b325a7138fdbc5bda0f1a0476d3275" dependencies = [ "pest", "pest_meta", @@ -1956,40 +1018,20 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.7" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6733073c7cff3d8459fda0e42f13a047870242aed8b509fe98000928975f359e" +checksum = "a7ff62f5259e53b78d1af898941cdcdccfae7385cf7d793a6e55de5d05bb4b7d" dependencies = [ "once_cell", "pest", "sha2", ] -[[package]] -name = "pin-project" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1999,33 +1041,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "pq-sys" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b845d6d8ec554f972a2c5298aad68953fd64e7441e846075450b44656a016d1" -dependencies = [ - "vcpkg", -] - -[[package]] -name = "proc-macro-crate" -version = "0.1.5" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml", -] +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "proc-macro-crate" @@ -2037,30 +1055,6 @@ dependencies = [ "toml_edit", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.78" @@ -2074,179 +1068,78 @@ dependencies = [ name = "prometheus" version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" -dependencies = [ - "cfg-if", - "fnv", - "lazy_static", - "memchr", - "parking_lot 0.12.1", - "protobuf", - "thiserror", -] - -[[package]] -name = "prometheus_exporter" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf17cbebe0bfdf4f279ef84eeefe0d50468b0b7116f078acf41d456e48fe81a" -dependencies = [ - "ascii 1.1.0", - "lazy_static", - "log", - "prometheus", - "thiserror", - "tiny_http", -] - -[[package]] -name = "protobuf" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" - -[[package]] -name = "quickcheck" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" -dependencies = [ - "env_logger", - "log", - "rand", -] - -[[package]] -name = "quickcheck_macros" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22a693222d716a9587786f37ac3f6b4faedb5b80c23914e7303ff5a1d8016e9" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "r2d2" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93" -dependencies = [ - "log", - "parking_lot 0.12.1", - "scheduled-thread-pool", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" dependencies = [ - "bitflags", + "cfg-if", + "fnv", + "lazy_static", + "memchr", + "parking_lot", + "thiserror", ] [[package]] -name = "redox_syscall" -version = "0.3.5" +name = "quote" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ - "bitflags", + "proc-macro2", ] [[package]] -name = "redox_users" -version = "0.4.3" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "getrandom", - "redox_syscall 0.2.16", - "thiserror", + "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.7.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ "aho-corasick", "memchr", + "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" -version = "0.1.10" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "reqwest" -version = "0.11.16" +version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64 0.21.0", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", "futures-util", - "h2 0.3.17", - "http 0.2.9", - "http-body 0.4.5", - "hyper 0.14.25", + "h2", + "http 0.2.11", + "http-body", + "hyper", "hyper-tls", "ipnet", "js-sys", @@ -2259,6 +1152,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -2269,18 +1163,23 @@ dependencies = [ "winreg", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustix" -version = "0.37.11" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags", + "bitflags 2.4.2", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2297,41 +1196,26 @@ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "schannel" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" -dependencies = [ - "windows-sys 0.42.0", -] - -[[package]] -name = "scheduled-thread-pool" -version = "0.2.7" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "parking_lot 0.12.1", + "windows-sys 0.52.0", ] [[package]] name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "scratch" -version = "1.0.5" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "security-framework" -version = "2.8.2" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -2340,9 +1224,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.8.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -2379,16 +1263,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_path_to_error" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c" -dependencies = [ - "itoa", - "serde", -] - [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2401,105 +1275,31 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_with" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" -dependencies = [ - "serde", - "serde_with_macros", -] - -[[package]] -name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling 0.13.4", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "serde_yaml" -version = "0.9.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9d684e3ec7de3bf5466b32bd75303ac16f0736426e5a4e0d6e489559ce1249c" -dependencies = [ - "indexmap 1.9.3", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", "digest", ] -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "socket2" -version = "0.4.9" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" @@ -2517,124 +1317,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -[[package]] -name = "sqlformat" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c12bc9199d1db8234678b7051747c07f517cdcf019262d1847b94ec8b1aee3e" -dependencies = [ - "itertools", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188" -dependencies = [ - "sqlx-core", - "sqlx-macros", -] - -[[package]] -name = "sqlx-core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" -dependencies = [ - "ahash 0.7.6", - "atoi", - "base64 0.13.1", - "bitflags", - "byteorder", - "bytes", - "crc", - "crossbeam-queue", - "dirs", - "dotenvy", - "either", - "event-listener", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-util", - "hashlink", - "hex", - "hkdf", - "hmac", - "indexmap 1.9.3", - "itoa", - "libc", - "log", - "md-5", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "rand", - "serde", - "serde_json", - "sha1", - "sha2", - "smallvec", - "sqlformat", - "sqlx-rt", - "stringprep", - "thiserror", - "tokio-stream", - "url", - "whoami", -] - -[[package]] -name = "sqlx-macros" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9966e64ae989e7e575b19d7265cb79d7fc3cbbdf179835cb0d716f294c2049c9" -dependencies = [ - "dotenvy", - "either", - "heck", - "once_cell", - "proc-macro2", - "quote", - "sha2", - "sqlx-core", - "sqlx-rt", - "syn 1.0.109", - "url", -] - -[[package]] -name = "sqlx-rt" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "804d3f245f894e61b1e6263c84b23ca675d96753b5abfd5cc8597d86806e8024" -dependencies = [ - "native-tls", - "once_cell", - "tokio", - "tokio-native-tls", -] - [[package]] name = "static_assertions_next" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" -[[package]] -name = "stringprep" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "strsim" version = "0.10.0" @@ -2663,12 +1351,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "subtle" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - [[package]] name = "syn" version = "1.0.109" @@ -2676,202 +1358,73 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - -[[package]] -name = "tempfile" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.45.0", -] - -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "testcontainers" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d2931d7f521af5bae989f716c3fa43a6af9af7ec7a5e21b59ae40878cec00" -dependencies = [ - "bollard-stubs", - "futures", - "hex", - "hmac", - "log", - "rand", - "serde", - "serde_json", - "sha2", -] - -[[package]] -name = "testcontainers-modules" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd4f62dbab24872d1ba3bf8c495c6674fe73035ba1489df319620bf5fd4d3857" -dependencies = [ - "testcontainers", -] - -[[package]] -name = "thiserror" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "time" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" -dependencies = [ - "itoa", - "serde", - "time-core", - "time-macros", + "quote", + "unicode-ident", ] [[package]] -name = "time-core" -version = "0.1.1" +name = "syn" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "time-macros" -version = "0.2.9" +name = "system-configuration" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "time-core", + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", ] [[package]] -name = "tiny-cid" -version = "0.3.0" +name = "system-configuration-sys" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add6ab1597c883a38fc0ade108679461b297ab696d417151b85996047a605c81" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" dependencies = [ - "multibase", - "tiny-multihash", - "unsigned-varint", + "core-foundation-sys", + "libc", ] [[package]] -name = "tiny-multihash" -version = "0.5.0" +name = "tempfile" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de7d692794abd4dbba87073e4701150029887b01993e4d152d7ad3376701f50d" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ - "generic-array", - "tiny-multihash-derive", - "unsigned-varint", + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys 0.52.0", ] [[package]] -name = "tiny-multihash-derive" -version = "0.5.0" +name = "thiserror" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "010febb03c87ee95ee6823f001345e92ddc073e85e0b8873ff725e261b4e5e0d" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ - "proc-macro-crate 0.1.5", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure", + "thiserror-impl", ] [[package]] -name = "tiny_http" -version = "0.10.0" +name = "thiserror-impl" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f8734c6d6943ad6df6b588d228a87b4af184998bcffa268ceddf05c2055a8c" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ - "ascii 1.1.0", - "chunked_transfer", - "log", - "time 0.3.21", - "url", + "proc-macro2", + "quote", + "syn 2.0.48", ] [[package]] @@ -2891,28 +1444,26 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.27.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", "mio", "num_cpus", - "parking_lot 0.12.1", "pin-project-lite", - "signal-hook-registry", - "socket2 0.4.9", + "socket2", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", @@ -2929,92 +1480,37 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-stream" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", -] - [[package]] name = "tokio-util" -version = "0.7.7" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", "pin-project-lite", "tokio", "tracing", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "toml_datetime" -version = "0.6.1" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" [[package]] name = "toml_edit" -version = "0.19.8" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 1.9.3", + "indexmap", "toml_datetime", "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - [[package]] name = "tower-service" version = "0.3.2" @@ -3023,12 +1519,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -3036,119 +1530,47 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.23" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] name = "tracing-core" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" -dependencies = [ - "lazy_static", - "log", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.16" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ - "matchers", - "nu-ansi-term", "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "tracing-test" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" -dependencies = [ - "lazy_static", - "tracing-core", - "tracing-subscriber", - "tracing-test-macro", -] - -[[package]] -name = "tracing-test-macro" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" -dependencies = [ - "lazy_static", - "quote", - "syn 1.0.109", ] [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - -[[package]] -name = "tungstenite" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 1.0.0", - "httparse", - "log", - "rand", - "sha1", - "thiserror", - "url", - "utf-8", -] +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -3165,30 +1587,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - [[package]] name = "unreachable" version = "1.0.0" @@ -3198,66 +1596,17 @@ dependencies = [ "void", ] -[[package]] -name = "unsafe-libyaml" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1865806a559042e51ab5414598446a5871b561d21b6764f2eabb0dd481d880a6" - -[[package]] -name = "unsigned-varint" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fdeedbf205afadfe39ae559b75c3240f24e257d0ca27e85f85cb82aa19ac35" - [[package]] name = "url" -version = "2.3.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "uuid" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" -dependencies = [ - "getrandom", - "serde", -] - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "vcpkg" version = "0.2.15" @@ -3278,20 +1627,13 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3300,9 +1642,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3310,24 +1652,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -3337,9 +1679,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3347,264 +1689,180 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", ] -[[package]] -name = "whoami" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c70234412ca409cc04e864e89523cb0fc37f5e1344ebed5a3ebf4192b6b9f68" -dependencies = [ - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets 0.48.0", -] - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.42.2", + "windows-targets 0.48.5", ] [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.48.0", + "windows-targets 0.52.0", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.4.1" +version = "0.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +checksum = "1931d78a9c73861da0134f453bb1f790ce49b2e30eba8410b4b79bac72b46a2d" dependencies = [ "memchr", ] [[package]] name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", + "cfg-if", + "windows-sys 0.48.0", ] diff --git a/Cargo.toml b/Cargo.toml index 45ddcc8..a848b85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "2" -members = ["backend/crates/*"] +members = ["crates/*"] diff --git a/backend/crates/api-server/Cargo.toml b/api-server/Cargo.toml similarity index 92% rename from backend/crates/api-server/Cargo.toml rename to api-server/Cargo.toml index 8117f62..7fa1180 100644 --- a/backend/crates/api-server/Cargo.toml +++ b/api-server/Cargo.toml @@ -15,7 +15,7 @@ async-graphql = "7" async-graphql-axum = "7" axum = "0.7" clap = { version = "4", features = ["derive", "env"] } -graphix-common = { path = "../common" } +graphix-lib = { path = "../graphix-lib" } serde_json = "1" tokio = { version = "1.15.0", features = ["full"] } tracing = "0.1.29" diff --git a/backend/crates/api-server/src/main.rs b/api-server/src/main.rs similarity index 100% rename from backend/crates/api-server/src/main.rs rename to api-server/src/main.rs diff --git a/backend/crates/schema/Cargo.toml b/autogen_graphql_schema/Cargo.toml similarity index 51% rename from backend/crates/schema/Cargo.toml rename to autogen_graphql_schema/Cargo.toml index 2e6f1f3..28d51cf 100644 --- a/backend/crates/schema/Cargo.toml +++ b/autogen_graphql_schema/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "graphix-schema" +name = "graphix-autogen-graphql-schema" version = "0.1.0" edition = "2021" [build-dependencies] async-graphql = "7" -graphix-common = { path = "../common" } +graphix-lib = { path = "../graphix-lib" } diff --git a/backend/crates/schema/build.rs b/autogen_graphql_schema/build.rs similarity index 100% rename from backend/crates/schema/build.rs rename to autogen_graphql_schema/build.rs diff --git a/backend/crates/schema/graphql/api_schema.graphql b/autogen_graphql_schema/graphql/api_schema.graphql similarity index 100% rename from backend/crates/schema/graphql/api_schema.graphql rename to autogen_graphql_schema/graphql/api_schema.graphql diff --git a/backend/crates/schema/src/lib.rs b/autogen_graphql_schema/src/lib.rs similarity index 100% rename from backend/crates/schema/src/lib.rs rename to autogen_graphql_schema/src/lib.rs diff --git a/backend/crates/common/Cargo.toml b/backend/crates/common/Cargo.toml deleted file mode 100644 index 4bc04a9..0000000 --- a/backend/crates/common/Cargo.toml +++ /dev/null @@ -1,47 +0,0 @@ -[package] -name = "graphix-common" -version = "0.1.0" -edition = "2021" - -[dependencies] -anyhow = "1.0.48" -async-graphql = "7" -async-trait = "0.1.52" -chrono = "0.4.19" -diesel = { version = "2.0", features = ["postgres", "r2d2", "chrono", "serde_json"] } -diesel_migrations = "2.0" -eventuals = "0.6.6" -futures = "0.3.18" -futures-retry = "0.6.0" -graphql_client = "0.12.0" -hex = "0.4.3" -itertools = "0.10.3" -prometheus = "0.13.3" -prometheus_exporter = "0.8.5" -reqwest = { version = "0.11.6", features = ["json"] } -serde = { version = "1.0.130", features = ["derive"] } -serde_derive = "1.0.130" -serde_json = "1.0.78" -serde_yaml = "0.9" -tiny-cid = "0.3.0" -testcontainers = "0.15" -testcontainers-modules = { version = "0.2", features = ["postgres"] } -tokio = { version = "1.14.0", features = ["full"] } -tracing = "0.1.29" -rand = { version = "0.8.4", features = ["small_rng"], optional = true } -sqlx = { version = "0.6", features = ["postgres", "runtime-tokio-native-tls"] } -once_cell = { version = "1.9.0", optional = true } -uuid = { version = "1.3", features = ["serde", "v4"] } - -[features] -tests = ["rand", "once_cell"] - -[build-dependencies] -reqwest = { version = "0.11", features = ["blocking"] } - -[dev-dependencies] -graphix-common = { path = ".", features = ["tests"] } -once_cell = { version = "1.9.0" } -quickcheck = "1" -quickcheck_macros = "1" -rand = { version = "0.8.4", features = ["small_rng"] } diff --git a/backend/crates/common/src/indexer/mod.rs b/backend/crates/common/src/indexer/mod.rs deleted file mode 100644 index 12b2cc9..0000000 --- a/backend/crates/common/src/indexer/mod.rs +++ /dev/null @@ -1,167 +0,0 @@ -mod interceptor; -mod real_indexer; - -use std::borrow::Cow; -use std::collections::HashMap; -use std::fmt::Debug; -use std::hash::Hash; -use std::sync::Arc; - -use anyhow::anyhow; -use async_trait::async_trait; -pub use interceptor::IndexerInterceptor; -pub use real_indexer::RealIndexer; - -use crate::types::{self, HexString, IndexingStatus, PoiRequest, ProofOfIndexing}; - -/// An indexer is a `graph-node` instance that can be queried for information. -#[async_trait] -pub trait Indexer: Send + Sync + Debug { - /// The indexer's address. - fn address(&self) -> &[u8]; - - /// Human-readable name of the indexer. - fn name(&self) -> Option>; - - async fn ping(self: Arc) -> anyhow::Result<()>; - - async fn indexing_statuses(self: Arc) -> anyhow::Result>; - - async fn proofs_of_indexing(self: Arc, requests: Vec) - -> Vec; - - async fn version(self: Arc) -> anyhow::Result; - - async fn subgraph_api_versions( - self: Arc, - subgraph_id: &str, - ) -> anyhow::Result>; - - /// Convenience wrapper around calling [`Indexer::proofs_of_indexing`] for a - /// single POI. - async fn proof_of_indexing( - self: Arc, - request: PoiRequest, - ) -> Result { - let pois = self.proofs_of_indexing(vec![request.clone()]).await; - match pois.len() { - 0 => return Err(anyhow!("no proof of indexing returned {:?}", request)), - 1 => return Ok(pois.into_iter().next().unwrap()), - _ => return Err(anyhow!("multiple proofs of indexing returned")), - } - } - - /// Returns the cached Ethereum calls for the given block hash. - async fn cached_eth_calls( - self: Arc, - network: &str, - block_hash: &[u8], - ) -> anyhow::Result>; - - /// Returns the block cache contents for the given block hash. - async fn block_cache_contents( - self: Arc, - network: &str, - block_hash: &[u8], - ) -> anyhow::Result>; - - /// Returns the entity changes for the given block number. - async fn entity_changes( - self: Arc, - subgraph_id: &str, - block_number: u64, - ) -> anyhow::Result; -} - -/// Graphix defines an indexer's ID as either its Ethereum address (if it has -/// one) or its name (if it doesn't have an address i.e. it's not a network -/// participant), strictly in this order. -pub trait IndexerId { - fn address(&self) -> &[u8]; - fn name(&self) -> Option>; - - /// Returns the string representation of the indexer's address using - /// [`HexString`]. - fn address_string(&self) -> String { - HexString(self.address()).to_string() - } -} - -impl IndexerId for T -where - T: Indexer, -{ - fn address(&self) -> &[u8] { - Indexer::address(self) - } - - fn name(&self) -> Option> { - Indexer::name(self) - } -} - -impl IndexerId for Arc { - fn address(&self) -> &[u8] { - Indexer::address(&**self) - } - - fn name(&self) -> Option> { - Indexer::name(&**self) - } -} - -impl PartialEq for dyn Indexer { - fn eq(&self, other: &Self) -> bool { - self.address() == other.address() - } -} - -impl Eq for dyn Indexer {} - -impl Hash for dyn Indexer { - fn hash(&self, state: &mut H) { - // It's best to hash addresses even though entropy is typically already - // high, because some Graphix configurations may use human-readable - // strings as fake addresses. - self.address().hash(state) - } -} - -impl PartialOrd for dyn Indexer { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for dyn Indexer { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.address().cmp(other.address()) - } -} - -/// A wrapper around some inner data `T` that has an associated [`Indexer`]. -pub struct WithIndexer { - pub indexer: Arc, - pub inner: T, -} - -impl WithIndexer { - pub fn new(indexer: Arc, inner: T) -> Self { - Self { indexer, inner } - } -} - -#[derive(Debug)] -pub struct CachedEthereumCall { - pub id_hash: Vec, - pub return_value: Vec, - pub contract_address: Vec, -} - -pub type EntityType = String; -pub type EntityId = String; - -pub struct EntityChanges { - pub updates: HashMap>, - pub deletions: HashMap>, -} diff --git a/crates/indexer-client/Cargo.toml b/crates/indexer-client/Cargo.toml new file mode 100644 index 0000000..9c2d54a --- /dev/null +++ b/crates/indexer-client/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "graphix_indexer_client" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1" +async-trait = "0.1" +async-graphql = "7" +graphql_client = "0.13" +hex = "0.4" +prometheus = { version = "0.13", default-features = false } +reqwest = { version = "0.11", features = ["json"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +tracing = "0.1" + +[build-dependencies] +reqwest = { version = "0.11", features = ["blocking"] } diff --git a/backend/crates/common/build.rs b/crates/indexer-client/build.rs similarity index 100% rename from backend/crates/common/build.rs rename to crates/indexer-client/build.rs diff --git a/backend/crates/common/graphql/indexer/queries/block-data.gql b/crates/indexer-client/graphql/indexer/queries/block-data.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/block-data.gql rename to crates/indexer-client/graphql/indexer/queries/block-data.gql diff --git a/backend/crates/common/graphql/indexer/queries/cached-eth-calls.gql b/crates/indexer-client/graphql/indexer/queries/cached-eth-calls.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/cached-eth-calls.gql rename to crates/indexer-client/graphql/indexer/queries/cached-eth-calls.gql diff --git a/backend/crates/common/graphql/indexer/queries/entity-changes-in-block.gql b/crates/indexer-client/graphql/indexer/queries/entity-changes-in-block.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/entity-changes-in-block.gql rename to crates/indexer-client/graphql/indexer/queries/entity-changes-in-block.gql diff --git a/backend/crates/common/graphql/indexer/queries/indexer-version.gql b/crates/indexer-client/graphql/indexer/queries/indexer-version.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/indexer-version.gql rename to crates/indexer-client/graphql/indexer/queries/indexer-version.gql diff --git a/backend/crates/common/graphql/indexer/queries/indexing-statuses.gql b/crates/indexer-client/graphql/indexer/queries/indexing-statuses.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/indexing-statuses.gql rename to crates/indexer-client/graphql/indexer/queries/indexing-statuses.gql diff --git a/backend/crates/common/graphql/indexer/queries/pois.gql b/crates/indexer-client/graphql/indexer/queries/pois.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/pois.gql rename to crates/indexer-client/graphql/indexer/queries/pois.gql diff --git a/backend/crates/common/graphql/indexer/queries/subgraph-api-versions.gql b/crates/indexer-client/graphql/indexer/queries/subgraph-api-versions.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/subgraph-api-versions.gql rename to crates/indexer-client/graphql/indexer/queries/subgraph-api-versions.gql diff --git a/backend/crates/common/graphql/indexer/queries/typename.gql b/crates/indexer-client/graphql/indexer/queries/typename.gql similarity index 100% rename from backend/crates/common/graphql/indexer/queries/typename.gql rename to crates/indexer-client/graphql/indexer/queries/typename.gql diff --git a/backend/crates/common/graphql/indexer/schema.gql b/crates/indexer-client/graphql/indexer/schema.gql similarity index 100% rename from backend/crates/common/graphql/indexer/schema.gql rename to crates/indexer-client/graphql/indexer/schema.gql diff --git a/backend/crates/common/graphql/touch-this-file-to-refetch-schema b/crates/indexer-client/graphql/touch-this-file-to-refetch-schema similarity index 100% rename from backend/crates/common/graphql/touch-this-file-to-refetch-schema rename to crates/indexer-client/graphql/touch-this-file-to-refetch-schema diff --git a/backend/crates/common/src/indexer/interceptor.rs b/crates/indexer-client/src/interceptor.rs similarity index 94% rename from backend/crates/common/src/indexer/interceptor.rs rename to crates/indexer-client/src/interceptor.rs index ff9a817..f49ad54 100644 --- a/backend/crates/common/src/indexer/interceptor.rs +++ b/crates/indexer-client/src/interceptor.rs @@ -6,8 +6,8 @@ use std::sync::Arc; use async_trait::async_trait; use super::{CachedEthereumCall, EntityChanges}; -use crate::indexer::Indexer; -use crate::types::{self, Bytes32, IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::{Bytes32, Indexer, IndexerVersion}; +use crate::{IndexingStatus, PoiRequest, ProofOfIndexing}; /// Pretends to be an indexer by routing requests a /// [`RealIndexer`](crate::indexer::RealIndexer) and then intercepting the @@ -57,7 +57,7 @@ impl Indexer for IndexerInterceptor { Ok(hijacked_statuses) } - async fn version(self: Arc) -> anyhow::Result { + async fn version(self: Arc) -> anyhow::Result { self.target.clone().version().await } diff --git a/crates/indexer-client/src/lib.rs b/crates/indexer-client/src/lib.rs new file mode 100644 index 0000000..aed7bc6 --- /dev/null +++ b/crates/indexer-client/src/lib.rs @@ -0,0 +1,346 @@ +mod interceptor; +mod real_indexer; + +use std::borrow::Cow; +use std::collections::HashMap; +use std::fmt::Debug; +use std::hash::Hash; +use std::sync::Arc; + +use anyhow::anyhow; +use async_trait::async_trait; +pub use interceptor::IndexerInterceptor; +pub use real_indexer::RealIndexer; + +/// An indexer is a `graph-node` instance that can be queried for information. +#[async_trait] +pub trait Indexer: Send + Sync + Debug { + /// The indexer's address. + fn address(&self) -> &[u8]; + + /// Human-readable name of the indexer. + fn name(&self) -> Option>; + + async fn ping(self: Arc) -> anyhow::Result<()>; + + async fn indexing_statuses(self: Arc) -> anyhow::Result>; + + async fn proofs_of_indexing(self: Arc, requests: Vec) + -> Vec; + + async fn version(self: Arc) -> anyhow::Result; + + async fn subgraph_api_versions( + self: Arc, + subgraph_id: &str, + ) -> anyhow::Result>; + + /// Convenience wrapper around calling [`Indexer::proofs_of_indexing`] for a + /// single POI. + async fn proof_of_indexing( + self: Arc, + request: PoiRequest, + ) -> Result { + let pois = self.proofs_of_indexing(vec![request.clone()]).await; + match pois.len() { + 0 => return Err(anyhow!("no proof of indexing returned {:?}", request)), + 1 => return Ok(pois.into_iter().next().unwrap()), + _ => return Err(anyhow!("multiple proofs of indexing returned")), + } + } + + /// Returns the cached Ethereum calls for the given block hash. + async fn cached_eth_calls( + self: Arc, + network: &str, + block_hash: &[u8], + ) -> anyhow::Result>; + + /// Returns the block cache contents for the given block hash. + async fn block_cache_contents( + self: Arc, + network: &str, + block_hash: &[u8], + ) -> anyhow::Result>; + + /// Returns the entity changes for the given block number. + async fn entity_changes( + self: Arc, + subgraph_id: &str, + block_number: u64, + ) -> anyhow::Result; +} + +/// Graphix defines an indexer's ID as either its Ethereum address (if it has +/// one) or its name (if it doesn't have an address i.e. it's not a network +/// participant), strictly in this order. +pub trait IndexerId { + fn address(&self) -> &[u8]; + fn name(&self) -> Option>; + + /// Returns the string representation of the indexer's address using + /// [`HexString`]. + fn address_string(&self) -> String { + HexString(self.address()).to_string() + } +} + +impl IndexerId for T +where + T: Indexer, +{ + fn address(&self) -> &[u8] { + Indexer::address(self) + } + + fn name(&self) -> Option> { + Indexer::name(self) + } +} + +impl IndexerId for Arc { + fn address(&self) -> &[u8] { + Indexer::address(&**self) + } + + fn name(&self) -> Option> { + Indexer::name(&**self) + } +} + +impl PartialEq for dyn Indexer { + fn eq(&self, other: &Self) -> bool { + self.address() == other.address() + } +} + +impl Eq for dyn Indexer {} + +impl Hash for dyn Indexer { + fn hash(&self, state: &mut H) { + // It's best to hash addresses even though entropy is typically already + // high, because some Graphix configurations may use human-readable + // strings as fake addresses. + self.address().hash(state) + } +} + +impl PartialOrd for dyn Indexer { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for dyn Indexer { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.address().cmp(other.address()) + } +} + +/// A wrapper around some inner data `T` that has an associated [`Indexer`]. +pub struct WithIndexer { + pub indexer: Arc, + pub inner: T, +} + +impl WithIndexer { + pub fn new(indexer: Arc, inner: T) -> Self { + Self { indexer, inner } + } +} + +#[derive(Debug)] +pub struct CachedEthereumCall { + pub id_hash: Vec, + pub return_value: Vec, + pub contract_address: Vec, +} + +pub type EntityType = String; +pub type EntityId = String; + +pub struct EntityChanges { + pub updates: HashMap>, + pub deletions: HashMap>, +} + +use std::fmt::{self, Display}; +use std::ops::Deref; + +use async_graphql::SimpleObject; +use serde::{Deserialize, Serialize}; + +#[derive(Copy, Clone, Debug)] +pub struct HexString(pub T); + +impl> Display for HexString { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "0x{}", hex::encode(self.0.as_ref())) + } +} + +impl> Serialize for HexString { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.collect_str(&self) + } +} + +impl<'a> Deserialize<'a> for HexString> { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'a>, + { + let s = String::deserialize(deserializer)?; + if !s.starts_with("0x") { + return Err(serde::de::Error::custom("hexstring must start with 0x")); + } + hex::decode(&s[2..]) + .map(Self) + .map_err(serde::de::Error::custom) + } +} + +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd, SimpleObject)] +pub struct IndexerVersion { + pub version: String, + pub commit: String, +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] +pub struct BlockPointer { + pub number: u64, + pub hash: Option, +} + +impl fmt::Display for BlockPointer { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "#{} ({})", + self.number, + self.hash + .as_ref() + .map_or("no hash".to_string(), |hash| format!("{}", hash)) + ) + } +} + +#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] +pub struct SubgraphDeployment(pub String); + +impl Deref for SubgraphDeployment { + type Target = String; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[derive(Debug, Clone, Eq)] +pub struct IndexingStatus { + pub indexer: Arc, + pub deployment: SubgraphDeployment, + pub network: String, + pub latest_block: BlockPointer, + pub earliest_block_num: u64, +} + +impl PartialEq for IndexingStatus { + fn eq(&self, other: &Self) -> bool { + self.indexer.as_ref() == other.indexer.as_ref() + && self.deployment == other.deployment + && self.network == other.network + && self.latest_block == other.latest_block + } +} + +/// A 32-byte array that can be easily converted to and from hex strings. +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] +pub struct Bytes32(pub [u8; 32]); + +impl TryFrom<&str> for Bytes32 { + type Error = anyhow::Error; + + fn try_from(s: &str) -> Result { + Ok(Self(hex::FromHex::from_hex(s.trim_start_matches("0x"))?)) + } +} + +impl TryFrom> for Bytes32 { + type Error = anyhow::Error; + + fn try_from(v: Vec) -> Result { + if v.len() != 32 { + return Err(anyhow::anyhow!("Expected 32 bytes, got {}", v.len())); + } + let mut bytes = [0u8; 32]; + bytes.copy_from_slice(&v); + Ok(Self(bytes)) + } +} + +impl fmt::Display for Bytes32 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + +#[derive(Debug, Clone, Eq, PartialOrd, Ord)] +pub struct ProofOfIndexing { + pub indexer: Arc, + pub deployment: SubgraphDeployment, + pub block: BlockPointer, + pub proof_of_indexing: Bytes32, +} + +impl PartialEq for ProofOfIndexing { + fn eq(&self, other: &Self) -> bool { + self.indexer.as_ref() == other.indexer.as_ref() + && self.deployment == other.deployment + && self.block == other.block + && self.proof_of_indexing == other.proof_of_indexing + } +} + +//impl WritablePoi for ProofOfIndexing { +// type IndexerId = Arc; +// +// fn deployment_cid(&self) -> &str { +// self.deployment.as_str() +// } +// +// fn indexer_id(&self) -> Self::IndexerId { +// self.indexer.clone() +// } +// +// fn block(&self) -> BlockPointer { +// self.block +// } +// +// fn proof_of_indexing(&self) -> &[u8] { +// &self.proof_of_indexing.0 +// } +//} + +#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] +pub struct DivergingBlock { + pub block: BlockPointer, + pub proof_of_indexing1: Bytes32, + pub proof_of_indexing2: Bytes32, +} + +#[derive(Clone, Debug)] +pub struct POICrossCheckReport { + pub poi1: ProofOfIndexing, + pub poi2: ProofOfIndexing, + pub diverging_block: Option, +} + +#[derive(Debug, Clone)] +pub struct PoiRequest { + pub deployment: SubgraphDeployment, + pub block_number: u64, +} diff --git a/backend/crates/common/src/indexer/real_indexer.rs b/crates/indexer-client/src/real_indexer.rs similarity index 95% rename from backend/crates/common/src/indexer/real_indexer.rs rename to crates/indexer-client/src/real_indexer.rs index 5f53a0d..53743fb 100644 --- a/backend/crates/common/src/indexer/real_indexer.rs +++ b/crates/indexer-client/src/real_indexer.rs @@ -10,12 +10,7 @@ use serde::Serialize; use tracing::*; use super::{CachedEthereumCall, EntityChanges, Indexer}; -use crate::config::{IndexerConfig, IndexerUrls}; -use crate::indexer::{IndexerId, WithIndexer}; -use crate::prometheus_metrics::metrics; -use crate::types::{ - BlockPointer, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, -}; +use crate::{IndexerId, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, WithIndexer}; const REQUEST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); @@ -23,19 +18,28 @@ const REQUEST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30); pub struct RealIndexer { address: Vec, name: Option, - urls: IndexerUrls, + endpoint: String, client: reqwest::Client, + // Metrics + // ------- + public_poi_requests: prometheus::IntCounterVec, } impl RealIndexer { // FIXME: this logic is bug-prone and should be replaced with proper sum types. #[instrument(skip_all)] - pub fn new(config: IndexerConfig) -> Self { + pub fn new( + name: Option, + address: Vec, + endpoint: String, + public_poi_requests: prometheus::IntCounterVec, + ) -> Self { Self { - name: config.name, - address: config.address, - urls: config.urls, + name, + address, + endpoint, client: reqwest::Client::new(), + public_poi_requests, } } @@ -49,7 +53,7 @@ impl RealIndexer { ) -> anyhow::Result { let response_raw = self .client - .post(self.urls.status.clone()) + .post(self.endpoint.clone()) .timeout(REQUEST_TIMEOUT) .json(&request) .send() @@ -164,8 +168,7 @@ impl Indexer for RealIndexer { match result { Ok(batch_pois) => { - metrics() - .public_proofs_of_indexing_requests + self.public_poi_requests .get_metric_with_label_values(&[&self.address_string(), "1"]) .unwrap() .inc(); @@ -173,8 +176,7 @@ impl Indexer for RealIndexer { pois.extend(batch_pois); } Err(error) => { - metrics() - .public_proofs_of_indexing_requests + self.public_poi_requests .get_metric_with_label_values(&[&self.address_string(), "0"]) .unwrap() .inc(); @@ -313,6 +315,8 @@ impl Indexer for RealIndexer { } mod gql_types { + use crate::{BlockPointer, SubgraphDeployment}; + use super::*; pub type JSONObject = serde_json::Value; diff --git a/crates/network-sg-client/Cargo.toml b/crates/network-sg-client/Cargo.toml new file mode 100644 index 0000000..c08740b --- /dev/null +++ b/crates/network-sg-client/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "graphix_network_sg_client" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1" +graphix_indexer_client = { path = "../indexer-client" } +hex = "0.4" +prometheus = { version = "0.13", default-features = false } +reqwest = "0.11" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +tracing = "0.1" + +[dev-dependencies] +tokio = { version = "1", features = ["macros"] } diff --git a/backend/crates/common/src/network_subgraph_client/mod.rs b/crates/network-sg-client/src/lib.rs similarity index 93% rename from backend/crates/common/src/network_subgraph_client/mod.rs rename to crates/network-sg-client/src/lib.rs index f131b43..d4daa90 100644 --- a/backend/crates/common/src/network_subgraph_client/mod.rs +++ b/crates/network-sg-client/src/lib.rs @@ -5,13 +5,13 @@ use std::sync::Arc; use std::time::Duration; use anyhow::anyhow; +use prometheus::IntCounterVec; use reqwest::Url; use serde::de::DeserializeOwned; -use serde_derive::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use tracing::warn; -use crate::config::{IndexerConfig, IndexerUrls}; -use crate::indexer::{Indexer as IndexerTrait, RealIndexer}; +use graphix_indexer_client::{Indexer as IndexerTrait, RealIndexer}; /// A GraphQL client that can query the network subgraph and extract useful /// data. @@ -24,6 +24,9 @@ pub struct NetworkSubgraphClient { endpoint: String, timeout: Duration, client: reqwest::Client, + // Metrics + // ------- + public_poi_requests: IntCounterVec, } impl NetworkSubgraphClient { @@ -35,6 +38,7 @@ impl NetworkSubgraphClient { endpoint: endpoint.to_string(), timeout: DEFAULT_TIMEOUT, client: reqwest::Client::new(), + public_poi_requests: todo!(), } } @@ -97,13 +101,12 @@ impl NetworkSubgraphClient { for indexer in response_data.indexers { if let Some(url) = indexer.url { let address = hex::decode(indexer.id.trim_start_matches("0x"))?; - let real_indexer = RealIndexer::new(IndexerConfig { - name: indexer.default_display_name, + let real_indexer = RealIndexer::new( + indexer.default_display_name, address, - urls: IndexerUrls { - status: Url::parse(&format!("{}/status", url))?, - }, - }); + Url::parse(&format!("{}/status", url))?.to_string(), + self.public_poi_requests.clone(), + ); indexers.push(Arc::new(real_indexer)); } } @@ -155,13 +158,12 @@ impl NetworkSubgraphClient { anyhow::anyhow!("No indexer found for address 0x{}", hex::encode(address)) })?; - let indexer = RealIndexer::new(IndexerConfig { - name: Some(indexer_data.default_display_name.clone()), - address: address.to_vec(), - urls: IndexerUrls { - status: Url::parse(&format!("{}/status", indexer_data.url))?, - }, - }); + let indexer = RealIndexer::new( + Some(indexer_data.default_display_name.clone()), + address.to_vec(), + Url::parse(&format!("{}/status", indexer_data.url))?.to_string(), + self.public_poi_requests.clone(), + ); Ok(Arc::new(indexer)) } @@ -264,12 +266,7 @@ fn indexer_allocation_data_to_real_indexer( .ok_or_else(|| anyhow!("Indexer without URL"))? .parse()?; url.set_path("/status"); - let config = IndexerConfig { - name, - address, - urls: IndexerUrls { status: url }, - }; - Ok(RealIndexer::new(config)) + Ok(RealIndexer::new(name, address, url.to_string(), todo!())) } #[derive(Serialize)] diff --git a/backend/crates/common/src/network_subgraph_client/queries/deployments.graphql b/crates/network-sg-client/src/queries/deployments.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph_client/queries/deployments.graphql rename to crates/network-sg-client/src/queries/deployments.graphql diff --git a/backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql b/crates/network-sg-client/src/queries/indexer_by_address.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph_client/queries/indexer_by_address.graphql rename to crates/network-sg-client/src/queries/indexer_by_address.graphql diff --git a/backend/crates/common/src/network_subgraph_client/queries/indexers_by_allocations.graphql b/crates/network-sg-client/src/queries/indexers_by_allocations.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph_client/queries/indexers_by_allocations.graphql rename to crates/network-sg-client/src/queries/indexers_by_allocations.graphql diff --git a/backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql b/crates/network-sg-client/src/queries/indexers_by_staked_tokens.graphql similarity index 100% rename from backend/crates/common/src/network_subgraph_client/queries/indexers_by_staked_tokens.graphql rename to crates/network-sg-client/src/queries/indexers_by_staked_tokens.graphql diff --git a/backend/crates/cross-checker/Cargo.toml b/cross-checker/Cargo.toml similarity index 88% rename from backend/crates/cross-checker/Cargo.toml rename to cross-checker/Cargo.toml index 8357828..0a1d275 100644 --- a/backend/crates/cross-checker/Cargo.toml +++ b/cross-checker/Cargo.toml @@ -15,7 +15,7 @@ async-trait = "0.1.52" clap = { version = "4", features = ["derive"] } eventuals = "0.6.6" futures = "0.3.18" -graphix-common = { path = "../common" } +graphix-lib = { path = "../common" } nanoid = "0.4.0" prometheus_exporter = "0.8.5" serde_json = "1" @@ -26,7 +26,7 @@ tracing-subscriber = { version = "0.3.2", features = ["env-filter"] } uuid = { version = "0.8.2", features = ["v4"] } [dev-dependencies] -graphix-common = { path = "../common", features = ["tests"] } +graphix-lib = { path = "../common", features = ["tests"] } hex = "0.4.3" once_cell = "1.9.0" rand = { version = "0.8.4", features = ["small_rng"] } diff --git a/backend/crates/cross-checker/src/bisect.rs b/cross-checker/src/bisect.rs similarity index 100% rename from backend/crates/cross-checker/src/bisect.rs rename to cross-checker/src/bisect.rs diff --git a/backend/crates/cross-checker/src/main.rs b/cross-checker/src/main.rs similarity index 100% rename from backend/crates/cross-checker/src/main.rs rename to cross-checker/src/main.rs diff --git a/backend/crates/cross-checker/src/utils.rs b/cross-checker/src/utils.rs similarity index 100% rename from backend/crates/cross-checker/src/utils.rs rename to cross-checker/src/utils.rs diff --git a/graphix-lib/Cargo.toml b/graphix-lib/Cargo.toml new file mode 100644 index 0000000..7dbd0a4 --- /dev/null +++ b/graphix-lib/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "graphix-lib" +version = "0.1.0" +edition = "2021" + +[dependencies] +graphix-store = { path = "../store" } + +[build-dependencies] +reqwest = { version = "0.11", features = ["blocking"] } + +[dev-dependencies] +graphix-lib = { path = ".", features = ["tests"] } +once_cell = { version = "1.9.0" } +quickcheck = "1" +quickcheck_macros = "1" +rand = { version = "0.8.4", features = ["small_rng"] } diff --git a/backend/crates/common/src/block_choice.rs b/graphix-lib/src/block_choice.rs similarity index 100% rename from backend/crates/common/src/block_choice.rs rename to graphix-lib/src/block_choice.rs diff --git a/backend/crates/common/src/config.rs b/graphix-lib/src/config.rs similarity index 100% rename from backend/crates/common/src/config.rs rename to graphix-lib/src/config.rs diff --git a/backend/crates/common/src/graphql_api/mod.rs b/graphix-lib/src/graphql_api/mod.rs similarity index 100% rename from backend/crates/common/src/graphql_api/mod.rs rename to graphix-lib/src/graphql_api/mod.rs diff --git a/backend/crates/common/src/graphql_api/server.rs b/graphix-lib/src/graphql_api/server.rs similarity index 100% rename from backend/crates/common/src/graphql_api/server.rs rename to graphix-lib/src/graphql_api/server.rs diff --git a/backend/crates/common/src/graphql_api/types.rs b/graphix-lib/src/graphql_api/types.rs similarity index 100% rename from backend/crates/common/src/graphql_api/types.rs rename to graphix-lib/src/graphql_api/types.rs diff --git a/backend/crates/common/src/lib.rs b/graphix-lib/src/lib.rs similarity index 100% rename from backend/crates/common/src/lib.rs rename to graphix-lib/src/lib.rs diff --git a/backend/crates/common/src/prometheus_metrics.rs b/graphix-lib/src/prometheus_metrics.rs similarity index 100% rename from backend/crates/common/src/prometheus_metrics.rs rename to graphix-lib/src/prometheus_metrics.rs diff --git a/backend/crates/common/src/queries.rs b/graphix-lib/src/queries.rs similarity index 100% rename from backend/crates/common/src/queries.rs rename to graphix-lib/src/queries.rs diff --git a/backend/crates/common/src/test_utils/gen.rs b/graphix-lib/src/test_utils/gen.rs similarity index 100% rename from backend/crates/common/src/test_utils/gen.rs rename to graphix-lib/src/test_utils/gen.rs diff --git a/backend/crates/common/src/test_utils/mocks.rs b/graphix-lib/src/test_utils/mocks.rs similarity index 100% rename from backend/crates/common/src/test_utils/mocks.rs rename to graphix-lib/src/test_utils/mocks.rs diff --git a/backend/crates/common/src/test_utils/mod.rs b/graphix-lib/src/test_utils/mod.rs similarity index 100% rename from backend/crates/common/src/test_utils/mod.rs rename to graphix-lib/src/test_utils/mod.rs diff --git a/backend/crates/common/src/types.rs b/graphix-lib/src/types.rs similarity index 100% rename from backend/crates/common/src/types.rs rename to graphix-lib/src/types.rs diff --git a/backend/crates/common/tests/indexing_statuses.rs b/graphix-lib/tests/indexing_statuses.rs similarity index 100% rename from backend/crates/common/tests/indexing_statuses.rs rename to graphix-lib/tests/indexing_statuses.rs diff --git a/backend/crates/common/tests/it_indexing_statuses.rs b/graphix-lib/tests/it_indexing_statuses.rs similarity index 100% rename from backend/crates/common/tests/it_indexing_statuses.rs rename to graphix-lib/tests/it_indexing_statuses.rs diff --git a/backend/crates/common/tests/it_proofs_of_indexing.rs b/graphix-lib/tests/it_proofs_of_indexing.rs similarity index 100% rename from backend/crates/common/tests/it_proofs_of_indexing.rs rename to graphix-lib/tests/it_proofs_of_indexing.rs diff --git a/backend/crates/common/tests/proofs_of_indexing.rs b/graphix-lib/tests/proofs_of_indexing.rs similarity index 100% rename from backend/crates/common/tests/proofs_of_indexing.rs rename to graphix-lib/tests/proofs_of_indexing.rs diff --git a/store/Cargo.toml b/store/Cargo.toml new file mode 100644 index 0000000..299a2ae --- /dev/null +++ b/store/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "graphix-store" +version = "0.1.0" +edition = "2021" diff --git a/backend/crates/common/diesel.toml b/store/diesel.toml similarity index 100% rename from backend/crates/common/diesel.toml rename to store/diesel.toml diff --git a/backend/crates/common/migrations/00000000000000_diesel_initial_setup/down.sql b/store/migrations/00000000000000_diesel_initial_setup/down.sql similarity index 100% rename from backend/crates/common/migrations/00000000000000_diesel_initial_setup/down.sql rename to store/migrations/00000000000000_diesel_initial_setup/down.sql diff --git a/backend/crates/common/migrations/00000000000000_diesel_initial_setup/up.sql b/store/migrations/00000000000000_diesel_initial_setup/up.sql similarity index 100% rename from backend/crates/common/migrations/00000000000000_diesel_initial_setup/up.sql rename to store/migrations/00000000000000_diesel_initial_setup/up.sql diff --git a/backend/crates/common/migrations/2023-03-30-000000_initial_schema/down.sql b/store/migrations/2023-03-30-000000_initial_schema/down.sql similarity index 100% rename from backend/crates/common/migrations/2023-03-30-000000_initial_schema/down.sql rename to store/migrations/2023-03-30-000000_initial_schema/down.sql diff --git a/backend/crates/common/migrations/2023-03-30-000000_initial_schema/up.sql b/store/migrations/2023-03-30-000000_initial_schema/up.sql similarity index 100% rename from backend/crates/common/migrations/2023-03-30-000000_initial_schema/up.sql rename to store/migrations/2023-03-30-000000_initial_schema/up.sql diff --git a/backend/crates/common/migrations/2023-05-26-125000_caip2/down.sql b/store/migrations/2023-05-26-125000_caip2/down.sql similarity index 100% rename from backend/crates/common/migrations/2023-05-26-125000_caip2/down.sql rename to store/migrations/2023-05-26-125000_caip2/down.sql diff --git a/backend/crates/common/migrations/2023-05-26-125000_caip2/up.sql b/store/migrations/2023-05-26-125000_caip2/up.sql similarity index 100% rename from backend/crates/common/migrations/2023-05-26-125000_caip2/up.sql rename to store/migrations/2023-05-26-125000_caip2/up.sql diff --git a/backend/crates/common/migrations/2023-10-09-122825_cleanup/down.sql b/store/migrations/2023-10-09-122825_cleanup/down.sql similarity index 100% rename from backend/crates/common/migrations/2023-10-09-122825_cleanup/down.sql rename to store/migrations/2023-10-09-122825_cleanup/down.sql diff --git a/backend/crates/common/migrations/2023-10-09-122825_cleanup/up.sql b/store/migrations/2023-10-09-122825_cleanup/up.sql similarity index 100% rename from backend/crates/common/migrations/2023-10-09-122825_cleanup/up.sql rename to store/migrations/2023-10-09-122825_cleanup/up.sql diff --git a/backend/crates/common/migrations/2023-12-04-133234_versions/down.sql b/store/migrations/2023-12-04-133234_versions/down.sql similarity index 100% rename from backend/crates/common/migrations/2023-12-04-133234_versions/down.sql rename to store/migrations/2023-12-04-133234_versions/down.sql diff --git a/backend/crates/common/migrations/2023-12-04-133234_versions/up.sql b/store/migrations/2023-12-04-133234_versions/up.sql similarity index 100% rename from backend/crates/common/migrations/2023-12-04-133234_versions/up.sql rename to store/migrations/2023-12-04-133234_versions/up.sql diff --git a/backend/crates/common/migrations/2024-01-22-122801_non_null_address/down.sql b/store/migrations/2024-01-22-122801_non_null_address/down.sql similarity index 100% rename from backend/crates/common/migrations/2024-01-22-122801_non_null_address/down.sql rename to store/migrations/2024-01-22-122801_non_null_address/down.sql diff --git a/backend/crates/common/migrations/2024-01-22-122801_non_null_address/up.sql b/store/migrations/2024-01-22-122801_non_null_address/up.sql similarity index 100% rename from backend/crates/common/migrations/2024-01-22-122801_non_null_address/up.sql rename to store/migrations/2024-01-22-122801_non_null_address/up.sql diff --git a/backend/crates/common/src/store/diesel_queries.rs b/store/src/diesel_queries.rs similarity index 100% rename from backend/crates/common/src/store/diesel_queries.rs rename to store/src/diesel_queries.rs diff --git a/backend/crates/common/src/store/mod.rs b/store/src/lib.rs similarity index 100% rename from backend/crates/common/src/store/mod.rs rename to store/src/lib.rs diff --git a/backend/crates/common/src/store/models.rs b/store/src/models.rs similarity index 100% rename from backend/crates/common/src/store/models.rs rename to store/src/models.rs diff --git a/backend/crates/common/src/store/schema.rs b/store/src/schema.rs similarity index 100% rename from backend/crates/common/src/store/schema.rs rename to store/src/schema.rs diff --git a/backend/crates/common/src/store/tests.rs b/store/src/tests.rs similarity index 100% rename from backend/crates/common/src/store/tests.rs rename to store/src/tests.rs From aae0fa6dd9347ede2130dc998811eae1472b0564 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 10:40:46 +0100 Subject: [PATCH 28/34] get it to compile --- Cargo.lock | 1180 ++++++++++++++++- ops/api-server.dockerfile => Dockerfile | 12 +- api-server/Cargo.toml | 22 - .../autogen_graphql_schema}/Cargo.toml | 2 +- .../autogen_graphql_schema}/build.rs | 2 +- .../graphql/api_schema.graphql | 0 .../autogen_graphql_schema}/src/lib.rs | 0 crates/common-types/Cargo.toml | 10 + .../common-types/src/lib.rs | 49 +- crates/graphix-lib/Cargo.toml | 41 + .../graphix-lib}/src/block_choice.rs | 3 +- .../graphix-lib}/src/config.rs | 14 +- .../graphix-lib}/src/graphql_api/mod.rs | 3 +- .../graphix-lib}/src/graphql_api/server.rs | 31 +- .../graphix-lib}/src/lib.rs | 4 - .../graphix-lib}/src/prometheus_metrics.rs | 0 .../graphix-lib}/src/queries.rs | 7 +- .../graphix-lib}/src/test_utils/gen.rs | 3 +- .../graphix-lib}/src/test_utils/mocks.rs | 8 +- .../graphix-lib}/src/test_utils/mod.rs | 0 .../graphix-lib}/tests/indexing_statuses.rs | 10 +- .../tests/it_indexing_statuses.rs | 12 +- .../tests/it_proofs_of_indexing.rs | 12 +- .../graphix-lib}/tests/proofs_of_indexing.rs | 8 +- {cross-checker => crates/graphix}/Cargo.toml | 24 +- {api-server/src => crates/graphix}/main.rs | 4 +- .../graphix}/src/bisect.rs | 19 +- {cross-checker => crates/graphix}/src/main.rs | 15 +- .../graphix}/src/utils.rs | 8 +- crates/indexer-client/Cargo.toml | 1 + crates/indexer-client/src/interceptor.rs | 3 +- crates/indexer-client/src/lib.rs | 70 +- crates/store/Cargo.toml | 18 + {store => crates/store}/diesel.toml | 0 .../down.sql | 0 .../up.sql | 0 .../2023-03-30-000000_initial_schema/down.sql | 0 .../2023-03-30-000000_initial_schema/up.sql | 0 .../2023-05-26-125000_caip2/down.sql | 0 .../migrations/2023-05-26-125000_caip2/up.sql | 0 .../2023-10-09-122825_cleanup/down.sql | 0 .../2023-10-09-122825_cleanup/up.sql | 0 .../2023-12-04-133234_versions/down.sql | 0 .../2023-12-04-133234_versions/up.sql | 0 .../down.sql | 0 .../2024-01-22-122801_non_null_address/up.sql | 0 {store => crates/store}/src/diesel_queries.rs | 13 +- {store => crates/store}/src/lib.rs | 16 +- {store => crates/store}/src/models.rs | 54 +- {store => crates/store}/src/schema.rs | 0 {store => crates/store}/src/tests.rs | 0 graphix-lib/Cargo.toml | 17 - graphix-lib/src/types.rs | 184 --- ops/cross-checker.dockerfile | 51 - store/Cargo.toml | 4 - 55 files changed, 1436 insertions(+), 498 deletions(-) rename ops/api-server.dockerfile => Dockerfile (76%) delete mode 100644 api-server/Cargo.toml rename {autogen_graphql_schema => crates/autogen_graphql_schema}/Cargo.toml (75%) rename {autogen_graphql_schema => crates/autogen_graphql_schema}/build.rs (92%) rename {autogen_graphql_schema => crates/autogen_graphql_schema}/graphql/api_schema.graphql (100%) rename {autogen_graphql_schema => crates/autogen_graphql_schema}/src/lib.rs (100%) create mode 100644 crates/common-types/Cargo.toml rename graphix-lib/src/graphql_api/types.rs => crates/common-types/src/lib.rs (90%) create mode 100644 crates/graphix-lib/Cargo.toml rename {graphix-lib => crates/graphix-lib}/src/block_choice.rs (97%) rename {graphix-lib => crates/graphix-lib}/src/config.rs (95%) rename {graphix-lib => crates/graphix-lib}/src/graphql_api/mod.rs (92%) rename {graphix-lib => crates/graphix-lib}/src/graphql_api/server.rs (90%) rename {graphix-lib => crates/graphix-lib}/src/lib.rs (73%) rename {graphix-lib => crates/graphix-lib}/src/prometheus_metrics.rs (100%) rename {graphix-lib => crates/graphix-lib}/src/queries.rs (97%) rename {graphix-lib => crates/graphix-lib}/src/test_utils/gen.rs (96%) rename {graphix-lib => crates/graphix-lib}/src/test_utils/mocks.rs (94%) rename {graphix-lib => crates/graphix-lib}/src/test_utils/mod.rs (100%) rename {graphix-lib => crates/graphix-lib}/tests/indexing_statuses.rs (83%) rename {graphix-lib => crates/graphix-lib}/tests/it_indexing_statuses.rs (84%) rename {graphix-lib => crates/graphix-lib}/tests/it_proofs_of_indexing.rs (95%) rename {graphix-lib => crates/graphix-lib}/tests/proofs_of_indexing.rs (84%) rename {cross-checker => crates/graphix}/Cargo.toml (55%) rename {api-server/src => crates/graphix}/main.rs (95%) rename {cross-checker => crates/graphix}/src/bisect.rs (96%) rename {cross-checker => crates/graphix}/src/main.rs (86%) rename {cross-checker => crates/graphix}/src/utils.rs (95%) create mode 100644 crates/store/Cargo.toml rename {store => crates/store}/diesel.toml (100%) rename {store => crates/store}/migrations/00000000000000_diesel_initial_setup/down.sql (100%) rename {store => crates/store}/migrations/00000000000000_diesel_initial_setup/up.sql (100%) rename {store => crates/store}/migrations/2023-03-30-000000_initial_schema/down.sql (100%) rename {store => crates/store}/migrations/2023-03-30-000000_initial_schema/up.sql (100%) rename {store => crates/store}/migrations/2023-05-26-125000_caip2/down.sql (100%) rename {store => crates/store}/migrations/2023-05-26-125000_caip2/up.sql (100%) rename {store => crates/store}/migrations/2023-10-09-122825_cleanup/down.sql (100%) rename {store => crates/store}/migrations/2023-10-09-122825_cleanup/up.sql (100%) rename {store => crates/store}/migrations/2023-12-04-133234_versions/down.sql (100%) rename {store => crates/store}/migrations/2023-12-04-133234_versions/up.sql (100%) rename {store => crates/store}/migrations/2024-01-22-122801_non_null_address/down.sql (100%) rename {store => crates/store}/migrations/2024-01-22-122801_non_null_address/up.sql (100%) rename {store => crates/store}/src/diesel_queries.rs (97%) rename {store => crates/store}/src/lib.rs (97%) rename {store => crates/store}/src/models.rs (73%) rename {store => crates/store}/src/schema.rs (100%) rename {store => crates/store}/src/tests.rs (100%) delete mode 100644 graphix-lib/Cargo.toml delete mode 100644 graphix-lib/src/types.rs delete mode 100644 ops/cross-checker.dockerfile delete mode 100644 store/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index abd8e9f..e51e43a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,69 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.70" @@ -48,6 +111,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +[[package]] +name = "ascii" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" + [[package]] name = "ascii_utils" version = "0.9.3" @@ -87,6 +156,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "async-graphql-axum" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3415c9dbaf54397292da0bb81a907e2b989661ce068e4ccfebac33dc9e245e" +dependencies = [ + "async-graphql", + "async-trait", + "axum", + "bytes", + "futures-util", + "serde_json", + "tokio", + "tokio-stream", + "tokio-util", + "tower-service", +] + [[package]] name = "async-graphql-derive" version = "7.0.1" @@ -167,6 +254,64 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" +dependencies = [ + "async-trait", + "axum-core", + "base64 0.21.7", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.1.0", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sha1", + "sync_wrapper", + "tokio", + "tokio-tungstenite", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -194,6 +339,19 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "bigdecimal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06619be423ea5bb86c95f087d5707942791a08a85530df0db2209a3ecfb8bc9" +dependencies = [ + "autocfg", + "libm", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -251,13 +409,79 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.0", +] + +[[package]] +name = "chunked_transfer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" + +[[package]] +name = "clap" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "combine" version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" dependencies = [ - "ascii", + "ascii 0.9.3", "byteorder", "either", "memchr", @@ -334,6 +558,77 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "diesel" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62c6fcf842f17f8c78ecf7c81d75c5ce84436b41ee07e03f490fbb5f5a8731d8" +dependencies = [ + "bigdecimal", + "bitflags 2.4.2", + "byteorder", + "chrono", + "diesel_derives", + "ipnetwork", + "itoa", + "libc", + "num-bigint", + "num-integer", + "num-traits", + "pq-sys", + "r2d2", + "serde_json", + "time", + "uuid 1.7.0", +] + +[[package]] +name = "diesel_derives" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44" +dependencies = [ + "diesel_table_macro_syntax", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "diesel_migrations" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6036b3f0120c5961381b570ee20a02432d7e2d27ea60de9578799cf9156914ac" +dependencies = [ + "diesel", + "migrations_internals", + "migrations_macros", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +dependencies = [ + "syn 2.0.48", +] + [[package]] name = "digest" version = "0.10.7" @@ -359,6 +654,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "log", + "regex", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -420,6 +725,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -427,6 +747,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -435,6 +756,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -470,6 +802,7 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -491,12 +824,70 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "graphix" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-graphql-axum", + "async-trait", + "axum", + "clap", + "futures", + "graphix_common_types", + "graphix_indexer_client", + "graphix_lib", + "graphix_network_sg_client", + "graphix_store", + "hex", + "nanoid", + "once_cell", + "prometheus_exporter", + "rand", + "serde_json", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "tracing-test", + "uuid 0.8.2", +] + +[[package]] +name = "graphix-autogen-graphql-schema" +version = "0.1.0" +dependencies = [ + "async-graphql", + "graphix_lib", +] + +[[package]] +name = "graphix_common_types" +version = "0.1.0" +dependencies = [ + "async-graphql", + "diesel", + "serde", + "serde_json", +] + [[package]] name = "graphix_indexer_client" version = "0.1.0" @@ -504,6 +895,7 @@ dependencies = [ "anyhow", "async-graphql", "async-trait", + "graphix_common_types", "graphql_client", "hex", "prometheus", @@ -513,6 +905,36 @@ dependencies = [ "tracing", ] +[[package]] +name = "graphix_lib" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-graphql", + "async-trait", + "diesel", + "futures", + "graphix_common_types", + "graphix_indexer_client", + "graphix_lib", + "graphix_network_sg_client", + "graphix_store", + "hex", + "itertools", + "once_cell", + "prometheus_exporter", + "quickcheck", + "quickcheck_macros", + "rand", + "reqwest", + "serde", + "serde_json", + "serde_yaml", + "tokio", + "tracing", + "url", +] + [[package]] name = "graphix_network_sg_client" version = "0.1.0" @@ -528,6 +950,24 @@ dependencies = [ "tracing", ] +[[package]] +name = "graphix_store" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-graphql", + "chrono", + "diesel", + "diesel_migrations", + "graphix_common_types", + "graphix_indexer_client", + "hex", + "serde", + "serde_json", + "tracing", + "uuid 1.7.0", +] + [[package]] name = "graphql-introspection-query" version = "0.2.0" @@ -605,6 +1045,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.0.0", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "handlebars" version = "4.5.0" @@ -676,6 +1135,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.0.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -698,9 +1180,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.24", "http 0.2.11", - "http-body", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -712,6 +1194,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -719,12 +1220,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.28", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.1.0", + "pin-project-lite", + "socket2", + "tokio", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -758,6 +1300,24 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "ipnetwork" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" +dependencies = [ + "serde", +] + +[[package]] +name = "itertools" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" @@ -785,6 +1345,12 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -807,12 +1373,48 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "migrations_internals" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f23f71580015254b020e856feac3df5878c2c7a8812297edd6c0a485ac9dada" +dependencies = [ + "serde", + "toml", +] + +[[package]] +name = "migrations_macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cce3325ac70e67bbab5bd837a31cae01f1a6db64e0e744a33cb03a543469ef08" +dependencies = [ + "migrations_internals", + "proc-macro2", + "quote", +] + [[package]] name = "mime" version = "0.3.17" @@ -857,6 +1459,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "nanoid" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ffa00dec017b5b1a8b7cf5e2c008bfda1aa7e0697ac1508b491fdf2622fb4d8" +dependencies = [ + "rand", +] + [[package]] name = "native-tls" version = "0.2.11" @@ -875,6 +1486,37 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -953,6 +1595,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1027,6 +1675,26 @@ dependencies = [ "sha2", ] +[[package]] +name = "pin-project" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -1045,46 +1713,144 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "pq-sys" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c0052426df997c0cbd30789eb44ca097e3541717a7b8fa36b1c464ee7edebd" +dependencies = [ + "vcpkg", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prometheus" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +dependencies = [ + "cfg-if", + "fnv", + "lazy_static", + "memchr", + "parking_lot", + "thiserror", +] + +[[package]] +name = "prometheus_exporter" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf17cbebe0bfdf4f279ef84eeefe0d50468b0b7116f078acf41d456e48fe81a" +dependencies = [ + "ascii 1.1.0", + "lazy_static", + "log", + "prometheus", + "thiserror", + "tiny_http", +] + +[[package]] +name = "quickcheck" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" +dependencies = [ + "env_logger", + "log", + "rand", +] + +[[package]] +name = "quickcheck_macros" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b22a693222d716a9587786f37ac3f6b4faedb5b80c23914e7303ff5a1d8016e9" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r2d2" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93" dependencies = [ - "once_cell", - "toml_edit", + "log", + "parking_lot", + "scheduled-thread-pool", ] [[package]] -name = "proc-macro2" -version = "1.0.78" +name = "rand" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "unicode-ident", + "libc", + "rand_chacha", + "rand_core", ] [[package]] -name = "prometheus" -version = "0.13.3" +name = "rand_chacha" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "cfg-if", - "fnv", - "lazy_static", - "memchr", - "parking_lot", - "thiserror", + "ppv-lite86", + "rand_core", ] [[package]] -name = "quote" -version = "1.0.35" +name = "rand_core" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "proc-macro2", + "getrandom", ] [[package]] @@ -1104,8 +1870,17 @@ checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.3.7", + "regex-syntax 0.7.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -1116,9 +1891,15 @@ checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.5" @@ -1136,10 +1917,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", + "h2 0.3.24", "http 0.2.11", - "http-body", - "hyper", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-tls", "ipnet", "js-sys", @@ -1203,6 +1984,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "scheduled-thread-pool" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19" +dependencies = [ + "parking_lot", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1263,6 +2053,25 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1275,6 +2084,30 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1286,6 +2119,24 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.9" @@ -1373,6 +2224,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "system-configuration" version = "0.5.1" @@ -1427,6 +2284,58 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +dependencies = [ + "deranged", + "itoa", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +dependencies = [ + "time-core", +] + +[[package]] +name = "tiny_http" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f8734c6d6943ad6df6b588d228a87b4af184998bcffa268ceddf05c2055a8c" +dependencies = [ + "ascii 1.1.0", + "chunked_transfer", + "log", + "time", + "url", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1453,7 +2362,9 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.48.0", @@ -1480,6 +2391,29 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -1488,17 +2422,33 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", "tracing", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -1507,10 +2457,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -1523,6 +2497,7 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -1546,6 +2521,59 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-test" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" +dependencies = [ + "lazy_static", + "tracing-core", + "tracing-subscriber", + "tracing-test-macro", +] + +[[package]] +name = "tracing-test-macro" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" +dependencies = [ + "lazy_static", + "quote", + "syn 1.0.109", ] [[package]] @@ -1554,6 +2582,25 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.0.0", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "url", + "utf-8", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1596,6 +2643,12 @@ dependencies = [ "void", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" + [[package]] name = "url" version = "2.5.0" @@ -1607,6 +2660,42 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "uuid" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +dependencies = [ + "getrandom", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1716,6 +2805,37 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/ops/api-server.dockerfile b/Dockerfile similarity index 76% rename from ops/api-server.dockerfile rename to Dockerfile index a26fb97..43354e3 100644 --- a/ops/api-server.dockerfile +++ b/Dockerfile @@ -22,15 +22,15 @@ COPY --from=planner /app/recipe.json recipe.json RUN apt-get update && apt-get install -y libpq-dev ca-certificates pkg-config libssl-dev # Use cargo-chef to compile dependencies only - this will be cached by Docker. -RUN cargo chef cook --profile $CARGO_PROFILE --recipe-path recipe.json --bin graphix-api-server +RUN cargo chef cook --profile $CARGO_PROFILE --recipe-path recipe.json --bin graphix # ... and then build the rest of the application. COPY . . -RUN cargo build --profile $CARGO_PROFILE --bin graphix-api-server +RUN cargo build --profile $CARGO_PROFILE --bin graphix # Instead of calculating where the binary is located based on $CARGO_PROFILE, we # simply try to copy both `debug` and `release` binaries. -RUN cp target/release/graphix-api-server /usr/local/bin | true && \ - cp target/debug/graphix-api-server /usr/local/bin | true +RUN cp target/release/graphix /usr/local/bin | true && \ + cp target/debug/graphix /usr/local/bin | true FROM debian:bullseye-slim @@ -40,10 +40,10 @@ RUN apt-get update && \ apt-get install -y libpq-dev ca-certificates libssl-dev && \ apt-get clean -COPY --from=builder /usr/local/bin/graphix-api-server /usr/local/bin +COPY --from=builder /usr/local/bin/graphix /usr/local/bin ENV RUST_LOG="graphix=debug" EXPOSE 3030 -ENTRYPOINT [ "graphix-api-server" ] +ENTRYPOINT [ "graphix" ] diff --git a/api-server/Cargo.toml b/api-server/Cargo.toml deleted file mode 100644 index 7fa1180..0000000 --- a/api-server/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "graphix-api-server" -version = "0.1.0" -authors = ["Jannis Pohlmann "] -edition = "2021" -default-run = "graphix-api-server" - -[[bin]] -name = "graphix-api-server" -path = "src/main.rs" - -[dependencies] -anyhow = "1.0.52" -async-graphql = "7" -async-graphql-axum = "7" -axum = "0.7" -clap = { version = "4", features = ["derive", "env"] } -graphix-lib = { path = "../graphix-lib" } -serde_json = "1" -tokio = { version = "1.15.0", features = ["full"] } -tracing = "0.1.29" -tracing-subscriber = { version = "0.3.6", features = ["env-filter"] } diff --git a/autogen_graphql_schema/Cargo.toml b/crates/autogen_graphql_schema/Cargo.toml similarity index 75% rename from autogen_graphql_schema/Cargo.toml rename to crates/autogen_graphql_schema/Cargo.toml index 28d51cf..b635731 100644 --- a/autogen_graphql_schema/Cargo.toml +++ b/crates/autogen_graphql_schema/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [build-dependencies] async-graphql = "7" -graphix-lib = { path = "../graphix-lib" } +graphix_lib = { path = "../graphix-lib" } diff --git a/autogen_graphql_schema/build.rs b/crates/autogen_graphql_schema/build.rs similarity index 92% rename from autogen_graphql_schema/build.rs rename to crates/autogen_graphql_schema/build.rs index 0283cf7..93bc0b5 100644 --- a/autogen_graphql_schema/build.rs +++ b/crates/autogen_graphql_schema/build.rs @@ -2,7 +2,7 @@ use std::env; use std::fs::File; use std::io::*; -use graphix_common::graphql_api::api_schema_builder; +use graphix_lib::graphql_api::api_schema_builder; fn main() -> std::io::Result<()> { // We're only interested in re-generating the API schema if build diff --git a/autogen_graphql_schema/graphql/api_schema.graphql b/crates/autogen_graphql_schema/graphql/api_schema.graphql similarity index 100% rename from autogen_graphql_schema/graphql/api_schema.graphql rename to crates/autogen_graphql_schema/graphql/api_schema.graphql diff --git a/autogen_graphql_schema/src/lib.rs b/crates/autogen_graphql_schema/src/lib.rs similarity index 100% rename from autogen_graphql_schema/src/lib.rs rename to crates/autogen_graphql_schema/src/lib.rs diff --git a/crates/common-types/Cargo.toml b/crates/common-types/Cargo.toml new file mode 100644 index 0000000..c27b95d --- /dev/null +++ b/crates/common-types/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "graphix_common_types" +version = "0.1.0" +edition = "2021" + +[dependencies] +async-graphql = "7" +diesel = "2" +serde = { version = "1", features = ["derive"] } +serde_json = "1" diff --git a/graphix-lib/src/graphql_api/types.rs b/crates/common-types/src/lib.rs similarity index 90% rename from graphix-lib/src/graphql_api/types.rs rename to crates/common-types/src/lib.rs index 1ea158f..a8a2a43 100644 --- a/graphix-lib/src/graphql_api/types.rs +++ b/crates/common-types/src/lib.rs @@ -7,9 +7,8 @@ use async_graphql::*; use diesel::deserialize::FromSqlRow; use serde::{Deserialize, Serialize}; -use crate::indexer::IndexerId; -use crate::store::models::{self}; -use crate::types::IndexerVersion; +//use crate::indexer::IndexerId; +//use crate::types::IndexerVersion; type HexBytesWith0xPrefix = String; type UuidString = String; @@ -273,38 +272,10 @@ pub struct Indexer { pub allocated_tokens: Option, } -impl From for Indexer { - fn from(indexer: models::Indexer) -> Self { - let address_string = indexer.address_string(); - Self { - id: address_string.clone(), - name: indexer.name, - version: None, // TODO - address: Some(address_string), - allocated_tokens: None, // TODO: we don't store this in the db yet - } - } -} - -impl From for ProofOfIndexing { - fn from(poi: models::Poi) -> Self { - Self { - allocated_tokens: None, - deployment: Deployment { - id: poi.sg_deployment.cid.clone(), - }, - hash: poi.poi_hex(), - block: Block { - network: Network { - name: "mainnet".to_string(), - caip2: None, - }, - number: poi.block.number as u64, - hash: hex::encode(poi.block.hash), - }, - indexer: Indexer::from(poi.indexer), - } - } +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd, SimpleObject)] +pub struct IndexerVersion { + pub version: String, + pub commit: String, } #[derive(InputObject)] @@ -316,10 +287,10 @@ struct POICrossCheckReportRequest { } #[derive(SimpleObject)] -struct DivergingBlock { - block: PartialBlock, - proof_of_indexing1: String, - proof_of_indexing2: String, +pub struct DivergingBlock { + pub block: PartialBlock, + pub proof_of_indexing1: String, + pub proof_of_indexing2: String, } #[derive(SimpleObject)] diff --git a/crates/graphix-lib/Cargo.toml b/crates/graphix-lib/Cargo.toml new file mode 100644 index 0000000..ea93de0 --- /dev/null +++ b/crates/graphix-lib/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "graphix_lib" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1" +async-graphql = "7" +async-trait = { version = "0.1", optional = true } +diesel = "2" +futures = "0.3" +graphix_common_types = { path = "../common-types" } +graphix_indexer_client = { path = "../indexer-client" } +graphix_network_sg_client = { path = "../network-sg-client" } +graphix_store = { path = "../store" } +hex = "0.4" +once_cell = { version = "1", optional = true } +prometheus_exporter = "0.8" +rand = { version = "0.8", optional = true } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +serde_yaml = "0.9" +tracing = "0.1" +url = "2.5" + +[build-dependencies] +reqwest = { version = "0.11", features = ["blocking"] } + +[features] +tests = ["async-trait", "once_cell", "rand"] + +[dev-dependencies] +graphix_common_types = { path = "../common-types" } +graphix_lib = { path = ".", features = ["tests"] } +itertools = "0.12" +once_cell = { version = "1.9.0" } +quickcheck = "1" +quickcheck_macros = "1" +rand = { version = "0.8.4", features = ["small_rng"] } +reqwest = { version = "0.11" } +tokio = { version = "1", features = ["macros"] } diff --git a/graphix-lib/src/block_choice.rs b/crates/graphix-lib/src/block_choice.rs similarity index 97% rename from graphix-lib/src/block_choice.rs rename to crates/graphix-lib/src/block_choice.rs index ab68202..a26d405 100644 --- a/graphix-lib/src/block_choice.rs +++ b/crates/graphix-lib/src/block_choice.rs @@ -1,7 +1,6 @@ +use graphix_indexer_client::IndexingStatus; use serde::Deserialize; -use crate::types::IndexingStatus; - #[derive(Copy, Clone, Debug, Default, Deserialize)] #[serde(rename_all = "camelCase")] pub enum BlockChoicePolicy { diff --git a/graphix-lib/src/config.rs b/crates/graphix-lib/src/config.rs similarity index 95% rename from graphix-lib/src/config.rs rename to crates/graphix-lib/src/config.rs index 8795365..bc2ca59 100644 --- a/graphix-lib/src/config.rs +++ b/crates/graphix-lib/src/config.rs @@ -4,14 +4,13 @@ use std::path::Path; use std::sync::Arc; use anyhow::Context; -use reqwest::Url; use serde::{Deserialize, Deserializer}; use tracing::{info, warn}; +use url::Url; use crate::block_choice::BlockChoicePolicy; -use crate::indexer::{Indexer, IndexerId, IndexerInterceptor, RealIndexer}; -use crate::network_subgraph_client::NetworkSubgraphClient; -use crate::types::HexString; +use graphix_indexer_client::{HexString, Indexer, IndexerId, IndexerInterceptor, RealIndexer}; +use graphix_network_sg_client::NetworkSubgraphClient; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] @@ -181,7 +180,12 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result; diff --git a/graphix-lib/src/graphql_api/server.rs b/crates/graphix-lib/src/graphql_api/server.rs similarity index 90% rename from graphix-lib/src/graphql_api/server.rs rename to crates/graphix-lib/src/graphql_api/server.rs index daaca90..d355071 100644 --- a/graphix-lib/src/graphql_api/server.rs +++ b/crates/graphix-lib/src/graphql_api/server.rs @@ -3,9 +3,12 @@ use std::collections::BTreeMap; use anyhow::Context as _; use async_graphql::{Context, Object, Result}; -use super::types::*; -use crate::store::models::QueriedSgDeployment; -use crate::store::Store; +use graphix_common_types as types; +use graphix_common_types::*; +use graphix_store::{ + models::{Indexer, QueriedSgDeployment}, + Store, +}; pub struct QueryRoot; @@ -24,11 +27,15 @@ impl QueryRoot { /// Fetches all tracked indexers in this Graphix instance and filters them /// according to some filtering rules. - async fn indexers(&self, ctx: &Context<'_>, filter: IndexersQuery) -> Result> { + async fn indexers( + &self, + ctx: &Context<'_>, + filter: IndexersQuery, + ) -> Result> { let api_ctx = ctx.data::()?; let indexers = api_ctx.store.indexers(filter)?; - Ok(indexers.into_iter().map(Indexer::from).collect()) + Ok(indexers.into_iter().map(Into::into).collect()) } /// Filters through all PoIs ever collected by this Graphix @@ -37,13 +44,13 @@ impl QueryRoot { &self, ctx: &Context<'_>, filter: PoisQuery, - ) -> Result> { + ) -> Result> { let api_ctx = ctx.data::()?; let pois = api_ctx .store .pois(&filter.deployments, filter.block_range, filter.limit)?; - Ok(pois.into_iter().map(ProofOfIndexing::from).collect()) + Ok(pois.into_iter().map(types::ProofOfIndexing::from).collect()) } /// Same as [`QueryRoot::proofs_of_indexing`], but only returns PoIs that @@ -53,7 +60,7 @@ impl QueryRoot { &self, ctx: &Context<'_>, filter: PoisQuery, - ) -> Result> { + ) -> Result> { let api_ctx = ctx.data::()?; let pois = api_ctx.store.live_pois( None, @@ -62,7 +69,7 @@ impl QueryRoot { filter.limit, )?; - Ok(pois.into_iter().map(ProofOfIndexing::from).collect()) + Ok(pois.into_iter().map(Into::into).collect()) } async fn poi_agreement_ratios( @@ -89,9 +96,9 @@ impl QueryRoot { .live_pois(None, Some(&deployment_cids), None, None)?; // Convert POIs to ProofOfIndexing and group by deployment - let mut deployment_to_pois: BTreeMap> = BTreeMap::new(); + let mut deployment_to_pois: BTreeMap> = BTreeMap::new(); for poi in all_deployment_pois { - let proof_of_indexing: ProofOfIndexing = poi.into(); + let proof_of_indexing: types::ProofOfIndexing = poi.into(); deployment_to_pois .entry(proof_of_indexing.deployment.id.clone()) .or_default() @@ -101,7 +108,7 @@ impl QueryRoot { let mut agreement_ratios: Vec = Vec::new(); for poi in indexer_pois { - let poi: ProofOfIndexing = poi.into(); + let poi: types::ProofOfIndexing = poi.into(); let deployment = Deployment { id: poi.deployment.id.clone(), diff --git a/graphix-lib/src/lib.rs b/crates/graphix-lib/src/lib.rs similarity index 73% rename from graphix-lib/src/lib.rs rename to crates/graphix-lib/src/lib.rs index 435015a..b549a43 100644 --- a/graphix-lib/src/lib.rs +++ b/crates/graphix-lib/src/lib.rs @@ -1,12 +1,8 @@ pub mod block_choice; pub mod config; pub mod graphql_api; -pub mod indexer; -pub mod network_subgraph_client; mod prometheus_metrics; pub mod queries; -pub mod store; -pub mod types; #[cfg(feature = "tests")] pub mod test_utils; diff --git a/graphix-lib/src/prometheus_metrics.rs b/crates/graphix-lib/src/prometheus_metrics.rs similarity index 100% rename from graphix-lib/src/prometheus_metrics.rs rename to crates/graphix-lib/src/prometheus_metrics.rs diff --git a/graphix-lib/src/queries.rs b/crates/graphix-lib/src/queries.rs similarity index 97% rename from graphix-lib/src/queries.rs rename to crates/graphix-lib/src/queries.rs index 1912492..ad3288f 100644 --- a/graphix-lib/src/queries.rs +++ b/crates/graphix-lib/src/queries.rs @@ -6,11 +6,10 @@ use futures::StreamExt; use tracing::*; use crate::block_choice::BlockChoicePolicy; -use crate::indexer::{Indexer, IndexerId}; -use crate::types::{ - IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, -}; use crate::PrometheusMetrics; +use graphix_common_types::IndexerVersion; +use graphix_indexer_client::{Indexer, IndexerId}; +use graphix_indexer_client::{IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment}; /// Queries all `indexingStatuses` for all the given indexers. #[instrument(skip_all)] diff --git a/graphix-lib/src/test_utils/gen.rs b/crates/graphix-lib/src/test_utils/gen.rs similarity index 96% rename from graphix-lib/src/test_utils/gen.rs rename to crates/graphix-lib/src/test_utils/gen.rs index 12ac741..8564b65 100644 --- a/graphix-lib/src/test_utils/gen.rs +++ b/crates/graphix-lib/src/test_utils/gen.rs @@ -6,8 +6,7 @@ use rand::seq::IteratorRandom; use rand::Rng; use super::mocks::{DeploymentDetails, MockIndexer, PartialProofOfIndexing}; -use crate::indexer::Indexer; -use crate::types::{BlockPointer, Bytes32, SubgraphDeployment}; +use graphix_indexer_client::{BlockPointer, Bytes32, Indexer, SubgraphDeployment}; pub fn gen_deployments() -> Vec { vec![ diff --git a/graphix-lib/src/test_utils/mocks.rs b/crates/graphix-lib/src/test_utils/mocks.rs similarity index 94% rename from graphix-lib/src/test_utils/mocks.rs rename to crates/graphix-lib/src/test_utils/mocks.rs index 9c6b8ed..40f6a26 100644 --- a/graphix-lib/src/test_utils/mocks.rs +++ b/crates/graphix-lib/src/test_utils/mocks.rs @@ -4,11 +4,11 @@ use std::sync::Arc; use anyhow::anyhow; use async_trait::async_trait; -use crate::indexer::{CachedEthereumCall, EntityChanges, Indexer}; -use crate::types::{ - BlockPointer, Bytes32, IndexerVersion, IndexingStatus, PoiRequest, ProofOfIndexing, - SubgraphDeployment, +use graphix_common_types::IndexerVersion; +use graphix_indexer_client::{ + BlockPointer, Bytes32, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, }; +use graphix_indexer_client::{CachedEthereumCall, EntityChanges, Indexer}; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeploymentDetails { diff --git a/graphix-lib/src/test_utils/mod.rs b/crates/graphix-lib/src/test_utils/mod.rs similarity index 100% rename from graphix-lib/src/test_utils/mod.rs rename to crates/graphix-lib/src/test_utils/mod.rs diff --git a/graphix-lib/tests/indexing_statuses.rs b/crates/graphix-lib/tests/indexing_statuses.rs similarity index 83% rename from graphix-lib/tests/indexing_statuses.rs rename to crates/graphix-lib/tests/indexing_statuses.rs index 5f8bd7f..a58869a 100644 --- a/graphix-lib/tests/indexing_statuses.rs +++ b/crates/graphix-lib/tests/indexing_statuses.rs @@ -1,10 +1,10 @@ use futures::stream::FuturesUnordered; use futures::{future, StreamExt}; -use graphix_common::metrics; -use graphix_common::queries::query_indexing_statuses; -use graphix_common::test_utils::fast_rng; -use graphix_common::test_utils::gen::*; -use graphix_common::types::IndexingStatus; +use graphix_indexer_client::IndexingStatus; +use graphix_lib::metrics; +use graphix_lib::queries::query_indexing_statuses; +use graphix_lib::test_utils::fast_rng; +use graphix_lib::test_utils::gen::*; #[tokio::test] async fn indexing_statuses() { diff --git a/graphix-lib/tests/it_indexing_statuses.rs b/crates/graphix-lib/tests/it_indexing_statuses.rs similarity index 84% rename from graphix-lib/tests/it_indexing_statuses.rs rename to crates/graphix-lib/tests/it_indexing_statuses.rs index e3039fa..b85a2d8 100644 --- a/graphix-lib/tests/it_indexing_statuses.rs +++ b/crates/graphix-lib/tests/it_indexing_statuses.rs @@ -1,9 +1,8 @@ use std::sync::Arc; use std::time::Duration; -use graphix_common::config::{IndexerConfig, IndexerUrls}; -use graphix_common::indexer::{Indexer, RealIndexer}; -use graphix_common::types::SubgraphDeployment; +use graphix_indexer_client::{Indexer, RealIndexer, SubgraphDeployment}; +use graphix_lib::config::{IndexerConfig, IndexerUrls}; use reqwest::Url; /// Test utility function to create a valid `Indexer` from an arbitrary base url. @@ -16,7 +15,12 @@ fn test_indexer_from_url(url: impl Into) -> Arc { status: url.join("status").unwrap(), }, }; - Arc::new(RealIndexer::new(conf)) + Arc::new(RealIndexer::new( + conf.name, + conf.address, + conf.urls.status.to_string(), + todo!(), + )) } /// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment diff --git a/graphix-lib/tests/it_proofs_of_indexing.rs b/crates/graphix-lib/tests/it_proofs_of_indexing.rs similarity index 95% rename from graphix-lib/tests/it_proofs_of_indexing.rs rename to crates/graphix-lib/tests/it_proofs_of_indexing.rs index c5a30dc..8d2c276 100644 --- a/graphix-lib/tests/it_proofs_of_indexing.rs +++ b/crates/graphix-lib/tests/it_proofs_of_indexing.rs @@ -1,9 +1,8 @@ use std::sync::Arc; use std::time::Duration; -use graphix_common::config::{IndexerConfig, IndexerUrls}; -use graphix_common::indexer::{Indexer, RealIndexer}; -use graphix_common::types::{PoiRequest, SubgraphDeployment}; +use graphix_indexer_client::{Indexer, PoiRequest, RealIndexer, SubgraphDeployment}; +use graphix_lib::config::{IndexerConfig, IndexerUrls}; use reqwest::Url; /// Test utility function to create a valid `Indexer` from an arbitrary base url. @@ -16,7 +15,12 @@ fn test_indexer_from_url(url: impl Into) -> Arc { status: url.join("status").unwrap(), }, }; - Arc::new(RealIndexer::new(conf)) + Arc::new(RealIndexer::new( + conf.name, + conf.address, + conf.urls.status.to_string(), + todo!(), + )) } /// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment diff --git a/graphix-lib/tests/proofs_of_indexing.rs b/crates/graphix-lib/tests/proofs_of_indexing.rs similarity index 84% rename from graphix-lib/tests/proofs_of_indexing.rs rename to crates/graphix-lib/tests/proofs_of_indexing.rs index 18215ab..c85086c 100644 --- a/graphix-lib/tests/proofs_of_indexing.rs +++ b/crates/graphix-lib/tests/proofs_of_indexing.rs @@ -1,9 +1,9 @@ use std::collections::BTreeSet; -use graphix_common::block_choice::BlockChoicePolicy; -use graphix_common::test_utils::fast_rng; -use graphix_common::test_utils::gen::gen_indexers; -use graphix_common::{metrics, queries}; +use graphix_lib::block_choice::BlockChoicePolicy; +use graphix_lib::test_utils::fast_rng; +use graphix_lib::test_utils::gen::gen_indexers; +use graphix_lib::{metrics, queries}; use itertools::Itertools; #[tokio::test] diff --git a/cross-checker/Cargo.toml b/crates/graphix/Cargo.toml similarity index 55% rename from cross-checker/Cargo.toml rename to crates/graphix/Cargo.toml index 0a1d275..d54d078 100644 --- a/cross-checker/Cargo.toml +++ b/crates/graphix/Cargo.toml @@ -1,21 +1,19 @@ [package] -name = "graphix-cross-checker" +name = "graphix" version = "0.1.0" authors = ["Jannis Pohlmann "] edition = "2021" -default-run = "graphix-cross-checker" - -[[bin]] -name = "graphix-cross-checker" -path = "src/main.rs" [dependencies] -anyhow = "1.0.48" +anyhow = "1" async-trait = "0.1.52" -clap = { version = "4", features = ["derive"] } -eventuals = "0.6.6" +clap = { version = "4", features = ["derive", "env"] } futures = "0.3.18" -graphix-lib = { path = "../common" } +graphix_common_types = { path = "../common-types" } +graphix_indexer_client = { path = "../indexer-client" } +graphix_lib = { path = "../graphix-lib" } +graphix_network_sg_client = { path = "../network-sg-client" } +graphix_store = { path = "../store" } nanoid = "0.4.0" prometheus_exporter = "0.8.5" serde_json = "1" @@ -25,8 +23,12 @@ tracing = "0.1.29" tracing-subscriber = { version = "0.3.2", features = ["env-filter"] } uuid = { version = "0.8.2", features = ["v4"] } +# From api-server +async-graphql-axum = "7" +axum = "0.7" + [dev-dependencies] -graphix-lib = { path = "../common", features = ["tests"] } +graphix_lib = { path = "../graphix-lib", features = ["tests"] } hex = "0.4.3" once_cell = "1.9.0" rand = { version = "0.8.4", features = ["small_rng"] } diff --git a/api-server/src/main.rs b/crates/graphix/main.rs similarity index 95% rename from api-server/src/main.rs rename to crates/graphix/main.rs index 9bc055e..44706ed 100644 --- a/api-server/src/main.rs +++ b/crates/graphix/main.rs @@ -5,8 +5,8 @@ use async_graphql_axum::GraphQL; use axum::response::IntoResponse; use axum::Router; use clap::Parser; -use graphix_common::graphql_api::{self}; -use graphix_common::store::Store; +use graphix_lib::graphql_api::{self}; +use graphix_lib::store::Store; use tokio::net::TcpListener; #[derive(Parser, Debug)] diff --git a/cross-checker/src/bisect.rs b/crates/graphix/src/bisect.rs similarity index 96% rename from cross-checker/src/bisect.rs rename to crates/graphix/src/bisect.rs index fcc2f62..da7a1db 100644 --- a/cross-checker/src/bisect.rs +++ b/crates/graphix/src/bisect.rs @@ -1,15 +1,15 @@ use std::sync::Arc; use std::time::Duration; -use graphix_common::graphql_api::types::{ +use graphix_common_types::DivergingBlock as DivergentBlock; +use graphix_common_types::{ BisectionReport, BisectionRunReport, DivergenceBlockBounds, DivergenceInvestigationReport, DivergenceInvestigationRequest, DivergenceInvestigationStatus, PartialBlock, }; -use graphix_common::indexer::{Indexer, IndexerId}; -use graphix_common::store::Store; -use graphix_common::types::{ - BlockPointer, DivergingBlock as DivergentBlock, PoiRequest, ProofOfIndexing, SubgraphDeployment, +use graphix_indexer_client::{ + BlockPointer, Indexer, IndexerId, PoiRequest, ProofOfIndexing, SubgraphDeployment, }; +use graphix_store::Store; use thiserror::Error; use tokio::sync::watch; use tracing::{debug, error, info}; @@ -25,9 +25,12 @@ pub struct DivergingBlock { impl From for DivergentBlock { fn from(other: DivergingBlock) -> DivergentBlock { Self { - block: other.poi1.block, - proof_of_indexing1: other.poi1.proof_of_indexing, - proof_of_indexing2: other.poi2.proof_of_indexing, + block: PartialBlock { + number: other.poi1.block.number as _, + hash: other.poi1.block.hash.map(|h| h.to_string()), + }, + proof_of_indexing1: other.poi1.proof_of_indexing.to_string(), + proof_of_indexing2: other.poi2.proof_of_indexing.to_string(), } } } diff --git a/cross-checker/src/main.rs b/crates/graphix/src/main.rs similarity index 86% rename from cross-checker/src/main.rs rename to crates/graphix/src/main.rs index 43f6d62..227403d 100644 --- a/cross-checker/src/main.rs +++ b/crates/graphix/src/main.rs @@ -9,10 +9,11 @@ use std::sync::Arc; use std::time::Duration; use clap::Parser; -use graphix_common::config::Config; -use graphix_common::indexer::{Indexer, IndexerId}; -use graphix_common::queries::{query_indexing_statuses, query_proofs_of_indexing}; -use graphix_common::{config, metrics, store, PrometheusExporter}; +use graphix_indexer_client::{Indexer, IndexerId}; +use graphix_lib::config::Config; +use graphix_lib::queries::{query_indexing_statuses, query_proofs_of_indexing}; +use graphix_lib::{config, metrics, PrometheusExporter}; +use graphix_store::{PoiLiveness, Store}; use prometheus_exporter::prometheus; use tokio::sync::watch; use tracing::*; @@ -36,7 +37,7 @@ async fn main() -> anyhow::Result<()> { let config = Config::read(&cli_options.config)?; info!("Initialize store and running migrations"); - let store = store::Store::new(&config.database_url).await?; + let store = Store::new(&config.database_url).await?; info!("Store initialization successful"); let sleep_duration = Duration::from_secs(config.polling_period_in_seconds); @@ -68,7 +69,7 @@ async fn main() -> anyhow::Result<()> { tx_indexers.send(indexers.clone())?; let graph_node_versions = - graphix_common::queries::query_graph_node_versions(&indexers, metrics()).await; + graphix_lib::queries::query_graph_node_versions(&indexers, metrics()).await; store.write_graph_node_versions(graph_node_versions)?; let indexing_statuses = query_indexing_statuses(indexers, metrics()).await; @@ -78,7 +79,7 @@ async fn main() -> anyhow::Result<()> { info!(pois = pois.len(), "Finished tracking Pois"); - let write_err = store.write_pois(&pois, store::PoiLiveness::Live).err(); + let write_err = store.write_pois(&pois, PoiLiveness::Live).err(); if let Some(err) = write_err { error!(error = %err, "Failed to write POIs to database"); } diff --git a/cross-checker/src/utils.rs b/crates/graphix/src/utils.rs similarity index 95% rename from cross-checker/src/utils.rs rename to crates/graphix/src/utils.rs index 65aaf1a..b3b8c1c 100644 --- a/cross-checker/src/utils.rs +++ b/crates/graphix/src/utils.rs @@ -4,8 +4,8 @@ use std::collections::HashSet; use std::hash::Hash; use std::sync::Arc; -use graphix_common::indexer::Indexer; -use graphix_common::store; +use graphix_indexer_client::Indexer; +use graphix_store::Store; use crate::bisect::DivergenceInvestigationError; @@ -26,7 +26,7 @@ where /// Given a Poi, find any of the indexers that have been known to produce it. pub fn find_any_indexer_for_poi( - store: &store::Store, + store: &Store, poi_s: &str, indexers: &[Arc], ) -> anyhow::Result>> { @@ -45,7 +45,7 @@ pub fn find_any_indexer_for_poi( } pub fn find_indexer_pair( - store: &store::Store, + store: &Store, poi_1: &str, poi_2: &str, indexers: &[Arc], diff --git a/crates/indexer-client/Cargo.toml b/crates/indexer-client/Cargo.toml index 9c2d54a..030b6ff 100644 --- a/crates/indexer-client/Cargo.toml +++ b/crates/indexer-client/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" anyhow = "1" async-trait = "0.1" async-graphql = "7" +graphix_common_types = { path = "../common-types" } graphql_client = "0.13" hex = "0.4" prometheus = { version = "0.13", default-features = false } diff --git a/crates/indexer-client/src/interceptor.rs b/crates/indexer-client/src/interceptor.rs index f49ad54..f097f8e 100644 --- a/crates/indexer-client/src/interceptor.rs +++ b/crates/indexer-client/src/interceptor.rs @@ -4,9 +4,10 @@ use std::borrow::Cow; use std::sync::Arc; use async_trait::async_trait; +use graphix_common_types::IndexerVersion; use super::{CachedEthereumCall, EntityChanges}; -use crate::{Bytes32, Indexer, IndexerVersion}; +use crate::{Bytes32, Indexer}; use crate::{IndexingStatus, PoiRequest, ProofOfIndexing}; /// Pretends to be an indexer by routing requests a diff --git a/crates/indexer-client/src/lib.rs b/crates/indexer-client/src/lib.rs index aed7bc6..f5b042e 100644 --- a/crates/indexer-client/src/lib.rs +++ b/crates/indexer-client/src/lib.rs @@ -7,10 +7,15 @@ use std::fmt::Debug; use std::hash::Hash; use std::sync::Arc; +use std::fmt::{self, Display}; +use std::ops::Deref; + use anyhow::anyhow; use async_trait::async_trait; +use graphix_common_types::IndexerVersion; pub use interceptor::IndexerInterceptor; pub use real_indexer::RealIndexer; +use serde::{Deserialize, Serialize}; /// An indexer is a `graph-node` instance that can be queried for information. #[async_trait] @@ -164,12 +169,6 @@ pub struct EntityChanges { pub deletions: HashMap>, } -use std::fmt::{self, Display}; -use std::ops::Deref; - -use async_graphql::SimpleObject; -use serde::{Deserialize, Serialize}; - #[derive(Copy, Clone, Debug)] pub struct HexString(pub T); @@ -203,12 +202,6 @@ impl<'a> Deserialize<'a> for HexString> { } } -#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd, SimpleObject)] -pub struct IndexerVersion { - pub version: String, - pub commit: String, -} - #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] pub struct BlockPointer { pub number: u64, @@ -305,25 +298,40 @@ impl PartialEq for ProofOfIndexing { } } -//impl WritablePoi for ProofOfIndexing { -// type IndexerId = Arc; -// -// fn deployment_cid(&self) -> &str { -// self.deployment.as_str() -// } -// -// fn indexer_id(&self) -> Self::IndexerId { -// self.indexer.clone() -// } -// -// fn block(&self) -> BlockPointer { -// self.block -// } -// -// fn proof_of_indexing(&self) -> &[u8] { -// &self.proof_of_indexing.0 -// } -//} +impl From for graphix_common_types::ProofOfIndexing { + fn from(value: ProofOfIndexing) -> Self { + todo!() + } +} + +pub trait WritablePoi { + type IndexerId: IndexerId; + + fn deployment_cid(&self) -> &str; + fn indexer_id(&self) -> Self::IndexerId; + fn block(&self) -> BlockPointer; + fn proof_of_indexing(&self) -> &[u8]; +} + +impl WritablePoi for ProofOfIndexing { + type IndexerId = Arc; + + fn deployment_cid(&self) -> &str { + self.deployment.as_str() + } + + fn indexer_id(&self) -> Self::IndexerId { + self.indexer.clone() + } + + fn block(&self) -> BlockPointer { + self.block + } + + fn proof_of_indexing(&self) -> &[u8] { + &self.proof_of_indexing.0 + } +} #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] pub struct DivergingBlock { diff --git a/crates/store/Cargo.toml b/crates/store/Cargo.toml new file mode 100644 index 0000000..ca365c6 --- /dev/null +++ b/crates/store/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "graphix_store" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1" +async-graphql = "7" +chrono = "0.4" +diesel = { version = "2", features = ["postgres", "r2d2", "chrono", "uuid", "extras"] } +diesel_migrations = { version = "2", features = ["postgres"] } +graphix_common_types = { path = "../common-types" } +graphix_indexer_client = { path = "../indexer-client" } +hex = "0.4" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +tracing = "0.1" +uuid = { version = "1", features = ["v4"] } diff --git a/store/diesel.toml b/crates/store/diesel.toml similarity index 100% rename from store/diesel.toml rename to crates/store/diesel.toml diff --git a/store/migrations/00000000000000_diesel_initial_setup/down.sql b/crates/store/migrations/00000000000000_diesel_initial_setup/down.sql similarity index 100% rename from store/migrations/00000000000000_diesel_initial_setup/down.sql rename to crates/store/migrations/00000000000000_diesel_initial_setup/down.sql diff --git a/store/migrations/00000000000000_diesel_initial_setup/up.sql b/crates/store/migrations/00000000000000_diesel_initial_setup/up.sql similarity index 100% rename from store/migrations/00000000000000_diesel_initial_setup/up.sql rename to crates/store/migrations/00000000000000_diesel_initial_setup/up.sql diff --git a/store/migrations/2023-03-30-000000_initial_schema/down.sql b/crates/store/migrations/2023-03-30-000000_initial_schema/down.sql similarity index 100% rename from store/migrations/2023-03-30-000000_initial_schema/down.sql rename to crates/store/migrations/2023-03-30-000000_initial_schema/down.sql diff --git a/store/migrations/2023-03-30-000000_initial_schema/up.sql b/crates/store/migrations/2023-03-30-000000_initial_schema/up.sql similarity index 100% rename from store/migrations/2023-03-30-000000_initial_schema/up.sql rename to crates/store/migrations/2023-03-30-000000_initial_schema/up.sql diff --git a/store/migrations/2023-05-26-125000_caip2/down.sql b/crates/store/migrations/2023-05-26-125000_caip2/down.sql similarity index 100% rename from store/migrations/2023-05-26-125000_caip2/down.sql rename to crates/store/migrations/2023-05-26-125000_caip2/down.sql diff --git a/store/migrations/2023-05-26-125000_caip2/up.sql b/crates/store/migrations/2023-05-26-125000_caip2/up.sql similarity index 100% rename from store/migrations/2023-05-26-125000_caip2/up.sql rename to crates/store/migrations/2023-05-26-125000_caip2/up.sql diff --git a/store/migrations/2023-10-09-122825_cleanup/down.sql b/crates/store/migrations/2023-10-09-122825_cleanup/down.sql similarity index 100% rename from store/migrations/2023-10-09-122825_cleanup/down.sql rename to crates/store/migrations/2023-10-09-122825_cleanup/down.sql diff --git a/store/migrations/2023-10-09-122825_cleanup/up.sql b/crates/store/migrations/2023-10-09-122825_cleanup/up.sql similarity index 100% rename from store/migrations/2023-10-09-122825_cleanup/up.sql rename to crates/store/migrations/2023-10-09-122825_cleanup/up.sql diff --git a/store/migrations/2023-12-04-133234_versions/down.sql b/crates/store/migrations/2023-12-04-133234_versions/down.sql similarity index 100% rename from store/migrations/2023-12-04-133234_versions/down.sql rename to crates/store/migrations/2023-12-04-133234_versions/down.sql diff --git a/store/migrations/2023-12-04-133234_versions/up.sql b/crates/store/migrations/2023-12-04-133234_versions/up.sql similarity index 100% rename from store/migrations/2023-12-04-133234_versions/up.sql rename to crates/store/migrations/2023-12-04-133234_versions/up.sql diff --git a/store/migrations/2024-01-22-122801_non_null_address/down.sql b/crates/store/migrations/2024-01-22-122801_non_null_address/down.sql similarity index 100% rename from store/migrations/2024-01-22-122801_non_null_address/down.sql rename to crates/store/migrations/2024-01-22-122801_non_null_address/down.sql diff --git a/store/migrations/2024-01-22-122801_non_null_address/up.sql b/crates/store/migrations/2024-01-22-122801_non_null_address/up.sql similarity index 100% rename from store/migrations/2024-01-22-122801_non_null_address/up.sql rename to crates/store/migrations/2024-01-22-122801_non_null_address/up.sql diff --git a/store/src/diesel_queries.rs b/crates/store/src/diesel_queries.rs similarity index 97% rename from store/src/diesel_queries.rs rename to crates/store/src/diesel_queries.rs index 41e1d5a..c74325b 100644 --- a/store/src/diesel_queries.rs +++ b/crates/store/src/diesel_queries.rs @@ -4,17 +4,18 @@ use std::collections::BTreeMap; use chrono::Utc; use diesel::prelude::*; use diesel::sql_types; +use graphix_common_types::BlockRangeInput; +use graphix_common_types::IndexerVersion; +use graphix_indexer_client::WritablePoi; use tracing::info; -use super::models::WritablePoi; use super::PoiLiveness; -use crate::graphql_api::types::BlockRangeInput; -use crate::indexer::{Indexer, IndexerId}; -use crate::store::models::{ +use crate::models::{ self, Indexer as IndexerModel, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, }; -use crate::store::schema::{self, live_pois}; -use crate::types::{BlockPointer, IndexerVersion}; +use crate::schema::{self, live_pois}; +use graphix_indexer_client::BlockPointer; +use graphix_indexer_client::{Indexer, IndexerId}; pub(super) fn poi(conn: &mut PgConnection, poi: &str) -> anyhow::Result> { use schema::{blocks, indexers, pois, sg_deployments}; diff --git a/store/src/lib.rs b/crates/store/src/lib.rs similarity index 97% rename from store/src/lib.rs rename to crates/store/src/lib.rs index 1bb267b..bf08448 100644 --- a/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -5,6 +5,9 @@ mod diesel_queries; #[cfg(tests)] pub use diesel_queries; +use graphix_common_types::{ + BlockRangeInput, IndexerVersion, IndexersQuery, Network, SgDeploymentsQuery, +}; pub mod models; mod schema; @@ -18,14 +21,13 @@ use diesel::{Connection, PgConnection}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use tracing::info; -use self::models::{QueriedSgDeployment, WritablePoi}; -use crate::graphql_api::types::{BlockRangeInput, IndexersQuery, Network, SgDeploymentsQuery}; -use crate::indexer::Indexer; -use crate::store::models::{Indexer as IndexerModel, Poi}; -use crate::types::IndexerVersion; +use self::models::QueriedSgDeployment; +use crate::models::{Indexer as IndexerModel, Poi}; +use graphix_indexer_client::{Indexer, WritablePoi}; -#[cfg(test)] -mod tests; +// TODO +//#[cfg(test)] +//mod tests; const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); diff --git a/store/src/models.rs b/crates/store/src/models.rs similarity index 73% rename from store/src/models.rs rename to crates/store/src/models.rs index 20ae46c..0a2d142 100644 --- a/store/src/models.rs +++ b/crates/store/src/models.rs @@ -2,16 +2,17 @@ use std::borrow::Cow; use async_graphql::SimpleObject; use chrono::NaiveDateTime; +use diesel::backend::Backend; use diesel::deserialize::FromSql; use diesel::pg::Pg; use diesel::sql_types::Jsonb; -use diesel::{backend, AsChangeset, AsExpression, FromSqlRow, Insertable, Queryable}; +use diesel::{AsChangeset, AsExpression, FromSqlRow, Insertable, Queryable}; use serde::{Deserialize, Serialize}; -use types::BlockPointer; +use types::{Deployment, Network}; use super::schema::*; -use crate::indexer::IndexerId; -use crate::types::{self}; +use graphix_common_types as types; +use graphix_indexer_client::{BlockPointer, IndexerId}; pub type IntId = i32; pub type BigIntId = i64; @@ -53,15 +54,6 @@ pub struct NewPoi { pub block_id: BigIntId, } -pub trait WritablePoi { - type IndexerId: IndexerId; - - fn deployment_cid(&self) -> &str; - fn indexer_id(&self) -> Self::IndexerId; - fn block(&self) -> BlockPointer; - fn proof_of_indexing(&self) -> &[u8]; -} - #[derive(Queryable, Debug, Serialize)] pub struct Block { pub(super) id: BigIntId, @@ -161,8 +153,42 @@ impl From for DivergingBlock { } impl FromSql for DivergingBlock { - fn from_sql(bytes: backend::RawValue) -> diesel::deserialize::Result { + fn from_sql(bytes: ::RawValue<'_>) -> diesel::deserialize::Result { let value = >::from_sql(bytes)?; Ok(serde_json::from_value(value)?) } } + +impl From for graphix_common_types::Indexer { + fn from(indexer: Indexer) -> Self { + let address_string = indexer.address_string(); + Self { + id: address_string.clone(), + name: indexer.name, + version: None, // TODO + address: Some(address_string), + allocated_tokens: None, // TODO: we don't store this in the db yet + } + } +} + +impl From for types::ProofOfIndexing { + fn from(poi: Poi) -> Self { + Self { + allocated_tokens: None, + deployment: Deployment { + id: poi.sg_deployment.cid.clone(), + }, + hash: poi.poi_hex(), + block: graphix_common_types::Block { + network: Network { + name: "mainnet".to_string(), + caip2: None, + }, + number: poi.block.number as u64, + hash: hex::encode(poi.block.hash), + }, + indexer: poi.indexer.into(), + } + } +} diff --git a/store/src/schema.rs b/crates/store/src/schema.rs similarity index 100% rename from store/src/schema.rs rename to crates/store/src/schema.rs diff --git a/store/src/tests.rs b/crates/store/src/tests.rs similarity index 100% rename from store/src/tests.rs rename to crates/store/src/tests.rs diff --git a/graphix-lib/Cargo.toml b/graphix-lib/Cargo.toml deleted file mode 100644 index 7dbd0a4..0000000 --- a/graphix-lib/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "graphix-lib" -version = "0.1.0" -edition = "2021" - -[dependencies] -graphix-store = { path = "../store" } - -[build-dependencies] -reqwest = { version = "0.11", features = ["blocking"] } - -[dev-dependencies] -graphix-lib = { path = ".", features = ["tests"] } -once_cell = { version = "1.9.0" } -quickcheck = "1" -quickcheck_macros = "1" -rand = { version = "0.8.4", features = ["small_rng"] } diff --git a/graphix-lib/src/types.rs b/graphix-lib/src/types.rs deleted file mode 100644 index 3ccb179..0000000 --- a/graphix-lib/src/types.rs +++ /dev/null @@ -1,184 +0,0 @@ -use std::fmt::{self, Display}; -use std::ops::Deref; -use std::sync::Arc; - -use async_graphql::SimpleObject; -use serde::{Deserialize, Serialize}; - -use crate::indexer::Indexer; -use crate::store::models::WritablePoi; - -#[derive(Copy, Clone, Debug)] -pub struct HexString(pub T); - -impl> Display for HexString { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "0x{}", hex::encode(self.0.as_ref())) - } -} - -impl> Serialize for HexString { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - serializer.collect_str(&self) - } -} - -impl<'a> Deserialize<'a> for HexString> { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'a>, - { - let s = String::deserialize(deserializer)?; - if !s.starts_with("0x") { - return Err(serde::de::Error::custom("hexstring must start with 0x")); - } - hex::decode(&s[2..]) - .map(Self) - .map_err(serde::de::Error::custom) - } -} - -#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd, SimpleObject)] -pub struct IndexerVersion { - pub version: String, - pub commit: String, -} - -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] -pub struct BlockPointer { - pub number: u64, - pub hash: Option, -} - -impl fmt::Display for BlockPointer { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "#{} ({})", - self.number, - self.hash - .as_ref() - .map_or("no hash".to_string(), |hash| format!("{}", hash)) - ) - } -} - -#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub struct SubgraphDeployment(pub String); - -impl Deref for SubgraphDeployment { - type Target = String; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[derive(Debug, Clone, Eq)] -pub struct IndexingStatus { - pub indexer: Arc, - pub deployment: SubgraphDeployment, - pub network: String, - pub latest_block: BlockPointer, - pub earliest_block_num: u64, -} - -impl PartialEq for IndexingStatus { - fn eq(&self, other: &Self) -> bool { - self.indexer.as_ref() == other.indexer.as_ref() - && self.deployment == other.deployment - && self.network == other.network - && self.latest_block == other.latest_block - } -} - -/// A 32-byte array that can be easily converted to and from hex strings. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Ord, PartialOrd)] -pub struct Bytes32(pub [u8; 32]); - -impl TryFrom<&str> for Bytes32 { - type Error = anyhow::Error; - - fn try_from(s: &str) -> Result { - Ok(Self(hex::FromHex::from_hex(s.trim_start_matches("0x"))?)) - } -} - -impl TryFrom> for Bytes32 { - type Error = anyhow::Error; - - fn try_from(v: Vec) -> Result { - if v.len() != 32 { - return Err(anyhow::anyhow!("Expected 32 bytes, got {}", v.len())); - } - let mut bytes = [0u8; 32]; - bytes.copy_from_slice(&v); - Ok(Self(bytes)) - } -} - -impl fmt::Display for Bytes32 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", hex::encode(self.0)) - } -} - -#[derive(Debug, Clone, Eq, PartialOrd, Ord)] -pub struct ProofOfIndexing { - pub indexer: Arc, - pub deployment: SubgraphDeployment, - pub block: BlockPointer, - pub proof_of_indexing: Bytes32, -} - -impl PartialEq for ProofOfIndexing { - fn eq(&self, other: &Self) -> bool { - self.indexer.as_ref() == other.indexer.as_ref() - && self.deployment == other.deployment - && self.block == other.block - && self.proof_of_indexing == other.proof_of_indexing - } -} - -impl WritablePoi for ProofOfIndexing { - type IndexerId = Arc; - - fn deployment_cid(&self) -> &str { - self.deployment.as_str() - } - - fn indexer_id(&self) -> Self::IndexerId { - self.indexer.clone() - } - - fn block(&self) -> BlockPointer { - self.block - } - - fn proof_of_indexing(&self) -> &[u8] { - &self.proof_of_indexing.0 - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] -pub struct DivergingBlock { - pub block: BlockPointer, - pub proof_of_indexing1: Bytes32, - pub proof_of_indexing2: Bytes32, -} - -#[derive(Clone, Debug)] -pub struct POICrossCheckReport { - pub poi1: ProofOfIndexing, - pub poi2: ProofOfIndexing, - pub diverging_block: Option, -} - -#[derive(Debug, Clone)] -pub struct PoiRequest { - pub deployment: SubgraphDeployment, - pub block_number: u64, -} diff --git a/ops/cross-checker.dockerfile b/ops/cross-checker.dockerfile deleted file mode 100644 index 756dc42..0000000 --- a/ops/cross-checker.dockerfile +++ /dev/null @@ -1,51 +0,0 @@ -FROM rust:slim-bullseye AS chef - -WORKDIR /app -COPY rust-toolchain.toml . -# Triggers the install of the predefined Rust toolchain. -# See . -RUN rustup show -RUN cargo install cargo-chef - -FROM chef AS planner - -COPY . . -RUN cargo chef prepare --recipe-path recipe.json - -FROM chef AS builder - -# We support both `release` and `dev`. -ARG CARGO_PROFILE=release - -COPY --from=planner /app/recipe.json recipe.json - -RUN apt-get update && apt-get install -y libpq-dev ca-certificates pkg-config libssl-dev - -# Use cargo-chef to compile dependencies only - this will be cached by Docker. -RUN cargo chef cook --profile $CARGO_PROFILE --recipe-path recipe.json --bin graphix-cross-checker -# ... and then build the rest of the application. -COPY . . -RUN cargo build --profile $CARGO_PROFILE --bin graphix-cross-checker - -# Instead of calculating where the binary is located based on $CARGO_PROFILE, we -# simply try to copy both `debug` and `release` binaries. -RUN cp target/release/graphix-cross-checker /usr/local/bin | true && \ - cp target/debug/graphix-cross-checker /usr/local/bin | true - -FROM debian:buster-slim - -WORKDIR /app - -RUN apt-get update && \ - apt-get install -y libpq-dev ca-certificates libssl-dev && \ - apt-get clean - -COPY --from=builder /usr/local/bin/graphix-cross-checker /usr/local/bin -COPY --from=builder /app/examples/testnet.yml /app/config.yml - -ENV RUST_LOG="graphix=debug" - -EXPOSE 14265 - -ENTRYPOINT [ "graphix-cross-checker" ] -CMD ["--config", "/app/config.yml"] diff --git a/store/Cargo.toml b/store/Cargo.toml deleted file mode 100644 index 299a2ae..0000000 --- a/store/Cargo.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -name = "graphix-store" -version = "0.1.0" -edition = "2021" From 7bf84dfad08cdfb268da266296efd56540aa68d5 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 10:41:24 +0100 Subject: [PATCH 29/34] cargo +nightly fmt --all Signed-off-by: Filippo Costa --- crates/graphix-lib/src/config.rs | 4 ++-- crates/graphix-lib/src/graphql_api/mod.rs | 2 +- crates/graphix-lib/src/graphql_api/server.rs | 7 ++----- crates/graphix-lib/src/queries.rs | 7 ++++--- crates/graphix-lib/src/test_utils/gen.rs | 2 +- crates/graphix-lib/src/test_utils/mocks.rs | 5 ++--- crates/graphix/src/bisect.rs | 4 ++-- crates/indexer-client/src/interceptor.rs | 3 +-- crates/indexer-client/src/lib.rs | 6 ++---- crates/indexer-client/src/real_indexer.rs | 3 +-- crates/network-sg-client/src/lib.rs | 3 +-- crates/store/src/diesel_queries.rs | 7 ++----- crates/store/src/lib.rs | 2 +- crates/store/src/models.rs | 4 ++-- 14 files changed, 24 insertions(+), 35 deletions(-) diff --git a/crates/graphix-lib/src/config.rs b/crates/graphix-lib/src/config.rs index bc2ca59..9a14375 100644 --- a/crates/graphix-lib/src/config.rs +++ b/crates/graphix-lib/src/config.rs @@ -4,13 +4,13 @@ use std::path::Path; use std::sync::Arc; use anyhow::Context; +use graphix_indexer_client::{HexString, Indexer, IndexerId, IndexerInterceptor, RealIndexer}; +use graphix_network_sg_client::NetworkSubgraphClient; use serde::{Deserialize, Deserializer}; use tracing::{info, warn}; use url::Url; use crate::block_choice::BlockChoicePolicy; -use graphix_indexer_client::{HexString, Indexer, IndexerId, IndexerInterceptor, RealIndexer}; -use graphix_network_sg_client::NetworkSubgraphClient; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] diff --git a/crates/graphix-lib/src/graphql_api/mod.rs b/crates/graphix-lib/src/graphql_api/mod.rs index bcbaa6e..c294944 100644 --- a/crates/graphix-lib/src/graphql_api/mod.rs +++ b/crates/graphix-lib/src/graphql_api/mod.rs @@ -1,9 +1,9 @@ mod server; use async_graphql::{EmptySubscription, Schema, SchemaBuilder}; +use graphix_store::Store; use self::server::{MutationRoot, QueryRoot}; -use graphix_store::Store; pub type ApiSchema = Schema; diff --git a/crates/graphix-lib/src/graphql_api/server.rs b/crates/graphix-lib/src/graphql_api/server.rs index d355071..abe4bff 100644 --- a/crates/graphix-lib/src/graphql_api/server.rs +++ b/crates/graphix-lib/src/graphql_api/server.rs @@ -2,13 +2,10 @@ use std::collections::BTreeMap; use anyhow::Context as _; use async_graphql::{Context, Object, Result}; - use graphix_common_types as types; use graphix_common_types::*; -use graphix_store::{ - models::{Indexer, QueriedSgDeployment}, - Store, -}; +use graphix_store::models::{Indexer, QueriedSgDeployment}; +use graphix_store::Store; pub struct QueryRoot; diff --git a/crates/graphix-lib/src/queries.rs b/crates/graphix-lib/src/queries.rs index ad3288f..2a790cd 100644 --- a/crates/graphix-lib/src/queries.rs +++ b/crates/graphix-lib/src/queries.rs @@ -3,13 +3,14 @@ use std::sync::Arc; use futures::stream::FuturesUnordered; use futures::StreamExt; +use graphix_common_types::IndexerVersion; +use graphix_indexer_client::{ + Indexer, IndexerId, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, +}; use tracing::*; use crate::block_choice::BlockChoicePolicy; use crate::PrometheusMetrics; -use graphix_common_types::IndexerVersion; -use graphix_indexer_client::{Indexer, IndexerId}; -use graphix_indexer_client::{IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment}; /// Queries all `indexingStatuses` for all the given indexers. #[instrument(skip_all)] diff --git a/crates/graphix-lib/src/test_utils/gen.rs b/crates/graphix-lib/src/test_utils/gen.rs index 8564b65..0a04a47 100644 --- a/crates/graphix-lib/src/test_utils/gen.rs +++ b/crates/graphix-lib/src/test_utils/gen.rs @@ -1,12 +1,12 @@ use std::iter::repeat_with; use std::sync::Arc; +use graphix_indexer_client::{BlockPointer, Bytes32, Indexer, SubgraphDeployment}; use rand::distributions::Alphanumeric; use rand::seq::IteratorRandom; use rand::Rng; use super::mocks::{DeploymentDetails, MockIndexer, PartialProofOfIndexing}; -use graphix_indexer_client::{BlockPointer, Bytes32, Indexer, SubgraphDeployment}; pub fn gen_deployments() -> Vec { vec![ diff --git a/crates/graphix-lib/src/test_utils/mocks.rs b/crates/graphix-lib/src/test_utils/mocks.rs index 40f6a26..ef9c578 100644 --- a/crates/graphix-lib/src/test_utils/mocks.rs +++ b/crates/graphix-lib/src/test_utils/mocks.rs @@ -3,12 +3,11 @@ use std::sync::Arc; use anyhow::anyhow; use async_trait::async_trait; - use graphix_common_types::IndexerVersion; use graphix_indexer_client::{ - BlockPointer, Bytes32, IndexingStatus, PoiRequest, ProofOfIndexing, SubgraphDeployment, + BlockPointer, Bytes32, CachedEthereumCall, EntityChanges, Indexer, IndexingStatus, PoiRequest, + ProofOfIndexing, SubgraphDeployment, }; -use graphix_indexer_client::{CachedEthereumCall, EntityChanges, Indexer}; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeploymentDetails { diff --git a/crates/graphix/src/bisect.rs b/crates/graphix/src/bisect.rs index da7a1db..3150540 100644 --- a/crates/graphix/src/bisect.rs +++ b/crates/graphix/src/bisect.rs @@ -1,10 +1,10 @@ use std::sync::Arc; use std::time::Duration; -use graphix_common_types::DivergingBlock as DivergentBlock; use graphix_common_types::{ BisectionReport, BisectionRunReport, DivergenceBlockBounds, DivergenceInvestigationReport, - DivergenceInvestigationRequest, DivergenceInvestigationStatus, PartialBlock, + DivergenceInvestigationRequest, DivergenceInvestigationStatus, + DivergingBlock as DivergentBlock, PartialBlock, }; use graphix_indexer_client::{ BlockPointer, Indexer, IndexerId, PoiRequest, ProofOfIndexing, SubgraphDeployment, diff --git a/crates/indexer-client/src/interceptor.rs b/crates/indexer-client/src/interceptor.rs index f097f8e..621338b 100644 --- a/crates/indexer-client/src/interceptor.rs +++ b/crates/indexer-client/src/interceptor.rs @@ -7,8 +7,7 @@ use async_trait::async_trait; use graphix_common_types::IndexerVersion; use super::{CachedEthereumCall, EntityChanges}; -use crate::{Bytes32, Indexer}; -use crate::{IndexingStatus, PoiRequest, ProofOfIndexing}; +use crate::{Bytes32, Indexer, IndexingStatus, PoiRequest, ProofOfIndexing}; /// Pretends to be an indexer by routing requests a /// [`RealIndexer`](crate::indexer::RealIndexer) and then intercepting the diff --git a/crates/indexer-client/src/lib.rs b/crates/indexer-client/src/lib.rs index f5b042e..8e9bb91 100644 --- a/crates/indexer-client/src/lib.rs +++ b/crates/indexer-client/src/lib.rs @@ -3,12 +3,10 @@ mod real_indexer; use std::borrow::Cow; use std::collections::HashMap; -use std::fmt::Debug; +use std::fmt::{self, Debug, Display}; use std::hash::Hash; -use std::sync::Arc; - -use std::fmt::{self, Display}; use std::ops::Deref; +use std::sync::Arc; use anyhow::anyhow; use async_trait::async_trait; diff --git a/crates/indexer-client/src/real_indexer.rs b/crates/indexer-client/src/real_indexer.rs index 53743fb..7eea5c4 100644 --- a/crates/indexer-client/src/real_indexer.rs +++ b/crates/indexer-client/src/real_indexer.rs @@ -315,9 +315,8 @@ impl Indexer for RealIndexer { } mod gql_types { - use crate::{BlockPointer, SubgraphDeployment}; - use super::*; + use crate::{BlockPointer, SubgraphDeployment}; pub type JSONObject = serde_json::Value; pub type BigInt = String; diff --git a/crates/network-sg-client/src/lib.rs b/crates/network-sg-client/src/lib.rs index d4daa90..8695f5a 100644 --- a/crates/network-sg-client/src/lib.rs +++ b/crates/network-sg-client/src/lib.rs @@ -5,14 +5,13 @@ use std::sync::Arc; use std::time::Duration; use anyhow::anyhow; +use graphix_indexer_client::{Indexer as IndexerTrait, RealIndexer}; use prometheus::IntCounterVec; use reqwest::Url; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use tracing::warn; -use graphix_indexer_client::{Indexer as IndexerTrait, RealIndexer}; - /// A GraphQL client that can query the network subgraph and extract useful /// data. /// diff --git a/crates/store/src/diesel_queries.rs b/crates/store/src/diesel_queries.rs index c74325b..bcc6857 100644 --- a/crates/store/src/diesel_queries.rs +++ b/crates/store/src/diesel_queries.rs @@ -4,9 +4,8 @@ use std::collections::BTreeMap; use chrono::Utc; use diesel::prelude::*; use diesel::sql_types; -use graphix_common_types::BlockRangeInput; -use graphix_common_types::IndexerVersion; -use graphix_indexer_client::WritablePoi; +use graphix_common_types::{BlockRangeInput, IndexerVersion}; +use graphix_indexer_client::{BlockPointer, Indexer, IndexerId, WritablePoi}; use tracing::info; use super::PoiLiveness; @@ -14,8 +13,6 @@ use crate::models::{ self, Indexer as IndexerModel, NewIndexer, NewLivePoi, NewPoi, NewSgDeployment, SgDeployment, }; use crate::schema::{self, live_pois}; -use graphix_indexer_client::BlockPointer; -use graphix_indexer_client::{Indexer, IndexerId}; pub(super) fn poi(conn: &mut PgConnection, poi: &str) -> anyhow::Result> { use schema::{blocks, indexers, pois, sg_deployments}; diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index bf08448..bddd9a0 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -19,11 +19,11 @@ use diesel::prelude::*; use diesel::r2d2::{self, ConnectionManager, Pool, PooledConnection}; use diesel::{Connection, PgConnection}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; +use graphix_indexer_client::{Indexer, WritablePoi}; use tracing::info; use self::models::QueriedSgDeployment; use crate::models::{Indexer as IndexerModel, Poi}; -use graphix_indexer_client::{Indexer, WritablePoi}; // TODO //#[cfg(test)] diff --git a/crates/store/src/models.rs b/crates/store/src/models.rs index 0a2d142..17c3390 100644 --- a/crates/store/src/models.rs +++ b/crates/store/src/models.rs @@ -7,12 +7,12 @@ use diesel::deserialize::FromSql; use diesel::pg::Pg; use diesel::sql_types::Jsonb; use diesel::{AsChangeset, AsExpression, FromSqlRow, Insertable, Queryable}; +use graphix_common_types as types; +use graphix_indexer_client::{BlockPointer, IndexerId}; use serde::{Deserialize, Serialize}; use types::{Deployment, Network}; use super::schema::*; -use graphix_common_types as types; -use graphix_indexer_client::{BlockPointer, IndexerId}; pub type IntId = i32; pub type BigIntId = i64; From caecc9f7dc6204677addfeb49831cc74725c5ab8 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 11:13:05 +0100 Subject: [PATCH 30/34] Reduce name cloning --- crates/common-types/src/lib.rs | 3 --- crates/graphix-lib/src/config.rs | 16 ++++++++-------- crates/graphix-lib/src/graphql_api/server.rs | 2 +- crates/indexer-client/src/interceptor.rs | 2 +- crates/indexer-client/src/lib.rs | 8 ++++---- crates/indexer-client/src/real_indexer.rs | 7 +++++-- crates/store/src/diesel_queries.rs | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/common-types/src/lib.rs b/crates/common-types/src/lib.rs index a8a2a43..97476f2 100644 --- a/crates/common-types/src/lib.rs +++ b/crates/common-types/src/lib.rs @@ -7,9 +7,6 @@ use async_graphql::*; use diesel::deserialize::FromSqlRow; use serde::{Deserialize, Serialize}; -//use crate::indexer::IndexerId; -//use crate::types::IndexerVersion; - type HexBytesWith0xPrefix = String; type UuidString = String; diff --git a/crates/graphix-lib/src/config.rs b/crates/graphix-lib/src/config.rs index 9a14375..89b0306 100644 --- a/crates/graphix-lib/src/config.rs +++ b/crates/graphix-lib/src/config.rs @@ -93,6 +93,14 @@ pub struct IndexerUrls { pub status: Url, } +fn deserialize_url<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let s = String::deserialize(deserializer)?; + Url::parse(&s).map_err(serde::de::Error::custom) +} + #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct IndexerConfig { @@ -155,14 +163,6 @@ pub enum ConfigSource { NetworkSubgraph(NetworkSubgraphConfig), } -fn deserialize_url<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let s = String::deserialize(deserializer)?; - Url::parse(&s).map_err(serde::de::Error::custom) -} - fn deserialize_hexstring<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, diff --git a/crates/graphix-lib/src/graphql_api/server.rs b/crates/graphix-lib/src/graphql_api/server.rs index abe4bff..9d77224 100644 --- a/crates/graphix-lib/src/graphql_api/server.rs +++ b/crates/graphix-lib/src/graphql_api/server.rs @@ -4,7 +4,7 @@ use anyhow::Context as _; use async_graphql::{Context, Object, Result}; use graphix_common_types as types; use graphix_common_types::*; -use graphix_store::models::{Indexer, QueriedSgDeployment}; +use graphix_store::models::QueriedSgDeployment; use graphix_store::Store; pub struct QueryRoot; diff --git a/crates/indexer-client/src/interceptor.rs b/crates/indexer-client/src/interceptor.rs index 621338b..984317d 100644 --- a/crates/indexer-client/src/interceptor.rs +++ b/crates/indexer-client/src/interceptor.rs @@ -28,7 +28,7 @@ impl IndexerInterceptor { #[async_trait] impl Indexer for IndexerInterceptor { - fn name(&self) -> Option> { + fn name(&self) -> Option> { self.target .name() .map(|name| Cow::Owned(format!("interceptor-{}", name))) diff --git a/crates/indexer-client/src/lib.rs b/crates/indexer-client/src/lib.rs index 8e9bb91..0b4a613 100644 --- a/crates/indexer-client/src/lib.rs +++ b/crates/indexer-client/src/lib.rs @@ -22,7 +22,7 @@ pub trait Indexer: Send + Sync + Debug { fn address(&self) -> &[u8]; /// Human-readable name of the indexer. - fn name(&self) -> Option>; + fn name(&self) -> Option>; async fn ping(self: Arc) -> anyhow::Result<()>; @@ -79,7 +79,7 @@ pub trait Indexer: Send + Sync + Debug { /// participant), strictly in this order. pub trait IndexerId { fn address(&self) -> &[u8]; - fn name(&self) -> Option>; + fn name(&self) -> Option>; /// Returns the string representation of the indexer's address using /// [`HexString`]. @@ -96,7 +96,7 @@ where Indexer::address(self) } - fn name(&self) -> Option> { + fn name(&self) -> Option> { Indexer::name(self) } } @@ -106,7 +106,7 @@ impl IndexerId for Arc { Indexer::address(&**self) } - fn name(&self) -> Option> { + fn name(&self) -> Option> { Indexer::name(&**self) } } diff --git a/crates/indexer-client/src/real_indexer.rs b/crates/indexer-client/src/real_indexer.rs index 7eea5c4..8b26b1e 100644 --- a/crates/indexer-client/src/real_indexer.rs +++ b/crates/indexer-client/src/real_indexer.rs @@ -108,8 +108,11 @@ impl Indexer for RealIndexer { self.address.as_slice() } - fn name(&self) -> Option> { - self.name.as_ref().map(Cow::Borrowed) + fn name(&self) -> Option> { + match &self.name { + Some(name) => Some(Cow::Borrowed(name.as_str())), + None => None, + } } async fn ping(self: Arc) -> anyhow::Result<()> { diff --git a/crates/store/src/diesel_queries.rs b/crates/store/src/diesel_queries.rs index bcc6857..d60ff60 100644 --- a/crates/store/src/diesel_queries.rs +++ b/crates/store/src/diesel_queries.rs @@ -314,7 +314,7 @@ pub fn write_graph_node_version( fn get_indexer_id( conn: &mut PgConnection, - name: Option>, + name: Option>, address: &[u8], ) -> anyhow::Result { use schema::indexers; From df023e920fcfcd1142b09bec7e9b0842f763b69a Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 11:14:06 +0100 Subject: [PATCH 31/34] Reduce name cloning part 2 --- crates/graphix-lib/src/config.rs | 7 +++++-- crates/graphix-lib/src/test_utils/mocks.rs | 2 +- crates/store/src/models.rs | 9 ++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/graphix-lib/src/config.rs b/crates/graphix-lib/src/config.rs index 89b0306..dc277dc 100644 --- a/crates/graphix-lib/src/config.rs +++ b/crates/graphix-lib/src/config.rs @@ -114,8 +114,11 @@ impl IndexerId for IndexerConfig { self.address.as_slice() } - fn name(&self) -> Option> { - self.name.as_ref().map(Cow::Borrowed) + fn name(&self) -> Option> { + match &self.name { + Some(name) => Some(Cow::Borrowed(name)), + None => None, + } } } diff --git a/crates/graphix-lib/src/test_utils/mocks.rs b/crates/graphix-lib/src/test_utils/mocks.rs index ef9c578..c621e25 100644 --- a/crates/graphix-lib/src/test_utils/mocks.rs +++ b/crates/graphix-lib/src/test_utils/mocks.rs @@ -27,7 +27,7 @@ pub struct MockIndexer { #[async_trait] impl Indexer for MockIndexer { - fn name(&self) -> Option> { + fn name(&self) -> Option> { Some(Cow::Borrowed(&self.name)) } diff --git a/crates/store/src/models.rs b/crates/store/src/models.rs index 17c3390..c55d955 100644 --- a/crates/store/src/models.rs +++ b/crates/store/src/models.rs @@ -8,7 +8,7 @@ use diesel::pg::Pg; use diesel::sql_types::Jsonb; use diesel::{AsChangeset, AsExpression, FromSqlRow, Insertable, Queryable}; use graphix_common_types as types; -use graphix_indexer_client::{BlockPointer, IndexerId}; +use graphix_indexer_client::IndexerId; use serde::{Deserialize, Serialize}; use types::{Deployment, Network}; @@ -84,8 +84,11 @@ impl IndexerId for Indexer { self.address.as_slice() } - fn name(&self) -> Option> { - self.name.as_ref().map(Cow::Borrowed) + fn name(&self) -> Option> { + match &self.name { + Some(name) => Some(Cow::Borrowed(name)), + None => None, + } } } From 0628c63146e5c3cfc95a44159a14f63c2d699d19 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 12:08:56 +0100 Subject: [PATCH 32/34] Fix a few tests --- Cargo.lock | 129 +++++++++++++++++- crates/graphix-lib/Cargo.toml | 4 +- crates/graphix-lib/src/config.rs | 64 ++++++--- crates/graphix-lib/src/test_utils/mod.rs | 29 ++++ .../graphix-lib/tests/it_indexing_statuses.rs | 30 +--- .../tests/it_proofs_of_indexing.rs | 30 +--- crates/graphix/src/main.rs | 2 +- crates/network-sg-client/Cargo.toml | 1 + crates/network-sg-client/src/lib.rs | 39 ++++-- crates/store/Cargo.toml | 5 + crates/store/src/diesel_queries.rs | 3 + crates/store/src/lib.rs | 4 +- crates/store/src/tests.rs | 7 +- 13 files changed, 242 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e51e43a..b5ecc0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,7 +182,7 @@ checksum = "a6a7349168b79030e3172a620f4f0e0062268a954604e41475eff082380fe505" dependencies = [ "Inflector", "async-graphql-parser", - "darling", + "darling 0.20.3", "proc-macro-crate", "proc-macro2", "quote", @@ -373,6 +373,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bollard-stubs" +version = "1.42.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed59b5c00048f48d7af971b71f800fdf23e858844a6f9e4d32ca72e9399e7864" +dependencies = [ + "serde", + "serde_with", +] + [[package]] name = "bumpalo" version = "3.14.0" @@ -523,14 +533,38 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + [[package]] name = "darling" version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.20.3", + "darling_macro 0.20.3", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", ] [[package]] @@ -547,13 +581,24 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core 0.13.4", + "quote", + "syn 1.0.109", +] + [[package]] name = "darling_macro" version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ - "darling_core", + "darling_core 0.20.3", "quote", "syn 2.0.48", ] @@ -637,6 +682,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -922,6 +968,7 @@ dependencies = [ "hex", "itertools", "once_cell", + "prometheus", "prometheus_exporter", "quickcheck", "quickcheck_macros", @@ -948,6 +995,7 @@ dependencies = [ "serde_json", "tokio", "tracing", + "url", ] [[package]] @@ -964,6 +1012,9 @@ dependencies = [ "hex", "serde", "serde_json", + "testcontainers", + "testcontainers-modules", + "tokio", "tracing", "uuid 1.7.0", ] @@ -1102,6 +1153,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "http" version = "0.2.11" @@ -1764,6 +1824,7 @@ dependencies = [ "lazy_static", "memchr", "parking_lot", + "protobuf", "thiserror", ] @@ -1781,6 +1842,12 @@ dependencies = [ "tiny_http", ] +[[package]] +name = "protobuf" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + [[package]] name = "quickcheck" version = "1.0.3" @@ -2084,6 +2151,28 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +dependencies = [ + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +dependencies = [ + "darling 0.13.4", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "serde_yaml" version = "0.9.31" @@ -2202,6 +2291,12 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "syn" version = "1.0.109" @@ -2264,6 +2359,32 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "testcontainers" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d2931d7f521af5bae989f716c3fa43a6af9af7ec7a5e21b59ae40878cec00" +dependencies = [ + "bollard-stubs", + "futures", + "hex", + "hmac", + "log", + "rand", + "serde", + "serde_json", + "sha2", +] + +[[package]] +name = "testcontainers-modules" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd5c0d66f296de264c0593f42ea2ef2ad3ff9a62bc946a5d4e8d21be1317c505" +dependencies = [ + "testcontainers", +] + [[package]] name = "thiserror" version = "1.0.40" diff --git a/crates/graphix-lib/Cargo.toml b/crates/graphix-lib/Cargo.toml index ea93de0..16ad997 100644 --- a/crates/graphix-lib/Cargo.toml +++ b/crates/graphix-lib/Cargo.toml @@ -15,6 +15,7 @@ graphix_network_sg_client = { path = "../network-sg-client" } graphix_store = { path = "../store" } hex = "0.4" once_cell = { version = "1", optional = true } +prometheus = { version = "0.13", optional = true } prometheus_exporter = "0.8" rand = { version = "0.8", optional = true } serde = { version = "1", features = ["derive"] } @@ -27,13 +28,14 @@ url = "2.5" reqwest = { version = "0.11", features = ["blocking"] } [features] -tests = ["async-trait", "once_cell", "rand"] +tests = ["async-trait", "once_cell", "prometheus", "rand"] [dev-dependencies] graphix_common_types = { path = "../common-types" } graphix_lib = { path = ".", features = ["tests"] } itertools = "0.12" once_cell = { version = "1.9.0" } +prometheus = "0.13" quickcheck = "1" quickcheck_macros = "1" rand = { version = "0.8.4", features = ["small_rng"] } diff --git a/crates/graphix-lib/src/config.rs b/crates/graphix-lib/src/config.rs index dc277dc..c6368e1 100644 --- a/crates/graphix-lib/src/config.rs +++ b/crates/graphix-lib/src/config.rs @@ -10,19 +10,29 @@ use serde::{Deserialize, Deserializer}; use tracing::{info, warn}; use url::Url; -use crate::block_choice::BlockChoicePolicy; +use crate::{block_choice::BlockChoicePolicy, PrometheusMetrics}; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Config { - pub database_url: String, + #[serde(default = "Config::default_true")] + pub enable_indexing: bool, + #[serde(default = "Config::default_true")] + pub enable_api: bool, + #[serde(default = "Config::default_prometheus_port")] pub prometheus_port: u16, + #[serde(default = "Config::default_api_port")] + pub api_port: u16, + + pub database_url: String, + + // Indexing options + // ---------------- pub sources: Vec, #[serde(default)] pub block_choice_policy: BlockChoicePolicy, - #[serde(default = "Config::default_polling_period_in_seconds")] pub polling_period_in_seconds: u64, } @@ -84,13 +94,23 @@ impl Config { fn default_prometheus_port() -> u16 { 9184 } + + fn default_api_port() -> u16 { + 3030 + } + + fn default_true() -> bool { + true + } } -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct IndexerUrls { +pub struct IndexerConfig { + pub name: Option, + pub address: Vec, #[serde(deserialize_with = "deserialize_url")] - pub status: Url, + pub index_node_endpoint: Url, } fn deserialize_url<'de, D>(deserializer: D) -> Result @@ -101,14 +121,6 @@ where Url::parse(&s).map_err(serde::de::Error::custom) } -#[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct IndexerConfig { - pub name: Option, - pub address: Vec, - pub urls: IndexerUrls, -} - impl IndexerId for IndexerConfig { fn address(&self) -> &[u8] { self.address.as_slice() @@ -171,13 +183,17 @@ where D: Deserializer<'de>, { let s = String::deserialize(deserializer)?; - if !s.starts_with("0x") { - return Err(serde::de::Error::custom("hexstring must start with 0x")); + if let Some(s) = s.strip_prefix("0x") { + hex::decode(s).map_err(serde::de::Error::custom) + } else { + Err(serde::de::Error::custom("missing 0x prefix")) } - hex::decode(&s[2..]).map_err(serde::de::Error::custom) } -pub async fn config_to_indexers(config: Config) -> anyhow::Result>> { +pub async fn config_to_indexers( + config: Config, + metrics: &PrometheusMetrics, +) -> anyhow::Result>> { let mut indexers: Vec> = vec![]; // First, configure all the real, static indexers. @@ -186,8 +202,8 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result anyhow::Result { network_subgraph.indexers_by_allocations(config.limit).await @@ -236,7 +255,8 @@ pub async fn config_to_indexers(config: Config) -> anyhow::Result = Lazy::new(|| { let seed = env::var("TEST_SEED") .map(|seed| seed.parse().expect("Invalid TEST_SEED value")) @@ -20,6 +27,28 @@ pub static TEST_SEED: Lazy = Lazy::new(|| { seed }); +/// Test utility function to create a valid `Indexer` from an arbitrary base url. +pub fn test_indexer_from_url(url: impl Into) -> Arc { + let url: Url = url.into().parse().expect("Invalid status url"); + let conf = IndexerConfig { + name: Some(url.host().unwrap().to_string()), + address: url.as_str().as_bytes().to_owned(), + index_node_endpoint: url.join("status").unwrap(), + }; + Arc::new(RealIndexer::new( + conf.name, + conf.address, + conf.index_node_endpoint.to_string(), + IntCounterVec::new(prometheus::Opts::new("foo", "bar"), &["a", "b"]).unwrap(), + )) +} + +/// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment +/// id/ipfs hash. +pub fn test_deployment_id(deployment: impl Into) -> SubgraphDeployment { + SubgraphDeployment(deployment.into()) +} + pub fn fast_rng(seed_extra: u64) -> SmallRng { SmallRng::seed_from_u64(*TEST_SEED + seed_extra) } diff --git a/crates/graphix-lib/tests/it_indexing_statuses.rs b/crates/graphix-lib/tests/it_indexing_statuses.rs index b85a2d8..4b4ffb6 100644 --- a/crates/graphix-lib/tests/it_indexing_statuses.rs +++ b/crates/graphix-lib/tests/it_indexing_statuses.rs @@ -1,33 +1,7 @@ -use std::sync::Arc; use std::time::Duration; -use graphix_indexer_client::{Indexer, RealIndexer, SubgraphDeployment}; -use graphix_lib::config::{IndexerConfig, IndexerUrls}; -use reqwest::Url; - -/// Test utility function to create a valid `Indexer` from an arbitrary base url. -fn test_indexer_from_url(url: impl Into) -> Arc { - let url: Url = url.into().parse().expect("Invalid status url"); - let conf = IndexerConfig { - name: Some(url.host().unwrap().to_string()), - address: url.as_str().as_bytes().to_owned(), - urls: IndexerUrls { - status: url.join("status").unwrap(), - }, - }; - Arc::new(RealIndexer::new( - conf.name, - conf.address, - conf.urls.status.to_string(), - todo!(), - )) -} - -/// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment -/// id/ipfs hash. -fn test_deployment_id(deployment: impl Into) -> SubgraphDeployment { - SubgraphDeployment(deployment.into()) -} +use graphix_indexer_client::Indexer; +use graphix_lib::test_utils::{test_deployment_id, test_indexer_from_url}; #[tokio::test] async fn send_indexer_statuses_query() { diff --git a/crates/graphix-lib/tests/it_proofs_of_indexing.rs b/crates/graphix-lib/tests/it_proofs_of_indexing.rs index 8d2c276..c790d9b 100644 --- a/crates/graphix-lib/tests/it_proofs_of_indexing.rs +++ b/crates/graphix-lib/tests/it_proofs_of_indexing.rs @@ -1,33 +1,7 @@ -use std::sync::Arc; use std::time::Duration; -use graphix_indexer_client::{Indexer, PoiRequest, RealIndexer, SubgraphDeployment}; -use graphix_lib::config::{IndexerConfig, IndexerUrls}; -use reqwest::Url; - -/// Test utility function to create a valid `Indexer` from an arbitrary base url. -fn test_indexer_from_url(url: impl Into) -> Arc { - let url: Url = url.into().parse().expect("Invalid status url"); - let conf = IndexerConfig { - name: Some(url.host().unwrap().to_string()), - address: url.as_str().as_bytes().to_owned(), - urls: IndexerUrls { - status: url.join("status").unwrap(), - }, - }; - Arc::new(RealIndexer::new( - conf.name, - conf.address, - conf.urls.status.to_string(), - todo!(), - )) -} - -/// Test utility function to create a valid `SubgraphDeployment` with an arbitrary deployment -/// id/ipfs hash. -fn test_deployment_id(deployment: impl Into) -> SubgraphDeployment { - SubgraphDeployment(deployment.into()) -} +use graphix_indexer_client::{Indexer, PoiRequest}; +use graphix_lib::test_utils::{test_deployment_id, test_indexer_from_url}; #[tokio::test] async fn send_single_query_and_process_result() { diff --git a/crates/graphix/src/main.rs b/crates/graphix/src/main.rs index 227403d..83dc5d7 100644 --- a/crates/graphix/src/main.rs +++ b/crates/graphix/src/main.rs @@ -59,7 +59,7 @@ async fn main() -> anyhow::Result<()> { info!("New main loop iteration"); info!("Initialize inputs (indexers, indexing statuses etc.)"); - let mut indexers = config::config_to_indexers(config.clone()).await?; + let mut indexers = config::config_to_indexers(config.clone(), metrics()).await?; // Different data sources, especially network subgraphs, result in // duplicate indexers. indexers = deduplicate_indexers(&indexers); diff --git a/crates/network-sg-client/Cargo.toml b/crates/network-sg-client/Cargo.toml index c08740b..4ca1c3b 100644 --- a/crates/network-sg-client/Cargo.toml +++ b/crates/network-sg-client/Cargo.toml @@ -12,6 +12,7 @@ reqwest = "0.11" serde = { version = "1", features = ["derive"] } serde_json = "1" tracing = "0.1" +url = "2" [dev-dependencies] tokio = { version = "1", features = ["macros"] } diff --git a/crates/network-sg-client/src/lib.rs b/crates/network-sg-client/src/lib.rs index 8695f5a..55f64c8 100644 --- a/crates/network-sg-client/src/lib.rs +++ b/crates/network-sg-client/src/lib.rs @@ -7,10 +7,10 @@ use std::time::Duration; use anyhow::anyhow; use graphix_indexer_client::{Indexer as IndexerTrait, RealIndexer}; use prometheus::IntCounterVec; -use reqwest::Url; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use tracing::warn; +use url::Url; /// A GraphQL client that can query the network subgraph and extract useful /// data. @@ -20,7 +20,7 @@ use tracing::warn; /// deployments. #[derive(Debug, Clone)] pub struct NetworkSubgraphClient { - endpoint: String, + endpoint: Url, timeout: Duration, client: reqwest::Client, // Metrics @@ -29,15 +29,15 @@ pub struct NetworkSubgraphClient { } impl NetworkSubgraphClient { - /// Creates a new [`NetworkSubgraphClient`] with the given endpoint. - pub fn new(endpoint: impl ToString) -> Self { - const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); + const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); + /// Creates a new [`NetworkSubgraphClient`] with the given endpoint. + pub fn new(endpoint: Url, public_poi_requests: IntCounterVec) -> Self { Self { - endpoint: endpoint.to_string(), - timeout: DEFAULT_TIMEOUT, + endpoint, + timeout: Self::DEFAULT_TIMEOUT, client: reqwest::Client::new(), - public_poi_requests: todo!(), + public_poi_requests, } } @@ -59,8 +59,10 @@ impl NetworkSubgraphClient { let mut indexers: Vec> = vec![]; for indexer in response_data.indexers { let indexer_id = indexer.id.clone(); - let real_indexer = - indexer_allocation_data_to_real_indexer(IndexerAllocation { indexer }); + let real_indexer = indexer_allocation_data_to_real_indexer( + IndexerAllocation { indexer }, + self.public_poi_requests.clone(), + ); match real_indexer { Ok(indexer) => indexers.push(Arc::new(indexer)), @@ -239,11 +241,11 @@ impl NetworkSubgraphClient { variables: BTreeMap::from_iter(variables), }; - tracing::trace!(timeout = ?self.timeout, endpoint = self.endpoint, "Sending GraphQL request"); + tracing::trace!(timeout = ?self.timeout, endpoint = %self.endpoint, "Sending GraphQL request"); Ok(self .client - .post(&self.endpoint) + .post(self.endpoint.as_str()) .json(&request) .timeout(self.timeout) .send() @@ -256,6 +258,7 @@ impl NetworkSubgraphClient { fn indexer_allocation_data_to_real_indexer( indexer_allocation: IndexerAllocation, + public_poi_requests: IntCounterVec, ) -> anyhow::Result { let name = indexer_allocation.indexer.default_display_name.clone(); let indexer = indexer_allocation.indexer; @@ -265,7 +268,12 @@ fn indexer_allocation_data_to_real_indexer( .ok_or_else(|| anyhow!("Indexer without URL"))? .parse()?; url.set_path("/status"); - Ok(RealIndexer::new(name, address, url.to_string(), todo!())) + Ok(RealIndexer::new( + name, + address, + url.to_string(), + public_poi_requests, + )) } #[derive(Serialize)] @@ -331,7 +339,10 @@ mod tests { fn network_sg_client_on_ethereum() -> NetworkSubgraphClient { NetworkSubgraphClient::new( - "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet", + "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet" + .parse() + .unwrap(), + IntCounterVec::new(prometheus::Opts::new("foo", "bar"), &["a", "b"]).unwrap(), ) } diff --git a/crates/store/Cargo.toml b/crates/store/Cargo.toml index ca365c6..5e624c9 100644 --- a/crates/store/Cargo.toml +++ b/crates/store/Cargo.toml @@ -16,3 +16,8 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" tracing = "0.1" uuid = { version = "1", features = ["v4"] } + +[dev-dependencies] +testcontainers = "0.15" +testcontainers-modules = { version = "0.3", features = ["postgres"] } +tokio = { version = "1", features = ["macros"] } diff --git a/crates/store/src/diesel_queries.rs b/crates/store/src/diesel_queries.rs index d60ff60..0de48d8 100644 --- a/crates/store/src/diesel_queries.rs +++ b/crates/store/src/diesel_queries.rs @@ -1,3 +1,6 @@ +//! Provides the diesel queries, callers should handle connection pooling and +//! transactions. + use std::borrow::Cow; use std::collections::BTreeMap; diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index bddd9a0..d440e31 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -1,7 +1,5 @@ -//! Database access (read and write) abstractions for all Graphix backend -//! services. +//! Database access (read and write) abstractions for the Graphix backend. -// Provides the diesel queries, callers should handle connection pooling and transactions. mod diesel_queries; #[cfg(tests)] pub use diesel_queries; diff --git a/crates/store/src/tests.rs b/crates/store/src/tests.rs index 8c61086..d68294b 100644 --- a/crates/store/src/tests.rs +++ b/crates/store/src/tests.rs @@ -2,18 +2,17 @@ use std::collections::BTreeSet; use std::ops::Deref; use diesel::Connection; +use graphix_common_types::SgDeploymentsQuery; use testcontainers::clients::Cli; use testcontainers::Container; use crate::block_choice::BlockChoicePolicy; -use crate::graphql_api::types::SgDeploymentsQuery; -use crate::indexer::IndexerId; use crate::prometheus_metrics::metrics; use crate::queries; -use crate::store::{diesel_queries, PoiLiveness, Store}; use crate::test_utils::fast_rng; use crate::test_utils::gen::{gen_bytes32, gen_indexers}; -use crate::types::ProofOfIndexing; +use crate::{diesel_queries, PoiLiveness, Store}; +use graphix_indexer_client::{IndexerId, ProofOfIndexing}; /// A wrapper around a [`Store`] that is backed by a containerized Postgres /// database. From fabe88fd12840e4def16a01717e492fb1701c14e Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 12:23:04 +0100 Subject: [PATCH 33/34] Fix docker-compose --- ops/compose/graphix/network.yml | 2 ++ ops/compose/graphix/two-empty-graph-nodes.yml | 2 ++ ops/compose/network.yml | 31 ++----------------- ops/compose/two-empty-graph-nodes.yml | 30 ++---------------- 4 files changed, 10 insertions(+), 55 deletions(-) diff --git a/ops/compose/graphix/network.yml b/ops/compose/graphix/network.yml index 4d6edd3..fcb445c 100644 --- a/ops/compose/graphix/network.yml +++ b/ops/compose/graphix/network.yml @@ -1,3 +1,5 @@ +apiPort: 3030 + # A good mix of data sources for local development, both mainnet and testnet. databaseUrl: postgres://graphix:password@postgres-graphix:5432/graphix diff --git a/ops/compose/graphix/two-empty-graph-nodes.yml b/ops/compose/graphix/two-empty-graph-nodes.yml index 6e4a132..9b09396 100644 --- a/ops/compose/graphix/two-empty-graph-nodes.yml +++ b/ops/compose/graphix/two-empty-graph-nodes.yml @@ -1,3 +1,5 @@ +apiPort: 3030 + databaseUrl: postgres://graphix:password@postgres-graphix:5432/graphix environments: - id: graph-node-1 diff --git a/ops/compose/network.yml b/ops/compose/network.yml index b6701e3..8ce5cca 100644 --- a/ops/compose/network.yml +++ b/ops/compose/network.yml @@ -35,12 +35,11 @@ services: volumes: - ./prometheus/:/etc/prometheus/ - graphix-cross-checker: - image: edgeandnode/graphix-cross-checker + graphix: + image: edgeandnode/graphix restart: on-failure build: context: ../.. - dockerfile: ops/cross-checker.dockerfile args: CARGO_PROFILE: dev depends_on: @@ -50,34 +49,10 @@ services: RUST_LOG: graphix=debug ports: - "9184:9184" - volumes: - - ./graphix/:/config/ - command: ["--config", "/config/network.yml"] - - graphix-api-server: - image: edgeandnode/graphix-api-server - restart: on-failure - build: - context: ../.. - dockerfile: ops/api-server.dockerfile - args: - CARGO_PROFILE: dev - ports: - "3030:3030" - depends_on: - postgres-graphix: - condition: service_healthy - environment: - RUST_LOG: graphix=debug volumes: - ./graphix/:/config/ - command: - [ - "--database-url", - "postgres://graphix:password@postgres-graphix:5432/graphix", - "--port", - "3030", - ] + command: ["--config", "/config/two-empty-graph-nodes.yml"] postgres-graphix: image: postgres diff --git a/ops/compose/two-empty-graph-nodes.yml b/ops/compose/two-empty-graph-nodes.yml index b24f939..953bd7f 100644 --- a/ops/compose/two-empty-graph-nodes.yml +++ b/ops/compose/two-empty-graph-nodes.yml @@ -44,12 +44,11 @@ services: timeout: 1s retries: 1000 - graphix-cross-checker: - image: edgeandnode/graphix-cross-checker + graphix: + image: edgeandnode/graphix restart: on-failure build: context: ../.. - dockerfile: ops/cross-checker.dockerfile args: CARGO_PROFILE: dev depends_on: @@ -59,33 +58,10 @@ services: RUST_LOG: graphix=debug ports: - "9184:9184" - volumes: - - ./graphix/:/config/ - command: ["--config", "/config/two-empty-graph-nodes.yml"] - graphix-api-server: - image: edgeandnode/graphix-api-server - restart: on-failure - build: - context: ../.. - dockerfile: ops/api-server.dockerfile - args: - CARGO_PROFILE: dev - ports: - "3030:3030" - depends_on: - postgres-graphix: - condition: service_healthy - environment: - RUST_LOG: graphix=debug volumes: - ./graphix/:/config/ - command: - [ - "--database-url", - "postgres://graphix:password@postgres-graphix:5432/graphix", - "--port", - "3030", - ] + command: ["--config", "/config/two-empty-graph-nodes.yml"] graph-node-1: image: graphprotocol/graph-node From 222f24c82d5ea541522d9932db6b81640cfd780c Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Mon, 29 Jan 2024 17:26:09 +0100 Subject: [PATCH 34/34] Fix binary running conditions Signed-off-by: Filippo Costa --- .github/workflows/ci.yml | 13 +-- Cargo.lock | 1 + crates/graphix-lib/src/config.rs | 3 +- crates/graphix-lib/src/test_utils/mod.rs | 7 +- crates/graphix/Cargo.toml | 1 + crates/graphix/src/main.rs | 119 ++++++++++++++++------- 6 files changed, 91 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3643ec0..e82fdca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,20 +53,11 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push API server Docker image + - name: Build and push Graphix backend Docker image uses: docker/build-push-action@v4 with: - context: . - file: ops/api-server.dockerfile push: true - tags: ghcr.io/${{ github.repository_owner }}/graphix-api-server:latest - - name: Build and push cross-checker service Docker image - uses: docker/build-push-action@v4 - with: - context: . - file: ops/cross-checker.dockerfile - push: true - tags: ghcr.io/${{ github.repository_owner }}/graphix-cross-checker:latest + tags: ghcr.io/${{ github.repository_owner }}/graphix:latest build: name: Build diff --git a/Cargo.lock b/Cargo.lock index b5ecc0f..aff6ff7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -892,6 +892,7 @@ name = "graphix" version = "0.1.0" dependencies = [ "anyhow", + "async-graphql", "async-graphql-axum", "async-trait", "axum", diff --git a/crates/graphix-lib/src/config.rs b/crates/graphix-lib/src/config.rs index c6368e1..9179ed9 100644 --- a/crates/graphix-lib/src/config.rs +++ b/crates/graphix-lib/src/config.rs @@ -10,7 +10,8 @@ use serde::{Deserialize, Deserializer}; use tracing::{info, warn}; use url::Url; -use crate::{block_choice::BlockChoicePolicy, PrometheusMetrics}; +use crate::block_choice::BlockChoicePolicy; +use crate::PrometheusMetrics; /// A [`serde`]-compatible representation of Graphix's YAML configuration file. #[derive(Debug, Clone, Deserialize)] diff --git a/crates/graphix-lib/src/test_utils/mod.rs b/crates/graphix-lib/src/test_utils/mod.rs index ab43381..cbcb292 100644 --- a/crates/graphix-lib/src/test_utils/mod.rs +++ b/crates/graphix-lib/src/test_utils/mod.rs @@ -2,17 +2,16 @@ pub mod gen; pub mod mocks; use std::env; +use std::sync::Arc; +use graphix_indexer_client::{Indexer, RealIndexer, SubgraphDeployment}; use once_cell::sync::Lazy; use prometheus_exporter::prometheus::IntCounterVec; use rand::rngs::{OsRng, SmallRng}; use rand::{RngCore, SeedableRng}; - -use std::sync::Arc; +use url::Url; use crate::config::IndexerConfig; -use graphix_indexer_client::{Indexer, RealIndexer, SubgraphDeployment}; -use url::Url; pub static TEST_SEED: Lazy = Lazy::new(|| { let seed = env::var("TEST_SEED") diff --git a/crates/graphix/Cargo.toml b/crates/graphix/Cargo.toml index d54d078..292a4ce 100644 --- a/crates/graphix/Cargo.toml +++ b/crates/graphix/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] anyhow = "1" +async-graphql = "7" async-trait = "0.1.52" clap = { version = "4", features = ["derive", "env"] } futures = "0.3.18" diff --git a/crates/graphix/src/main.rs b/crates/graphix/src/main.rs index 83dc5d7..24fc4cf 100644 --- a/crates/graphix/src/main.rs +++ b/crates/graphix/src/main.rs @@ -4,17 +4,24 @@ mod bisect; mod utils; use std::collections::HashSet; +use std::net::Ipv4Addr; use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; +use async_graphql::http::GraphiQLSource; +use async_graphql_axum::GraphQL; +use axum::response::IntoResponse; +use axum::Router; use clap::Parser; use graphix_indexer_client::{Indexer, IndexerId}; use graphix_lib::config::Config; +use graphix_lib::graphql_api::{self}; use graphix_lib::queries::{query_indexing_statuses, query_proofs_of_indexing}; use graphix_lib::{config, metrics, PrometheusExporter}; use graphix_store::{PoiLiveness, Store}; use prometheus_exporter::prometheus; +use tokio::net::TcpListener; use tokio::sync::watch; use tracing::*; @@ -40,56 +47,76 @@ async fn main() -> anyhow::Result<()> { let store = Store::new(&config.database_url).await?; info!("Store initialization successful"); - let sleep_duration = Duration::from_secs(config.polling_period_in_seconds); + if config.enable_api { + let config = config.clone(); + tokio::spawn(async move { + // Listen to requests forever. + axum::serve( + TcpListener::bind((Ipv4Addr::UNSPECIFIED, config.api_port)).await?, + axum_server(&config).await?, + ) + .await?; + + Result::<(), anyhow::Error>::Ok(()) + }); + } - // Prometheus metrics. - let registry = prometheus::default_registry().clone(); - let _exporter = PrometheusExporter::start(config.prometheus_port, registry.clone()).unwrap(); + if config.enable_indexing { + let sleep_duration = Duration::from_secs(config.polling_period_in_seconds); - info!("Initializing bisect request handler"); - let store_clone = store.clone(); - let (tx_indexers, rx_indexers) = watch::channel(vec![]); - tokio::spawn(async move { - handle_divergence_investigation_requests(&store_clone, rx_indexers) - .await - .unwrap() - }); + // Prometheus metrics. + let registry = prometheus::default_registry().clone(); + let _exporter = + PrometheusExporter::start(config.prometheus_port, registry.clone()).unwrap(); - loop { - info!("New main loop iteration"); - info!("Initialize inputs (indexers, indexing statuses etc.)"); + info!("Initializing bisect request handler"); + let store_clone = store.clone(); + let (tx_indexers, rx_indexers) = watch::channel(vec![]); + tokio::spawn(async move { + handle_divergence_investigation_requests(&store_clone, rx_indexers) + .await + .unwrap() + }); - let mut indexers = config::config_to_indexers(config.clone(), metrics()).await?; - // Different data sources, especially network subgraphs, result in - // duplicate indexers. - indexers = deduplicate_indexers(&indexers); + loop { + info!("New main loop iteration"); + info!("Initialize inputs (indexers, indexing statuses etc.)"); - store.write_indexers(&indexers)?; + let mut indexers = config::config_to_indexers(config.clone(), metrics()).await?; + // Different data sources, especially network subgraphs, result in + // duplicate indexers. + indexers = deduplicate_indexers(&indexers); - tx_indexers.send(indexers.clone())?; + store.write_indexers(&indexers)?; - let graph_node_versions = - graphix_lib::queries::query_graph_node_versions(&indexers, metrics()).await; - store.write_graph_node_versions(graph_node_versions)?; + tx_indexers.send(indexers.clone())?; - let indexing_statuses = query_indexing_statuses(indexers, metrics()).await; + let graph_node_versions = + graphix_lib::queries::query_graph_node_versions(&indexers, metrics()).await; + store.write_graph_node_versions(graph_node_versions)?; - info!("Monitor proofs of indexing"); - let pois = query_proofs_of_indexing(indexing_statuses, config.block_choice_policy).await; + let indexing_statuses = query_indexing_statuses(indexers, metrics()).await; - info!(pois = pois.len(), "Finished tracking Pois"); + info!("Monitor proofs of indexing"); + let pois = + query_proofs_of_indexing(indexing_statuses, config.block_choice_policy).await; - let write_err = store.write_pois(&pois, PoiLiveness::Live).err(); - if let Some(err) = write_err { - error!(error = %err, "Failed to write POIs to database"); - } + info!(pois = pois.len(), "Finished tracking Pois"); + + let write_err = store.write_pois(&pois, PoiLiveness::Live).err(); + if let Some(err) = write_err { + error!(error = %err, "Failed to write POIs to database"); + } - info!( - sleep_seconds = sleep_duration.as_secs(), - "Sleeping for a while before next main loop iteration" - ); - tokio::time::sleep(sleep_duration).await; + info!( + sleep_seconds = sleep_duration.as_secs(), + "Sleeping for a while before next main loop iteration" + ); + tokio::time::sleep(sleep_duration).await; + } } + + Ok(()) } fn init_tracing() { @@ -113,3 +140,21 @@ fn deduplicate_indexers(indexers: &[Arc]) -> Vec> ); deduplicated } + +async fn axum_server(config: &Config) -> anyhow::Result> { + use axum::routing::get; + + let store = Store::new(config.database_url.as_str()).await?; + let api_schema = graphql_api::api_schema(graphql_api::ApiSchemaContext { store }); + + Ok(axum::Router::new() + .route("/", get(|| async { "Ready to roll!" })) + .route( + "/graphql", + get(graphiql_route).post_service(GraphQL::new(api_schema)), + )) +} + +async fn graphiql_route() -> impl IntoResponse { + axum::response::Html(GraphiQLSource::build().endpoint("/graphql").finish()) +}