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

enable static filters for SGs with many dynamic datasource #4008

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

mangas
Copy link
Contributor

@mangas mangas commented Sep 29, 2022

Add a subgraph start check for number of dynamic data sources. If above the defined threshold, force static filters.

@@ -230,6 +230,9 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
(manifest, manifest_idx_and_name)
};

let static_filters = self.static_filters
|| (manifest.network_name() == "bsc" && manifest.templates.len() > 10000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to do this for any network.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leoyvens thoughts about this?

@@ -230,6 +230,9 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
(manifest, manifest_idx_and_name)
};

let static_filters = self.static_filters
|| (manifest.network_name() == "bsc" && manifest.templates.len() > 10000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't manifest.templates.len() just the number of templates in the manifest? We want to count actual dynamic data sources, so want to look at data_sources.len() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was trying to avoid including the data_sources but you're right, it's prolly a few in 10000 so that should be fine, I'll change this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this also uses the previously stored data sources, so I need to trim those as well

@leoyvens
Copy link
Collaborator

leoyvens commented Sep 29, 2022

Looking at how static filters are currently implemented, this might not have the intended effect. Because it currently will add the filters from the templates but it doesn't prevent the filters from the dynamic data sources from being added.

When static filters are enabled, we need the final filter to be static data sources + templates, ignoring the stored dynamic data sources.

Edit: I see @mangas just said the same thing in the above thread.

@@ -218,18 +218,28 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {

info!(logger, "Successfully resolved subgraph files using IPFS");

// Add dynamic data sources to the subgraph
manifest.data_sources.extend(data_sources);

info!(
logger,
"Data source count at start: {}",
manifest.data_sources.len()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do want this log to include the count of dynamic data sources.

let dds_count = manifest
.data_sources
.len()
.abs_diff(static_data_sources.len());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother doing the diff and would just use the total len but this is also fine.

let onchain_data_sources = static_data_sources
.iter()
.filter_map(|d| d.as_onchain().cloned())
.collect::<Vec<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to collect if iter() will be called right after.

// if static_filters is enabled, build a minimal filter with the static data sources and
// add the necessary filters based on templates.
// if not enabled we just stick to the filter based on all the data sources.
// This changes specifically removes dynamic data sources based filters because these can be derived
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This changes specifically removes dynamic data sources based filters because these can be derived
// This specifically removes dynamic data sources based filters because these can be derived

@mangas mangas marked this pull request as ready for review September 29, 2022 18:11
graph/src/env/mod.rs Outdated Show resolved Hide resolved
@mangas mangas changed the title enable static filters for BSC enable static filters for SGs with many dynamic datasource Oct 3, 2022
@mangas mangas merged commit 7cf57b0 into master Oct 3, 2022
@mangas mangas deleted the enable-bsc-static-filters branch October 3, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants