@@ -64,7 +64,7 @@ pub struct SenderAccountsManagerArgs {
64
64
65
65
pub struct State {
66
66
sender_ids : HashSet < Address > ,
67
- new_receipts_watcher_handle : tokio:: task:: JoinHandle < ( ) > ,
67
+ new_receipts_watcher_handle : Option < tokio:: task:: JoinHandle < ( ) > > ,
68
68
_eligible_allocations_senders_pipe : PipeHandle ,
69
69
70
70
config : & ' static config:: Config ,
@@ -108,12 +108,6 @@ impl Actor for SenderAccountsManager {
108
108
"should be able to subscribe to Postgres Notify events on the channel \
109
109
'scalar_tap_receipt_notification'",
110
110
) ;
111
- // Start the new_receipts_watcher task that will consume from the `pglistener`
112
- let new_receipts_watcher_handle = tokio:: spawn ( new_receipts_watcher (
113
- pglistener,
114
- escrow_accounts. clone ( ) ,
115
- prefix. clone ( ) ,
116
- ) ) ;
117
111
let clone = myself. clone ( ) ;
118
112
let _eligible_allocations_senders_pipe =
119
113
escrow_accounts. clone ( ) . pipe_async ( move |escrow_accounts| {
@@ -134,14 +128,14 @@ impl Actor for SenderAccountsManager {
134
128
config,
135
129
domain_separator,
136
130
sender_ids : HashSet :: new ( ) ,
137
- new_receipts_watcher_handle,
131
+ new_receipts_watcher_handle : None ,
138
132
_eligible_allocations_senders_pipe,
139
133
pgpool,
140
134
indexer_allocations,
141
- escrow_accounts,
135
+ escrow_accounts : escrow_accounts . clone ( ) ,
142
136
escrow_subgraph,
143
137
sender_aggregator_endpoints,
144
- prefix,
138
+ prefix : prefix . clone ( ) ,
145
139
} ;
146
140
let sender_allocation = select ! {
147
141
sender_allocation = state. get_pending_sender_allocation_id( ) => sender_allocation,
@@ -157,6 +151,14 @@ impl Actor for SenderAccountsManager {
157
151
. await ?;
158
152
}
159
153
154
+ // Start the new_receipts_watcher task that will consume from the `pglistener`
155
+ // after starting all senders
156
+ state. new_receipts_watcher_handle = Some ( tokio:: spawn ( new_receipts_watcher (
157
+ pglistener,
158
+ escrow_accounts,
159
+ prefix,
160
+ ) ) ) ;
161
+
160
162
tracing:: info!( "SenderAccountManager created!" ) ;
161
163
Ok ( state)
162
164
}
@@ -167,7 +169,9 @@ impl Actor for SenderAccountsManager {
167
169
) -> std:: result:: Result < ( ) , ActorProcessingErr > {
168
170
// Abort the notification watcher on drop. Otherwise it may panic because the PgPool could
169
171
// get dropped before. (Observed in tests)
170
- state. new_receipts_watcher_handle . abort ( ) ;
172
+ if let Some ( handle) = & state. new_receipts_watcher_handle {
173
+ handle. abort ( ) ;
174
+ }
171
175
Ok ( ( ) )
172
176
}
173
177
@@ -608,7 +612,7 @@ mod tests {
608
612
config,
609
613
domain_separator : TAP_EIP712_DOMAIN_SEPARATOR . clone ( ) ,
610
614
sender_ids : HashSet :: new ( ) ,
611
- new_receipts_watcher_handle : tokio :: spawn ( async { } ) ,
615
+ new_receipts_watcher_handle : None ,
612
616
_eligible_allocations_senders_pipe : Eventual :: from_value ( ( ) )
613
617
. pipe_async ( |_| async { } ) ,
614
618
pgpool,
0 commit comments