Skip to content

Commit

Permalink
fix: network subgraph queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Jul 29, 2024
1 parent b934317 commit f3074d0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ semver = { version = "1.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.116", features = ["raw_value"] }
serde_with = "3.8.1"
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "16e22a8" }
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "db1ab45" }
thegraph-graphql-http = "0.2.1"
thiserror = "1.0.59"
tokio = { version = "1.38.0", features = [
Expand Down
17 changes: 3 additions & 14 deletions graph-gateway/src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ use super::{
ResolutionError,
};

/// Default update interval for the network topology information.
pub const DEFAULT_UPDATE_INTERVAL: Duration = Duration::from_secs(60);

const NETWORK_TOPOLOGY_FETCH_TIMEOUT: Duration = Duration::from_secs(15);

/// Subgraph resolution information returned by the [`NetworkService`].
pub struct ResolvedSubgraphInfo {
/// Subgraph chain name.
Expand Down Expand Up @@ -230,7 +225,7 @@ impl NetworkServiceBuilder {
indexer_indexing_progress_resolver,
indexer_indexing_cost_model_resolver,
indexer_indexing_cost_model_compiler,
update_interval: DEFAULT_UPDATE_INTERVAL,
update_interval: Duration::from_secs(60),
}
}

Expand Down Expand Up @@ -349,17 +344,11 @@ fn spawn_updater_task(

let mut timer = tokio::time::interval(update_interval);
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);

// Fetch the network topology information every `update_interval` duration
// If the fetch fails or takes too long, log a warning and skip the update
loop {
timer.tick().await;

match fetch_and_preprocess_subgraph_info(
&mut subgraph_client,
NETWORK_TOPOLOGY_FETCH_TIMEOUT,
)
.await
match fetch_and_preprocess_subgraph_info(&mut subgraph_client, Duration::from_secs(30))
.await
{
Ok(info) => network_info = Some(info),
Err(network_subgraph_update_err) => tracing::error!(%network_subgraph_update_err),
Expand Down
10 changes: 5 additions & 5 deletions graph-gateway/src/network/subgraph_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ impl Client {
);
query_block = Some(data.meta.block);
}
let last_entry_id = data.results.last().map(|entry| entry.id.to_string());
last_id = data.results.last().map(|entry| entry.id.to_string());
let page_len = data.results.len();
results.append(&mut data.results);
last_id = match last_entry_id {
Some(last_id) => Some(last_id),
None => break,
};
if page_len < self.page_size {
break;
}
}

self.latest_block = Some(query_block.unwrap());
Expand Down

0 comments on commit f3074d0

Please sign in to comment.