Skip to content

Commit 66e1dc0

Browse files
committed
refactor: move tap manager into indexer-common
1 parent 9e84f5c commit 66e1dc0

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

Cargo.lock

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

common/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ reqwest = "0.11.20"
2121
secp256k1 = { version = "0.28.0", features = ["recovery"] }
2222
serde = { version = "1.0.188", features = ["derive"] }
2323
serde_json = "1.0.107"
24+
sqlx = { version = "0.7.1", features = [
25+
"postgres",
26+
"runtime-tokio",
27+
"bigdecimal",
28+
"rust_decimal",
29+
"time",
30+
] }
2431
tokio = { version = "1.32.0", features = ["full", "macros", "rt"] }
2532
toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = [
2633
"graphql",
2734
] }
2835
graphql = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }
36+
tap_core = "0.6.0"
2937

3038
[dev-dependencies]
3139
env_logger = "0.9.0"

common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod escrow_accounts;
77
pub mod graphql;
88
pub mod signature_verification;
99
pub mod subgraph_client;
10+
pub mod tap_manager;
1011

1112
#[cfg(test)]
1213
mod test_vectors;
@@ -20,4 +21,5 @@ pub mod prelude {
2021
};
2122
pub use super::escrow_accounts::escrow_accounts;
2223
pub use super::subgraph_client::SubgraphClient;
24+
pub use super::tap_manager::TapManager;
2325
}

service/src/tap_manager.rs renamed to common/src/tap_manager.rs

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

44
use alloy_primitives::Address;
55
use alloy_sol_types::Eip712Domain;
6+
use anyhow::anyhow;
67
use ethers_core::types::U256;
78
use eventuals::Eventual;
8-
use indexer_common::prelude::Allocation;
99
use log::error;
1010
use sqlx::{types::BigDecimal, PgPool};
1111
use std::{collections::HashMap, sync::Arc};
1212
use tap_core::tap_manager::SignedReceipt;
1313

14-
use crate::query_processor::QueryError;
14+
use crate::prelude::Allocation;
1515

1616
#[derive(Clone)]
1717
pub struct TapManager {
@@ -42,7 +42,10 @@ impl TapManager {
4242
///
4343
/// The rest of the TAP receipt checks are expected to be performed out-of-band by the receipt aggregate requester
4444
/// service.
45-
pub async fn verify_and_store_receipt(&self, receipt: SignedReceipt) -> Result<(), QueryError> {
45+
pub async fn verify_and_store_receipt(
46+
&self,
47+
receipt: SignedReceipt,
48+
) -> Result<(), anyhow::Error> {
4649
let allocation_id = &receipt.message.allocation_id;
4750
if !self
4851
.indexer_allocations
@@ -51,17 +54,17 @@ impl TapManager {
5154
.map(|allocations| allocations.contains_key(allocation_id))
5255
.unwrap_or(false)
5356
{
54-
return Err(QueryError::Other(anyhow::Error::msg(format!(
57+
return Err(anyhow!(
5558
"Receipt allocation ID `{}` is not eligible for this indexer",
5659
allocation_id
57-
))));
60+
));
5861
}
5962

6063
let receipt_signer = receipt
6164
.recover_signer(self.domain_separator.as_ref())
6265
.map_err(|e| {
6366
error!("Failed to recover receipt signer: {}", e);
64-
QueryError::Other(anyhow::Error::from(e))
67+
anyhow!(e)
6568
})?;
6669
if !self
6770
.escrow_accounts
@@ -74,10 +77,10 @@ impl TapManager {
7477
})
7578
.unwrap_or(false)
7679
{
77-
return Err(QueryError::Other(anyhow::Error::msg(format!(
80+
return Err(anyhow!(
7881
"Receipt sender `{}` is not eligible for this indexer",
7982
receipt_signer
80-
))));
83+
));
8184
}
8285

8386
// TODO: consider doing this in another async task to avoid slowing down the paid query flow.
@@ -91,13 +94,13 @@ impl TapManager {
9194
.unwrap()
9295
.to_owned(),
9396
BigDecimal::from(receipt.message.timestamp_ns),
94-
serde_json::to_value(receipt).map_err(|e| QueryError::Other(anyhow::Error::from(e)))?
97+
serde_json::to_value(receipt).map_err(|e| anyhow!(e))?
9598
)
9699
.execute(&self.pgpool)
97100
.await
98101
.map_err(|e| {
99102
error!("Failed to store receipt: {}", e);
100-
QueryError::Other(anyhow::Error::from(e))
103+
anyhow!(e)
101104
})?;
102105

103106
Ok(())
@@ -108,11 +111,11 @@ impl TapManager {
108111
mod test {
109112
use std::str::FromStr;
110113

114+
use crate::prelude::{AllocationStatus, SubgraphDeployment};
111115
use alloy_primitives::Address;
112116
use alloy_sol_types::{eip712_domain, Eip712Domain};
113-
use ethereum_types::{H256, U256};
114117
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
115-
use indexer_common::prelude::{AllocationStatus, SubgraphDeployment};
118+
use keccak_hash::H256;
116119
use sqlx::postgres::PgListener;
117120

118121
use tap_core::tap_manager::SignedReceipt;

service/src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use ethereum_types::U256;
88
use std::{net::SocketAddr, str::FromStr, time::Duration};
99
use tracing::info;
1010

11-
use indexer_common::prelude::{
12-
attestation_signers, dispute_manager, escrow_accounts, indexer_allocations, SubgraphClient,
11+
use indexer_common::{
12+
prelude::{
13+
attestation_signers, dispute_manager, escrow_accounts, indexer_allocations, SubgraphClient,
14+
},
15+
tap_manager::TapManager,
1316
};
1417

1518
use util::{package_version, shutdown_signal};
@@ -27,7 +30,6 @@ mod graph_node;
2730
mod metrics;
2831
mod query_processor;
2932
mod server;
30-
mod tap_manager;
3133
mod util;
3234

3335
#[cfg(test)]
@@ -119,7 +121,7 @@ async fn main() -> Result<(), std::io::Error> {
119121
Duration::from_secs(config.escrow_subgraph.escrow_syncing_interval),
120122
);
121123

122-
let tap_manager = tap_manager::TapManager::new(
124+
let tap_manager = TapManager::new(
123125
indexer_management_db.clone(),
124126
indexer_allocations,
125127
escrow_accounts,

service/src/query_processor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::collections::HashMap;
55

66
use alloy_primitives::Address;
77
use eventuals::Eventual;
8+
use indexer_common::tap_manager::TapManager;
89
use log::error;
910
use serde::{Deserialize, Serialize};
1011
use tap_core::tap_manager::SignedReceipt;
@@ -14,7 +15,6 @@ use toolshed::thegraph::DeploymentId;
1415
use indexer_common::prelude::AttestationSigner;
1516

1617
use crate::graph_node::GraphNodeInstance;
17-
use crate::tap_manager::TapManager;
1818

1919
#[derive(Debug, Clone, Serialize, Deserialize)]
2020
pub struct QueryResult {
@@ -117,7 +117,8 @@ impl QueryProcessor {
117117

118118
self.tap_manager
119119
.verify_and_store_receipt(parsed_receipt)
120-
.await?;
120+
.await
121+
.map_err(QueryError::Other)?;
121122

122123
let signers = self
123124
.attestation_signers

0 commit comments

Comments
 (0)