diff --git a/Cargo.lock b/Cargo.lock index 84a722d4..8f2d636e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -965,6 +965,49 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "build-info" +version = "0.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "155eb070980e96aeb4ef3b8620b0febb2ae5e17451dc1b329681bdd4eb0a94e1" +dependencies = [ + "build-info-common", + "build-info-proc", +] + +[[package]] +name = "build-info-common" +version = "0.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8209c0c2b13da7e5f7202e591b6d41b46c8f0e78d031dedf5cff71cc8c6ec773" +dependencies = [ + "chrono", + "derive_more", + "semver 1.0.17", + "serde", +] + +[[package]] +name = "build-info-proc" +version = "0.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc1874cb1995691fb01f9bb56e75f9660d2614e74607fa71c08a8b3bd7e30e4" +dependencies = [ + "anyhow", + "base64 0.21.4", + "bincode", + "build-info-common", + "chrono", + "num-bigint", + "num-traits", + "proc-macro-error", + "proc-macro2", + "quote", + "serde_json", + "syn 2.0.28", + "zstd 0.12.4", +] + [[package]] name = "bumpalo" version = "3.13.0" @@ -1096,15 +1139,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", "serde", - "winapi", + "windows-targets 0.48.0", ] [[package]] @@ -2943,6 +2986,7 @@ dependencies = [ "arc-swap", "async-trait", "axum 0.6.20", + "build-info", "env_logger", "ethers", "ethers-core", @@ -6767,7 +6811,7 @@ dependencies = [ "pbkdf2 0.11.0", "sha1", "time", - "zstd", + "zstd 0.11.2+zstd.1.5.2", ] [[package]] @@ -6776,7 +6820,16 @@ version = "0.11.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" dependencies = [ - "zstd-safe", + "zstd-safe 5.0.2+zstd.1.5.2", +] + +[[package]] +name = "zstd" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +dependencies = [ + "zstd-safe 6.0.6", ] [[package]] @@ -6789,6 +6842,16 @@ dependencies = [ "zstd-sys", ] +[[package]] +name = "zstd-safe" +version = "6.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +dependencies = [ + "libc", + "zstd-sys", +] + [[package]] name = "zstd-sys" version = "2.0.8+zstd.1.5.5" diff --git a/Cargo.toml b/Cargo.toml index c0b50447..cdc8e47e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,5 @@ [workspace] -members = [ - "common", - "service", -] +members = ["common", "service"] resolver = "2" [profile.dev.package."*"] diff --git a/common/Cargo.toml b/common/Cargo.toml index a62a0b35..18839bde 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -39,6 +39,7 @@ thiserror = "1.0.49" async-trait = "0.1.74" headers-derive = "0.1.1" headers = "0.3.9" +build-info = "0.0.34" [dev-dependencies] env_logger = "0.9.0" diff --git a/common/src/indexer_service/http/indexer_service.rs b/common/src/indexer_service/http/indexer_service.rs index 7dd24cda..df1c888d 100644 --- a/common/src/indexer_service/http/indexer_service.rs +++ b/common/src/indexer_service/http/indexer_service.rs @@ -8,8 +8,9 @@ use axum::{ body::Body, response::{IntoResponse, Response}, routing::{get, post}, - Router, Server, + Json, Router, Server, }; +use build_info::BuildInfo; use eventuals::Eventual; use reqwest::StatusCode; use serde::{de::DeserializeOwned, Serialize}; @@ -114,12 +115,34 @@ where } } +#[derive(Clone, Serialize)] +pub struct IndexerServiceRelease { + version: String, + dependencies: HashMap, +} + +impl From<&BuildInfo> for IndexerServiceRelease { + fn from(value: &BuildInfo) -> Self { + Self { + version: value.crate_info.version.to_string(), + dependencies: HashMap::from_iter( + value + .crate_info + .dependencies + .iter() + .map(|d| (d.name.clone(), d.version.to_string())), + ), + } + } +} + pub struct IndexerServiceOptions where I: IndexerServiceImpl + Sync + Send + 'static, { pub service_impl: I, pub config: IndexerServiceConfig, + pub release: IndexerServiceRelease, pub extra_routes: Router>, Body>, } @@ -230,6 +253,7 @@ impl IndexerService { let router = Router::new() .route("/", get("Service is up and running")) + .route("/version", get(Json(options.release))) .route( PathBuf::from(options.config.server.url_prefix) .join("manifests/:id") diff --git a/common/src/indexer_service/http/mod.rs b/common/src/indexer_service/http/mod.rs index 26ab0f83..bf7b580f 100644 --- a/common/src/indexer_service/http/mod.rs +++ b/common/src/indexer_service/http/mod.rs @@ -8,5 +8,5 @@ pub use config::{ NetworkSubgraphConfig, ServerConfig, }; pub use indexer_service::{ - IndexerService, IndexerServiceImpl, IndexerServiceOptions, IsAttestable, + IndexerService, IndexerServiceImpl, IndexerServiceOptions, IndexerServiceRelease, IsAttestable, }; diff --git a/service/Cargo.toml b/service/Cargo.toml index d9e9c0d9..a7c7f2f3 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -2,7 +2,7 @@ name = "service" version = "0.1.0" edition = "2021" -description="Could not find crate on crates.io and could not import with git and path at the same time, so copied a version directly at https://github.com/graphprotocol/indexer/blob/972658b3ce8c512ad7b4dc575d29cd9d5377e3fe/packages/indexer-native/native" +description = "Could not find crate on crates.io and could not import with git and path at the same time, so copied a version directly at https://github.com/graphprotocol/indexer/blob/972658b3ce8c512ad7b4dc575d29cd9d5377e3fe/packages/indexer-native/native" license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -25,7 +25,11 @@ serde_json = "1" axum = "0.5" hyper = "0.14.27" tower = { version = "0.4", features = ["util", "timeout", "limit"] } -tower-http = { version = "0.4.0", features = ["add-extension", "trace", "cors"] } +tower-http = { version = "0.4.0", features = [ + "add-extension", + "trace", + "cors", +] } toml = "0.7.4" once_cell = "1.17" async-graphql = "4.0.16" @@ -44,11 +48,19 @@ prometheus = "0.13.3" hex = "0.4.3" tap_core = "0.6.0" ethereum-types = "0.14.1" -sqlx = { version = "0.7.1", features = ["postgres", "runtime-tokio", "bigdecimal", "rust_decimal", "time"] } +sqlx = { version = "0.7.1", features = [ + "postgres", + "runtime-tokio", + "bigdecimal", + "rust_decimal", + "time", +] } alloy-primitives = { version = "0.4.2", features = ["serde"] } alloy-sol-types = "0.4.2" lazy_static = "1.4.0" -toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = ["graphql"] } +toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = [ + "graphql", +] } [dev-dependencies] faux = "0.1.10" @@ -65,4 +77,4 @@ wiremock = "0.5.19" version = "1" default-features = false # Disable features which are enabled by default -features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"] \ No newline at end of file +features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"]