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+
417pub use extra_data:: { DefaultFromExtra , DurationInfo , NoExtraData } ;
518use generic_tracker:: GenericTracker ;
619pub use sender_fee_stats:: SenderFeeStats ;
@@ -16,14 +29,34 @@ pub use generic_tracker::GlobalFeeTracker;
1629
1730use 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
1936pub 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.
2041pub 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
2347pub 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}
0 commit comments