Skip to content

Commit 39f859a

Browse files
committed
sweepbatcher: send spend error to notifier
1 parent 501faa8 commit 39f859a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

sweepbatcher/sweep_batch.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,8 @@ func (b *batch) monitorSpend(ctx context.Context, primarySweep sweep) error {
18341834
return
18351835

18361836
case err := <-spendErr:
1837+
b.writeToSpendErrChan(ctx, err)
1838+
18371839
b.writeToErrChan(
18381840
fmt.Errorf("spend error: %w", err),
18391841
)
@@ -2285,6 +2287,43 @@ func (b *batch) writeToErrChan(err error) {
22852287
}
22862288
}
22872289

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+
22882327
func (b *batch) persistSweep(ctx context.Context, sweep sweep,
22892328
completed bool) error {
22902329

0 commit comments

Comments
 (0)