Skip to content

Commit 235693f

Browse files
committed
feat: support prioritizing local subgraph if synced and healthy
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.
1 parent 06c26b7 commit 235693f

File tree

9 files changed

+362
-156
lines changed

9 files changed

+362
-156
lines changed

common/src/allocations/monitor.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,28 +189,29 @@ pub fn indexer_allocations(
189189

190190
#[cfg(test)]
191191
mod test {
192-
use reqwest::Url;
193192
use serde_json::json;
194193
use wiremock::{
195194
matchers::{body_string_contains, method, path},
196195
Mock, MockServer, ResponseTemplate,
197196
};
198197

199-
use crate::{prelude::SubgraphClient, test_vectors};
198+
use crate::{prelude::SubgraphClient, subgraph_client::DeploymentDetails, test_vectors};
200199

201200
use super::*;
202201

203202
async fn setup_mock_network_subgraph() -> (&'static SubgraphClient, MockServer) {
204203
// Set up a mock network subgraph
205204
let mock_server = MockServer::start().await;
206-
let network_subgraph_endpoint = Url::parse(&format!(
207-
"{}/subgraphs/id/{}",
208-
&mock_server.uri(),
209-
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
210-
))
205+
let network_subgraph = SubgraphClient::new(
206+
None,
207+
DeploymentDetails::for_query_url(&format!(
208+
"{}/subgraphs/id/{}",
209+
&mock_server.uri(),
210+
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
211+
))
212+
.unwrap(),
213+
)
211214
.unwrap();
212-
let network_subgraph =
213-
SubgraphClient::new("network-subgraph", network_subgraph_endpoint.as_ref()).unwrap();
214215

215216
// Mock result for current epoch requests
216217
mock_server

common/src/attestations/dispute_manager.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub fn dispute_manager(
8181

8282
#[cfg(test)]
8383
mod test {
84-
use reqwest::Url;
8584
use serde_json::json;
8685
use wiremock::{
8786
matchers::{method, path},
@@ -90,6 +89,7 @@ mod test {
9089

9190
use crate::{
9291
prelude::SubgraphClient,
92+
subgraph_client::DeploymentDetails,
9393
test_vectors::{self, DISPUTE_MANAGER_ADDRESS},
9494
};
9595

@@ -98,14 +98,16 @@ mod test {
9898
async fn setup_mock_network_subgraph() -> (&'static SubgraphClient, MockServer) {
9999
// Set up a mock network subgraph
100100
let mock_server = MockServer::start().await;
101-
let network_subgraph_endpoint = Url::parse(&format!(
102-
"{}/subgraphs/id/{}",
103-
&mock_server.uri(),
104-
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
105-
))
101+
let network_subgraph = SubgraphClient::new(
102+
None,
103+
DeploymentDetails::for_query_url(&format!(
104+
"{}/subgraphs/id/{}",
105+
&mock_server.uri(),
106+
*test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT
107+
))
108+
.unwrap(),
109+
)
106110
.unwrap();
107-
let network_subgraph =
108-
SubgraphClient::new("network-subgraph", network_subgraph_endpoint.as_ref()).unwrap();
109111

110112
// Mock result for current epoch requests
111113
mock_server

common/src/escrow_accounts.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ pub fn escrow_accounts(
115115

116116
#[cfg(test)]
117117
mod tests {
118-
use reqwest::Url;
119118
use wiremock::matchers::{method, path};
120119
use wiremock::{Mock, MockServer, ResponseTemplate};
121120

121+
use crate::prelude::DeploymentDetails;
122122
use crate::test_vectors;
123123

124124
use super::*;
@@ -127,14 +127,17 @@ mod tests {
127127
async fn test_current_accounts() {
128128
// Set up a mock escrow subgraph
129129
let mock_server = MockServer::start().await;
130-
let escrow_subgraph_endpoint = Url::parse(&format!(
131-
"{}/subgraphs/id/{}",
132-
&mock_server.uri(),
133-
*test_vectors::ESCROW_SUBGRAPH_DEPLOYMENT
134-
))
135-
.unwrap();
136130
let escrow_subgraph = Box::leak(Box::new(
137-
SubgraphClient::new("escrow-subgraph", escrow_subgraph_endpoint.as_ref()).unwrap(),
131+
SubgraphClient::new(
132+
None,
133+
DeploymentDetails::for_query_url(&format!(
134+
"{}/subgraphs/id/{}",
135+
&mock_server.uri(),
136+
*test_vectors::ESCROW_SUBGRAPH_DEPLOYMENT
137+
))
138+
.unwrap(),
139+
)
140+
.unwrap(),
138141
));
139142

140143
let mock = Mock::given(method("POST"))

common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ pub mod prelude {
2020
dispute_manager::dispute_manager, signer::AttestationSigner, signers::attestation_signers,
2121
};
2222
pub use super::escrow_accounts::escrow_accounts;
23-
pub use super::subgraph_client::SubgraphClient;
23+
pub use super::subgraph_client::{DeploymentDetails, SubgraphClient};
2424
pub use super::tap_manager::TapManager;
2525
}

common/src/subgraph_client.rs

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)