Skip to content

Commit 2663e8b

Browse files
committed
refactor: use generic manager
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent c3ede8f commit 2663e8b

File tree

24 files changed

+251
-248
lines changed

24 files changed

+251
-248
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ axum = { version = "0.7.9", default-features = false, features = [
2424
"http1",
2525
"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"
@@ -52,22 +52,22 @@ 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 = [
5858
"json",
5959
"env-filter",
6060
"ansi",
6161
], default-features = false }
62-
thegraph-core = { version = "0.10.0", features = [
62+
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "a1d0509", features = [
6363
"attestation",
6464
"alloy-eip712",
6565
"alloy-sol-types",
6666
"alloy-rlp",
6767
"alloy-signers",
6868
"alloy-signer-local",
6969
"alloy-signer-mnemonic",
70-
"serde"
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/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ pub mod server;
2222
pub mod store;
2323

2424
use store::AgreementStore;
25-
use uuid::Uuid;
26-
2725
use thiserror::Error;
26+
use uuid::Uuid;
2827

2928
sol! {
3029
// EIP712 encoded bytes, ABI - ethers
@@ -264,9 +263,10 @@ pub async fn validate_and_cancel_agreement(
264263

265264
#[cfg(test)]
266265
mod test {
267-
use std::sync::Arc;
268-
269-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
266+
use std::{
267+
sync::Arc,
268+
time::{Duration, SystemTime, UNIX_EPOCH},
269+
};
270270

271271
use thegraph_core::{
272272
alloy::{
@@ -276,12 +276,12 @@ mod test {
276276
},
277277
attestation::eip712_domain,
278278
};
279-
280-
use crate::{CancellationRequest, DipsError};
281-
use crate::{IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata};
282279
use uuid::Uuid;
283280

284281
pub use crate::store::{AgreementStore, InMemoryAgreementStore};
282+
use crate::{
283+
CancellationRequest, DipsError, IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
284+
};
285285

286286
#[tokio::test]
287287
async fn test_validate_and_create_agreement() -> anyhow::Result<()> {

crates/dips/src/server.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
use std::{str::FromStr, sync::Arc, time::Duration};
55

6+
use anyhow::anyhow;
7+
use async_trait::async_trait;
8+
use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain};
9+
use uuid::Uuid;
10+
611
use crate::{
712
proto::graphprotocol::indexer::dips::*, store::AgreementStore, validate_and_cancel_agreement,
813
validate_and_create_agreement, DipsError,
914
};
10-
use anyhow::anyhow;
11-
use async_trait::async_trait;
12-
use thegraph_core::alloy::{dyn_abi::Eip712Domain, primitives::Address};
13-
use uuid::Uuid;
1415

1516
#[derive(Debug)]
1617
pub struct DipsServer {

crates/service/src/database/dips.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
use anyhow::bail;
55
use axum::async_trait;
66
use build_info::chrono::Utc;
7-
87
use indexer_dips::{
98
store::AgreementStore, SignedCancellationRequest, SignedIndexingAgreementVoucher,
109
};
11-
1210
use sqlx::PgPool;
1311
use thegraph_core::alloy::rlp::Decodable;
1412
use uuid::Uuid;

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/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration};
66

77
use anyhow::anyhow;
88
use axum::{extract::Request, serve, ServiceExt};
9+
use clap::Parser;
910
use indexer_config::{Config, DipsConfig, GraphNodeConfig, SubgraphConfig};
1011
use indexer_dips::{
1112
proto::graphprotocol::indexer::dips::agreement_service_server::{
@@ -19,14 +20,13 @@ use reqwest::Url;
1920
use tap_core::tap_eip712_domain;
2021
use tokio::{net::TcpListener, signal};
2122
use tower_http::normalize_path::NormalizePath;
23+
use tracing::info;
2224

2325
use crate::{
2426
cli::Cli,
2527
database::{self, dips::PsqlAgreementStore},
2628
metrics::serve_metrics,
2729
};
28-
use clap::Parser;
29-
use tracing::info;
3030

3131
mod release;
3232
mod router;

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>()

0 commit comments

Comments
 (0)