Merge pull request #1874 from LeoDog896/patch-1
[rust-lightning] / README.md
1 Rust-Lightning
2 ==============
3
4 [![Crate](https://img.shields.io/crates/v/lightning.svg?logo=rust)](https://crates.io/crates/lightning)
5 [![Documentation](https://img.shields.io/static/v1?logo=read-the-docs&label=docs.rs&message=lightning&color=informational)](https://docs.rs/lightning/)
6 [![Safety Dance](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
7
8 [LDK](https://lightningdevkit.org)/`rust-lightning` is a highly performant and flexible 
9 implementation of the Lightning Network protocol.
10
11 The primary crate, `lightning`, is runtime-agnostic. Data persistence, chain interactions,
12 and networking can be provided by LDK's [sample modules](#crates), or you may provide your
13 own custom implementations.
14 More information is available in the [`About`](#about) section.
15
16 Status
17 ------
18 The project implements all of the [BOLT specifications](https://github.com/lightning/bolts),
19 and has been in production use since 2021. As with any Lightning implementation, care and attention
20 to detail is important for safe deployment.
21
22 Communications for `rust-lightning` and Lightning Development Kit happen through
23 our LDK [Discord](https://discord.gg/5AcknnMfBw) channels.
24
25 Crates
26 -----------
27 1. [lightning](./lightning)
28   The core of the LDK library, implements the Lightning protocol, channel state machine,
29   and on-chain logic. Supports `no-std` and exposes only relatively low-level interfaces.
30 2. [lightning-background-processor](./lightning-background-processor)
31   Utilities to perform required background tasks for Rust Lightning.
32 3. [lightning-block-sync](./lightning-block-sync)
33   Utilities to fetch the chain data from a block source and feed them into Rust Lightning.
34 4. [lightning-invoice](./lightning-invoice)
35   Data structures to parse and serialize
36   [BOLT #11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
37   Lightning invoices.
38 5. [lightning-net-tokio](./lightning-net-tokio)
39   Implementation of the `rust-lightning` network stack using the
40   [Tokio](https://github.com/tokio-rs/tokio) `async` runtime. For `rust-lightning`
41   clients which wish to make direct connections to Lightning P2P nodes, this is
42   a simple alternative to implementing the required network stack, especially
43   for those already using Tokio.
44 6. [lightning-persister](./lightning-persister)
45   Implements utilities to manage `rust-lightning` channel data persistence and retrieval.
46   Persisting channel data is crucial to avoiding loss of channel funds.
47 7. [lightning-rapid-gossip-sync](./lightning-rapid-gossip-sync)
48   Client for rapid gossip graph syncing, aimed primarily at mobile clients.
49
50 About
51 -----------
52 LDK/`rust-lightning` is a generic library that allows you to build a Lightning
53 node without needing to worry about getting all of the Lightning state machine,
54 routing, and on-chain punishment code (and other chain interactions) exactly
55 correct. Note that LDK isn't, in itself, a node. For an out-of-the-box Lightning
56 node based on LDK, see [Sensei](https://l2.technology/sensei). However, if you
57 want to integrate Lightning with custom features such as your own chain sync,
58 key management, data storage/backup logic, etc., LDK is likely your best option.
59 Some `rust-lightning` utilities such as those in
60 [`chan_utils`](./lightning/src/ln/chan_utils.rs) are also suitable for use in
61 non-LN Bitcoin applications such as Discreet Log Contracts (DLCs) and bulletin boards.
62
63 A sample node which fetches blockchain data and manages on-chain funds via the
64 Bitcoin Core RPC/REST interface is available
65 [here](https://github.com/lightningdevkit/ldk-sample/). The individual pieces of
66 that demo are composable, so you can pick the off-the-shelf parts you want
67 and replace the rest.
68
69 In general, `rust-lightning` does not provide (but LDK has implementations of):
70 * on-disk storage - you can store the channel state any way you want - whether
71   Google Drive/iCloud, a local disk, any key-value store/database/a remote
72   server, or any combination of them - we provide a clean API that provides
73   objects which can be serialized into simple binary blobs, and stored in any
74   way you wish.
75 * blockchain data - we provide a simple `block_connected`/`block_disconnected`
76   API which you provide block headers and transaction information to. We also
77   provide an API for getting information about transactions we wish to be
78   informed of, which is compatible with Electrum server requests/neutrino
79   filtering/etc.
80 * UTXO management - RL/LDK owns on-chain funds as long as they are claimable as
81   part of a Lightning output which can be contested - once a channel is closed
82   and all on-chain outputs are spendable only by the user, we provide users
83   notifications that a UTXO is "theirs" again and it is up to them to spend it
84   as they wish. Additionally, channel funding is accomplished with a generic API
85   which notifies users of the output which needs to appear on-chain, which they
86   can then create a transaction for. Once a transaction is created, we handle
87   the rest. This is a large part of our API's goals - making it easier to
88   integrate Lightning into existing on-chain wallets which have their own
89   on-chain logic - without needing to move funds in and out of a separate
90   Lightning wallet with on-chain transactions and a separate private key system.
91 * networking - to enable a user to run a full Lightning node on an embedded
92   machine, we don't specify exactly how to connect to another node at all! We
93   provide a default implementation which uses TCP sockets, but, e.g., if you
94   wanted to run your full Lightning node on a hardware wallet, you could, by
95   piping the Lightning network messages over USB/serial and then sending them in
96   a TCP socket from another machine.
97 * private keys - again we have "default implementations", but users can chose to
98   provide private keys to RL/LDK in any way they wish following a simple API. We
99   even support a generic API for signing transactions, allowing users to run
100   RL/LDK without any private keys in memory/putting private keys only on
101   hardware wallets.
102
103 LDK's customizability was presented about at Advancing Bitcoin in February 2020:
104 https://vimeo.com/showcase/8372504/video/412818125
105
106 Design Goal
107 -----------
108 The goal is to provide a fully-featured and incredibly flexible Lightning
109 implementation, allowing users to decide how they wish to use it. With that
110 in mind, everything should be exposed via simple, composable APIs. More
111 information about `rust-lightning`'s flexibility is provided in the `About`
112 section above.
113
114 For security reasons, do not add new dependencies. Really do not add new
115 non-optional/non-test/non-library dependencies. Really really do not add
116 dependencies with dependencies. Do convince Andrew to cut down dependency usage
117 in `rust-bitcoin`.
118
119 Rust-Lightning vs. LDK (Lightning Development Kit)
120 -------------
121 `rust-lightning` refers to the core `lightning` crate within this repo, whereas
122 LDK encompasses `rust-lightning` and all of its sample modules and crates (e.g.
123 the `lightning-persister` crate), language bindings, sample node
124 implementation(s), and other tools built around using `rust-lightning` for
125 Lightning integration or building a Lightning node.
126
127 Tagline
128 -------
129
130 *"Rust-Lightning, not Rusty's Lightning!"*
131
132 Contributing
133 ------------
134
135 Contributors are warmly welcome, see [CONTRIBUTING.md](CONTRIBUTING.md).
136
137 Project Architecture
138 ---------------------
139
140 For a `rust-lightning` high-level API introduction, see [ARCH.md](ARCH.md).
141
142 License is either Apache-2.0 or MIT, at the option of the user (ie dual-license
143 Apache-2.0 and MIT).