@@ -21,7 +21,7 @@ use serde::Deserialize;
2121use sqlx:: PgPool ;
2222use tap_core:: rav:: SignedRAV ;
2323use thegraph_core:: Address ;
24- use tracing:: { error, warn , Level } ;
24+ use tracing:: { error, Level } ;
2525
2626use super :: sender_allocation:: { SenderAllocation , SenderAllocationArgs } ;
2727use crate :: agent:: sender_allocation:: SenderAllocationMessage ;
@@ -297,40 +297,6 @@ 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- }
334300}
335301
336302#[ async_trait:: async_trait]
@@ -567,6 +533,18 @@ impl Actor for SenderAccount {
567533 message = ?message,
568534 "New SenderAccount message"
569535 ) ;
536+ // If state is denied and receivied new message, sender was removed manually from DB
537+ if state. denied {
538+ tracing:: warn!(
539+ "
540+ No new messages should have been receieved, sender has been denied before. \
541+ You SHOULD NOT remove a denied sender manually from the database. \
542+ If you do so you are exposing yourself to potentially LOOSING ALL of your query
543+ fee MONEY.
544+ "
545+ ) ;
546+ state. add_to_denylist ( ) . await ;
547+ }
570548 match message {
571549 SenderAccountMessage :: UpdateRav ( rav) => {
572550 state
@@ -580,7 +558,10 @@ impl Actor for SenderAccount {
580558 ] )
581559 . set ( rav. message . valueAggregate as f64 ) ;
582560
583- state. check_denylist_state ( ) . await ;
561+ let should_deny = !state. denied && state. deny_condition_reached ( ) ;
562+ if should_deny {
563+ state. add_to_denylist ( ) . await ;
564+ }
584565 }
585566 SenderAccountMessage :: UpdateInvalidReceiptFees ( allocation_id, unaggregated_fees) => {
586567 INVALID_RECEIPT_FEES
@@ -592,7 +573,10 @@ impl Actor for SenderAccount {
592573 . update ( allocation_id, unaggregated_fees. value ) ;
593574
594575 // invalid receipts can't go down
595- state. check_denylist_state ( ) . await ;
576+ let should_deny = !state. denied && state. deny_condition_reached ( ) ;
577+ if should_deny {
578+ state. add_to_denylist ( ) . await ;
579+ }
596580 }
597581 SenderAccountMessage :: UpdateReceiptFees ( allocation_id, receipt_fees) => {
598582 // If we're here because of a new receipt, abort any scheduled UpdateReceiptFees
@@ -629,7 +613,10 @@ impl Actor for SenderAccount {
629613 // Eagerly deny the sender (if needed), before the RAV request. To be sure not to
630614 // delay the denial because of the RAV request, which could take some time.
631615
632- state. check_denylist_state ( ) . await ;
616+ let should_deny = !state. denied && state. deny_condition_reached ( ) ;
617+ if should_deny {
618+ state. add_to_denylist ( ) . await ;
619+ }
633620
634621 if state. sender_fee_tracker . get_total_fee_outside_buffer ( )
635622 >= state. config . tap . rav_request_trigger_value
@@ -752,7 +739,7 @@ impl Actor for SenderAccount {
752739 // now that balance and rav tracker is updated, check
753740 match ( state. denied , state. deny_condition_reached ( ) ) {
754741 ( true , false ) => state. remove_from_denylist ( ) . await ,
755- ( false , true ) => state. check_denylist_state ( ) . await ,
742+ ( false , true ) => state. add_to_denylist ( ) . await ,
756743 ( _, _) => { }
757744 }
758745 }
0 commit comments