Skip to content

Commit cba489f

Browse files
committed
docs: update requested changes
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent cfb5dcb commit cba489f

File tree

15 files changed

+160
-147
lines changed

15 files changed

+160
-147
lines changed

README.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,69 @@
22

33
## Overview
44

5-
The TAP (Timeline Aggregation Protocol) facilitates a series of payments from a sender to a receiver, who aggregates these payments into a single payment. This aggregate payment can then be verified on-chain by a payment verifier, reducing the number of transactions and simplifying the payment process.
5+
The TAP (Timeline Aggregation Protocol) facilitates a series of payments from a
6+
sender to a receiver (TAP Receipts), who aggregates these payments into a single
7+
payment (a Receipt Aggregate Voucher, or RAV). This aggregate payment can then be
8+
verified on-chain by a payment verifier, reducing the number of transactions and
9+
simplifying the payment process.
610

711
## Key Components
812

913
- **Sender:** Initiates the payment.
1014
- **Receiver:** Receives the payment.
1115
- **Signers:** Multiple signers authorized by the sender to sign receipts.
12-
- **State Channel:** A one-way channel opened by the sender with the receiver for sending receipts.
16+
- **State Channel:** A one-way channel opened by the sender with the receiver
17+
for sending receipts.
1318
- **Receipt:** A record of payment sent by the sender to the receiver.
14-
- **ReceiptAggregateVoucher (RAV):** A signed message containing the aggregate value of the receipts.
15-
- **tap_aggregator:** An entity managed by the sender that signs RAV requests.
16-
- **EscrowAccount:** An account created in the blockchain to hold funds for the sender-receiver pair.
19+
- **ReceiptAggregateVoucher (RAV):** A signed message containing the aggregate
20+
value of the receipts.
21+
- **tap_aggregator:** A service managed by the sender that aggregates receipts
22+
on the receiver's request into a signed RAV.
23+
- **EscrowAccount:** An account created in the blockchain to hold funds for
24+
the sender-receiver pair.
1725

1826
## Security Measures
1927

20-
- The protocol uses asymmetric cryptography to sign and verify messages, ensuring the integrity of receipts and RAVs.
28+
- The protocol uses asymmetric cryptography (ECDSA secp256k1) to sign and
29+
verify messages, ensuring the integrity of receipts and RAVs.
2130

2231
## Process
2332

24-
1. **Opening a State Channel:** A state channel is opened via a blockchain contract, creating an EscrowAccount for the sender-receiver pair.
25-
2. **Sending Receipts:** The sender sends receipts to the receiver through the state channel.
26-
3. **Storing Receipts:** The receiver stores the receipts and tracks the aggregate payment.
27-
4. **Creating a RAV Request:** A RAV request consists of a list of receipts and, optionally, the previous RAV.
28-
5. **Signing the RAV:** The receiver sends the RAV request to the tap_aggregator, which signs it into a RAV.
29-
6. **Tracking Aggregate Value:** The receiver tracks the aggregate value and new receipts since the last RAV.
30-
7. **Requesting a New RAV:** The receiver sends new receipts and the last RAV to the tap_aggregator for a new RAV.
31-
8. **Closing the State Channel:** When the allocation period ends, the receiver can send the last RAV to the blockchain and receive payment from the EscrowAccount.
33+
1. **Opening a State Channel:** A state channel is opened via a blockchain
34+
contract, creating an EscrowAccount for the sender-receiver pair.
35+
2. **Sending Receipts:** The sender sends receipts to the receiver through the
36+
state channel.
37+
3. **Storing Receipts:** The receiver stores the receipts and tracks the
38+
aggregate payment.
39+
4. **Creating a RAV Request:** A RAV request consists of a list of receipts and,
40+
optionally, the previous RAV.
41+
5. **Signing the RAV:** The receiver sends the RAV request to the tap_aggregator,
42+
which signs it into a new RAV.
43+
6. **Tracking Aggregate Value:** The receiver tracks the aggregate value and
44+
new receipts since the last RAV.
45+
7. **Requesting a New RAV:** The receiver sends new receipts and the last RAV
46+
to the tap_aggregator for a new RAV.
47+
8. **Closing the State Channel:** When the allocation period ends, the receiver
48+
can send the last RAV to the blockchain and receive payment from the EscrowAccount.
3249

3350
## Performance Considerations
3451

35-
- The primary performance limitations are the time required to verify receipts and network limitations for sending requests to the tap_aggregator.
52+
- The primary performance limitations are the time required to verify receipts
53+
and network limitations for sending requests to the tap_aggregator.
3654

3755
## Use Cases
3856

39-
- The TAP protocol is suitable for systems with sequential operations that are too expensive to redeem individually on-chain. By aggregating operations and redeeming them in one transaction, costs can be reduced.
57+
- The TAP protocol is suitable for systems with sequential operations that are
58+
too expensive to redeem individually on-chain. By aggregating operations
59+
off-chain and redeeming them in one transaction, costs are drastically reduced.
4060

4161
## Compatibility
4262

43-
- The current implementation is for EVM-compatible blockchains, with most of the system being off-chain.
63+
- The current implementation is for EVM-compatible blockchains, with most of the
64+
system being off-chain.
4465

4566
## Contributing
4667

47-
Contributions are welcome! Please submit a pull request or open an issue to discuss potential changes.
68+
Contributions are welcome! Please submit a pull request or open an issue to
69+
discuss potential changes.
4870
Also, make sure to follow the [Contributing Guide](CONTRIBUTING.md).

tap_core/src/lib.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,6 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
3-
4-
//! # Timeline Aggregation Protocol
5-
//!
6-
//! ## Overview
7-
//!
8-
//! The TAP (Timeline Aggregation Protocol) facilitates a series of payments from
9-
//! a sender to a receiver, who aggregates these payments into a single payment.
10-
//! This aggregate payment can then be verified on-chain by a payment verifier,
11-
//! reducing the number of transactions and simplifying the payment process.
12-
//!
13-
//! ## Key Components
14-
//!
15-
//! - **Sender:** Initiates the payment.
16-
//! - **Receiver:** Receives the payment.
17-
//! - **Signers:** Multiple signers authorized by the sender to sign receipts.
18-
//! - **State Channel:** A one-way channel opened by the sender with the receiver
19-
//! for sending receipts.
20-
//! - **Receipt:** A record of payment sent by the sender to the receiver.
21-
//! - **ReceiptAggregateVoucher (RAV):** A signed message containing the aggregate
22-
//! value of the receipts.
23-
//! - **tap_aggregator:** An entity managed by the sender that signs RAV requests.
24-
//! - **EscrowAccount:** An account created in the blockchain to hold funds for
25-
//! the sender-receiver pair.
26-
//!
27-
//! ## Security Measures
28-
//!
29-
//! - The protocol uses asymmetric cryptography to sign and verify messages,
30-
//! ensuring the integrity of receipts and RAVs.
31-
//!
32-
//! ## Process
33-
//!
34-
//! 1. **Opening a State Channel:** A state channel is opened via a blockchain
35-
//! contract, creating an EscrowAccount for the sender-receiver pair.
36-
//! 2. **Sending Receipts:** The sender sends receipts to the receiver through
37-
//! the state channel.
38-
//! 3. **Storing Receipts:** The receiver stores the receipts and tracks the
39-
//! aggregate payment.
40-
//! 4. **Creating a RAV Request:** A RAV request consists of a list of receipts
41-
//! and, optionally, the previous RAV.
42-
//! 5. **Signing the RAV:** The receiver sends the RAV request to the
43-
//! tap_aggregator, which signs it into a RAV.
44-
//! 6. **Tracking Aggregate Value:** The receiver tracks the aggregate value and
45-
//! new receipts since the last RAV.
46-
//! 7. **Requesting a New RAV:** The receiver sends new receipts and the last
47-
//! RAV to the tap_aggregator for a new RAV.
48-
//! 8. **Closing the State Channel:** When the allocation period ends, the receiver
49-
//! can send the last RAV to the blockchain and receive payment from the EscrowAccount.
50-
//!
51-
//! ## Performance Considerations
52-
//!
53-
//! - The primary performance limitations are the time required to verify receipts
54-
//! and network limitations for sending requests to the tap_aggregator.
55-
//!
56-
//! ## Use Cases
57-
//!
58-
//! - The TAP protocol is suitable for systems with sequential operations that
59-
//! are too expensive to redeem individually on-chain. By aggregating operations
60-
//! and redeeming them in one transaction, costs can be reduced.
61-
//!
62-
//! ## Compatibility
63-
//!
64-
//! - The current implementation is for EVM-compatible blockchains, with most
65-
//! of the system being off-chain.
66-
//!
3+
#![doc = include_str!("../../README.md")]
674
//! ## Getting started
685
//!
696
//! To get started with the TAP protocol, take a look on the [`manager`] module

tap_core/src/manager/adapters/escrow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use crate::{
2121
pub trait EscrowHandler: Send + Sync {
2222
/// Defines the user-specified error type.
2323
///
24-
/// This error type should implement the `Error` and `Debug` traits from the standard library.
24+
/// This error type should implement the `Error` and `Debug` traits from
25+
/// the standard library.
2526
/// Errors of this type are returned to the user when an operation fails.
2627
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
2728

tap_core/src/manager/adapters/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
//! Context adapters for the TAP manager.
55
//!
6-
//! Each adapter should be defined by the user of the library based on their specific storage and verification requirements. This modular design
7-
//! allows for easy integration with various storage solutions and verification procedures, thereby making the library adaptable to a wide range
8-
//! of use cases.
6+
//! Each adapter should be defined by the user of the library based on their
7+
//! specific storage and verification requirements. This modular design
8+
//! allows for easy integration with various storage solutions and verification
9+
//! procedures, thereby making the library adaptable to a wide range of use cases.
910
1011
mod escrow;
1112
mod rav;

tap_core/src/manager/adapters/rav.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ use crate::rav::SignedRAV;
1515
pub trait RAVStore {
1616
/// Defines the user-specified error type.
1717
///
18-
/// This error type should implement the `Error` and `Debug` traits from the standard library.
18+
/// This error type should implement the `Error` and `Debug` traits from
19+
/// the standard library.
1920
/// Errors of this type are returned to the user when an operation fails.
2021
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
2122

2223
/// Updates the storage with the latest validated `SignedRAV`.
2324
///
24-
/// This method should be implemented to store the most recent validated `SignedRAV` into your chosen storage system.
25-
/// Any errors that occur during this process should be captured and returned as an `AdapterError`.
25+
/// This method should be implemented to store the most recent validated
26+
/// `SignedRAV` into your chosen storage system. Any errors that occur
27+
/// during this process should be captured and returned as an `AdapterError`.
2628
async fn update_last_rav(&self, rav: SignedRAV) -> Result<(), Self::AdapterError>;
2729
}
2830

@@ -36,7 +38,8 @@ pub trait RAVStore {
3638
pub trait RAVRead {
3739
/// Defines the user-specified error type.
3840
///
39-
/// This error type should implement the `Error` and `Debug` traits from the standard library.
41+
/// This error type should implement the `Error` and `Debug` traits from
42+
/// the standard library.
4043
/// Errors of this type are returned to the user when an operation fails.
4144
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
4245

tap_core/src/manager/adapters/receipt.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ pub trait ReceiptDelete {
6565
pub trait ReceiptRead {
6666
/// Defines the user-specified error type.
6767
///
68-
/// This error type should implement the `Error` and `Debug` traits from the standard library.
68+
/// This error type should implement the `Error` and `Debug` traits from
69+
/// the standard library.
6970
/// Errors of this type are returned to the user when an operation fails.
7071
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
7172

7273
/// Retrieves all [`ReceiptWithState<Checking>`] within a specific timestamp range.
7374
///
74-
/// If a limit is specified, the adapter should return at most that many receipts, while making
75-
/// sure that no receipts are left behind for any timestamp that is returned. Examples:
75+
/// If a limit is specified, the adapter should return at most that many receipts,
76+
/// while making sure that no receipts are left behind for any timestamp that
77+
/// is returned. Examples:
7678
///
7779
/// - If the adapter has 10 receipts for timestamp 100, and 5 receipts for timestamp 200, and
7880
/// the limit is 10, the adapter should return all 10 receipts for timestamp 100, and none for

tap_core/src/manager/context/memory.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
//! In-memory context implementation for the TAP manager.
55
//!
6-
//! This module provides an in-memory implementation of the TAP manager context. It is useful for testing and development purposes.
6+
//! This module provides an in-memory implementation of the TAP manager context.
7+
//! It is useful for testing and development purposes.
78
89
use crate::{
910
manager::adapters::*,

tap_core/src/manager/context/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
//! Context implementations.
55
//!
6-
//! Contexts are used to store and retrieve data from the TAP manager. They are used to store receipts, escrow, and other data that is required for the manager to function.
7-
//! Currently, there's only one context implementation available, which is the `MemoryContext`. This context is used to store data in memory and is useful for testing and development purposes.
6+
//! Contexts are used to store and retrieve data from the TAP manager.
7+
//! They are used to store receipts, escrow, and other data that is required
8+
//! for the manager to function.
9+
//! Currently, there's only one context implementation available, which is
10+
//! the `MemoryContext`. This context is used to store data in memory and
11+
//! is useful for testing and development purposes.
812
pub mod memory;

tap_core/src/manager/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@
33

44
//! Point of entry for managing TAP receipts and RAVs.
55
//!
6-
//! The [`crate::manager`] module provides facilities for managing TAP receipt and RAV validation, as well as storage flow.
6+
//! The [`crate::manager`] module provides facilities for managing TAP receipt
7+
//! and RAV validation, as well as storage flow.
78
//!
8-
//! This module should be the primary interface for the receiver of funds to verify, store, and manage TAP receipts and RAVs.
9-
//! The [`Manager`] struct within this module allows the user to specify what checks should be performed on receipts, as well as
10-
//! when these checks should occur (either when a receipt is first received, or when it is being added to a RAV request).
9+
//! This module should be the primary interface for the receiver of funds to
10+
//! verify, store, and manage TAP receipts and RAVs.
11+
//! The [`Manager`] struct within this module allows the user to specify what
12+
//! checks should be performed on receipts, as well as
13+
//! when these checks should occur (either when a receipt is first received,
14+
//! or when it is being added to a RAV request).
1115
//!
12-
//! The [`Manager`] uses a context that implements user-defined [`adapters`] for storage handling.
13-
//! This design offers a high degree of flexibility, letting the user define their own behavior for these critical operations.
16+
//! The [`Manager`] uses a context that implements user-defined [`adapters`]
17+
//! for storage handling.
18+
//! This design offers a high degree of flexibility, letting the user define
19+
//! their own behavior for these critical operations.
1420
//!
15-
//! This solution is flexible enough to enable certain methods depending on the context provided. This is important
16-
//! because the context can be customized to include only the necessary adapters for the user's specific use case. For example,
17-
//! if the user wants to use two different applications, one to handle receipt storage and another to handle RAV storage, they
21+
//! This solution is flexible enough to enable certain methods depending on the
22+
//! context provided. This is important because the context can be customized
23+
//! to include only the necessary adapters for the user's specific use case.
24+
//! For example, if the user wants to use two different applications, one to
25+
//! handle receipt storage and another to handle RAV storage, they
1826
//! can create two different contexts with the appropriate adapters.
1927
//!
2028
//! # Adapters
21-
//! There are 6 main adapters that can be implemented to customize the behavior of the [`Manager`].
29+
//! There are 6 main adapters that can be implemented to customize the behavior
30+
//! of the [`Manager`].
2231
//! You can find more information about these adapters in the [`adapters`] module.
2332
//!
2433
//! # Example

tap_core/src/manager/tap_manager.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,20 @@ impl<E> Manager<E>
164164
where
165165
E: ReceiptRead + RAVRead + EscrowHandler,
166166
{
167-
/// Completes remaining checks on all receipts up to (current time - `timestamp_buffer_ns`). Returns them in
168-
/// two lists (valid receipts and invalid receipts) along with the expected RAV that should be received
169-
/// for aggregating list of valid receipts.
167+
/// Completes remaining checks on all receipts up to
168+
/// (current time - `timestamp_buffer_ns`). Returns them in two lists
169+
/// (valid receipts and invalid receipts) along with the expected RAV that
170+
/// should be received for aggregating list of valid receipts.
170171
///
171-
/// Returns [`Error::AggregateOverflow`] if any receipt value causes aggregate value to overflow while generating expected RAV
172+
/// Returns [`Error::AggregateOverflow`] if any receipt value causes
173+
/// aggregate value to overflow while generating expected RAV
172174
///
173-
/// Returns [`Error::AdapterError`] if unable to fetch previous RAV or if unable to fetch previous receipts
175+
/// Returns [`Error::AdapterError`] if unable to fetch previous RAV or
176+
/// if unable to fetch previous receipts
174177
///
175-
/// Returns [`Error::TimestampRangeError`] if the max timestamp of the previous RAV is greater than the min timestamp. Caused by timestamp buffer being too large, or requests coming too soon.
178+
/// Returns [`Error::TimestampRangeError`] if the max timestamp of the
179+
/// previous RAV is greater than the min timestamp. Caused by timestamp
180+
/// buffer being too large, or requests coming too soon.
176181
///
177182
pub async fn create_rav_request(
178183
&self,
@@ -223,14 +228,15 @@ impl<E> Manager<E>
223228
where
224229
E: ReceiptDelete + RAVRead,
225230
{
226-
/// Removes obsolete receipts from storage. Obsolete receipts are receipts that are older than the last RAV, and
227-
/// therefore already aggregated into the RAV.
228-
/// This function should be called after a new RAV is received to limit the number of receipts stored.
229-
/// No-op if there is no last RAV.
231+
/// Removes obsolete receipts from storage. Obsolete receipts are receipts
232+
/// that are older than the last RAV, and therefore already aggregated into the RAV.
233+
/// This function should be called after a new RAV is received to limit the
234+
/// number of receipts stored. No-op if there is no last RAV.
230235
///
231236
/// # Errors
232237
///
233-
/// Returns [`Error::AdapterError`] if there are any errors while retrieving last RAV or removing receipts
238+
/// Returns [`Error::AdapterError`] if there are any errors while retrieving
239+
/// last RAV or removing receipts
234240
///
235241
pub async fn remove_obsolete_receipts(&self) -> Result<(), Error> {
236242
match self.get_previous_rav().await? {
@@ -252,7 +258,8 @@ impl<E> Manager<E>
252258
where
253259
E: ReceiptStore,
254260
{
255-
/// Runs `initial_checks` on `signed_receipt` for initial verification, then stores received receipt.
261+
/// Runs `initial_checks` on `signed_receipt` for initial verification,
262+
/// then stores received receipt.
256263
/// The provided `query_id` will be used as a key when chaecking query appraisal.
257264
///
258265
/// # Errors

0 commit comments

Comments
 (0)