2020-02-25 21:57:58 +01:00
|
|
|
Rust-Lightning is broken into a number of high-level structures with APIs to hook them
|
|
|
|
together, as well as APIs for you, the user, to provide external data.
|
|
|
|
|
|
|
|
The two most important structures which nearly every application of Rust-Lightning will
|
|
|
|
need to use are `ChannelManager` and `ChannelMonitor`. `ChannelManager` holds multiple
|
|
|
|
channels, routes payments between them, and exposes a simple API to make and receive
|
|
|
|
payments. Individual `ChannelMonitor`s monitor the on-chain state of a channel, punish
|
|
|
|
counterparties if they misbehave, and force-close channels if they contain unresolved
|
2020-07-21 02:03:52 +02:00
|
|
|
HTLCs which are near expiration. The `chain::Watch` interface provides a way for you to
|
2020-02-25 21:57:58 +01:00
|
|
|
receive `ChannelMonitorUpdate`s from `ChannelManager` and persist them to disk before the
|
|
|
|
channel steps forward.
|
|
|
|
|
|
|
|
There are two additional important structures that you may use either on the same device
|
2022-06-01 19:28:34 +02:00
|
|
|
as the `ChannelManager` or on a separate one. `P2PGossipSync` handles receiving channel
|
2021-11-04 15:57:53 +01:00
|
|
|
and node announcements, which are then used to calculate routes by `find_route` for sending
|
|
|
|
payments. `PeerManager` handles the authenticated and encrypted communication protocol,
|
2022-06-01 19:28:34 +02:00
|
|
|
monitoring for liveness of peers, routing messages to `ChannelManager` and `P2PGossipSync`
|
2020-05-07 01:04:44 +02:00
|
|
|
instances directly, and receiving messages from them via the `EventsProvider` interface.
|
2020-02-25 21:57:58 +01:00
|
|
|
|
|
|
|
These structs communicate with each other using a public API, so that you can easily add
|
2024-10-08 15:17:47 +02:00
|
|
|
a proxy in between for special handling. Further, APIs for key generation, entropy source,
|
|
|
|
transaction broadcasting, block fetching, and fee estimation must be implemented and the
|
|
|
|
data provided by you, the user.
|
2020-02-25 21:57:58 +01:00
|
|
|
|
|
|
|
The library does not rely on the presence of a runtime environment outside of access to
|
|
|
|
heap, atomic integers, and basic Mutex primitives. This means the library will never
|
|
|
|
spawn threads or take any action whatsoever except when you call into it. Thus,
|
|
|
|
`ChannelManager` and `PeerManager` have public functions which you should call on a timer,
|
|
|
|
network reads and writes are external and provided by you, and the library relies only on
|
|
|
|
block time for current time knowledge.
|
|
|
|
|
|
|
|
At a high level, some of the common interfaces fit together as follows:
|
|
|
|
|
|
|
|
```
|
2024-10-08 15:17:47 +02:00
|
|
|
------------------ --------------
|
|
|
|
| SignerProvider | | NodeSigner |
|
|
|
|
------------------ --------------
|
|
|
|
----------------- ^ ^ --------------
|
|
|
|
| EntropySource | <---- \ / ----> | UserConfig |
|
|
|
|
----------------- \ | | / --------------
|
|
|
|
| | | |
|
|
|
|
-------------------- | | | | ----------------
|
|
|
|
------| MessageSendEvent | | | | | | FeeEstimator | <----------------
|
|
|
|
/ -------------------- | | | | ---------------- \
|
|
|
|
| (as MessageSendEventsProvider) | | | | ^ |
|
|
|
|
| ^ | | | | / ----------------------- |
|
|
|
|
| \ | | | | / ----> | BroadcasterInterface | |
|
|
|
|
| \ | | | | / / ----------------------- |
|
|
|
|
| \ | | | | / / ^ |
|
|
|
|
| (as ------------------ ---------------- | |
|
|
|
|
| ChannelMessageHandler)-> | ChannelManager | ----> | chain::Watch | | |
|
|
|
|
v / ------------------ ---------------- | |
|
|
|
|
--------------- / (as EventsProvider) ^ | |
|
|
|
|
| PeerManager |- \ | | |
|
|
|
|
--------------- \ | (is-a) / |
|
|
|
|
| -------------- \ _---------------- /
|
|
|
|
| | UtxoLookup | \ / | ChainMonitor |------------
|
2023-01-21 04:28:35 +01:00
|
|
|
| -------------- \ / ----------------
|
2020-08-04 01:55:11 +02:00
|
|
|
| ^ \ / |
|
|
|
|
(as RoutingMessageHandler) | v v
|
2022-06-01 19:28:34 +02:00
|
|
|
\ ----------------- --------- -----------------
|
|
|
|
-----------------> | P2PGossipSync | | Event | | chain::Filter |
|
|
|
|
----------------- --------- -----------------
|
2020-02-25 21:57:58 +01:00
|
|
|
```
|