@@ -5,6 +5,9 @@ use std::collections::HashSet;
55use std:: time:: Duration ;
66use std:: { collections:: HashMap , str:: FromStr } ;
77
8+ use super :: sender_account:: {
9+ SenderAccount , SenderAccountArgs , SenderAccountConfig , SenderAccountMessage ,
10+ } ;
811use crate :: agent:: sender_allocation:: SenderAllocationMessage ;
912use crate :: lazy_static;
1013use alloy:: dyn_abi:: Eip712Domain ;
@@ -14,6 +17,8 @@ use anyhow::{anyhow, bail};
1417use futures:: { stream, StreamExt } ;
1518use indexer_common:: escrow_accounts:: EscrowAccounts ;
1619use indexer_common:: prelude:: { Allocation , SubgraphClient } ;
20+ use indexer_common:: watcher:: watch_pipe;
21+ use prometheus:: { register_counter_vec, CounterVec } ;
1722use ractor:: concurrency:: JoinHandle ;
1823use ractor:: { Actor , ActorCell , ActorProcessingErr , ActorRef , SupervisionEvent } ;
1924use reqwest:: Url ;
@@ -23,12 +28,6 @@ use tokio::select;
2328use tokio:: sync:: watch:: { self , Receiver } ;
2429use tracing:: { error, warn} ;
2530
26- use prometheus:: { register_counter_vec, CounterVec } ;
27-
28- use super :: sender_account:: {
29- SenderAccount , SenderAccountArgs , SenderAccountConfig , SenderAccountMessage ,
30- } ;
31-
3231lazy_static ! {
3332 static ref RECEIPTS_CREATED : CounterVec = register_counter_vec!(
3433 "tap_receipts_received_total" ,
@@ -106,17 +105,11 @@ impl Actor for SenderAccountsManager {
106105 } : Self :: Arguments ,
107106 ) -> std:: result:: Result < Self :: State , ActorProcessingErr > {
108107 let ( allocations_tx, allocations_rx) = watch:: channel ( HashSet :: < Address > :: new ( ) ) ;
109- tokio :: spawn ( async move {
110- let mut indexer_allocations = indexer_allocations . clone ( ) ;
111- while indexer_allocations . changed ( ) . await . is_ok ( ) {
108+ watch_pipe ( indexer_allocations . clone ( ) , move |rx| {
109+ let allocations_tx = allocations_tx . clone ( ) ;
110+ async move {
112111 allocations_tx
113- . send (
114- indexer_allocations
115- . borrow ( )
116- . keys ( )
117- . cloned ( )
118- . collect :: < HashSet < Address > > ( ) ,
119- )
112+ . send ( rx. borrow ( ) . keys ( ) . cloned ( ) . collect :: < HashSet < Address > > ( ) )
120113 . expect ( "Failed to update indexer_allocations_set channel" ) ;
121114 }
122115 } ) ;
@@ -129,12 +122,13 @@ impl Actor for SenderAccountsManager {
129122 'scalar_tap_receipt_notification'",
130123 ) ;
131124 let myself_clone = myself. clone ( ) ;
132- let mut accounts_clone = escrow_accounts. clone ( ) ;
133- let _eligible_allocations_senders_handle = tokio:: spawn ( async move {
134- while accounts_clone. changed ( ) . await . is_ok ( ) {
135- myself_clone
125+ let accounts_clone = escrow_accounts. clone ( ) ;
126+ let _eligible_allocations_senders_handle = watch_pipe ( accounts_clone, move |rx| {
127+ let myself = myself_clone. clone ( ) ;
128+ async move {
129+ myself
136130 . cast ( SenderAccountsManagerMessage :: UpdateSenderAccounts (
137- accounts_clone . borrow ( ) . get_senders ( ) ,
131+ rx . borrow ( ) . get_senders ( ) ,
138132 ) )
139133 . unwrap_or_else ( |e| {
140134 error ! ( "Error while updating sender_accounts: {:?}" , e) ;
0 commit comments