Skip to content

Commit 3625028

Browse files
committed
fix: track ongoing requests
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent ab6fbda commit 3625028

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

tap-agent/src/agent/sender_account.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,17 @@ impl State {
217217
"Error while getting allocation actor {allocation_id} with most unaggregated fees"
218218
);
219219
};
220+
220221
allocation
221222
.cast(SenderAllocationMessage::TriggerRAVRequest)
222223
.map_err(|e| {
223224
anyhow::anyhow!(
224225
"Error while sending and waiting message for actor {allocation_id}. Error: {e}"
225226
)
226-
})
227+
})?;
228+
self.sender_fee_tracker.start_rav_request(allocation_id);
229+
230+
Ok(())
227231
}
228232

229233
fn deny_condition_reached(&self) -> bool {
@@ -569,6 +573,7 @@ impl Actor for SenderAccount {
569573
.add(value as f64);
570574
}
571575
ReceiptFees::RavRequestResponse(rav_result) => {
576+
state.sender_fee_tracker.finish_rav_request(allocation_id);
572577
match rav_result {
573578
Ok((fees, rav)) => {
574579
state.rav_tracker.ok_rav_request(allocation_id);

tap-agent/src/agent/sender_fee_tracker.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub struct SenderFeeTracker {
3434
id_to_fee: HashMap<Address, u128>,
3535
total_fee: u128,
3636

37+
fees_requesting: u128,
38+
ids_requesting: HashSet<Address>,
39+
3740
buffer_window_fee: HashMap<Address, ExpiringSum>,
3841
buffer_window_duration: Duration,
3942
// there are some allocations that we don't want it to be
@@ -120,6 +123,7 @@ impl SenderFeeTracker {
120123
self.id_to_fee
121124
.iter()
122125
.filter(|(addr, _)| !self.blocked_addresses.contains(*addr))
126+
.filter(|(addr, _)| !self.ids_requesting.contains(*addr))
123127
.filter(|(addr, _)| {
124128
self.failed_ravs
125129
.get(*addr)
@@ -171,6 +175,20 @@ impl SenderFeeTracker {
171175
acc + expiring.get_sum(&self.buffer_window_duration)
172176
})
173177
}
178+
179+
pub fn start_rav_request(&mut self, allocation_id: Address) {
180+
let current_fee = self.id_to_fee.entry(allocation_id).or_default();
181+
self.ids_requesting.insert(allocation_id);
182+
self.fees_requesting += *current_fee;
183+
}
184+
185+
/// Should be called before `update`
186+
pub fn finish_rav_request(&mut self, allocation_id: Address) {
187+
let current_fee = self.id_to_fee.entry(allocation_id).or_default();
188+
self.fees_requesting -= *current_fee;
189+
self.ids_requesting.remove(&allocation_id);
190+
}
191+
174192
pub fn failed_rav_backoff(&mut self, allocation_id: Address) {
175193
// backoff = max(100ms * 2 ^ retries, 60s)
176194
let failed_rav = self.failed_ravs.entry(allocation_id).or_default();

0 commit comments

Comments
 (0)