@@ -27,6 +27,7 @@ use tap_core::rav::SignedRAV;
2727use tracing:: { error, Level } ;
2828
2929use super :: sender_allocation:: { SenderAllocation , SenderAllocationArgs } ;
30+ use crate :: adaptative_concurrency:: AdaptiveLimiter ;
3031use crate :: agent:: sender_allocation:: SenderAllocationMessage ;
3132use crate :: agent:: unaggregated_receipts:: UnaggregatedReceipts ;
3233use crate :: tracker:: { SenderFeeTracker , SimpleFeeTracker } ;
@@ -77,6 +78,8 @@ lazy_static! {
7778 . unwrap( ) ;
7879}
7980
81+ const INITIAL_RAV_REQUEST_CONCURRENT : usize = 1 ;
82+
8083type RavMap = HashMap < Address , u128 > ;
8184type Balance = U256 ;
8285
@@ -146,6 +149,9 @@ pub struct State {
146149 sender_balance : U256 ,
147150 retry_interval : Duration ,
148151
152+ // concurrent rav request
153+ adaptive_limiter : AdaptiveLimiter ,
154+
149155 //Eventuals
150156 escrow_accounts : Eventual < EscrowAccounts > ,
151157
@@ -233,6 +239,7 @@ impl State {
233239 "Error while sending and waiting message for actor {allocation_id}. Error: {e}"
234240 )
235241 } ) ?;
242+ self . adaptive_limiter . acquire ( ) ;
236243 self . sender_fee_tracker . start_rav_request ( allocation_id) ;
237244
238245 Ok ( ( ) )
@@ -247,6 +254,7 @@ impl State {
247254 match rav_result {
248255 Ok ( ( fees, rav) ) => {
249256 self . sender_fee_tracker . ok_rav_request ( allocation_id) ;
257+ self . adaptive_limiter . on_success ( ) ;
250258
251259 let rav_value = rav. map_or ( 0 , |rav| rav. message . valueAggregate ) ;
252260 self . update_rav ( allocation_id, rav_value) ;
@@ -257,6 +265,7 @@ impl State {
257265 Err ( err) => {
258266 // TODO we should update the total value too
259267 self . sender_fee_tracker . failed_rav_backoff ( allocation_id) ;
268+ self . adaptive_limiter . on_failure ( ) ;
260269 error ! (
261270 "Error while requesting RAV for sender {} and allocation {}: {}" ,
262271 self . sender, allocation_id, err
@@ -536,6 +545,7 @@ impl Actor for SenderAccount {
536545 sender_balance,
537546 retry_interval,
538547 scheduled_rav_request : None ,
548+ adaptive_limiter : AdaptiveLimiter :: new ( INITIAL_RAV_REQUEST_CONCURRENT , 1 ..50 ) ,
539549 } ;
540550
541551 for allocation_id in & allocation_ids {
@@ -647,11 +657,13 @@ impl Actor for SenderAccount {
647657 let total_fee_outside_buffer = state. sender_fee_tracker . get_ravable_total_fee ( ) ;
648658 let total_fee_greater_trigger_value =
649659 total_fee_outside_buffer >= state. config . tap . rav_request_trigger_value ;
660+ let has_limit_available = state. adaptive_limiter . has_limit ( ) ;
650661 let rav_result = match (
662+ has_limit_available,
651663 counter_greater_receipt_limit,
652664 total_fee_greater_trigger_value,
653665 ) {
654- ( true , _) => {
666+ ( true , true , _) => {
655667 tracing:: debug!(
656668 total_counter_for_allocation,
657669 rav_request_receipt_limit = state. config. tap. rav_request_receipt_limit,
@@ -661,7 +673,7 @@ impl Actor for SenderAccount {
661673
662674 state. rav_request_for_allocation ( allocation_id) . await
663675 }
664- ( _, true ) => {
676+ ( true , _, true ) => {
665677 tracing:: debug!(
666678 total_fee_outside_buffer,
667679 trigger_value = state. config. tap. rav_request_trigger_value,
0 commit comments