Skip to content

Commit 01bda5e

Browse files
authored
Update fisherman challenge structure (#249)
- Related PR: edgeandnode/network-services#60
1 parent 76bea16 commit 01bda5e

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

graph-gateway/src/fisherman_client.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::indexer_client::Attestation;
22
use async_trait::async_trait;
3+
use indexer_selection::Indexing;
34
use prelude::*;
45
use reqwest;
56
use serde::Deserialize;
67
use serde_json::json;
7-
use std::error::Error;
88

99
#[derive(Clone, Copy, Debug, Deserialize)]
1010
pub enum ChallengeOutcome {
@@ -19,9 +19,10 @@ pub enum ChallengeOutcome {
1919
pub trait FishermanInterface {
2020
async fn challenge(
2121
&self,
22-
indexer: &Address,
22+
indexing: &Indexing,
2323
allocation: &Address,
2424
indexer_query: &str,
25+
indexer_response: &str,
2526
attestation: &Attestation,
2627
) -> ChallengeOutcome;
2728
}
@@ -36,13 +37,20 @@ pub struct FishermanClient {
3637
impl FishermanInterface for FishermanClient {
3738
async fn challenge(
3839
&self,
39-
indexer: &Address,
40+
indexing: &Indexing,
4041
allocation: &Address,
4142
indexer_query: &str,
43+
indexer_response: &str,
4244
attestation: &Attestation,
4345
) -> ChallengeOutcome {
4446
match self
45-
.send_challenge(indexer, allocation, indexer_query, attestation)
47+
.send_challenge(
48+
indexing,
49+
allocation,
50+
indexer_query,
51+
indexer_response,
52+
attestation,
53+
)
4654
.await
4755
{
4856
Ok(outcome) => outcome,
@@ -61,22 +69,25 @@ impl FishermanClient {
6169

6270
async fn send_challenge(
6371
&self,
64-
indexer: &Address,
72+
indexing: &Indexing,
6573
allocation: &Address,
6674
indexer_query: &str,
75+
indexer_response: &str,
6776
attestation: &Attestation,
68-
) -> Result<ChallengeOutcome, Box<dyn Error>> {
77+
) -> anyhow::Result<ChallengeOutcome> {
6978
let challenge = serde_json::to_string(&json!({
7079
"jsonrpc": "2.0",
7180
"id": 0,
7281
"method": "challenge",
7382
"params": {
74-
"readOperation": indexer_query,
75-
"allocationID": allocation.to_string(),
7683
"attestation": serde_json::to_value(attestation)?,
84+
"subgraphDeploymentID": format!("0x{}", hex::encode(&indexing.deployment.0)),
85+
"allocationID": allocation.to_string(),
86+
"query": indexer_query,
87+
"response": indexer_response,
7788
},
7889
}))?;
79-
tracing::trace!(%indexer, %challenge);
90+
tracing::trace!(?indexing, %challenge);
8091
self.client
8192
.post(self.url.0.clone())
8293
.header("Content-Type", "application/json")

graph-gateway/src/indexer_client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use indexer_selection::Selection;
44
use prelude::*;
55
use reqwest;
66
use serde::{Deserialize, Serialize};
7+
use std::sync::Arc;
78

89
#[async_trait]
910
pub trait IndexerInterface {
@@ -18,7 +19,7 @@ pub trait IndexerInterface {
1819
#[derive(Clone, Debug)]
1920
pub struct IndexerResponse {
2021
pub status: u16,
21-
pub payload: String,
22+
pub payload: Arc<String>,
2223
pub attestation: Option<Attestation>,
2324
}
2425

@@ -108,7 +109,7 @@ impl IndexerInterface for IndexerClient {
108109
};
109110
Ok(IndexerResponse {
110111
status: response_status.as_u16(),
111-
payload: graphql_response,
112+
payload: Arc::new(graphql_response),
112113
attestation: payload.attestation,
113114
})
114115
}

graph-gateway/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ async fn handle_subgraph_query_inner(
731731
Ok(HttpResponseBuilder::new(StatusCode::OK)
732732
.insert_header(header::ContentType::json())
733733
.insert_header(("Graph-Attestation", attestation))
734-
.body(&response.payload))
734+
.body(response.payload.as_ref()))
735735
}
736736

737737
pub fn graphql_error_response<S: ToString>(message: S) -> HttpResponse {

graph-gateway/src/query_engine.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ where
564564
selection.indexing.clone(),
565565
result.allocation.clone(),
566566
result.query.clone(),
567+
response.payload.clone(),
567568
attestation.clone(),
568569
);
569570
}
@@ -576,6 +577,7 @@ where
576577
indexing: Indexing,
577578
allocation: Address,
578579
indexer_query: Arc<String>,
580+
indexer_response: Arc<String>,
579581
attestation: Attestation,
580582
) {
581583
let fisherman = match &self.fisherman_client {
@@ -585,7 +587,13 @@ where
585587
let observations = self.observations.clone();
586588
tokio::spawn(async move {
587589
let outcome = fisherman
588-
.challenge(&indexing.indexer, &allocation, &indexer_query, &attestation)
590+
.challenge(
591+
&indexing,
592+
&allocation,
593+
&indexer_query,
594+
&indexer_response,
595+
&attestation,
596+
)
589597
.await;
590598
tracing::trace!(?outcome);
591599
let penalty = match outcome {

0 commit comments

Comments
 (0)