Skip to content

Commit 29b201b

Browse files
committed
refactor: use generic manager
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 5decbd1 commit 29b201b

File tree

21 files changed

+267
-266
lines changed

21 files changed

+267
-266
lines changed

Cargo.lock

Lines changed: 89 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[workspace]
22
members = [
3-
"crates/allocation",
4-
"crates/attestation",
5-
"crates/config",
6-
"crates/dips",
7-
"crates/monitor",
8-
"crates/query",
9-
"crates/service",
10-
"crates/tap-agent",
11-
"crates/test-assets",
12-
"crates/watcher",
3+
"crates/allocation",
4+
"crates/attestation",
5+
"crates/config",
6+
"crates/dips",
7+
"crates/monitor",
8+
"crates/query",
9+
"crates/service",
10+
"crates/tap-agent",
11+
"crates/test-assets",
12+
"crates/watcher",
1313
]
1414
resolver = "2"
1515

@@ -20,54 +20,54 @@ opt-level = 3
2020
clap = "4.4.3"
2121
lazy_static = "1.4.0"
2222
axum = { version = "0.7.9", default-features = false, features = [
23-
"tokio",
24-
"http1",
25-
"http2",
23+
"tokio",
24+
"http1",
25+
"http2",
2626
] }
27-
tokio = "1.40"
27+
tokio = "1"
2828
prometheus = "0.13.3"
2929
anyhow = { version = "1.0.72" }
3030
thiserror = "1.0.49"
3131
async-trait = "0.1.83"
3232
eventuals = "0.6.7"
3333
base64 = "0.22.1"
3434
reqwest = { version = "0.12", features = [
35-
"charset",
36-
"h2",
35+
"charset",
36+
"h2",
3737
], default-features = false }
3838
serde = { version = "1.0.206", default-features = false }
3939
serde_json = "1.0.124"
4040
sqlx = { version = "0.8.2", features = [
41-
"bigdecimal",
42-
"chrono",
43-
"json",
44-
"macros",
45-
"migrate",
46-
"postgres",
47-
"runtime-tokio",
48-
"rust_decimal",
49-
"uuid",
41+
"bigdecimal",
42+
"chrono",
43+
"json",
44+
"macros",
45+
"migrate",
46+
"postgres",
47+
"runtime-tokio",
48+
"rust_decimal",
49+
"uuid",
5050
], default-features = false }
5151
uuid = { version = "1.11.0", features = ["v7"] }
5252
tracing = { version = "0.1.40", default-features = false }
5353
bigdecimal = "0.4.3"
5454
build-info = "0.0.39"
55-
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "6af1add", default-features = false }
56-
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "6af1add", default-features = false }
55+
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1fc51a3", default-features = false }
56+
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1fc51a3", default-features = false }
5757
tracing-subscriber = { version = "0.3", features = [
58-
"json",
59-
"env-filter",
60-
"ansi",
58+
"json",
59+
"env-filter",
60+
"ansi",
6161
], default-features = false }
62-
thegraph-core = { version = "0.10.0", features = [
63-
"attestation",
64-
"alloy-eip712",
65-
"alloy-sol-types",
66-
"alloy-rlp",
67-
"alloy-signers",
68-
"alloy-signer-local",
69-
"alloy-signer-mnemonic",
70-
"serde"
62+
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "a1d0509", features = [
63+
"attestation",
64+
"alloy-eip712",
65+
"alloy-sol-types",
66+
"alloy-rlp",
67+
"alloy-signers",
68+
"alloy-signer-local",
69+
"alloy-signer-mnemonic",
70+
"serde",
7171
] }
7272
thegraph-graphql-http = { version = "0.3.2", features = ["reqwest"] }
7373
graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] }

crates/dips/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010
use anyhow::anyhow;
1111
use async_trait::async_trait;
12-
use thegraph_core::alloy::{dyn_abi::Eip712Domain, primitives::Address};
12+
use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain};
1313
use uuid::Uuid;
1414

1515
#[derive(Debug)]

crates/service/src/middleware/auth/tap.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use axum::{
1818
};
1919
use tap_core::{
2020
manager::{adapters::ReceiptStore, Manager},
21+
rav::ReceiptAggregateVoucher,
2122
receipt::{Context, SignedReceipt},
2223
};
2324
use tower_http::auth::AsyncAuthorizeRequest;
@@ -30,7 +31,7 @@ use crate::{error::IndexerServiceError, middleware::prometheus_metrics::MetricLa
3031
///
3132
/// Requires SignedReceipt, MetricLabels and Arc<Context> extensions
3233
pub fn tap_receipt_authorize<T, B>(
33-
tap_manager: Arc<Manager<T>>,
34+
tap_manager: Arc<Manager<T, SignedReceipt, ReceiptAggregateVoucher>>,
3435
failed_receipt_metric: &'static prometheus::CounterVec,
3536
) -> impl AsyncAuthorizeRequest<
3637
B,
@@ -40,7 +41,7 @@ pub fn tap_receipt_authorize<T, B>(
4041
> + Clone
4142
+ Send
4243
where
43-
T: ReceiptStore + Sync + Send + 'static,
44+
T: ReceiptStore<SignedReceipt> + Sync + Send + 'static,
4445
B: Send,
4546
{
4647
move |request: Request<B>| {
@@ -91,7 +92,7 @@ mod tests {
9192
receipt::{
9293
checks::{Check, CheckError, CheckList, CheckResult},
9394
state::Checking,
94-
ReceiptWithState,
95+
ReceiptWithState, SignedReceipt,
9596
},
9697
};
9798
use test_assets::{
@@ -133,11 +134,11 @@ mod tests {
133134

134135
struct MyCheck;
135136
#[async_trait::async_trait]
136-
impl Check for MyCheck {
137+
impl Check<SignedReceipt> for MyCheck {
137138
async fn check(
138139
&self,
139140
_: &tap_core::receipt::Context,
140-
receipt: &ReceiptWithState<Checking>,
141+
receipt: &ReceiptWithState<Checking, SignedReceipt>,
141142
) -> CheckResult {
142143
if receipt.signed_receipt().message.nonce == FAILED_NONCE {
143144
Err(CheckError::Failed(anyhow::anyhow!("Failed")))

crates/service/src/tap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use indexer_allocation::Allocation;
77
use indexer_monitor::EscrowAccounts;
88
use receipt_store::{DatabaseReceipt, InnerContext};
99
use sqlx::PgPool;
10-
use tap_core::receipt::checks::ReceiptCheck;
10+
use tap_core::receipt::{checks::ReceiptCheck, SignedReceipt};
1111
use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain};
1212
use tokio::sync::{
1313
mpsc::{self, Sender},
@@ -48,7 +48,7 @@ impl IndexerTapContext {
4848
escrow_accounts: Receiver<EscrowAccounts>,
4949
timestamp_error_tolerance: Duration,
5050
receipt_max_value: u128,
51-
) -> Vec<ReceiptCheck> {
51+
) -> Vec<ReceiptCheck<SignedReceipt>> {
5252
vec![
5353
Arc::new(AllocationEligible::new(indexer_allocations)),
5454
Arc::new(SenderBalanceCheck::new(escrow_accounts)),

crates/service/src/tap/checks/allocation_eligible.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use indexer_allocation::Allocation;
88
use tap_core::receipt::{
99
checks::{Check, CheckError, CheckResult},
1010
state::Checking,
11-
ReceiptWithState,
11+
ReceiptWithState, SignedReceipt,
1212
};
1313
use thegraph_core::alloy::primitives::Address;
1414
use tokio::sync::watch::Receiver;
@@ -25,11 +25,11 @@ impl AllocationEligible {
2525
}
2626
}
2727
#[async_trait::async_trait]
28-
impl Check for AllocationEligible {
28+
impl Check<SignedReceipt> for AllocationEligible {
2929
async fn check(
3030
&self,
3131
_: &tap_core::receipt::Context,
32-
receipt: &ReceiptWithState<Checking>,
32+
receipt: &ReceiptWithState<Checking, SignedReceipt>,
3333
) -> CheckResult {
3434
let allocation_id = receipt.signed_receipt().message.allocation_id;
3535
if !self

crates/service/src/tap/checks/deny_list_check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use sqlx::{postgres::PgListener, PgPool};
1111
use tap_core::receipt::{
1212
checks::{Check, CheckError, CheckResult},
1313
state::Checking,
14-
ReceiptWithState,
14+
ReceiptWithState, SignedReceipt,
1515
};
1616
use thegraph_core::alloy::primitives::Address;
1717

@@ -153,11 +153,11 @@ impl DenyListCheck {
153153
}
154154

155155
#[async_trait::async_trait]
156-
impl Check for DenyListCheck {
156+
impl Check<SignedReceipt> for DenyListCheck {
157157
async fn check(
158158
&self,
159159
ctx: &tap_core::receipt::Context,
160-
_: &ReceiptWithState<Checking>,
160+
_: &ReceiptWithState<Checking, SignedReceipt>,
161161
) -> CheckResult {
162162
let Sender(receipt_sender) = ctx
163163
.get::<Sender>()

crates/service/src/tap/checks/receipt_max_val_check.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct ReceiptMaxValueCheck {
99
use tap_core::receipt::{
1010
checks::{Check, CheckError, CheckResult},
1111
state::Checking,
12-
ReceiptWithState,
12+
ReceiptWithState, SignedReceipt,
1313
};
1414

1515
impl ReceiptMaxValueCheck {
@@ -19,11 +19,11 @@ impl ReceiptMaxValueCheck {
1919
}
2020

2121
#[async_trait::async_trait]
22-
impl Check for ReceiptMaxValueCheck {
22+
impl Check<SignedReceipt> for ReceiptMaxValueCheck {
2323
async fn check(
2424
&self,
2525
_: &tap_core::receipt::Context,
26-
receipt: &ReceiptWithState<Checking>,
26+
receipt: &ReceiptWithState<Checking, SignedReceipt>,
2727
) -> CheckResult {
2828
let receipt_value = receipt.signed_receipt().message.value;
2929

@@ -54,7 +54,9 @@ mod tests {
5454
use super::*;
5555
use crate::tap::Eip712Domain;
5656

57-
fn create_signed_receipt_with_custom_value(value: u128) -> ReceiptWithState<Checking> {
57+
fn create_signed_receipt_with_custom_value(
58+
value: u128,
59+
) -> ReceiptWithState<Checking, SignedReceipt> {
5860
let index: u32 = 0;
5961
let wallet: PrivateKeySigner = MnemonicBuilder::<English>::default()
6062
.phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
@@ -86,7 +88,7 @@ mod tests {
8688
&wallet,
8789
)
8890
.unwrap();
89-
ReceiptWithState::<Checking>::new(receipt)
91+
ReceiptWithState::new(receipt)
9092
}
9193

9294
const RECEIPT_LIMIT: u128 = 10;

crates/service/src/tap/checks/sender_balance_check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use indexer_monitor::EscrowAccounts;
66
use tap_core::receipt::{
77
checks::{Check, CheckError, CheckResult},
88
state::Checking,
9-
ReceiptWithState,
9+
ReceiptWithState, SignedReceipt,
1010
};
1111
use thegraph_core::alloy::primitives::U256;
1212
use tokio::sync::watch::Receiver;
@@ -24,11 +24,11 @@ impl SenderBalanceCheck {
2424
}
2525

2626
#[async_trait::async_trait]
27-
impl Check for SenderBalanceCheck {
27+
impl Check<SignedReceipt> for SenderBalanceCheck {
2828
async fn check(
2929
&self,
3030
ctx: &tap_core::receipt::Context,
31-
_: &ReceiptWithState<Checking>,
31+
_: &ReceiptWithState<Checking, SignedReceipt>,
3232
) -> CheckResult {
3333
let escrow_accounts_snapshot = self.escrow_accounts.borrow();
3434

crates/service/src/tap/checks/timestamp_check.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct TimestampCheck {
1111
use tap_core::receipt::{
1212
checks::{Check, CheckError, CheckResult},
1313
state::Checking,
14-
ReceiptWithState,
14+
ReceiptWithState, SignedReceipt,
1515
};
1616

1717
impl TimestampCheck {
@@ -23,11 +23,11 @@ impl TimestampCheck {
2323
}
2424

2525
#[async_trait::async_trait]
26-
impl Check for TimestampCheck {
26+
impl Check<SignedReceipt> for TimestampCheck {
2727
async fn check(
2828
&self,
2929
_: &tap_core::receipt::Context,
30-
receipt: &ReceiptWithState<Checking>,
30+
receipt: &ReceiptWithState<Checking, SignedReceipt>,
3131
) -> CheckResult {
3232
let timestamp_now = SystemTime::now()
3333
.duration_since(SystemTime::UNIX_EPOCH)
@@ -52,7 +52,7 @@ mod tests {
5252
use std::time::{Duration, SystemTime};
5353

5454
use tap_core::{
55-
receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState},
55+
receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState, SignedReceipt},
5656
signed_message::EIP712SignedMessage,
5757
tap_eip712_domain,
5858
};
@@ -66,7 +66,7 @@ mod tests {
6666

6767
fn create_signed_receipt_with_custom_timestamp(
6868
timestamp_ns: u64,
69-
) -> ReceiptWithState<Checking> {
69+
) -> ReceiptWithState<Checking, SignedReceipt> {
7070
let index: u32 = 0;
7171
let wallet: PrivateKeySigner = MnemonicBuilder::<English>::default()
7272
.phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
@@ -89,7 +89,7 @@ mod tests {
8989
&wallet,
9090
)
9191
.unwrap();
92-
ReceiptWithState::<Checking>::new(receipt)
92+
ReceiptWithState::new(receipt)
9393
}
9494

9595
#[tokio::test]

0 commit comments

Comments
 (0)