Skip to content

Commit 79e4516

Browse files
committed
fix: legacy receipt release
1 parent 7db1469 commit 79e4516

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

graph-gateway/src/client_query.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use gateway_framework::{
2626
indexing::Indexing,
2727
metrics::{with_metric, METRICS},
2828
network::{discovery::Status, indexing_performance::Snapshot},
29+
scalar::ReceiptStatus,
2930
topology::network::{Deployment, GraphNetwork, Manifest, Subgraph},
3031
};
3132
use headers::ContentType;
@@ -413,14 +414,12 @@ async fn run_indexer_queries(
413414
indexer,
414415
deployment,
415416
url: url.to_string(),
416-
allocation: receipt.allocation(),
417+
receipt,
417418
subgraph_chain,
418419
result,
419420
response_time_ms,
420421
seconds_behind,
421422
blocks_behind,
422-
legacy_scalar,
423-
fee,
424423
request: indexer_query,
425424
};
426425
tx.try_send(report).unwrap();
@@ -438,6 +437,21 @@ async fn run_indexer_queries(
438437
indexer_errors.insert(report.indexer, err.clone());
439438
}
440439
}
440+
441+
let receipt_status = match &report.result {
442+
Ok(_) => ReceiptStatus::Success,
443+
Err(IndexerError::Timeout) => ReceiptStatus::Unknown,
444+
Err(_) => ReceiptStatus::Failure,
445+
};
446+
ctx.receipt_signer
447+
.record_receipt(
448+
report.indexer,
449+
report.deployment,
450+
&report.receipt,
451+
receipt_status,
452+
)
453+
.await;
454+
441455
indexer_requests.push(report);
442456
}
443457

@@ -465,7 +479,10 @@ async fn run_indexer_queries(
465479
Err(Error::BadIndexers(IndexerErrors(indexer_errors)))
466480
};
467481

468-
let total_fees_grt: f64 = indexer_requests.iter().map(|i| i.fee as f64 * 1e-18).sum();
482+
let total_fees_grt: f64 = indexer_requests
483+
.iter()
484+
.map(|i| i.receipt.grt_value() as f64 * 1e-18)
485+
.sum();
469486
let total_fees_usd = USD(NotNan::new(total_fees_grt / *grt_per_usd).unwrap());
470487
let _ = ctx.budgeter.feedback.send(total_fees_usd);
471488

@@ -505,12 +522,12 @@ async fn run_indexer_queries(
505522
tracing::info!(
506523
indexer = ?indexer_request.indexer,
507524
deployment = %indexer_request.deployment,
508-
allocation = ?indexer_request.allocation,
525+
allocation = ?indexer_request.receipt.allocation(),
509526
url = indexer_request.url,
510527
result = ?indexer_request.result.as_ref().map(|_| ()),
511528
response_time_ms = indexer_request.response_time_ms,
512529
seconds_behind = indexer_request.seconds_behind,
513-
fee = indexer_request.fee as f64 * 1e-18,
530+
fee = indexer_request.receipt.grt_value() as f64 * 1e-18,
514531
"indexer_request"
515532
);
516533
tracing::trace!(indexer_request = indexer_request.request);

graph-gateway/src/reports.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use alloy_primitives::Address;
22
use anyhow::{anyhow, Context};
33
use gateway_common::utils::timestamp::unix_timestamp;
4-
use gateway_framework::errors::{self, IndexerError};
4+
use gateway_framework::{
5+
errors::{self, IndexerError},
6+
scalar::ScalarReceipt,
7+
};
58
use ordered_float::NotNan;
69
use prost::Message;
710
use serde_json::json;
@@ -25,14 +28,12 @@ pub struct IndexerRequest {
2528
pub indexer: Address,
2629
pub url: String,
2730
pub deployment: DeploymentId,
28-
pub allocation: Address,
31+
pub receipt: ScalarReceipt,
2932
pub subgraph_chain: String,
3033
pub result: Result<IndexerResponse, errors::IndexerError>,
3134
pub response_time_ms: u16,
3235
pub seconds_behind: u32,
3336
pub blocks_behind: u64, // TODO: rm
34-
pub legacy_scalar: bool,
35-
pub fee: u128,
3637
pub request: String,
3738
}
3839

@@ -87,7 +88,7 @@ impl Reporter {
8788
let total_fees_grt: f64 = client_request
8889
.indexer_requests
8990
.iter()
90-
.map(|i| i.fee as f64 * 1e-18)
91+
.map(|i| i.receipt.grt_value() as f64 * 1e-18)
9192
.sum();
9293
let total_fees_usd: f64 = total_fees_grt / *client_request.grt_per_usd;
9394

@@ -198,7 +199,7 @@ impl Reporter {
198199
"api_key": &client_request.api_key,
199200
"fee": total_fees_grt as f32,
200201
"response_time_ms": indexer_request.response_time_ms,
201-
"allocation": &indexer_request.allocation,
202+
"allocation": &indexer_request.receipt.allocation(),
202203
"indexer_errors": indexer_errors,
203204
"status": indexer_request.result.as_ref().map(|_| "200 OK".into()).unwrap_or_else(|err| err.to_string()),
204205
"status_code": legacy_status_code,
@@ -218,12 +219,12 @@ impl Reporter {
218219
"network": &indexer_request.subgraph_chain,
219220
"indexer": &indexer_request.indexer,
220221
"url": &indexer_request.url,
221-
"fee": (indexer_request.fee as f64 * 1e-18) as f32,
222-
"legacy_scalar": indexer_request.legacy_scalar,
222+
"fee": (indexer_request.receipt.grt_value() as f64 * 1e-18) as f32,
223+
"legacy_scalar": matches!(&indexer_request.receipt, ScalarReceipt::Legacy(_, _)),
223224
"utility": 1.0,
224225
"blocks_behind": indexer_request.blocks_behind,
225226
"response_time_ms": indexer_request.response_time_ms,
226-
"allocation": &indexer_request.allocation,
227+
"allocation": &indexer_request.receipt.allocation(),
227228
"indexer_errors": indexer_errors,
228229
"status": indexer_request.result.as_ref().map(|_| "200 OK".into()).unwrap_or_else(|err| err.to_string()),
229230
"status_code": legacy_status_code,
@@ -250,7 +251,7 @@ impl Reporter {
250251
AttestationProtobuf {
251252
request: Some(indexer_request.request).filter(|r| r.len() <= MAX_PAYLOAD_BYTES),
252253
response: Some(original_response).filter(|r| r.len() <= MAX_PAYLOAD_BYTES),
253-
allocation: indexer_request.allocation.0 .0.into(),
254+
allocation: indexer_request.receipt.allocation().0 .0.into(),
254255
subgraph_deployment: attestation.deployment.0.into(),
255256
request_cid: attestation.request_cid.0.into(),
256257
response_cid: attestation.response_cid.0.into(),

0 commit comments

Comments
 (0)