@@ -148,8 +148,8 @@ impl Actor for SenderAccountsManager {
148
148
for ( sender_id, allocation_ids) in sender_allocation {
149
149
state. sender_ids . insert ( sender_id) ;
150
150
state
151
- . create_sender_account ( myself. get_cell ( ) , sender_id, allocation_ids)
152
- . await ? ;
151
+ . create_or_deny_sender ( myself. get_cell ( ) , sender_id, allocation_ids)
152
+ . await ;
153
153
}
154
154
155
155
// Start the new_receipts_watcher task that will consume from the `pglistener`
@@ -191,16 +191,9 @@ impl Actor for SenderAccountsManager {
191
191
SenderAccountsManagerMessage :: UpdateSenderAccounts ( target_senders) => {
192
192
// Create new sender accounts
193
193
for sender in target_senders. difference ( & state. sender_ids ) {
194
- if let Err ( e) = state
195
- . create_sender_account ( myself. get_cell ( ) , * sender, HashSet :: new ( ) )
196
- . await
197
- {
198
- error ! (
199
- sender_address = %sender,
200
- error = %e,
201
- "There was an error while creating a sender account."
202
- ) ;
203
- }
194
+ state
195
+ . create_or_deny_sender ( myself. get_cell ( ) , * sender, HashSet :: new ( ) )
196
+ . await ;
204
197
}
205
198
206
199
// Remove sender accounts
@@ -263,16 +256,9 @@ impl Actor for SenderAccountsManager {
263
256
. remove ( & sender_id)
264
257
. unwrap_or ( HashSet :: new ( ) ) ;
265
258
266
- if let Err ( e) = state
267
- . create_sender_account ( myself. get_cell ( ) , sender_id, allocations)
268
- . await
269
- {
270
- error ! (
271
- error = %e,
272
- sender_address = %sender_id,
273
- "There was an error while re-creating sender account."
274
- ) ;
275
- }
259
+ state
260
+ . create_or_deny_sender ( myself. get_cell ( ) , sender_id, allocations)
261
+ . await ;
276
262
}
277
263
_ => { }
278
264
}
@@ -291,13 +277,46 @@ impl State {
291
277
sender_allocation_id
292
278
}
293
279
280
+ async fn create_or_deny_sender (
281
+ & self ,
282
+ supervisor : ActorCell ,
283
+ sender_id : Address ,
284
+ allocation_ids : HashSet < Address > ,
285
+ ) {
286
+ if let Err ( e) = self
287
+ . create_sender_account ( supervisor, sender_id, allocation_ids)
288
+ . await
289
+ {
290
+ error ! (
291
+ "There was an error while starting the sender {}, denying it. Error: {:?}" ,
292
+ sender_id, e
293
+ ) ;
294
+ SenderAccount :: deny_sender ( & self . pgpool , sender_id) . await ;
295
+ }
296
+ }
297
+
294
298
async fn create_sender_account (
295
299
& self ,
296
300
supervisor : ActorCell ,
297
301
sender_id : Address ,
298
302
allocation_ids : HashSet < Address > ,
299
303
) -> anyhow:: Result < ( ) > {
300
- let args = self . new_sender_account_args ( & sender_id, allocation_ids) ?;
304
+ let Ok ( args) = self . new_sender_account_args ( & sender_id, allocation_ids) else {
305
+ warn ! (
306
+ "Sender {} is not on your [tap.sender_aggregator_endpoints] list. \
307
+ \
308
+ This means that you don't recognize this sender and don't want to \
309
+ provide queries for it.
310
+ \
311
+ If you do recognize and want to serve queries for it, \
312
+ add a new entry to the config [tap.sender_aggregator_endpoints]",
313
+ sender_id
314
+ ) ;
315
+ bail ! (
316
+ "No sender_aggregator_endpoints found for sender {}" ,
317
+ sender_id
318
+ ) ;
319
+ } ;
301
320
SenderAccount :: spawn_linked (
302
321
Some ( self . format_sender_account ( & sender_id) ) ,
303
322
SenderAccount ,
@@ -428,12 +447,10 @@ impl State {
428
447
sender_aggregator_endpoint : self
429
448
. sender_aggregator_endpoints
430
449
. get ( sender_id)
431
- . ok_or_else ( || {
432
- anyhow ! (
433
- "No sender_aggregator_endpoint found for sender {}" ,
434
- sender_id
435
- )
436
- } ) ?
450
+ . ok_or ( anyhow ! (
451
+ "No sender_aggregator_endpoints found for sender {}" ,
452
+ sender_id
453
+ ) ) ?
437
454
. clone ( ) ,
438
455
allocation_ids,
439
456
prefix : self . prefix . clone ( ) ,
@@ -567,8 +584,9 @@ mod tests {
567
584
use crate :: config;
568
585
use crate :: tap:: test_utils:: {
569
586
create_rav, create_received_receipt, store_rav, store_receipt, ALLOCATION_ID_0 ,
570
- ALLOCATION_ID_1 , INDEXER , SENDER , SENDER_2 , SIGNER , TAP_EIP712_DOMAIN_SEPARATOR ,
587
+ ALLOCATION_ID_1 , INDEXER , SENDER , SENDER_2 , SENDER_3 , SIGNER , TAP_EIP712_DOMAIN_SEPARATOR ,
571
588
} ;
589
+ use alloy:: hex:: ToHexExt ;
572
590
use alloy:: primitives:: Address ;
573
591
use eventuals:: { Eventual , EventualExt } ;
574
592
use indexer_common:: allocations:: Allocation ;
@@ -783,6 +801,60 @@ mod tests {
783
801
handle. await . unwrap ( ) ;
784
802
}
785
803
804
+ #[ sqlx:: test( migrations = "../migrations" ) ]
805
+ async fn test_deny_sender_account_on_failure ( pgpool : PgPool ) {
806
+ struct DummyActor ;
807
+ #[ async_trait:: async_trait]
808
+ impl Actor for DummyActor {
809
+ type Msg = ( ) ;
810
+ type State = ( ) ;
811
+ type Arguments = ( ) ;
812
+
813
+ async fn pre_start (
814
+ & self ,
815
+ _: ActorRef < Self :: Msg > ,
816
+ _: Self :: Arguments ,
817
+ ) -> Result < Self :: State , ActorProcessingErr > {
818
+ Ok ( ( ) )
819
+ }
820
+ }
821
+
822
+ let ( _prefix, state) = create_state ( pgpool. clone ( ) ) ;
823
+ let ( supervisor, handle) = DummyActor :: spawn ( None , DummyActor , ( ) ) . await . unwrap ( ) ;
824
+ // we wait to check if the sender is created
825
+
826
+ let sender_id = SENDER_3 . 1 ;
827
+
828
+ state
829
+ . create_or_deny_sender ( supervisor. get_cell ( ) , sender_id, HashSet :: new ( ) )
830
+ . await ;
831
+
832
+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) . await ;
833
+
834
+ // TODO check if sender is denied
835
+
836
+ let denied = sqlx:: query!(
837
+ r#"
838
+ SELECT EXISTS (
839
+ SELECT 1
840
+ FROM scalar_tap_denylist
841
+ WHERE sender_address = $1
842
+ ) as denied
843
+ "# ,
844
+ sender_id. encode_hex( ) ,
845
+ )
846
+ . fetch_one ( & pgpool)
847
+ . await
848
+ . unwrap ( )
849
+ . denied
850
+ . expect ( "Deny status cannot be null" ) ;
851
+
852
+ assert ! ( denied, "Sender was not denied after failing." ) ;
853
+
854
+ supervisor. stop_and_wait ( None , None ) . await . unwrap ( ) ;
855
+ handle. await . unwrap ( ) ;
856
+ }
857
+
786
858
#[ sqlx:: test( migrations = "../migrations" ) ]
787
859
async fn test_receive_notifications_ ( pgpool : PgPool ) {
788
860
let prefix = format ! (
0 commit comments