@@ -2,6 +2,7 @@ package sweepbatcher
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "sync"
78 "time"
@@ -135,7 +136,7 @@ type SpendNotifier struct {
135136}
136137
137138var (
138- ErrBatcherShuttingDown = fmt . Errorf ("batcher shutting down" )
139+ ErrBatcherShuttingDown = errors . New ("batcher shutting down" )
139140)
140141
141142// Batcher is a system that is responsible for accepting sweep requests and
@@ -306,7 +307,7 @@ func (b *Batcher) handleSweep(ctx context.Context, sweep *sweep,
306307
307308 if batch .sweepExists (sweep .swapHash ) {
308309 accepted , err := batch .addSweep (ctx , sweep )
309- if err != nil {
310+ if err != nil && ! errors . Is ( err , ErrBatchShuttingDown ) {
310311 return err
311312 }
312313
@@ -321,7 +322,7 @@ func (b *Batcher) handleSweep(ctx context.Context, sweep *sweep,
321322 // If one of the batches accepts the sweep, we provide it to that batch.
322323 for _ , batch := range b .batches {
323324 accepted , err := batch .addSweep (ctx , sweep )
324- if err != nil && err != ErrBatchShuttingDown {
325+ if err != nil {
325326 return err
326327 }
327328
@@ -407,23 +408,16 @@ func (b *Batcher) spinUpBatch(ctx context.Context) (*batch, error) {
407408// spinUpBatchDB spins up a batch that already existed in storage, then
408409// returns it.
409410func (b * Batcher ) spinUpBatchFromDB (ctx context.Context , batch * batch ) error {
410- cfg := batchConfig {
411- maxTimeoutDistance : batch .cfg .maxTimeoutDistance ,
412- batchConfTarget : defaultBatchConfTarget ,
413- }
414-
415- rbfCache := rbfCache {
416- LastHeight : batch .rbfCache .LastHeight ,
417- FeeRate : batch .rbfCache .FeeRate ,
418- }
419-
420411 dbSweeps , err := b .store .FetchBatchSweeps (ctx , batch .id )
421412 if err != nil {
422413 return err
423414 }
424415
425416 if len (dbSweeps ) == 0 {
426- return fmt .Errorf ("batch %d has no sweeps" , batch .id )
417+ log .Infof ("skipping restored batch %d as it has no sweeps" ,
418+ batch .id )
419+
420+ return nil
427421 }
428422
429423 primarySweep := dbSweeps [0 ]
@@ -439,6 +433,11 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
439433 sweeps [sweep .swapHash ] = * sweep
440434 }
441435
436+ rbfCache := rbfCache {
437+ LastHeight : batch .rbfCache .LastHeight ,
438+ FeeRate : batch .rbfCache .FeeRate ,
439+ }
440+
442441 batchKit := batchKit {
443442 id : batch .id ,
444443 batchTxid : batch .batchTxid ,
@@ -458,6 +457,11 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
458457 log : batchPrefixLogger (fmt .Sprintf ("%d" , batch .id )),
459458 }
460459
460+ cfg := batchConfig {
461+ maxTimeoutDistance : batch .cfg .maxTimeoutDistance ,
462+ batchConfTarget : defaultBatchConfTarget ,
463+ }
464+
461465 newBatch := NewBatchFromDB (cfg , batchKit )
462466
463467 // We add the batch to our map of batches and start it.
0 commit comments