@@ -1834,6 +1834,8 @@ func (b *batch) monitorSpend(ctx context.Context, primarySweep sweep) error {
1834
1834
return
1835
1835
1836
1836
case err := <- spendErr :
1837
+ b .writeToSpendErrChan (ctx , err )
1838
+
1837
1839
b .writeToErrChan (
1838
1840
fmt .Errorf ("spend error: %w" , err ),
1839
1841
)
@@ -2285,6 +2287,43 @@ func (b *batch) writeToErrChan(err error) {
2285
2287
}
2286
2288
}
2287
2289
2290
+ // writeToSpendErrChan sends an error to spend error channels of all the sweeps.
2291
+ func (b * batch ) writeToSpendErrChan (ctx context.Context , spendErr error ) {
2292
+ done , err := b .scheduleNextCall ()
2293
+ if err != nil {
2294
+ done ()
2295
+
2296
+ return
2297
+ }
2298
+ notifiers := make ([]* SpendNotifier , 0 , len (b .sweeps ))
2299
+ for _ , s := range b .sweeps {
2300
+ // If the sweep's notifier is empty then this means that a swap
2301
+ // is not waiting to read an update from it, so we can skip
2302
+ // the notification part.
2303
+ if s .notifier == nil || s .notifier .SpendErrChan == nil {
2304
+ continue
2305
+ }
2306
+
2307
+ notifiers = append (notifiers , s .notifier )
2308
+ }
2309
+ done ()
2310
+
2311
+ for _ , notifier := range notifiers {
2312
+ select {
2313
+ // Try to write the error to the notification
2314
+ // channel.
2315
+ case notifier .SpendErrChan <- spendErr :
2316
+
2317
+ // If a quit signal was provided by the swap,
2318
+ // continue.
2319
+ case <- notifier .QuitChan :
2320
+
2321
+ // If the context was canceled, stop.
2322
+ case <- ctx .Done ():
2323
+ }
2324
+ }
2325
+ }
2326
+
2288
2327
func (b * batch ) persistSweep (ctx context.Context , sweep sweep ,
2289
2328
completed bool ) error {
2290
2329
0 commit comments