2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-08 01:10:29 +00:00
Commit Graph

17 Commits

Author SHA1 Message Date
Boris Nagaev
aa6d748647
sweepbatcher: add option WithCustomSignMuSig2
It is needed to provide a custom MuSig2 signer.
2024-06-28 13:13:35 -03:00
Boris Nagaev
fd971d4951
sweepbatcher: add field SweepInfo.MinFeeRate
MinFeeRate is minimum fee rate that must be used by a batch of
the sweep. If it is specified, confTarget is ignored.

This is useful for external source of fees.
2024-06-26 14:21:59 -03:00
Boris Nagaev
1b9e3069a8
sweepbatcher: add option WithNoBumping
It disables fee bumping. It is useful when fee rate is set externally.

Add test for fee bumping, testing both modes.
2024-06-26 10:19:49 -03:00
Boris Nagaev
029d0870b5
sweepbatcher: unit tests with SQL loopdb as well
This is needed to cover the code of SQLStore with tests.

To achieve compatibility with loopdb (SQLite), the following changes were done:

 - DestAddr is filled to avoid crash in SQL layer
 - Preimage is filled to avoid uniqueness checks by the DB
 - the code working with batch IDs was changed to work correctly
   when batch_id starts with 1 instead of 0
 - SQL swap store has to have a swap with swap_hash from sweep
   to satisfy foreign key constraint of the DB
2024-06-21 23:33:11 -03:00
Boris Nagaev
c34d04e2f7
sweepbatcher: fix race condition when stopping
The race was detected in CI and locally when running with -race.
It happened between the following calls:

WARNING: DATA RACE
Write at 0x00c0003e6638 by goroutine 1374:
  runtime.racewrite()
      <autogenerated>:1 +0x1e
  github.com/lightninglabs/loop/sweepbatcher.(*batch).Wait()
      sweepbatcher/sweep_batch.go:463 +0x6e
  github.com/lightninglabs/loop/sweepbatcher.(*Batcher).Run.func1()
      sweepbatcher/sweep_batcher.go:272 +0x10e

Previous read at 0x00c0003e6638 by goroutine 1388:
  runtime.raceread()
      <autogenerated>:1 +0x1e
  github.com/lightninglabs/loop/sweepbatcher.(*batch).monitorConfirmations()
      sweepbatcher/sweep_batch.go:1144 +0x285
  github.com/lightninglabs/loop/sweepbatcher.(*batch).handleSpend()
      sweepbatcher/sweep_batch.go:1309 +0x10e4
  github.com/lightninglabs/loop/sweepbatcher.(*batch).Run()
      sweepbatcher/sweep_batch.go:526 +0xb04
  github.com/lightninglabs/loop/sweepbatcher.(*Batcher).spinUpBatch.func1()
      sweepbatcher/sweep_batcher.go:455 +0xbd

The race was caused because wg.Add(1) and wg.Wait() were running from different
goroutines (one goroutine was running batch.Run() and another - batcher.Run()).

To avoid this scenario, wg.Wait() call was moved into batch.Run() call, so it
waits itself for its children goroutines, after which the channel b.finished
is closed, and it serves a signal for external waiters (the batcher, calling
batch.Wait()).

Also the channel batch.stopped was renamed to batch.stopping to better reflect
its nature.

Added TestSweepBatcherCloseDuringAdding to make sure adding a sweep during
shutting down does not cause a crash. The test did not catch the original
race condition.
2024-06-18 11:34:43 -03:00
Boris Nagaev
0c2ba74dba
sweepbatcher: factor out loopdb-less version
Changed argument of function NewBatcher from LoopOutFetcher to SweepFetcher
(returning new public type SweepInfo).
This change is backwards-incompatible on the package layer, but nobody seems
to use the package outside of Loop.

To use NewBatcher inside Loop, turn loopdb into SweepFetcher using
function NewSweepFetcherFromSwapStore.
2024-06-03 18:34:35 -03:00
Boris Nagaev
4be69e186e
Revert "sweepbatcher/StoreMock: load LoopOut from loopdb"
This reverts commit d38b7c55a7.

Batcher does not use this data anymore, since previous commit.
2024-05-31 12:28:02 -03:00
Boris Nagaev
40ad1ce609
sweepbatcher: load from DB preserves confTarget
It used to be set to default (defaultBatchConfTarget = 12) which
could in theory affect fee rate if updateRbfRate() and publish()
were not called before the batch was saved. (Unlikely scenario.)
2024-05-30 12:17:43 -03:00
Boris Nagaev
d38b7c55a7
sweepbatcher/StoreMock: load LoopOut from loopdb
Method sweepbatcher.Store.FetchBatchSweeps (implementation using real DB) runs
JOIN query to load LoopOut from swaps table. Now the mock does the same.

It is needed to test store and load scenarios in tests.
2024-05-30 10:24:38 -03:00
Boris Nagaev
4258b95dd2
sweepbatcher: fix too long lines 2024-05-29 12:17:18 -03:00
Boris Nagaev
0b2c177445
sweepbatcher: exit early in handleSweep
If the sweep was successfully updated in the batch, no need to
try to add it to all other batches.

Added a test reproducing adding a sweep to both batches without this change.
2024-05-29 12:03:14 -03:00
Boris Nagaev
b5b17991a5
sweepbatcher: use method AddSweep in test 2024-05-27 10:03:19 -03:00
Andras Banki-Horvath
14de8f1f5d
sweepbatcher: test that empty batches won't prevent startup 2024-05-24 18:44:05 +02:00
Andras Banki-Horvath
e5ade6a0b1
sweepbatcher: close the quit channel when the batcher is shutting down 2024-05-24 18:44:05 +02:00
Andras Banki-Horvath
56902352cd
loopout: fix negative reported fees 2024-05-23 16:48:05 +02:00
Andras Banki-Horvath
e1ddb50dfe
loopout+sweepbatcher: calculate the per sweep onchain fees correctly
Previously we'd report the fees per sweep as the total sweep cost of a
batch. With this change the reported cost will be the proportional fee
which should be equal for all sweeps except if there's any rounding
difference in which case that is paid by the sweep belonging to the
first input of the batch tx.
2024-03-04 16:15:21 +01:00
George Tsagkarelis
849d26bba6
sweepbatcher: add batcher tests 2024-01-23 20:38:10 +02:00