@@ -71,12 +71,18 @@ lazy_static! {
7171type  RavMap  = HashMap < Address ,  u128 > ; 
7272type  Balance  = U256 ; 
7373
74+ #[ derive( Debug ,  Eq ,  PartialEq ) ]  
75+ pub  enum  ReceiptFees  { 
76+     NewValue ( UnaggregatedReceipts ) , 
77+     Retry , 
78+ } 
79+ 
7480#[ derive( Debug ) ]  
7581pub  enum  SenderAccountMessage  { 
7682    UpdateBalanceAndLastRavs ( Balance ,  RavMap ) , 
7783    UpdateAllocationIds ( HashSet < Address > ) , 
7884    NewAllocationId ( Address ) , 
79-     UpdateReceiptFees ( Address ,  UnaggregatedReceipts ) , 
85+     UpdateReceiptFees ( Address ,  ReceiptFees ) , 
8086    UpdateInvalidReceiptFees ( Address ,  UnaggregatedReceipts ) , 
8187    UpdateRav ( SignedRAV ) , 
8288    #[ cfg( test) ]  
@@ -551,19 +557,21 @@ impl Actor for SenderAccount {
551557                    state. add_to_denylist ( ) . await ; 
552558                } 
553559            } 
554-             SenderAccountMessage :: UpdateReceiptFees ( allocation_id,  unaggregated_fees)  => { 
555-                 UNAGGREGATED_FEES 
556-                     . with_label_values ( & [ & state. sender . to_string ( ) ,  & allocation_id. to_string ( ) ] ) 
557-                     . set ( unaggregated_fees. value  as  f64 ) ; 
558- 
560+             SenderAccountMessage :: UpdateReceiptFees ( allocation_id,  receipt_fees)  => { 
559561                // If we're here because of a new receipt, abort any scheduled UpdateReceiptFees 
560562                if  let  Some ( scheduled_rav_request)  = state. scheduled_rav_request . take ( )  { 
561563                    scheduled_rav_request. abort ( ) ; 
562564                } 
563565
564-                 state
565-                     . sender_fee_tracker 
566-                     . update ( allocation_id,  unaggregated_fees. value ) ; 
566+                 if  let  ReceiptFees :: NewValue ( unaggregated_fees)  = receipt_fees { 
567+                     state
568+                         . sender_fee_tracker 
569+                         . update ( allocation_id,  unaggregated_fees. value ) ; 
570+ 
571+                     UNAGGREGATED_FEES 
572+                         . with_label_values ( & [ & state. sender . to_string ( ) ,  & allocation_id. to_string ( ) ] ) 
573+                         . set ( unaggregated_fees. value  as  f64 ) ; 
574+                 } 
567575
568576                // Eagerly deny the sender (if needed), before the RAV request. To be sure not to 
569577                // delay the denial because of the RAV request, which could take some time. 
@@ -602,7 +610,7 @@ impl Actor for SenderAccount {
602610                            Some ( myself. send_after ( state. retry_interval ,  move  || { 
603611                                SenderAccountMessage :: UpdateReceiptFees ( 
604612                                    allocation_id, 
605-                                     unaggregated_fees , 
613+                                     ReceiptFees :: Retry , 
606614                                ) 
607615                            } ) ) ; 
608616                    } 
@@ -760,7 +768,7 @@ impl Actor for SenderAccount {
760768                // update the receipt fees by reseting to 0 
761769                myself. cast ( SenderAccountMessage :: UpdateReceiptFees ( 
762770                    allocation_id, 
763-                     UnaggregatedReceipts :: default ( ) , 
771+                     ReceiptFees :: NewValue ( UnaggregatedReceipts :: default ( ) ) , 
764772                ) ) ?; 
765773
766774                // rav tracker is not updated because it's still not redeemed 
@@ -805,6 +813,7 @@ impl Actor for SenderAccount {
805813#[ cfg( test) ]  
806814pub  mod  tests { 
807815    use  super :: { SenderAccount ,  SenderAccountArgs ,  SenderAccountMessage } ; 
816+     use  crate :: agent:: sender_account:: ReceiptFees ; 
808817    use  crate :: agent:: sender_accounts_manager:: NewReceiptNotification ; 
809818    use  crate :: agent:: sender_allocation:: SenderAllocationMessage ; 
810819    use  crate :: agent:: unaggregated_receipts:: UnaggregatedReceipts ; 
@@ -1014,16 +1023,18 @@ pub mod tests {
10141023    } 
10151024
10161025    impl  MockSenderAllocation  { 
1017-         pub  fn  new_with_triggered_rav_request ( )  -> ( Self ,  Arc < AtomicU32 > )  { 
1026+         pub  fn  new_with_triggered_rav_request ( )  -> ( Self ,  Arc < AtomicU32 > ,   Arc < Mutex < u128 > > )  { 
10181027            let  triggered_rav_request = Arc :: new ( AtomicU32 :: new ( 0 ) ) ; 
1028+             let  unaggregated_fees = Arc :: new ( Mutex :: new ( 0 ) ) ; 
10191029            ( 
10201030                Self  { 
10211031                    triggered_rav_request :  triggered_rav_request. clone ( ) , 
10221032                    receipts :  Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) , 
10231033                    next_rav_value :  Arc :: new ( Mutex :: new ( 0 ) ) , 
1024-                     next_unaggregated_fees_value :  Arc :: new ( Mutex :: new ( 0 ) ) , 
1034+                     next_unaggregated_fees_value :  unaggregated_fees . clone ( ) , 
10251035                } , 
10261036                triggered_rav_request, 
1037+                 unaggregated_fees, 
10271038            ) 
10281039        } 
10291040
@@ -1120,18 +1131,24 @@ pub mod tests {
11201131        allocation :  Address , 
11211132    )  -> ( 
11221133        Arc < AtomicU32 > , 
1134+         Arc < Mutex < u128 > > , 
11231135        ActorRef < SenderAllocationMessage > , 
11241136        JoinHandle < ( ) > , 
11251137    )  { 
1126-         let  ( mock_sender_allocation,  triggered_rav_request)  =
1138+         let  ( mock_sender_allocation,  triggered_rav_request,  next_unaggregated_fees )  =
11271139            MockSenderAllocation :: new_with_triggered_rav_request ( ) ; 
11281140
11291141        let  name = format ! ( "{}:{}:{}" ,  prefix,  sender,  allocation) ; 
11301142        let  ( sender_account,  join_handle)  =
11311143            MockSenderAllocation :: spawn ( Some ( name) ,  mock_sender_allocation,  ( ) ) 
11321144                . await 
11331145                . unwrap ( ) ; 
1134-         ( triggered_rav_request,  sender_account,  join_handle) 
1146+         ( 
1147+             triggered_rav_request, 
1148+             next_unaggregated_fees, 
1149+             sender_account, 
1150+             join_handle, 
1151+         ) 
11351152    } 
11361153
11371154    #[ sqlx:: test( migrations = "../migrations" ) ]  
@@ -1145,17 +1162,17 @@ pub mod tests {
11451162        ) 
11461163        . await ; 
11471164
1148-         let  ( triggered_rav_request,  allocation,  allocation_handle)  =
1165+         let  ( triggered_rav_request,  _ ,   allocation,  allocation_handle)  =
11491166            create_mock_sender_allocation ( prefix,  SENDER . 1 ,  * ALLOCATION_ID_0 ) . await ; 
11501167
11511168        // create a fake sender allocation 
11521169        sender_account
11531170            . cast ( SenderAccountMessage :: UpdateReceiptFees ( 
11541171                * ALLOCATION_ID_0 , 
1155-                 UnaggregatedReceipts  { 
1172+                 ReceiptFees :: NewValue ( UnaggregatedReceipts  { 
11561173                    value :  TRIGGER_VALUE  - 1 , 
11571174                    last_id :  10 , 
1158-                 } , 
1175+                 } ) , 
11591176            ) ) 
11601177            . unwrap ( ) ; 
11611178
@@ -1184,17 +1201,17 @@ pub mod tests {
11841201        ) 
11851202        . await ; 
11861203
1187-         let  ( triggered_rav_request,  allocation,  allocation_handle)  =
1204+         let  ( triggered_rav_request,  _ ,   allocation,  allocation_handle)  =
11881205            create_mock_sender_allocation ( prefix,  SENDER . 1 ,  * ALLOCATION_ID_0 ) . await ; 
11891206
11901207        // create a fake sender allocation 
11911208        sender_account
11921209            . cast ( SenderAccountMessage :: UpdateReceiptFees ( 
11931210                * ALLOCATION_ID_0 , 
1194-                 UnaggregatedReceipts  { 
1211+                 ReceiptFees :: NewValue ( UnaggregatedReceipts  { 
11951212                    value :  TRIGGER_VALUE , 
11961213                    last_id :  10 , 
1197-                 } , 
1214+                 } ) , 
11981215            ) ) 
11991216            . unwrap ( ) ; 
12001217
@@ -1292,23 +1309,24 @@ pub mod tests {
12921309        ) 
12931310        . await ; 
12941311
1295-         let  ( triggered_rav_request,  allocation,  allocation_handle)  =
1312+         let  ( triggered_rav_request,  next_value ,   allocation,  allocation_handle)  =
12961313            create_mock_sender_allocation ( prefix,  SENDER . 1 ,  * ALLOCATION_ID_0 ) . await ; 
12971314
12981315        assert_eq ! ( 
12991316            triggered_rav_request. load( std:: sync:: atomic:: Ordering :: SeqCst ) , 
13001317            0 
13011318        ) ; 
1319+         * next_value. lock ( ) . unwrap ( )  = TRIGGER_VALUE ; 
13021320        sender_account
13031321            . cast ( SenderAccountMessage :: UpdateReceiptFees ( 
13041322                * ALLOCATION_ID_0 , 
1305-                 UnaggregatedReceipts  { 
1323+                 ReceiptFees :: NewValue ( UnaggregatedReceipts  { 
13061324                    value :  TRIGGER_VALUE , 
13071325                    last_id :  11 , 
1308-                 } , 
1326+                 } ) , 
13091327            ) ) 
13101328            . unwrap ( ) ; 
1311-         tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ; 
1329+         tokio:: time:: sleep ( Duration :: from_millis ( 200 ) ) . await ; 
13121330
13131331        let  retry_value = triggered_rav_request. load ( std:: sync:: atomic:: Ordering :: SeqCst ) ; 
13141332        assert ! ( retry_value > 1 ,  "It didn't retry more than once" ) ; 
@@ -1348,10 +1366,10 @@ pub mod tests {
13481366                sender_account
13491367                    . cast( SenderAccountMessage :: UpdateReceiptFees ( 
13501368                        * ALLOCATION_ID_0 , 
1351-                         UnaggregatedReceipts  { 
1369+                         ReceiptFees :: NewValue ( UnaggregatedReceipts  { 
13521370                            value:  $value, 
13531371                            last_id:  11 , 
1354-                         } , 
1372+                         } ) , 
13551373                    ) ) 
13561374                    . unwrap( ) ; 
13571375
@@ -1489,10 +1507,10 @@ pub mod tests {
14891507                sender_account
14901508                    . cast( SenderAccountMessage :: UpdateReceiptFees ( 
14911509                        * ALLOCATION_ID_0 , 
1492-                         UnaggregatedReceipts  { 
1510+                         ReceiptFees :: NewValue ( UnaggregatedReceipts  { 
14931511                            value:  $value, 
14941512                            last_id:  11 , 
1495-                         } , 
1513+                         } ) , 
14961514                    ) ) 
14971515                    . unwrap( ) ; 
14981516
@@ -1690,10 +1708,10 @@ pub mod tests {
16901708        sender_account
16911709            . cast ( SenderAccountMessage :: UpdateReceiptFees ( 
16921710                * ALLOCATION_ID_0 , 
1693-                 UnaggregatedReceipts  { 
1711+                 ReceiptFees :: NewValue ( UnaggregatedReceipts  { 
16941712                    value :  TRIGGER_VALUE , 
16951713                    last_id :  11 , 
1696-                 } , 
1714+                 } ) , 
16971715            ) ) 
16981716            . unwrap ( ) ; 
16991717        tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ; 
0 commit comments