Skip to content

Commit

Permalink
refactor: use requesting only in ravable_total_fee
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Nov 1, 2024
1 parent 264ac97 commit 0eb733f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tap-agent/src/tracker/generic_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ impl GenericTracker<GlobalFeeTracker, SenderFeeStats, DurationInfo, Unaggregated
}

pub fn get_ravable_total_fee(&mut self) -> u128 {
self.get_total_fee() - self.get_buffered_fee().min(self.global.total_fee)
self.get_total_fee()
- self.global.requesting
- self.get_buffered_fee().min(self.global.total_fee)
}

fn get_buffered_fee(&mut self) -> u128 {
Expand Down
2 changes: 1 addition & 1 deletion tap-agent/src/tracker/global_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl GlobalTracker<u128> for u128 {

impl GlobalTracker<UnaggregatedReceipts> for GlobalFeeTracker {
fn get_total_fee(&self) -> u128 {
self.total_fee - self.requesting
self.total_fee
}

fn update(&mut self, new_fee: u128) {
Expand Down
4 changes: 2 additions & 2 deletions tap-agent/src/tracker/tracker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ fn test_ongoing_rav_requests() {
tracker.start_rav_request(allocation_id_2);

assert_eq!(tracker.get_heaviest_allocation_id(), Some(allocation_id_1));
assert_eq!(tracker.get_total_fee(), 30);
assert_eq!(tracker.get_total_fee(), 60);
assert_eq!(tracker.get_ravable_total_fee(), 30);

tracker.add(allocation_id_2, 1, get_current_timestamp_u64_ns());

assert_eq!(tracker.get_heaviest_allocation_id(), Some(allocation_id_1));
assert_eq!(tracker.get_total_fee(), 31);
assert_eq!(tracker.get_total_fee(), 61);
assert_eq!(tracker.get_ravable_total_fee(), 31);

tracker.finish_rav_request(allocation_id_2);
Expand Down

0 comments on commit 0eb733f

Please sign in to comment.