Skip to content

Commit f430708

Browse files
gusinacioaasseman
andauthored
feat: auto retry RAVs if sender denied (#195)
* feat: retry if denied Signed-off-by: Gustavo Inacio <[email protected]> * chore: update comments Co-authored-by: Alexis Asseman <[email protected]> --------- Signed-off-by: Gustavo Inacio <[email protected]> Co-authored-by: Alexis Asseman <[email protected]>
1 parent cd0c1cd commit f430708

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

tap-agent/src/agent/sender_account.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use bigdecimal::num_bigint::ToBigInt;
55
use bigdecimal::ToPrimitive;
66
use std::collections::{HashMap, HashSet};
77
use std::str::FromStr;
8+
use std::time::Duration;
9+
use tokio::task::JoinHandle;
810

911
use alloy_primitives::hex::ToHex;
1012
use alloy_sol_types::Eip712Domain;
@@ -13,7 +15,7 @@ use ethereum_types::U256;
1315
use eventuals::{Eventual, EventualExt, PipeHandle};
1416
use indexer_common::subgraph_client::Query;
1517
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};
1719
use serde::Deserialize;
1820
use sqlx::PgPool;
1921
use tap_core::rav::SignedRAV;
@@ -73,6 +75,7 @@ pub struct State {
7375
allocation_ids: HashSet<Address>,
7476
_indexer_allocations_handle: PipeHandle,
7577
_escrow_account_monitor: PipeHandle,
78+
scheduled_rav_request: Option<JoinHandle<Result<(), MessagingErr<SenderAccountMessage>>>>,
7679

7780
sender: Address,
7881

@@ -416,6 +419,7 @@ impl Actor for SenderAccount {
416419
sender: sender_id,
417420
denied,
418421
sender_balance,
422+
scheduled_rav_request: None,
419423
};
420424

421425
for allocation_id in &allocation_ids {
@@ -455,6 +459,11 @@ impl Actor for SenderAccount {
455459
}
456460
}
457461
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+
458467
state
459468
.sender_fee_tracker
460469
.update(allocation_id, unaggregated_fees.value);
@@ -484,12 +493,23 @@ impl Actor for SenderAccount {
484493
}
485494
}
486495

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+
_ => {}
493513
}
494514
}
495515
SenderAccountMessage::UpdateAllocationIds(allocation_ids) => {

0 commit comments

Comments
 (0)