Skip to content

Commit 97e5e0e

Browse files
committed
feat: Add a warning in case senders are undenied manually from db
This also creates a new function which does the check for inital denial of a sender
1 parent 06140f5 commit 97e5e0e

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

tap-agent/src/agent/sender_account.rs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use serde::Deserialize;
2121
use sqlx::PgPool;
2222
use tap_core::rav::SignedRAV;
2323
use thegraph_core::Address;
24-
use tracing::{error, Level};
24+
use tracing::{error, warn, Level};
2525

2626
use super::sender_allocation::{SenderAllocation, SenderAllocationArgs};
2727
use crate::agent::sender_allocation::SenderAllocationMessage;
@@ -297,6 +297,40 @@ impl State {
297297
.with_label_values(&[&self.sender.to_string()])
298298
.set(0);
299299
}
300+
async fn check_denylist_state(&mut self) {
301+
let denied_db = sqlx::query!(
302+
r#"
303+
SELECT EXISTS (
304+
SELECT 1
305+
FROM scalar_tap_denylist
306+
WHERE sender_address = $1
307+
) as denied
308+
"#,
309+
self.sender.encode_hex(),
310+
)
311+
.fetch_one(&self.pgpool)
312+
.await
313+
.unwrap()
314+
.denied
315+
.expect("Deny status cannot be null");
316+
let denied_condition_met = self.deny_condition_reached();
317+
match (self.denied, denied_condition_met, denied_db) {
318+
// if self is denied and the denying condition has been met but its not in the db
319+
// it probably means it was removed by indexer manually which is dangerous
320+
(true, true, false) => {
321+
warn!(
322+
"You SHOULD NOT remove a denied sender manually from the database. \
323+
If you do so you are exposing yourself to potentially LOOSING ALL of your query
324+
fee MONEY.
325+
"
326+
);
327+
self.add_to_denylist().await;
328+
}
329+
// Not denied , denying condition met and not in DB, first time denying it, ok!
330+
(false, true, false) => self.add_to_denylist().await,
331+
_ => (),
332+
}
333+
}
300334
}
301335

302336
#[async_trait::async_trait]
@@ -546,10 +580,7 @@ impl Actor for SenderAccount {
546580
])
547581
.set(rav.message.valueAggregate as f64);
548582

549-
let should_deny = !state.denied && state.deny_condition_reached();
550-
if should_deny {
551-
state.add_to_denylist().await;
552-
}
583+
state.check_denylist_state().await;
553584
}
554585
SenderAccountMessage::UpdateInvalidReceiptFees(allocation_id, unaggregated_fees) => {
555586
INVALID_RECEIPT_FEES
@@ -561,10 +592,7 @@ impl Actor for SenderAccount {
561592
.update(allocation_id, unaggregated_fees.value);
562593

563594
// invalid receipts can't go down
564-
let should_deny = !state.denied && state.deny_condition_reached();
565-
if should_deny {
566-
state.add_to_denylist().await;
567-
}
595+
state.check_denylist_state().await;
568596
}
569597
SenderAccountMessage::UpdateReceiptFees(allocation_id, receipt_fees) => {
570598
// If we're here because of a new receipt, abort any scheduled UpdateReceiptFees
@@ -601,10 +629,7 @@ impl Actor for SenderAccount {
601629
// Eagerly deny the sender (if needed), before the RAV request. To be sure not to
602630
// delay the denial because of the RAV request, which could take some time.
603631

604-
let should_deny = !state.denied && state.deny_condition_reached();
605-
if should_deny {
606-
state.add_to_denylist().await;
607-
}
632+
state.check_denylist_state().await;
608633

609634
if state.sender_fee_tracker.get_total_fee_outside_buffer()
610635
>= state.config.tap.rav_request_trigger_value
@@ -727,7 +752,7 @@ impl Actor for SenderAccount {
727752
// now that balance and rav tracker is updated, check
728753
match (state.denied, state.deny_condition_reached()) {
729754
(true, false) => state.remove_from_denylist().await,
730-
(false, true) => state.add_to_denylist().await,
755+
(false, true) => state.check_denylist_state().await,
731756
(_, _) => {}
732757
}
733758
}

0 commit comments

Comments
 (0)