2020-10-01 19:34:02 -07:00
|
|
|
Rust-Lightning
|
|
|
|
==============
|
|
|
|
|
|
|
|
[](https://crates.io/crates/lightning)
|
|
|
|
[](https://docs.rs/lightning/)
|
2019-07-24 07:51:11 +02:00
|
|
|
[](https://github.com/rust-secure-code/safety-dance/)
|
|
|
|
|
2022-07-22 18:28:31 +02:00
|
|
|
`rust-lightning` is a Bitcoin Lightning library written in Rust. The main crate,
|
2020-10-01 20:28:41 -07:00
|
|
|
`lightning`, does not handle networking, persistence, or any other I/O. Thus,
|
|
|
|
it is runtime-agnostic, but users must implement basic networking logic, chain
|
2021-01-12 12:07:18 -05:00
|
|
|
interactions, and disk storage. More information is available in the `About`
|
|
|
|
section.
|
2020-10-01 20:28:41 -07:00
|
|
|
|
2020-10-01 19:34:02 -07:00
|
|
|
Status
|
|
|
|
------
|
2022-07-22 18:28:31 +02:00
|
|
|
The project implements all of the [BOLT
|
|
|
|
specifications](https://github.com/lightning/bolts). The
|
2020-02-06 21:43:47 -08:00
|
|
|
implementation has pretty good test coverage that is expected to continue to
|
2021-01-12 12:07:18 -05:00
|
|
|
improve. It is also anticipated that as developers begin using the API, the
|
|
|
|
lessons from that will result in changes to the API, so any developer using this
|
|
|
|
API at this stage should be prepared to embrace that. The current state is
|
2022-07-22 18:28:31 +02:00
|
|
|
sufficient for a developer or project to experiment with it.
|
2017-12-25 01:05:27 -05:00
|
|
|
|
2022-07-22 18:28:31 +02:00
|
|
|
Communications for `rust-lightning` and Lightning Development Kit happen through
|
|
|
|
our LDK [Discord](https://discord.gg/5AcknnMfBw) channels.
|
2020-02-12 13:31:37 -05:00
|
|
|
|
2022-01-18 02:43:45 +00:00
|
|
|
Crates
|
|
|
|
-----------
|
2022-07-22 18:28:31 +02:00
|
|
|
1. [lightning](./lightning)
|
|
|
|
The core of the LDK library, implements the Lightning protocol, channel state machine,
|
|
|
|
and on-chain logic. Supports `no-std` and exposes only relatively low-level interfaces.
|
2022-01-18 02:43:45 +00:00
|
|
|
2. [lightning-background-processor](./lightning-background-processor)
|
|
|
|
Utilities to perform required background tasks for Rust Lightning.
|
|
|
|
3. [lightning-block-sync](./lightning-block-sync)
|
|
|
|
Utilities to fetch the chain data from a block source and feed them into Rust Lightning.
|
|
|
|
4. [lightning-invoice](./lightning-invoice)
|
2022-07-22 18:28:31 +02:00
|
|
|
Data structures to parse and serialize
|
|
|
|
[BOLT #11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
|
|
|
|
Lightning invoices.
|
2022-01-18 02:43:45 +00:00
|
|
|
5. [lightning-net-tokio](./lightning-net-tokio)
|
2022-07-22 18:28:31 +02:00
|
|
|
Implementation of the `rust-lightning` network stack using the
|
|
|
|
[Tokio](https://github.com/tokio-rs/tokio) `async` runtime. For `rust-lightning`
|
|
|
|
clients which wish to make direct connections to Lightning P2P nodes, this is
|
|
|
|
a simple alternative to implementing the required network stack, especially
|
|
|
|
for those already using Tokio.
|
2022-01-18 02:43:45 +00:00
|
|
|
6. [lightning-persister](./lightning-persister)
|
2022-07-22 18:28:31 +02:00
|
|
|
Implements utilities to manage `rust-lightning` channel data persistence and retrieval.
|
|
|
|
Persisting channel data is crucial to avoiding loss of channel funds.
|
2022-06-07 23:50:07 -05:00
|
|
|
7. [lightning-rapid-gossip-sync](./lightning-rapid-gossip-sync)
|
|
|
|
Client for rapid gossip graph syncing, aimed primarily at mobile clients.
|
2022-01-18 02:43:45 +00:00
|
|
|
|
2021-01-12 12:07:18 -05:00
|
|
|
About
|
|
|
|
-----------
|
2022-07-22 18:28:31 +02:00
|
|
|
LDK/`rust-lightning` is a generic library which allows you to build a Lightning
|
|
|
|
node without needing to worry about getting all of the Lightning state machine,
|
2021-01-12 12:07:18 -05:00
|
|
|
routing, and on-chain punishment code (and other chain interactions) exactly
|
2022-07-22 18:28:31 +02:00
|
|
|
correct. Note that `rust-lightning` isn't, in itself, a node. There are various
|
2021-01-12 12:07:18 -05:00
|
|
|
working/in progress demos which could be used as a node today, but if you "just"
|
2022-07-22 18:28:31 +02:00
|
|
|
want a generic Lightning node, you're almost certainly better off with [Core
|
|
|
|
Lightning](https://github.com/ElementsProject/lightning) or
|
|
|
|
[LND](https://github.com/lightningnetwork/lnd). If, on the other hand, you want
|
|
|
|
to integrate Lightning with custom features such as your own chain sync, your
|
|
|
|
own key management, your own data storage/backup logic, etc., LDK is likely your
|
|
|
|
only option. Some `rust-lightning` utilities such as those in
|
|
|
|
[`chan_utils`](./lightning/src/ln/chan_utils.rs) are also suitable for use in
|
|
|
|
non-LN Bitcoin applications such as Discreet Log Contracts (DLCs) and bulletin boards.
|
|
|
|
|
|
|
|
A sample node which fetches blockchain data and manages on-chain funds via the
|
|
|
|
Bitcoin Core RPC/REST interface is available
|
|
|
|
[here](https://github.com/lightningdevkit/ldk-sample/). The individual pieces of
|
|
|
|
that demo are composable, so you can pick the off-the-shelf parts you want
|
|
|
|
and replace the rest.
|
|
|
|
|
|
|
|
In general, `rust-lightning` does not provide (but LDK has implementations of):
|
2021-01-12 12:07:18 -05:00
|
|
|
* on-disk storage - you can store the channel state any way you want - whether
|
|
|
|
Google Drive/iCloud, a local disk, any key-value store/database/a remote
|
|
|
|
server, or any combination of them - we provide a clean API that provides
|
|
|
|
objects which can be serialized into simple binary blobs, and stored in any
|
|
|
|
way you wish.
|
|
|
|
* blockchain data - we provide a simple `block_connected`/`block_disconnected`
|
|
|
|
API which you provide block headers and transaction information to. We also
|
|
|
|
provide an API for getting information about transactions we wish to be
|
|
|
|
informed of, which is compatible with Electrum server requests/neutrino
|
|
|
|
filtering/etc.
|
|
|
|
* UTXO management - RL/LDK owns on-chain funds as long as they are claimable as
|
2022-07-22 18:28:31 +02:00
|
|
|
part of a Lightning output which can be contested - once a channel is closed
|
2021-01-12 12:07:18 -05:00
|
|
|
and all on-chain outputs are spendable only by the user, we provide users
|
|
|
|
notifications that a UTXO is "theirs" again and it is up to them to spend it
|
|
|
|
as they wish. Additionally, channel funding is accomplished with a generic API
|
|
|
|
which notifies users of the output which needs to appear on-chain, which they
|
|
|
|
can then create a transaction for. Once a transaction is created, we handle
|
|
|
|
the rest. This is a large part of our API's goals - making it easier to
|
2022-07-22 18:28:31 +02:00
|
|
|
integrate Lightning into existing on-chain wallets which have their own
|
2021-01-12 12:07:18 -05:00
|
|
|
on-chain logic - without needing to move funds in and out of a separate
|
2022-07-22 18:28:31 +02:00
|
|
|
Lightning wallet with on-chain transactions and a separate private key system.
|
|
|
|
* networking - to enable a user to run a full Lightning node on an embedded
|
2021-01-12 12:07:18 -05:00
|
|
|
machine, we don't specify exactly how to connect to another node at all! We
|
|
|
|
provide a default implementation which uses TCP sockets, but, e.g., if you
|
2022-07-22 18:28:31 +02:00
|
|
|
wanted to run your full Lightning node on a hardware wallet, you could, by
|
|
|
|
piping the Lightning network messages over USB/serial and then sending them in
|
2021-01-12 12:07:18 -05:00
|
|
|
a TCP socket from another machine.
|
|
|
|
* private keys - again we have "default implementations", but users can chose to
|
|
|
|
provide private keys to RL/LDK in any way they wish following a simple API. We
|
|
|
|
even support a generic API for signing transactions, allowing users to run
|
|
|
|
RL/LDK without any private keys in memory/putting private keys only on
|
|
|
|
hardware wallets.
|
|
|
|
|
|
|
|
LDK's customizability was presented about at Advancing Bitcoin in February 2020:
|
2021-10-14 10:35:12 +02:00
|
|
|
https://vimeo.com/showcase/8372504/video/412818125
|
2021-01-12 12:07:18 -05:00
|
|
|
|
2020-02-12 13:31:37 -05:00
|
|
|
Design Goal
|
|
|
|
-----------
|
2022-07-22 18:28:31 +02:00
|
|
|
The goal is to provide a full-featured but also incredibly flexible Lightning
|
2017-12-25 01:05:27 -05:00
|
|
|
implementation, allowing the user to decide how they wish to use it. With that
|
2021-01-12 12:07:18 -05:00
|
|
|
in mind, everything should be exposed via simple, composable APIs. More
|
2022-07-22 18:28:31 +02:00
|
|
|
information about `rust-lightning`'s flexibility is provided in the `About`
|
2021-01-12 12:07:18 -05:00
|
|
|
section above.
|
2017-12-25 01:05:27 -05:00
|
|
|
|
|
|
|
For security reasons, do not add new dependencies. Really do not add new
|
|
|
|
non-optional/non-test/non-library dependencies. Really really do not add
|
|
|
|
dependencies with dependencies. Do convince Andrew to cut down dependency usage
|
2022-07-22 18:28:31 +02:00
|
|
|
in `rust-bitcoin`.
|
2017-12-25 01:05:27 -05:00
|
|
|
|
2021-01-12 12:07:18 -05:00
|
|
|
Rust-Lightning vs. LDK (Lightning Development Kit)
|
|
|
|
-------------
|
2022-07-22 18:28:31 +02:00
|
|
|
`rust-lightning` refers to the core `lightning` crate within this repo, whereas
|
|
|
|
LDK encompasses `rust-lightning` and all of its sample modules and crates (e.g.
|
2021-01-12 12:07:18 -05:00
|
|
|
the `lightning-persister` crate), language bindings, sample node
|
2022-07-22 18:28:31 +02:00
|
|
|
implementation(s), and other tools built around using `rust-lightning` for
|
|
|
|
Lightning integration or building a Lightning node.
|
2020-10-01 20:28:41 -07:00
|
|
|
|
|
|
|
Tagline
|
|
|
|
-------
|
|
|
|
|
|
|
|
*"Rust-Lightning, not Rusty's Lightning!"*
|
|
|
|
|
2020-02-12 13:31:37 -05:00
|
|
|
Contributing
|
|
|
|
------------
|
|
|
|
|
|
|
|
Contributors are warmly welcome, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
|
|
|
|
|
|
Project Architecture
|
|
|
|
---------------------
|
|
|
|
|
2022-07-22 18:28:31 +02:00
|
|
|
For a `rust-lightning` high-level API introduction, see [ARCH.md](ARCH.md).
|
2017-12-25 01:05:27 -05:00
|
|
|
|
2020-08-10 15:00:09 -04:00
|
|
|
License is either Apache-2.0 or MIT, at the option of the user (ie dual-license
|
|
|
|
Apache-2.0 and MIT).
|