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

1517 Commits

Author SHA1 Message Date
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
8f985143e2
Merge pull request #780 from starius/sweepbatcher-dropbatch-writetx
sweepbatcher: use write tx in DropBatch
2024-06-17 12:56:32 -03:00
Boris Nagaev
b311649ce4
sweepbatcher: use write tx in DropBatch 2024-06-17 12:26:37 -03:00
Boris Nagaev
3fd3fab8d1
loopdb: provide function NewSqlWriteOpts
It returns transaction options resulting in full (read+write) tx.

Use it in loopdb and instantout stores.
2024-06-17 12:26:37 -03:00
Slyghtning
174a6b888b
Merge pull request #777 from hieblmi/refactor-select-hop-hints
utils: refactor SelectHopHints to use narrower interface
2024-06-14 13:41:38 +02:00
Slyghtning
5b797055f8
utils: refactor SelectHopHints to use narrower interface 2024-06-14 12:37:58 +02:00
Slyghtning
3b3d3ac64f
Merge pull request #776 from chengehe/master
chore: make function comments match function names
2024-06-06 13:07:38 +02:00
chengehe
0aff202988 chore: make function comments match function names
Signed-off-by: chengehe <hechenge@yeah.net>
2024-06-06 17:39:29 +08:00
Alex Bosworth
88c7194e2e
Merge pull request #775 from lightninglabs/alexbosworth-patch-3
version: bump version to v0.28.5-beta
2024-06-05 14:06:47 -07:00
Alex Bosworth
2efe224b9a
version: bump version to v0.28.5-beta 2024-06-05 11:47:33 -07:00
Konstantin Nick
557ac34959
Merge pull request #774 from jinjingroad/master
chore: fix some comments
2024-06-05 09:54:13 +02:00
jinjingroad
12bc3b2e9e chore: fix some comments
Signed-off-by: jinjingroad <jinjingroad@sina.com>
2024-06-05 15:12:47 +08:00
András Bánki-Horváth
d47158d58e
Merge pull request #773 from bhandras/cost-migraton-pagination
loop: paginate fetching payments when running the cost migration
2024-06-05 09:00:13 +02:00
Andras Banki-Horvath
3754730525
loop: paginate fetching payments when running the cost migration 2024-06-05 08:54:24 +02:00
Alex Bosworth
4652417b25
Merge pull request #772 from lightninglabs/alexbosworth-patch-2
version: bump version to v0.28.4-beta
2024-06-04 11:02:35 -07:00
Alex Bosworth
6fe1686cc6
version: bump version to v0.28.4-beta 2024-06-04 10:57:17 -07:00
András Bánki-Horváth
18b0de3c5e
Merge pull request #771 from bhandras/cost-migration-timeout
loopd: make the LND RPC timeout configurable and fix cost migration for pending swaps
2024-06-04 19:41:44 +02:00
Andras Banki-Horvath
9cacd8eb75
loop: fix cost migration for pending swaps 2024-06-04 18:43:04 +02:00
Andras Banki-Horvath
28c09bec68
loopd: make the LND RPC timeout configurable 2024-06-04 18:28:03 +02:00
Boris Nagaev
3d1d3eb4aa
Merge pull request #766 from starius/sweepbatcher-sweep-fetcher
sweepbatcher: factor out loopdb-less version
2024-06-03 19:29:39 -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
295198a902
Merge pull request #770 from starius/lnd-v0.18.0-beta.1
go.mod: update LND to v0.18.0-beta.1
2024-06-03 18:33:55 -03:00
Boris Nagaev
99a0f831b3
go.mod: update LND to v0.18.0-beta.1
This is the same as v0.18.0-beta.
2024-06-03 16:36:32 -03:00
Konstantin Nick
c5245e1009
Merge pull request #769 from lightninglabs/fix_docker_build
build: fix dockerfile
2024-06-03 18:58:59 +02:00
sputn1ck
890718d0ee build: fix dockerfile 2024-06-03 18:03:14 +02:00
Alex Bosworth
67ab876879
Merge pull request #768 from lightninglabs/alexbosworth-patch-2
version: bump version to v0.28.3-beta
2024-06-03 07:57:04 -07:00
Alex Bosworth
9b1218a752
version: bump version to v0.28.3-beta 2024-06-03 07:54:04 -07:00
András Bánki-Horváth
55241ffe04
Merge pull request #764 from bhandras/costs-cleanup-migration
loop: add migration to fix stored loop out costs
2024-06-03 16:04:30 +02:00
Andras Banki-Horvath
c7fa1e4109
loopd: run the cost migration on start 2024-06-03 14:54:18 +02:00
Andras Banki-Horvath
f40ef193e9
loop: add migration for loopout swaps to fix negative stored costs
Previously we may have stored negative costs for some loop out swaps
which this commit attempts to correct by fetching all completed swap,
calculating the correct costs and overriding them in the database.
2024-06-03 14:54:18 +02:00
Andras Banki-Horvath
c650cdc8a8
loopdb: add ability to track manual migrations 2024-06-03 14:54:18 +02:00
Andras Banki-Horvath
4f5c806ba5
loopdb: add helper methods to update swap costs
This commit adds the necessary sqlc code and SwapStore function to
update swap costs for all swaps in one transaction.
2024-06-03 14:54:18 +02:00
Andras Banki-Horvath
08aa4db35d
loopout: correctly account for the prepay amount when calculating costs
Previously we'd not account for the prepay amount which resulted in the
total swap cost reported being lower than what it actually is.
2024-06-03 14:54:18 +02:00
Boris Nagaev
37194d31cf
Merge pull request #761 from starius/sweepbatcher-load-swaps-from-loopdb-only
sweepbatcher/Store: use only own tables (separating from loopdb)
2024-05-31 12:37:37 -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
Boris Nagaev
c5862898a8
sqlc: remove trailing spaces in queries 2024-05-31 12:28:02 -03:00
Slyghtning
6b09aaaca4
Merge pull request #763 from hieblmi/bump-lnd-0.18.0-beta
gomod: bump lnd to version 0.18.0-beta
2024-05-31 10:47:12 +02:00
Slyghtning
402d9a84df
gomod: bump lnd to version 0.18.0-beta 2024-05-31 09:39:20 +02:00
Boris Nagaev
60c149f885
Merge pull request #762 from starius/fix-flaky-autoloop-test
liquidity: fix flaky autoloop test
2024-05-30 15:46:55 -03:00
Boris Nagaev
3be5a37cd3
liquidity: fix flaky autoloop test
This failure became normal recently:

=== RUN   TestAutoLoopInEnabled
    autoloop_testcontext_test.go:318:
        	Error Trace:	/home/runner/work/loop/loop/liquidity/autoloop_testcontext_test.go:318
        	            				/home/runner/work/loop/loop/liquidity/autoloop_test.go:804
        	Error:      	Not equal:
        	            	expected: 80000
        	            	actual  : 160000
        	Test:       	TestAutoLoopInEnabled
    autoloop_testcontext_test.go:318:
        	Error Trace:	/home/runner/work/loop/loop/liquidity/autoloop_testcontext_test.go:318
        	            				/home/runner/work/loop/loop/liquidity/autoloop_test.go:804
        	Error:      	Not equal:
        	            	expected: 160000
        	            	actual  : 80000
        	Test:       	TestAutoLoopInEnabled
    autoloop_testcontext_test.go:343:
        	Error Trace:	/home/runner/work/loop/loop/liquidity/autoloop_testcontext_test.go:343
        	            				/home/runner/work/loop/loop/liquidity/autoloop_test.go:804
        	Error:      	Should be true
        	Test:       	TestAutoLoopInEnabled

The root cause is them the order of items in c.quoteRequestIn depends on the
order of loopInBuilder.buildSwap calls, which depends on the order of channel
handling in Manager.SuggestSwaps, which depends on the order of map traversal,
which is not determitistic.

Since in the test all the amounts are different, I used amount as a key and
put the expected calls into a map using amount as a key. When I extract an
item from c.quoteRequestIn channel, I find the corresponding item in the map
and remove it. All other logic is preserved.
2024-05-30 15:41:51 -03:00
Boris Nagaev
5c88cf86b9
Merge pull request #760 from starius/sweepbatcher-rm-defaultBatchConfTarget
sweepbatcher: load from DB preserves confTarget
2024-05-30 12:27:18 -03: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
22dd2e8bd1
Merge pull request #759 from starius/sweepbatcher-avoid-adding-to-two-batches
sweepbatcher: exit early in handleSweep
2024-05-30 10:18:44 -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
a135eb81f0
Merge pull request #755 from starius/sweepbatcher-changes
sweepbatcher: small refactorings
2024-05-27 10:16:11 -03:00