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

38 Commits

Author SHA1 Message Date
Boris Nagaev
38e86a1b0f
sweepbatcher: log tx weight in addition to feerate
Also log fee before applying clampBatchFee.

This is useful to debug fee ralated issues.
2024-06-28 10:26:38 -03:00
Boris Nagaev
3d5b7db1f7
sweepbatcher: factor out method musig2sign
It is long and is going to be even longer and hard to keep it inside a loop.
2024-06-28 10:26:13 -03:00
Boris Nagaev
822e4746c1
sweepbatcher: wrap error from MuSig2CreateSession
Make it more clear in the logs, what is the source of the error.
2024-06-26 17:22:01 -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
137dd80d39
sweepbatcher: use %w for wrapped errors
Fix errors.Is(err, context.Canceled) check in tests.
2024-06-20 14:14:24 -03:00
Boris Nagaev
1947b90842
multi: typed callback in ExecTx
Provide a wrapped store type, exposing ExecTx method with a subset
interface in the callback argument. BaseDB interfaces in instantout,
reservation and sweepbatcher use ExecTx with their subset Querier
instead of whole sqlc.Querier (*sqlc.Queries).

This is needed to make the packages more reusable, so they don't
depend on methods of *sqlc.Queries they don't use.
2024-06-19 10:38:55 -03:00
Boris Nagaev
2847e83fcf
multi: separate Querier from BaseDB interfaces
A Querier holds the methods of sqlc.Querier interface relevant for a package.
BaseDB has Querier + ExecTx method.

This change is needed to simplify further rework of ExecTx.
2024-06-19 10:38:55 -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
b311649ce4
sweepbatcher: use write tx in DropBatch 2024-06-17 12:26:37 -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
7a7ea05e52
sweepbatcher/Store: do not provide LoopOut field
This data is not used by Batcher since commit
"sweepbatcher: load swap from loopdb, not own store".

Now sweepbatcher.Store depends only on tables sweeps and sweep_batches
and does not depend on swaps, loopout_swaps and htlc_keys, making it
easier to reuse.
2024-05-31 12:28:02 -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
16132d1593
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.
2024-05-31 12:28:02 -03:00
Slyghtning
402d9a84df
gomod: bump lnd to version 0.18.0-beta 2024-05-31 09:39:20 +02:00
Boris Nagaev
87fb185a9b
sweepbatcher: remove const defaultBatchConfTarget
It is always overwritten with primary sweep's confTarget.

Print a warning if batchConfTarget is 0 in updateRbfRate.

See https://github.com/lightninglabs/loop/pull/754#discussion_r1613514363
2024-05-30 12:17:43 -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
870b60fada
sweepbatcher: fix docstring 2024-05-27 10:03:19 -03:00
Boris Nagaev
6def712dfe
sweepbatcher: fix typos in annotations of methods 2024-05-27 10:03:19 -03:00
Boris Nagaev
dc5d0fe30c
sweepbatcher: narrow down interface of swapStore
Only one method of loopdb.SwapStore is used (FetchLoopOutSwap).
Local interface LoopOutFetcher was defined to reflect this.
2024-05-27 10:03:19 -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
c01e8014e1
sweepbatcher: do not fail on restoring empty batches
Previously storing an empty batch would make the batcher fail to start
as spinning up a restored batch assumes that there's a primary sweep
added already. As there's no point in spinning up such batch we can just
skip over it.
Furthermore we'll ensure that we won't try to ever publish an empty
batch to avoid setting the fee rate too early.
2024-05-24 18:44:04 +02:00
Andras Banki-Horvath
939c9b4ccf
loopdb+sweepbatcher: add the DropBatch call 2024-05-24 18:44:04 +02:00
Andras Banki-Horvath
56902352cd
loopout: fix negative reported fees 2024-05-23 16:48:05 +02:00
Andras Banki-Horvath
75d7641d74
sweepbatcher: add more debug logging 2024-04-30 22:00:43 +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
Andras Banki-Horvath
b4ebb19a77
loopdb+sweepbatcher: add GetParentBatch and TotalSwept calls 2024-03-04 16:15:21 +01:00
Andras Banki-Horvath
c094ad4a85
sweepbatcher: refactor monitorSpendAndNotify to return an error 2024-03-04 16:15:20 +01:00
George Tsagkarelis
849d26bba6
sweepbatcher: add batcher tests 2024-01-23 20:38:10 +02:00
George Tsagkarelis
7081fb7aae
sweepbatcher: add sweep batcher 2024-01-23 20:38:09 +02:00
George Tsagkarelis
56784ab921
sweepbatcher: add sweep batch 2024-01-23 20:38:09 +02:00
George Tsagkarelis
99608ad515
loopdb+sweepbatcher: add sweepbatcher store 2024-01-23 20:38:06 +02:00