@@ -197,7 +197,11 @@ type batch struct {
197197 // main event loop.
198198 callLeave chan struct {}
199199
200- // quit signals that the batch must stop.
200+ // stopped signals that the batch has stopped.
201+ stopped chan struct {}
202+
203+ // quit is owned by the parent batcher and signals that the batch must
204+ // stop.
201205 quit chan struct {}
202206
203207 // wallet is the wallet client used to create and publish the batch
@@ -261,6 +265,7 @@ type batchKit struct {
261265 purger Purger
262266 store BatcherStore
263267 log btclog.Logger
268+ quit chan struct {}
264269}
265270
266271// scheduleNextCall schedules the next call to the batch handler's main event
@@ -270,6 +275,9 @@ func (b *batch) scheduleNextCall() (func(), error) {
270275 case b .callEnter <- struct {}{}:
271276
272277 case <- b .quit :
278+ return func () {}, ErrBatcherShuttingDown
279+
280+ case <- b .stopped :
273281 return func () {}, ErrBatchShuttingDown
274282 }
275283
@@ -293,7 +301,8 @@ func NewBatch(cfg batchConfig, bk batchKit) *batch {
293301 errChan : make (chan error , 1 ),
294302 callEnter : make (chan struct {}),
295303 callLeave : make (chan struct {}),
296- quit : make (chan struct {}),
304+ stopped : make (chan struct {}),
305+ quit : bk .quit ,
297306 batchTxid : bk .batchTxid ,
298307 wallet : bk .wallet ,
299308 chainNotifier : bk .chainNotifier ,
@@ -320,7 +329,8 @@ func NewBatchFromDB(cfg batchConfig, bk batchKit) *batch {
320329 errChan : make (chan error , 1 ),
321330 callEnter : make (chan struct {}),
322331 callLeave : make (chan struct {}),
323- quit : make (chan struct {}),
332+ stopped : make (chan struct {}),
333+ quit : bk .quit ,
324334 batchTxid : bk .batchTxid ,
325335 batchPkScript : bk .batchPkScript ,
326336 rbfCache : bk .rbfCache ,
@@ -447,7 +457,7 @@ func (b *batch) Run(ctx context.Context) error {
447457 runCtx , cancel := context .WithCancel (ctx )
448458 defer func () {
449459 cancel ()
450- close (b .quit )
460+ close (b .stopped )
451461 b .wg .Wait ()
452462 }()
453463
0 commit comments