mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-17 13:06:51 +02:00
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.
This commit is contained in:
parent
c5862898a8
commit
16132d1593
1 changed files with 11 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue