Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Graph Node version and commit to index-node API #4852

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions server/index-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ http = "0.2"
hyper = "0.14"
lazy_static = "1.2.0"
serde = "1.0"
git-testament = "0.2.4"
34 changes: 34 additions & 0 deletions server/index-node/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::convert::TryInto;
use graph::data::query::Trace;
use web3::types::Address;

use git_testament::{git_testament, CommitKind};
use graph::blockchain::{Blockchain, BlockchainKind, BlockchainMap};
use graph::components::store::{BlockPtrForNumber, BlockStore, EntityType, Store};
use graph::components::versions::VERSIONS;
Expand All @@ -18,6 +19,19 @@ use crate::auth::PoiProtection;
/// Timeout for calls to fetch the block from JSON-RPC or Firehose.
const BLOCK_HASH_FROM_NUMBER_TIMEOUT: Duration = Duration::from_secs(10);

git_testament!(TESTAMENT);

lazy_static! {
static ref VERSION: Version = Version {
version: env!("CARGO_PKG_VERSION").to_string(),
commit: match TESTAMENT.commit {
CommitKind::FromTag(_, hash, _, _) => hash.to_string(),
CommitKind::NoTags(hash, _) => hash.to_string(),
_ => "unknown".to_string(),
}
};
}

#[derive(Clone, Debug)]
struct PublicProofOfIndexingRequest {
pub deployment: DeploymentHash,
Expand All @@ -39,6 +53,21 @@ impl TryFromValue for PublicProofOfIndexingRequest {
}
}

#[derive(Clone, Debug)]
struct Version {
version: String,
commit: String,
}

impl IntoValue for Version {
fn into_value(self) -> r::Value {
object! {
version: self.version,
commit: self.commit,
}
}
}

#[derive(Debug)]
struct PublicProofOfIndexingResult {
pub deployment: DeploymentHash,
Expand Down Expand Up @@ -469,6 +498,10 @@ impl<S: Store> IndexNodeResolver<S> {
))
}

fn version(&self) -> Result<r::Value, QueryExecutionError> {
Ok(VERSION.clone().into_value())
}

async fn block_ptr_for_number(
&self,
network: String,
Expand Down Expand Up @@ -700,6 +733,7 @@ impl<S: Store> Resolver for IndexNodeResolver<S> {
(None, "entityChangesInBlock") => self.resolve_entity_changes_in_block(field),
// The top-level `subgraphVersions` field
(None, "apiVersions") => self.resolve_api_versions(field),
(None, "version") => self.version(),

// Resolve fields of `Object` values (e.g. the `latestBlock` field of `EthereumBlock`)
(value, _) => Ok(value.unwrap_or(r::Value::Null)),
Expand Down
6 changes: 6 additions & 0 deletions server/index-node/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ type Query {
entityChangesInBlock(subgraphId: String!, blockNumber: Int!): EntityChanges!
blockData(network: String!, blockHash: Bytes!): JSONObject
blockHashFromNumber(network: String!, blockNumber: Int!): Bytes
version: Version!
cachedEthereumCalls(
network: String!
blockHash: Bytes!
): [CachedEthereumCall!]
apiVersions(subgraphId: String!): [ApiVersion!]!
}

type Version {
version: String!
commit: String!
}

type SubgraphIndexingStatus {
subgraph: String!
synced: Boolean!
Expand Down