Skip to content

Commit

Permalink
feat: support prioritizing local subgraph if synced and healthy
Browse files Browse the repository at this point in the history
This is how the existing indexer-common does it - it uses the local
network subgraph if it's synced and healthy, otherwise falls back to a
remote subgraph URL.
  • Loading branch information
Jannis committed Oct 24, 2023
1 parent eac5926 commit aad4f52
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 156 deletions.
19 changes: 10 additions & 9 deletions common/src/allocations/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,29 @@ pub fn indexer_allocations(

#[cfg(test)]
mod test {
use reqwest::Url;
use serde_json::json;
use wiremock::{
matchers::{body_string_contains, method, path},
Mock, MockServer, ResponseTemplate,
};

use crate::{prelude::SubgraphClient, test_vectors};
use crate::{prelude::SubgraphClient, subgraph_client::DeploymentDetails, test_vectors};

use super::*;

async fn setup_mock_network_subgraph() -> (&'static SubgraphClient, MockServer) {
// Set up a mock network subgraph
let mock_server = MockServer::start().await;
let network_subgraph_endpoint = Url::parse(&format!(
"{}/subgraphs/id/{}",
&mock_server.uri(),
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
))
let network_subgraph = SubgraphClient::new(
None,
DeploymentDetails::for_query_url(&format!(
"{}/subgraphs/id/{}",
&mock_server.uri(),
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
))
.unwrap(),
)
.unwrap();
let network_subgraph =
SubgraphClient::new("network-subgraph", network_subgraph_endpoint.as_ref()).unwrap();

// Mock result for current epoch requests
mock_server
Expand Down
18 changes: 10 additions & 8 deletions common/src/attestations/dispute_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn dispute_manager(

#[cfg(test)]
mod test {
use reqwest::Url;
use serde_json::json;
use wiremock::{
matchers::{method, path},
Expand All @@ -90,6 +89,7 @@ mod test {

use crate::{
prelude::SubgraphClient,
subgraph_client::DeploymentDetails,
test_vectors::{self, DISPUTE_MANAGER_ADDRESS},
};

Expand All @@ -98,14 +98,16 @@ mod test {
async fn setup_mock_network_subgraph() -> (&'static SubgraphClient, MockServer) {
// Set up a mock network subgraph
let mock_server = MockServer::start().await;
let network_subgraph_endpoint = Url::parse(&format!(
"{}/subgraphs/id/{}",
&mock_server.uri(),
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
))
let network_subgraph = SubgraphClient::new(
None,
DeploymentDetails::for_query_url(&format!(
"{}/subgraphs/id/{}",
&mock_server.uri(),
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
))
.unwrap(),
)
.unwrap();
let network_subgraph =
SubgraphClient::new("network-subgraph", network_subgraph_endpoint.as_ref()).unwrap();

// Mock result for current epoch requests
mock_server
Expand Down
19 changes: 11 additions & 8 deletions common/src/escrow_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ pub fn escrow_accounts(

#[cfg(test)]
mod tests {
use reqwest::Url;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

use crate::prelude::DeploymentDetails;
use crate::test_vectors;

use super::*;
Expand All @@ -127,14 +127,17 @@ mod tests {
async fn test_current_accounts() {
// Set up a mock escrow subgraph
let mock_server = MockServer::start().await;
let escrow_subgraph_endpoint = Url::parse(&format!(
"{}/subgraphs/id/{}",
&mock_server.uri(),
*test_vectors::ESCROW_SUBGRAPH_DEPLOYMENT
))
.unwrap();
let escrow_subgraph = Box::leak(Box::new(
SubgraphClient::new("escrow-subgraph", escrow_subgraph_endpoint.as_ref()).unwrap(),
SubgraphClient::new(
None,
DeploymentDetails::for_query_url(&format!(
"{}/subgraphs/id/{}",
&mock_server.uri(),
*test_vectors::ESCROW_SUBGRAPH_DEPLOYMENT
))
.unwrap(),
)
.unwrap(),
));

let mock = Mock::given(method("POST"))
Expand Down
2 changes: 1 addition & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub mod prelude {
dispute_manager::dispute_manager, signer::AttestationSigner, signers::attestation_signers,
};
pub use super::escrow_accounts::escrow_accounts;
pub use super::subgraph_client::SubgraphClient;
pub use super::subgraph_client::{DeploymentDetails, SubgraphClient};
pub use super::tap_manager::TapManager;
}
126 changes: 0 additions & 126 deletions common/src/subgraph_client.rs

This file was deleted.

Loading

0 comments on commit aad4f52

Please sign in to comment.