@@ -30,6 +30,7 @@ use super::sender_allocation::{SenderAllocation, SenderAllocationArgs};
3030use crate :: adaptative_concurrency:: AdaptiveLimiter ;
3131use crate :: agent:: sender_allocation:: SenderAllocationMessage ;
3232use crate :: agent:: unaggregated_receipts:: UnaggregatedReceipts ;
33+ use crate :: backoff:: BackoffInfo ;
3334use crate :: tracker:: { SenderFeeTracker , SimpleFeeTracker } ;
3435use crate :: {
3536 config:: { self } ,
@@ -161,6 +162,9 @@ pub struct State {
161162 config : & ' static config:: Config ,
162163 pgpool : PgPool ,
163164 sender_aggregator : jsonrpsee:: http_client:: HttpClient ,
165+
166+ // Backoff info
167+ backoff_info : BackoffInfo ,
164168}
165169
166170impl State {
@@ -211,6 +215,7 @@ impl State {
211215 . sender_fee_tracker
212216 . get_heaviest_allocation_id ( )
213217 . ok_or_else ( || {
218+ self . backoff_info . fail ( ) ;
214219 anyhow:: anyhow!(
215220 "Error while getting the heaviest allocation, \
216221 this is due one of the following reasons: \n
@@ -221,6 +226,7 @@ impl State {
221226 If this doesn't work, open an issue on our Github."
222227 )
223228 } ) ?;
229+ self . backoff_info . ok ( ) ;
224230 self . rav_request_for_allocation ( allocation_id) . await
225231 }
226232
@@ -546,6 +552,7 @@ impl Actor for SenderAccount {
546552 retry_interval,
547553 scheduled_rav_request : None ,
548554 adaptive_limiter : AdaptiveLimiter :: new ( INITIAL_RAV_REQUEST_CONCURRENT , 1 ..50 ) ,
555+ backoff_info : BackoffInfo :: default ( ) ,
549556 } ;
550557
551558 for allocation_id in & allocation_ids {
@@ -650,39 +657,33 @@ impl Actor for SenderAccount {
650657
651658 let has_available_slots_for_requests = state. adaptive_limiter . has_limit ( ) ;
652659 if has_available_slots_for_requests {
660+ let total_fee_outside_buffer = state. sender_fee_tracker . get_ravable_total_fee ( ) ;
653661 let total_counter_for_allocation = state
654662 . sender_fee_tracker
655663 . get_count_outside_buffer_for_allocation ( & allocation_id) ;
656664 let can_trigger_rav = state. sender_fee_tracker . can_trigger_rav ( allocation_id) ;
657665 let counter_greater_receipt_limit = total_counter_for_allocation
658666 >= state. config . tap . rav_request_receipt_limit
659667 && 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- ) ;
674-
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 ( ( ) ) ,
668+ let rav_result = if !state. backoff_info . in_backoff ( )
669+ && total_fee_outside_buffer >= state. config . tap . rav_request_trigger_value
670+ {
671+ tracing:: debug!(
672+ total_fee_outside_buffer,
673+ trigger_value = state. config. tap. rav_request_trigger_value,
674+ "Total fee greater than the trigger value. Triggering RAV request"
675+ ) ;
676+ state. rav_request_for_heaviest_allocation ( ) . await
677+ } else if counter_greater_receipt_limit {
678+ tracing:: debug!(
679+ total_counter_for_allocation,
680+ rav_request_receipt_limit = state. config. tap. rav_request_receipt_limit,
681+ %allocation_id,
682+ "Total counter greater than the receipt limit per rav. Triggering RAV request"
683+ ) ;
684+ state. rav_request_for_allocation ( allocation_id) . await
685+ } else {
686+ Ok ( ( ) )
686687 } ;
687688 // In case we fail, we want our actor to keep running
688689 if let Err ( err) = rav_result {
0 commit comments