@@ -317,6 +317,10 @@ pub struct State {
317317 // reset in case of a successful response
318318 backoff_info : BackoffInfo ,
319319
320+ /// Allows the gateway to go over escrow balance
321+ /// limited to `max_amount_willing_to_lose_grt`
322+ trusted_gateway : bool ,
323+
320324 // Config forwarded to [SenderAllocation]
321325 config : & ' static SenderAccountConfig ,
322326}
@@ -343,6 +347,9 @@ pub struct SenderAccountConfig {
343347 ///
344348 /// This is reached if the database is too slow
345349 pub tap_sender_timeout : Duration ,
350+ /// Gateways that are allowed to spend up to
351+ /// `max_amount_willing_to_lose_grt` over the escrow balance
352+ pub trusted_gateways : HashSet < Address > ,
346353}
347354
348355impl SenderAccountConfig {
@@ -357,6 +364,7 @@ impl SenderAccountConfig {
357364 trigger_value : config. tap . get_trigger_value ( ) ,
358365 rav_request_timeout : config. tap . rav_request . request_timeout_secs ,
359366 tap_sender_timeout : config. tap . sender_timeout_secs ,
367+ trusted_gateways : config. tap . trusted_gateways . clone ( ) ,
360368 }
361369 }
362370}
@@ -531,9 +539,16 @@ impl State {
531539 fn deny_condition_reached ( & self ) -> bool {
532540 let pending_ravs = self . rav_tracker . get_total_fee ( ) ;
533541 let unaggregated_fees = self . sender_fee_tracker . get_total_fee ( ) ;
534- let pending_fees_over_balance =
535- U256 :: from ( pending_ravs + unaggregated_fees) >= self . sender_balance ;
536542 let max_amount_willing_to_lose = self . config . max_amount_willing_to_lose_grt ;
543+
544+ // if it's a trusted gateway, allow to spend up to max_amount_willing_to_lose
545+ let balance = if self . trusted_gateway {
546+ self . sender_balance + U256 :: from ( max_amount_willing_to_lose)
547+ } else {
548+ self . sender_balance
549+ } ;
550+
551+ let pending_fees_over_balance = U256 :: from ( pending_ravs + unaggregated_fees) >= balance;
537552 let invalid_receipt_fees = self . invalid_receipts_tracker . get_total_fee ( ) ;
538553 let total_fee_over_max_value =
539554 unaggregated_fees + invalid_receipt_fees >= max_amount_willing_to_lose;
@@ -841,6 +856,7 @@ impl Actor for SenderAccount {
841856 aggregator_v1,
842857 aggregator_v2,
843858 backoff_info : BackoffInfo :: default ( ) ,
859+ trusted_gateway : config. trusted_gateways . contains ( & sender_id) ,
844860 config,
845861 } ;
846862
0 commit comments