Skip to content

Commit 3f031eb

Browse files
committed
docs: add tap docs
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent fa39bab commit 3f031eb

File tree

6 files changed

+70
-13
lines changed

6 files changed

+70
-13
lines changed

crates/tap-agent/src/tap/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ use tonic::{transport::Channel, Code, Status};
3535
/// multiple matches. This way we can keep the code separated and we
3636
/// can easily add or remove network versions.
3737
pub trait NetworkVersion: Send + Sync + 'static {
38+
/// Sol struct returned from an aggregation
39+
///
40+
/// Usually this is wrapped around a [Eip712SignedMessage].
41+
///
42+
/// We provide all the trait bounds here to evict it spreading across other modules
3843
type Rav: SolStruct
3944
+ Aggregate<TapReceipt>
4045
+ Serialize
@@ -45,6 +50,7 @@ pub trait NetworkVersion: Send + Sync + 'static {
4550
+ std::fmt::Debug
4651
+ PartialEq;
4752

53+
/// gRPC client type used to process an aggregation request
4854
type AggregatorClient: Send + Sync;
4955

5056
/// Takes the aggregator client, a list of receipts and the previous rav
@@ -158,6 +164,7 @@ pub struct TapAgentContext<T> {
158164

159165
/// Allow any [NetworkVersion] to create a new context
160166
impl<T: NetworkVersion> TapAgentContext<T> {
167+
/// Creates a TapContext
161168
pub fn new(
162169
pgpool: PgPool,
163170
allocation_id: Address,

crates/tap-agent/src/tap/context/checks.rs

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

4+
//! # Receipt Checks
5+
//!
6+
//! Some additional receipt checks are done before an aggregation request.
7+
//! This allows us to have two layers of checks that allows some relieve in the performance
8+
//! critical part of the system in indexer-service
9+
410
mod allocation_id;
511
mod signature;
612

crates/tap-agent/src/tap/context/checks/allocation_id.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ use tokio::sync::watch::Receiver;
1313

1414
use crate::tap::{CheckingReceipt, TapReceipt};
1515

16+
/// AllocationId check
17+
///
18+
/// Verifies if the allocation is already redeemed.
1619
pub struct AllocationId {
1720
tap_allocation_redeemed: Receiver<bool>,
1821
allocation_id: Address,
1922
}
2023

2124
impl AllocationId {
25+
/// Creates a new allocation id check
2226
pub async fn new(
2327
indexer_address: Address,
2428
escrow_polling_interval: Duration,

crates/tap-agent/src/tap/context/checks/signature.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ use tokio::sync::watch::Receiver;
99

1010
use crate::tap::{CheckingReceipt, TapReceipt};
1111

12+
/// Signature check
13+
///
14+
/// Verifies if the signatures are signed correctly by the list of provided signers.
15+
/// This is an important step since [tap_core] doesn't verify signatures by default and RavRequests
16+
/// may fail if any of those are wrong.
1217
pub struct Signature {
1318
domain_separator: Eip712Domain,
1419
escrow_accounts: Receiver<EscrowAccounts>,
1520
}
1621

1722
impl Signature {
23+
/// Creates a new signature check
1824
pub fn new(domain_separator: Eip712Domain, escrow_accounts: Receiver<EscrowAccounts>) -> Self {
1925
Self {
2026
domain_separator,

crates/tap-agent/src/tap/context/error.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,61 @@
33

44
use thegraph_core::alloy::primitives::Address;
55

6+
/// AdapterError.
7+
///
8+
/// This is used to provide good error messages for indexers
69
#[derive(Debug, thiserror::Error)]
710
pub enum AdapterError {
11+
/// Error in case it could not get escrow accounts
812
#[error("Could not get escrow accounts from eventual")]
9-
EscrowEventualError { error: String },
13+
EscrowEventualError {
14+
/// Error message
15+
error: String,
16+
},
1017

18+
/// Error in case couldn't get the available escrow for a sender
1119
#[error("Could not get available escrow for sender")]
1220
AvailableEscrowError(#[from] indexer_monitor::EscrowAccountsError),
1321

22+
/// Overflow error
1423
#[error("Sender {sender} escrow balance is too large to fit in u128, could not get available escrow.")]
15-
BalanceTooLarge { sender: Address },
16-
17-
#[error("Sender {sender} does not have enough escrow to subtract {fees} from {balance}.")]
18-
NotEnoughEscrow {
24+
BalanceTooLarge {
25+
/// Sender address
1926
sender: Address,
20-
fees: u128,
21-
balance: u128,
2227
},
2328

29+
/// Database error while storing rav
2430
#[error("Error in while storing Ravs: {error}")]
25-
RavStore { error: String },
31+
RavStore {
32+
/// Error message
33+
error: String,
34+
},
2635

36+
/// Database error while reading receipt
2737
#[error("Error in while reading Ravs: {error}")]
28-
RavRead { error: String },
38+
RavRead {
39+
/// Error message
40+
error: String,
41+
},
2942

43+
/// Database error while deleting receipt
3044
#[error("Error while deleting receipts: {error}")]
31-
ReceiptDelete { error: String },
45+
ReceiptDelete {
46+
/// Error message
47+
error: String,
48+
},
3249

50+
/// Database error while reading receipt
3351
#[error("Error while reading receipts: {error}")]
34-
ReceiptRead { error: String },
52+
ReceiptRead {
53+
/// Error message
54+
error: String,
55+
},
3556

36-
#[error("Error while validating receipts: {error}")]
37-
ValidationError { error: String },
57+
/// Error validating signer for Ravs
58+
#[error("Error while validating rav signature: {error}")]
59+
ValidationError {
60+
/// Error message
61+
error: String,
62+
},
3863
}

crates/tap-agent/src/tap/mod.rs

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

4+
//! # tap
5+
//!
6+
//! This module implements all traits and functions necessary for a context in a
7+
//! [tap_core::manager::Manager] as well as receipt checks used to verify if receipts are valid.
8+
49
pub use ::indexer_receipt::TapReceipt;
510
use indexer_monitor::EscrowAccounts;
611
use tap_core::receipt::{state::Checking, ReceiptWithState};
712
use thegraph_core::alloy::{hex::ToHexExt, primitives::Address};
813
use tokio::sync::watch::Receiver;
14+
15+
/// [TapReceipt] wrapped around a [Checking] state.
916
pub type CheckingReceipt = ReceiptWithState<Checking, TapReceipt>;
1017

18+
/// Context implmentation
1119
pub mod context;
1220

21+
/// Helper function used to get a list of all signers in [String] for a given `sender`.
1322
pub async fn signers_trimmed(
1423
escrow_accounts_rx: Receiver<EscrowAccounts>,
1524
sender: Address,

0 commit comments

Comments
 (0)