@@ -5,6 +5,8 @@ use bigdecimal::num_bigint::ToBigInt;
5
5
use bigdecimal:: ToPrimitive ;
6
6
use std:: collections:: { HashMap , HashSet } ;
7
7
use std:: str:: FromStr ;
8
+ use std:: time:: Duration ;
9
+ use tokio:: task:: JoinHandle ;
8
10
9
11
use alloy_primitives:: hex:: ToHex ;
10
12
use alloy_sol_types:: Eip712Domain ;
@@ -13,7 +15,7 @@ use ethereum_types::U256;
13
15
use eventuals:: { Eventual , EventualExt , PipeHandle } ;
14
16
use indexer_common:: subgraph_client:: Query ;
15
17
use indexer_common:: { escrow_accounts:: EscrowAccounts , prelude:: SubgraphClient } ;
16
- use ractor:: { call, Actor , ActorProcessingErr , ActorRef , SupervisionEvent } ;
18
+ use ractor:: { call, Actor , ActorProcessingErr , ActorRef , MessagingErr , SupervisionEvent } ;
17
19
use serde:: Deserialize ;
18
20
use sqlx:: PgPool ;
19
21
use tap_core:: rav:: SignedRAV ;
@@ -73,6 +75,7 @@ pub struct State {
73
75
allocation_ids : HashSet < Address > ,
74
76
_indexer_allocations_handle : PipeHandle ,
75
77
_escrow_account_monitor : PipeHandle ,
78
+ scheduled_rav_request : Option < JoinHandle < Result < ( ) , MessagingErr < SenderAccountMessage > > > > ,
76
79
77
80
sender : Address ,
78
81
@@ -416,6 +419,7 @@ impl Actor for SenderAccount {
416
419
sender : sender_id,
417
420
denied,
418
421
sender_balance,
422
+ scheduled_rav_request : None ,
419
423
} ;
420
424
421
425
for allocation_id in & allocation_ids {
@@ -455,6 +459,11 @@ impl Actor for SenderAccount {
455
459
}
456
460
}
457
461
SenderAccountMessage :: UpdateReceiptFees ( allocation_id, unaggregated_fees) => {
462
+ // If we're here because of a new receipt, abort any scheduled UpdateReceiptFees
463
+ if let Some ( scheduled_rav_request) = state. scheduled_rav_request . take ( ) {
464
+ scheduled_rav_request. abort ( ) ;
465
+ }
466
+
458
467
state
459
468
. sender_fee_tracker
460
469
. update ( allocation_id, unaggregated_fees. value ) ;
@@ -484,12 +493,23 @@ impl Actor for SenderAccount {
484
493
}
485
494
}
486
495
487
- // Maybe allow the sender right after the potential RAV request. This way, the
488
- // sender can be allowed again as soon as possible if the RAV was successful.
489
-
490
- let should_allow = state. denied && !state. deny_condition_reached ( ) ;
491
- if should_allow {
492
- state. remove_from_denylist ( ) . await ;
496
+ match ( state. denied , state. deny_condition_reached ( ) ) {
497
+ // Allow the sender right after the potential RAV request. This way, the
498
+ // sender can be allowed again as soon as possible if the RAV was successful.
499
+ ( true , false ) => state. remove_from_denylist ( ) . await ,
500
+ // if couldn't remove from denylist, resend the message in 30 seconds
501
+ // this may trigger another rav request
502
+ ( true , true ) => {
503
+ // retry in a moment
504
+ state. scheduled_rav_request =
505
+ Some ( myself. send_after ( Duration :: from_secs ( 30 ) , move || {
506
+ SenderAccountMessage :: UpdateReceiptFees (
507
+ allocation_id,
508
+ unaggregated_fees,
509
+ )
510
+ } ) ) ;
511
+ }
512
+ _ => { }
493
513
}
494
514
}
495
515
SenderAccountMessage :: UpdateAllocationIds ( allocation_ids) => {
0 commit comments