Skip to content

Commit fa39bab

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

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

crates/tap-agent/src/tracker.rs

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

4+
//! # tracker
5+
//!
6+
//! This is the heart of tap-agent, every decision depends on these trackers.
7+
//!
8+
//! There are two main trackers: [SimpleFeeTracker] [SenderFeeTracker].
9+
//! Each of them enable certain methods that allows fine-grained control over what are the
10+
//! algorithm that selects the biggest allocation.
11+
//!
12+
//! The tracker contains a tricky feature called buffer that is used to count know the counter of
13+
//! any key in X amount of seconds ago. This is important since, receipt timestamp_ns is provided
14+
//! by senders, we want to have a tolerance buffer where we still accept receipts with timestamp
15+
//! older than our current clock.
16+
417
pub use extra_data::{DefaultFromExtra, DurationInfo, NoExtraData};
518
use generic_tracker::GenericTracker;
619
pub use sender_fee_stats::SenderFeeStats;
@@ -16,14 +29,34 @@ pub use generic_tracker::GlobalFeeTracker;
1629

1730
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
1831

32+
/// Simple Tracker used for just `u128` fees and no extra blocking or unblocking feature
33+
///
34+
/// It's mainly used for Invalid Receipts and Ravs, since they only need to store and retrieve the
35+
/// total amount of all allocations combined
1936
pub type SimpleFeeTracker = GenericTracker<u128, u128, NoExtraData, u128>;
37+
/// SenderFeeTracker used for more complex features.
38+
///
39+
/// It uses [UnaggregatedReceipts] instead of [u128], contains a buffer for selection, and contains
40+
/// more logic about if an allocation is available for selection or not.
2041
pub type SenderFeeTracker =
2142
GenericTracker<GlobalFeeTracker, SenderFeeStats, DurationInfo, UnaggregatedReceipts>;
2243

44+
/// Stats trait used by the Counter of a given allocation.
45+
///
46+
/// This is the data that goes in the Value side of the Map inside our Tracker
2347
pub trait AllocationStats<U> {
48+
/// updates its value with a new one
2449
fn update(&mut self, v: U);
50+
/// Returns if an allocation is allows to trigger a rav request
2551
fn is_allowed_to_trigger_rav_request(&self) -> bool;
52+
/// Get the stats U given
2653
fn get_stats(&self) -> U;
54+
/// Returns the total fee (validated and pending)
2755
fn get_total_fee(&self) -> u128;
56+
/// Returns only ravable fees (no pending fees) that is used for triggering
57+
///
58+
/// Pending fees are usually fees that not eligible to trigger a RAV,
59+
/// for example, you don't want to trigger a Rav Request if your only allocation is currently
60+
/// requesting, so this should return a value that don't contains that allocation
2861
fn get_valid_fee(&mut self) -> u128;
2962
}

crates/tap-agent/src/tracker/extra_data.rs

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

44
use std::time::Duration;
55

6+
/// Default values for a given extra data E
67
pub trait DefaultFromExtra<E> {
8+
/// Generates a new default Self given some extra data
79
fn default_from_extra(extra: &E) -> Self;
810
}
911

12+
/// Buffer information
1013
#[derive(Debug, Clone)]
1114
pub struct DurationInfo {
1215
pub(super) buffer_duration: Duration,
1316
}
1417

18+
/// No Extra Data struct
1519
#[derive(Debug, Clone, Default)]
1620
pub struct NoExtraData;
1721

crates/tap-agent/src/tracker/generic_tracker.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use super::{
1414
};
1515
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
1616

17+
/// Global Fee Tracker used inside SenderFeeTracker
18+
///
19+
/// This allows to keep a simple O(1) instead of looping over all allocations to get the total
20+
/// amount
1721
#[derive(Debug, Clone, Copy, Default, PartialEq)]
1822
pub struct GlobalFeeTracker {
1923
pub(super) requesting: u128,

crates/tap-agent/src/tracker/sender_fee_stats.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ use std::{
99
use super::{AllocationStats, DefaultFromExtra, DurationInfo};
1010
use crate::{agent::unaggregated_receipts::UnaggregatedReceipts, backoff::BackoffInfo};
1111

12+
/// Stats for a given allocation
1213
#[derive(Debug, Clone, Default)]
1314
pub struct SenderFeeStats {
15+
/// sum of all fees in the tracker
1416
pub(super) total_fee: u128,
17+
/// counter of receipts
1518
pub(super) count: u64,
16-
// there are some allocations that we don't want it to be
17-
// heaviest allocation, because they are already marked for finalization,
18-
// and thus requesting RAVs on their own in their `post_stop` routine.
19+
/// there are some allocations that we don't want it to be
20+
/// heaviest allocation, because they are already marked for finalization,
21+
/// and thus requesting RAVs on their own in their `post_stop` routine.
1922
pub(super) blocked: bool,
23+
/// amount of fees that are currently being requested
2024
pub(super) requesting: u128,
2125

22-
// Buffer info
26+
/// Buffer info
2327
pub(super) buffer_info: BufferInfo,
2428

25-
// Backoff info
29+
/// Backoff info
2630
pub(super) backoff_info: BackoffInfo,
2731
}
2832

0 commit comments

Comments
 (0)