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.
|
||
|---|---|---|
| .github | ||
| cmd | ||
| docs | ||
| fsm | ||
| instantout | ||
| labels | ||
| liquidity | ||
| loopd | ||
| loopdb | ||
| looprpc | ||
| regtest | ||
| scripts | ||
| staticaddr | ||
| swap | ||
| swapserverrpc | ||
| sweep | ||
| sweepbatcher | ||
| test | ||
| tools | ||
| utils | ||
| .gitignore | ||
| .golangci.yml | ||
| client.go | ||
| client_test.go | ||
| config.go | ||
| cost_migration.go | ||
| cost_migration_test.go | ||
| Dockerfile | ||
| executor.go | ||
| go.mod | ||
| go.sum | ||
| interface.go | ||
| LICENSE | ||
| log.go | ||
| loopin.go | ||
| loopin_test.go | ||
| loopin_testcontext_test.go | ||
| loopout.go | ||
| loopout_test.go | ||
| Makefile | ||
| README.md | ||
| release.sh | ||
| release_notes.md | ||
| routing_plugin.go | ||
| routing_plugin_test.go | ||
| sample-loopd.conf | ||
| server_mock_test.go | ||
| sqlc.yaml | ||
| swap.go | ||
| swap_server_client.go | ||
| testcontext_test.go | ||
| uncharge_state.go | ||
| updates.go | ||
| utils.go | ||
| version.go | ||
Lightning Loop
Lightning Loop is a non-custodial service offered by Lightning Labs that makes it easy to move bitcoin into and out of the Lightning Network.
Features
- Automated channel balancing
- Privacy-forward non-custodial swaps
- Opportunistic transaction batching to save on fees
- Progress monitoring of in-flight swaps
Use Cases
- Automate channel balancing with AutoLoop (Learn more)
- Deposit to a Bitcoin address without closing channels with Loop In
- Convert outbound liquidity into inbound liquidity with Loop Out
- Refill depleted Lightning channels with Loop In
Installation
Download the latest binaries from the releases page.
Execution
The Loop client needs its own short-lived daemon to facilitate swaps. To start loopd:
loopd
To use Loop in testnet, simply pass the network flag:
loopd --network=testnet
By default loopd attempts to connect to the lnd instance running on
localhost:10009 and reads the macaroon and tls certificate from ~/.lnd.
This can be altered using command line flags. See loopd --help.
Usage
AutoLoop
AutoLoop makes it easy to keep your channels balanced. Checkout our autoloop documentation for details.
Loop Out
Use Loop Out to move bitcoins on Lightning into an on-chain Bitcoin address.
To execute a Loop Out:
loop out <amt_in_satoshis>
Other notable options:
- Use the
--fastflag to swap immediately (Note: This opts-out of fee savings made possible by transaction batching) - Use the
--channelflag to loop out on specific channels - Use the
--addrflag to specify the address the looped out funds should be sent to (Note: By default funds are sent to the lnd wallet)
Run loop monitor to monitor the status of a swap.
Loop In
Use Loop In to convert on-chain bitcoin into spendable Lightning funds.
To execute a Loop In:
loop in <amt_in_satoshis>
More info
For more information about using Loop checkout our Loop FAQs.
Development
Regtest
To get started with local development against a stripped down dummy Loop server
running in a local regtest Bitcoin network, take a look at the
regtest server environment example documentation.
Testnet
To use Loop in testnet, simply pass the network flag:
loopd --network=testnet
Submit feature requests
The GitHub issue tracker can be used to request specific improvements or report bugs.
Join us on Slack
Join us on the LND Slack and join the #loop channel to ask questions and interact with the community.
LND
Note that Loop requires lnd to be built with all of its subservers. Download the latest official release binary or build lnd from source by following the installation instructions. If you choose to build lnd from source, use the following command to enable all the relevant subservers:
make install tags="signrpc walletrpc chainrpc invoicesrpc"
API
The Loop daemon exposes a gRPC API (defaults to port 11010) and a REST API (defaults to port 8081).
The gRPC and REST connections of loopd are encrypted with TLS and secured with
macaroon authentication the same way lnd is.
If no custom loop directory is set then the TLS certificate is stored in
~/.loop/<network>/tls.cert and the base macaroon in
~/.loop/<network>/loop.macaroon.
The loop command will pick up these file automatically on mainnet if no custom
loop directory is used. For other networks it should be sufficient to add the
--network flag to tell the CLI in what sub directory to look for the files.
For more information on macaroons, see the macaroon documentation of lnd.
NOTE: Loop's macaroons are independent from lnd's. The same macaroon
cannot be used for both loopd and lnd.
Build from source
If you’d prefer to build from source:
git clone https://github.com/lightninglabs/loop.git
cd loop/cmd
go install ./...