@@ -29,6 +29,7 @@ use tracing::{error, Level};
2929use super :: sender_allocation:: { SenderAllocation , SenderAllocationArgs } ;
3030use crate :: agent:: sender_allocation:: SenderAllocationMessage ;
3131use crate :: agent:: unaggregated_receipts:: UnaggregatedReceipts ;
32+ use crate :: backoff:: BackoffInfo ;
3233use crate :: tracker:: { SenderFeeTracker , SimpleFeeTracker } ;
3334use crate :: {
3435 config:: { self } ,
@@ -155,6 +156,9 @@ pub struct State {
155156 config : & ' static config:: Config ,
156157 pgpool : PgPool ,
157158 sender_aggregator : jsonrpsee:: http_client:: HttpClient ,
159+
160+ // Backoff info
161+ backoff_info : BackoffInfo ,
158162}
159163
160164impl State {
@@ -536,6 +540,7 @@ impl Actor for SenderAccount {
536540 sender_balance,
537541 retry_interval,
538542 scheduled_rav_request : None ,
543+ backoff_info : BackoffInfo :: default ( ) ,
539544 } ;
540545
541546 for allocation_id in & allocation_ids {
@@ -651,17 +656,16 @@ impl Actor for SenderAccount {
651656 counter_greater_receipt_limit,
652657 total_fee_greater_trigger_value,
653658 ) {
654- ( true , _) => {
659+ ( true , _) if !state . backoff_info . in_backoff ( ) => {
655660 tracing:: debug!(
656661 total_counter_for_allocation,
657662 rav_request_receipt_limit = state. config. tap. rav_request_receipt_limit,
658663 %allocation_id,
659664 "Total counter greater than the receipt limit per rav. Triggering RAV request"
660665 ) ;
661-
662666 state. rav_request_for_allocation ( allocation_id) . await
663667 }
664- ( _, true ) => {
668+ ( _, true ) if !state . backoff_info . in_backoff ( ) => {
665669 tracing:: debug!(
666670 total_fee_outside_buffer,
667671 trigger_value = state. config. tap. rav_request_trigger_value,
@@ -673,10 +677,13 @@ impl Actor for SenderAccount {
673677 } ;
674678 // In case we fail, we want our actor to keep running
675679 if let Err ( err) = rav_result {
680+ state. backoff_info . fail ( ) ;
676681 tracing:: error!(
677682 error = %err,
678683 "There was an error while requesting a RAV."
679684 ) ;
685+ } else {
686+ state. backoff_info . ok ( ) ;
680687 }
681688
682689 match ( state. denied , state. deny_condition_reached ( ) ) {
0 commit comments