Skip to content

Commit 16132d1

Browse files
committed
sweepbatcher: load swap from loopdb, not own store
Method Store.GetBatchSweeps provides data from tables outside of sweepbatcher: swaps, loopout_swaps, htlc_keys. It makes it harder to reuse. Batcher already has a straightforward way to get swap data: LoopOutFetcher interface (loopdb). In this commit I switch the source of data from the field returned by Store (LoopOut) to loading independently by calling LoopOutFetcher.FetchLoopOutSwap.
1 parent c586289 commit 16132d1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sweepbatcher/sweep_batcher.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
450450
sweeps := make(map[lntypes.Hash]sweep)
451451

452452
for _, dbSweep := range dbSweeps {
453-
sweep, err := b.convertSweep(dbSweep)
453+
sweep, err := b.convertSweep(ctx, dbSweep)
454454
if err != nil {
455455
return err
456456
}
@@ -656,9 +656,16 @@ func (b *Batcher) writeToErrChan(ctx context.Context, err error) error {
656656
}
657657

658658
// convertSweep converts a fetched sweep from the database to a sweep that is
659-
// ready to be processed by the batcher.
660-
func (b *Batcher) convertSweep(dbSweep *dbSweep) (*sweep, error) {
661-
swap := dbSweep.LoopOut
659+
// ready to be processed by the batcher. It loads swap from loopdb by calling
660+
// method FetchLoopOutSwap.
661+
func (b *Batcher) convertSweep(ctx context.Context, dbSweep *dbSweep) (
662+
*sweep, error) {
663+
664+
swap, err := b.swapStore.FetchLoopOutSwap(ctx, dbSweep.SwapHash)
665+
if err != nil {
666+
return nil, fmt.Errorf("failed to fetch loop out for %x: %w",
667+
dbSweep.SwapHash[:6], err)
668+
}
662669

663670
htlc, err := utils.GetHtlc(
664671
dbSweep.SwapHash, &swap.Contract.SwapContract, b.chainParams,

0 commit comments

Comments
 (0)