Skip to content

Commit 4b6f009

Browse files
committed
refactor: remove option from tap receipt
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 3587e67 commit 4b6f009

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

crates/monitor/src/deployment_to_allocation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ mod tests {
3434
let deployment = deployment_to_allocation(allocations_watcher);
3535

3636
let deployments = deployment.borrow();
37-
assert_eq!(deployments.len(), allocations.len());
37+
// one of the allocation id point to the same subgraph
38+
assert_eq!(deployments.len(), 3);
39+
// check if all allocations point to the subgraph id
3840
for (key, val) in deployments.iter() {
3941
assert_eq!(allocations.get(val).unwrap().subgraph_deployment.id, *key);
4042
}

crates/service/src/middleware/inject_receipt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use crate::service::TapReceipt;
1010
///
1111
/// This is useful to not deserialize multiple times the same receipt
1212
pub async fn receipt_middleware(mut request: Request, next: Next) -> Response {
13-
if let Ok(TypedHeader(receipt)) = request.extract_parts::<TypedHeader<TapReceipt>>().await {
14-
if let Some(receipt) = receipt.into_signed_receipt() {
15-
request.extensions_mut().insert(receipt);
16-
}
13+
if let Ok(TypedHeader(TapReceipt(receipt))) =
14+
request.extract_parts::<TypedHeader<TapReceipt>>().await
15+
{
16+
request.extensions_mut().insert(receipt);
1717
}
1818
next.run(request).await
1919
}

crates/service/src/service/tap_receipt_header.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::ops::Deref;
5-
64
use axum_extra::headers::{self, Header, HeaderName, HeaderValue};
75
use lazy_static::lazy_static;
86
use prometheus::{register_counter, Counter};
97
use tap_core::receipt::SignedReceipt;
108

119
#[derive(Debug, PartialEq)]
12-
pub struct TapReceipt(Option<SignedReceipt>);
13-
14-
impl TapReceipt {
15-
pub fn into_signed_receipt(self) -> Option<SignedReceipt> {
16-
self.0
17-
}
18-
}
19-
20-
impl Deref for TapReceipt {
21-
type Target = Option<SignedReceipt>;
22-
23-
fn deref(&self) -> &Self::Target {
24-
&self.0
25-
}
26-
}
10+
pub struct TapReceipt(pub SignedReceipt);
2711

2812
lazy_static! {
2913
static ref TAP_RECEIPT: HeaderName = HeaderName::from_static("tap-receipt");
@@ -42,14 +26,12 @@ impl Header for TapReceipt {
4226
{
4327
let mut execute = || {
4428
let value = values.next();
45-
let raw_receipt = value
46-
.map(|value| value.to_str())
47-
.transpose()
48-
.map_err(|_| headers::Error::invalid())?;
49-
let parsed_receipt = raw_receipt
50-
.map(serde_json::from_str)
51-
.transpose()
29+
let raw_receipt = value.ok_or(headers::Error::invalid())?;
30+
let raw_receipt = raw_receipt
31+
.to_str()
5232
.map_err(|_| headers::Error::invalid())?;
33+
let parsed_receipt =
34+
serde_json::from_str(raw_receipt).map_err(|_| headers::Error::invalid())?;
5335
Ok(TapReceipt(parsed_receipt))
5436
};
5537
execute().inspect_err(|_| TAP_RECEIPT_INVALID.inc())
@@ -86,7 +68,7 @@ mod test {
8668
let decoded_receipt = TapReceipt::decode(&mut header_values.into_iter())
8769
.expect("tap receipt header value should be valid");
8870

89-
assert_eq!(decoded_receipt, TapReceipt(Some(original_receipt.clone())));
71+
assert_eq!(decoded_receipt, TapReceipt(original_receipt));
9072
}
9173

9274
#[test]

0 commit comments

Comments
 (0)