From 16132d1593ce0db7a867b33a2f9cf09154d91f3f Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 30 May 2024 13:05:47 -0300 Subject: [PATCH] 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. --- sweepbatcher/sweep_batcher.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sweepbatcher/sweep_batcher.go b/sweepbatcher/sweep_batcher.go index 749da451..79481a11 100644 --- a/sweepbatcher/sweep_batcher.go +++ b/sweepbatcher/sweep_batcher.go @@ -450,7 +450,7 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error { sweeps := make(map[lntypes.Hash]sweep) for _, dbSweep := range dbSweeps { - sweep, err := b.convertSweep(dbSweep) + sweep, err := b.convertSweep(ctx, dbSweep) if err != nil { return err } @@ -656,9 +656,16 @@ func (b *Batcher) writeToErrChan(ctx context.Context, err error) error { } // convertSweep converts a fetched sweep from the database to a sweep that is -// ready to be processed by the batcher. -func (b *Batcher) convertSweep(dbSweep *dbSweep) (*sweep, error) { - swap := dbSweep.LoopOut +// ready to be processed by the batcher. It loads swap from loopdb by calling +// method FetchLoopOutSwap. +func (b *Batcher) convertSweep(ctx context.Context, dbSweep *dbSweep) ( + *sweep, error) { + + swap, err := b.swapStore.FetchLoopOutSwap(ctx, dbSweep.SwapHash) + if err != nil { + return nil, fmt.Errorf("failed to fetch loop out for %x: %w", + dbSweep.SwapHash[:6], err) + } htlc, err := utils.GetHtlc( dbSweep.SwapHash, &swap.Contract.SwapContract, b.chainParams,