Skip to content

Commit a349d98

Browse files
incrypto32lutter
authored andcommitted
Revert "graph, store: Simplify VersionInfo"
This reverts commit 2d18674.
1 parent 553b6ac commit a349d98

File tree

8 files changed

+104
-29
lines changed

8 files changed

+104
-29
lines changed

graph/src/components/server/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/// Component for running GraphQL queries over HTTP.
22
pub mod query;
33

4+
/// Component for the index node server.
5+
pub mod index_node;
6+
47
pub mod server;

store/postgres/src/deployment.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,27 @@ pub fn schema(conn: &mut PgConnection, site: &Site) -> Result<(InputSchema, bool
341341
}
342342

343343
pub struct ManifestInfo {
344+
pub description: Option<String>,
345+
pub repository: Option<String>,
344346
pub spec_version: String,
345347
pub instrument: bool,
346348
}
347349

348350
impl ManifestInfo {
349351
pub fn load(conn: &mut PgConnection, site: &Site) -> Result<ManifestInfo, StoreError> {
350352
use subgraph_manifest as sm;
351-
let (spec_version, features): (String, Vec<String>) = sm::table
352-
.select((sm::spec_version, sm::features))
353+
let (description, repository, spec_version, features): (
354+
Option<String>,
355+
Option<String>,
356+
String,
357+
Vec<String>,
358+
) = sm::table
359+
.select((
360+
sm::description,
361+
sm::repository,
362+
sm::spec_version,
363+
sm::features,
364+
))
353365
.filter(sm::id.eq(site.id))
354366
.first(conn)?;
355367

@@ -359,6 +371,8 @@ impl ManifestInfo {
359371
let instrument = features.iter().any(|s| s == "instrument");
360372

361373
Ok(ManifestInfo {
374+
description,
375+
repository,
362376
spec_version,
363377
instrument,
364378
})

store/postgres/src/deployment_store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub(crate) struct SubgraphInfo {
8282
/// The deployment hash of the remote subgraph whose store
8383
/// will be GraphQL queried, for debugging purposes.
8484
pub(crate) debug_fork: Option<DeploymentHash>,
85+
pub(crate) description: Option<String>,
86+
pub(crate) repository: Option<String>,
8587
pub(crate) poi_version: ProofOfIndexingVersion,
8688
pub(crate) instrument: bool,
8789
}
@@ -497,6 +499,8 @@ impl DeploymentStore {
497499
api,
498500
graft_block,
499501
debug_fork,
502+
description: manifest_info.description,
503+
repository: manifest_info.repository,
500504
poi_version,
501505
instrument: manifest_info.instrument,
502506
};

store/postgres/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub mod layout_for_tests {
4848
make_dummy_site, Connection, Mirror, Namespace, EVENT_TAP, EVENT_TAP_ENABLED,
4949
};
5050
pub use crate::relational::*;
51-
pub use crate::store::VersionInfo;
5251
pub mod writable {
5352
pub use crate::writable::test_support::allow_steps;
5453
}

store/postgres/src/primary.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,13 @@ pub fn make_dummy_site(deployment: DeploymentHash, namespace: Namespace, network
441441
/// read-only
442442
mod queries {
443443
use diesel::data_types::PgTimestamp;
444-
use diesel::dsl::exists;
444+
use diesel::dsl::{exists, sql};
445445
use diesel::pg::PgConnection;
446446
use diesel::prelude::{
447447
ExpressionMethods, JoinOnDsl, NullableExpressionMethods, OptionalExtension, QueryDsl,
448448
RunQueryDsl,
449449
};
450+
use diesel::sql_types::Text;
450451
use graph::prelude::NodeId;
451452
use graph::{
452453
components::store::DeploymentId as GraphDeploymentId,
@@ -713,14 +714,14 @@ mod queries {
713714
.transpose()
714715
}
715716

716-
pub(super) fn deployment_for_version(
717+
pub(super) fn version_info(
717718
conn: &mut PgConnection,
718719
version: &str,
719-
) -> Result<Option<String>, StoreError> {
720+
) -> Result<Option<(String, String)>, StoreError> {
720721
Ok(v::table
721-
.select(v::deployment)
722+
.select((v::deployment, sql::<Text>("created_at::text")))
722723
.filter(v::id.eq(version))
723-
.first::<String>(conn)
724+
.first::<(String, String)>(conn)
724725
.optional()?)
725726
}
726727
}
@@ -2074,8 +2075,8 @@ impl Mirror {
20742075
self.read(|conn| queries::fill_assignments(conn, infos))
20752076
}
20762077

2077-
pub fn deployment_for_version(&self, version: &str) -> Result<Option<String>, StoreError> {
2078-
self.read(|conn| queries::deployment_for_version(conn, version))
2078+
pub fn version_info(&self, version: &str) -> Result<Option<(String, String)>, StoreError> {
2079+
self.read(|conn| queries::version_info(conn, version))
20792080
}
20802081

20812082
pub fn find_site_in_shard(

store/postgres/src/store.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ use async_trait::async_trait;
22
use std::sync::Arc;
33

44
use graph::{
5-
components::store::{
6-
BlockPtrForNumber, BlockStore as BlockStoreTrait, QueryPermit, QueryStoreManager,
7-
StatusStore, Store as StoreTrait,
5+
components::{
6+
server::index_node::VersionInfo,
7+
store::{
8+
BlockPtrForNumber, BlockStore as BlockStoreTrait, QueryPermit, QueryStoreManager,
9+
StatusStore, Store as StoreTrait,
10+
},
811
},
912
data::subgraph::status,
1013
internal_error,
@@ -16,14 +19,6 @@ use graph::{
1619

1720
use crate::{block_store::BlockStore, query_store::QueryStore, SubgraphStore};
1821

19-
/// This is only needed for some tests
20-
#[derive(Debug)]
21-
pub struct VersionInfo {
22-
pub deployment_id: String,
23-
pub latest_ethereum_block_number: Option<BlockNumber>,
24-
pub failed: bool,
25-
}
26-
2722
/// The overall store of the system, consisting of a [`SubgraphStore`] and a
2823
/// [`BlockStore`], each of which multiplex across multiple database shards.
2924
/// The `SubgraphStore` is responsible for storing all data and metadata related
@@ -57,7 +52,9 @@ impl Store {
5752
}
5853

5954
pub fn version_info(&self, version_id: &str) -> Result<VersionInfo, StoreError> {
60-
let info = self.subgraph_store.version_info(version_id)?;
55+
let mut info = self.subgraph_store.version_info(version_id)?;
56+
57+
info.total_ethereum_blocks_count = self.block_store.chain_head_block(&info.network)?;
6158

6259
Ok(info)
6360
}

store/postgres/src/subgraph_store.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ use std::{iter::FromIterator, time::Duration};
1414
use graph::futures03::future::join_all;
1515
use graph::{
1616
cheap_clone::CheapClone,
17-
components::store::{
18-
self, BlockPtrForNumber, BlockStore, DeploymentLocator, EnsLookup as EnsLookupTrait,
19-
PruneReporter, PruneRequest, SubgraphFork,
17+
components::{
18+
server::index_node::VersionInfo,
19+
store::{
20+
self, BlockPtrForNumber, BlockStore, DeploymentLocator, EnsLookup as EnsLookupTrait,
21+
PruneReporter, PruneRequest, SubgraphFork,
22+
},
2023
},
2124
data::query::QueryTarget,
2225
data::subgraph::{schema::DeploymentCreate, status, DeploymentFeatures},
@@ -41,7 +44,6 @@ use crate::{
4144
index::{IndexList, Method},
4245
Layout,
4346
},
44-
store::VersionInfo,
4547
writable::{SourceableStore, WritableStore},
4648
ConnectionPool, NotificationSender,
4749
};
@@ -980,7 +982,7 @@ impl SubgraphStoreInner {
980982
}
981983

982984
pub(crate) fn version_info(&self, version: &str) -> Result<VersionInfo, StoreError> {
983-
if let Some(deployment_id) = self.mirror.deployment_for_version(version)? {
985+
if let Some((deployment_id, created_at)) = self.mirror.version_info(version)? {
984986
let id = DeploymentHash::new(deployment_id.clone())
985987
.map_err(|id| internal_error!("illegal deployment id {}", id))?;
986988
let (store, site) = self.store(&id)?;
@@ -994,11 +996,21 @@ impl SubgraphStoreInner {
994996
.ok_or_else(|| internal_error!("no chain info for {}", deployment_id))?;
995997
let latest_ethereum_block_number =
996998
chain.latest_block.as_ref().map(|block| block.number());
999+
let subgraph_info = store.subgraph_info(site.cheap_clone())?;
1000+
let layout = store.find_layout(site.cheap_clone())?;
1001+
let network = site.network.clone();
9971002

9981003
let info = VersionInfo {
1004+
created_at,
9991005
deployment_id,
10001006
latest_ethereum_block_number,
1007+
total_ethereum_blocks_count: None,
1008+
synced: status.synced,
10011009
failed: status.health.is_failed(),
1010+
description: subgraph_info.description,
1011+
repository: subgraph_info.repository,
1012+
schema: layout.input_schema.cheap_clone(),
1013+
network,
10021014
};
10031015
Ok(info)
10041016
} else {

store/test-store/tests/postgres/subgraph.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use graph::futures03;
22
use graph::{
3-
components::store::{DeploymentId, DeploymentLocator, StatusStore},
3+
components::{
4+
server::index_node::VersionInfo,
5+
store::{DeploymentId, DeploymentLocator, StatusStore},
6+
},
47
data::query::QueryTarget,
58
data::subgraph::{schema::SubgraphHealth, SubgraphFeature},
69
data::subgraph::{
@@ -19,7 +22,7 @@ use graph::{
1922
schema::InputSchema,
2023
semver::Version,
2124
};
22-
use graph_store_postgres::layout_for_tests::{Connection as Primary, VersionInfo};
25+
use graph_store_postgres::layout_for_tests::Connection as Primary;
2326
use graph_store_postgres::SubgraphStore;
2427
use std::{collections::HashSet, marker::PhantomData, sync::Arc};
2528
use test_store::*;
@@ -470,6 +473,48 @@ fn status() {
470473
})
471474
}
472475

476+
#[test]
477+
fn version_info() {
478+
const NAME: &str = "versionInfoSubgraph";
479+
480+
async fn setup() -> DeploymentLocator {
481+
let id = DeploymentHash::new(NAME).unwrap();
482+
remove_subgraphs();
483+
block_store::set_chain(vec![], NETWORK_NAME).await;
484+
create_test_subgraph(&id, SUBGRAPH_GQL).await
485+
}
486+
487+
run_test_sequentially(|store| async move {
488+
let deployment = setup().await;
489+
transact_and_wait(
490+
&store.subgraph_store(),
491+
&deployment,
492+
BLOCK_ONE.clone(),
493+
vec![],
494+
)
495+
.await
496+
.unwrap();
497+
498+
let vi = get_version_info(&store, NAME);
499+
assert_eq!(NAME, vi.deployment_id.as_str());
500+
assert_eq!(false, vi.synced);
501+
assert_eq!(false, vi.failed);
502+
assert_eq!(
503+
Some("manifest for versionInfoSubgraph"),
504+
vi.description.as_deref()
505+
);
506+
assert_eq!(
507+
Some("repo for versionInfoSubgraph"),
508+
vi.repository.as_deref()
509+
);
510+
assert_eq!(NAME, vi.schema.id().as_str());
511+
assert_eq!(Some(1), vi.latest_ethereum_block_number);
512+
assert_eq!(NETWORK_NAME, vi.network.as_str());
513+
// We set the head for the network to null in the test framework
514+
assert_eq!(None, vi.total_ethereum_blocks_count);
515+
})
516+
}
517+
473518
#[test]
474519
fn subgraph_features() {
475520
run_test_sequentially(|_store| async move {

0 commit comments

Comments
 (0)