Skip to content

Commit 50b10f4

Browse files
committed
refactor: check before if has limit
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent c23b128 commit 50b10f4

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

tap-agent/src/agent/sender_account.rs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -647,48 +647,50 @@ impl Actor for SenderAccount {
647647
if should_deny {
648648
state.add_to_denylist().await;
649649
}
650-
let total_counter_for_allocation = state
651-
.sender_fee_tracker
652-
.get_count_outside_buffer_for_allocation(&allocation_id);
653-
let can_trigger_rav = state.sender_fee_tracker.can_trigger_rav(allocation_id);
654-
let counter_greater_receipt_limit = total_counter_for_allocation
655-
>= state.config.tap.rav_request_receipt_limit
656-
&& can_trigger_rav;
657-
let total_fee_outside_buffer = state.sender_fee_tracker.get_ravable_total_fee();
658-
let total_fee_greater_trigger_value =
659-
total_fee_outside_buffer >= state.config.tap.rav_request_trigger_value;
650+
660651
let has_limit_available = state.adaptive_limiter.has_limit();
661-
let rav_result = match (
662-
has_limit_available,
663-
counter_greater_receipt_limit,
664-
total_fee_greater_trigger_value,
665-
) {
666-
(true, true, _) => {
667-
tracing::debug!(
668-
total_counter_for_allocation,
669-
rav_request_receipt_limit = state.config.tap.rav_request_receipt_limit,
670-
%allocation_id,
671-
"Total counter greater than the receipt limit per rav. Triggering RAV request"
672-
);
652+
if has_limit_available {
653+
let total_counter_for_allocation = state
654+
.sender_fee_tracker
655+
.get_count_outside_buffer_for_allocation(&allocation_id);
656+
let can_trigger_rav = state.sender_fee_tracker.can_trigger_rav(allocation_id);
657+
let counter_greater_receipt_limit = total_counter_for_allocation
658+
>= state.config.tap.rav_request_receipt_limit
659+
&& can_trigger_rav;
660+
let total_fee_outside_buffer = state.sender_fee_tracker.get_ravable_total_fee();
661+
let total_fee_greater_trigger_value =
662+
total_fee_outside_buffer >= state.config.tap.rav_request_trigger_value;
663+
let rav_result = match (
664+
counter_greater_receipt_limit,
665+
total_fee_greater_trigger_value,
666+
) {
667+
(true, _) => {
668+
tracing::debug!(
669+
total_counter_for_allocation,
670+
rav_request_receipt_limit = state.config.tap.rav_request_receipt_limit,
671+
%allocation_id,
672+
"Total counter greater than the receipt limit per rav. Triggering RAV request"
673+
);
673674

674-
state.rav_request_for_allocation(allocation_id).await
675-
}
676-
(true, _, true) => {
677-
tracing::debug!(
678-
total_fee_outside_buffer,
679-
trigger_value = state.config.tap.rav_request_trigger_value,
680-
"Total fee greater than the trigger value. Triggering RAV request"
675+
state.rav_request_for_allocation(allocation_id).await
676+
}
677+
(_, true) => {
678+
tracing::debug!(
679+
total_fee_outside_buffer,
680+
trigger_value = state.config.tap.rav_request_trigger_value,
681+
"Total fee greater than the trigger value. Triggering RAV request"
682+
);
683+
state.rav_request_for_heaviest_allocation().await
684+
}
685+
_ => Ok(()),
686+
};
687+
// In case we fail, we want our actor to keep running
688+
if let Err(err) = rav_result {
689+
tracing::error!(
690+
error = %err,
691+
"There was an error while requesting a RAV."
681692
);
682-
state.rav_request_for_heaviest_allocation().await
683693
}
684-
_ => Ok(()),
685-
};
686-
// In case we fail, we want our actor to keep running
687-
if let Err(err) = rav_result {
688-
tracing::error!(
689-
error = %err,
690-
"There was an error while requesting a RAV."
691-
);
692694
}
693695

694696
match (state.denied, state.deny_condition_reached()) {

0 commit comments

Comments
 (0)