Cleanup network graph persisting and ensure write succeeds
[rapid-gossip-sync-server] / README.md
1 # rust-ln-sync
2
3 This is a server that connects to peers on the Lightning network and calculates compact rapid sync
4 gossip data.
5
6 These are the components it's comprised of.
7
8 ## Modules
9
10 ### config
11
12 A config file where the Postgres credentials and Lightning peers can be adjusted. Most adjustments
13 can be made by setting environment variables, whose usage is as follows:
14
15 | Name                     | Default       | Description                                                                                                |
16 |:-------------------------|:--------------|:-----------------------------------------------------------------------------------------------------------|
17 | RUST_LN_SYNC_DB_HOST     | localhost     | Domain of the Postgres database                                                                            |
18 | RUST_LN_SYNC_DB_USER     | alice         | Username to access Postgres                                                                                |
19 | RUST_LN_SYNC_DB_PASSWORD | _None_        | Password to access Postgres                                                                                |
20 | RUST_LN_SYNC_DB_NAME     | ln_graph_sync | Name of the database to be used for gossip storage                                                         |
21 | BITCOIN_REST_DOMAIN      | 127.0.0.1     | Domain of the [bitcoind REST server](https://github.com/bitcoin/bitcoin/blob/master/doc/REST-interface.md) |
22 | BITCOIN_REST_PORT        | 80            | HTTP port of the bitcoind REST server                                                                      |
23 | BITCOIN_REST_PATH        | /rest/        | Path infix to access the bitcoind REST endpoints                                                           |
24
25 Notably, one property needs to be modified in code, namely the `ln_peers()` method. It specifies how
26 many and which peers to use for retrieving gossip.
27
28 ### downloader
29
30 The module responsible for initiating the scraping of the network graph from its peers.
31
32 ### persistence
33
34 The module responsible for persisting all the downloaded graph data to Postgres.
35
36 ### snapshot
37
38 The snapshotting module is responsible for calculating and storing snapshots. It's started up
39 as soon as the first full graph sync completes, and then keeps updating the snapshots at a
40 24-hour-interval.
41
42 ### lookup
43
44 The lookup module is responsible for fetching the latest data from the network graph and Postgres,
45 and reconciling it into an actionable delta set that the server can return in a serialized format.
46
47 It works by collecting all the channels that are currently in the network graph, and gathering
48 announcements as well as updates for each of them. For the updates specifically, the last update
49 seen prior to the given timestamp, the latest known updates, and, if necessary, all intermediate
50 updates are collected.
51
52 Then, any channel that has only had an announcement but never an update is dropped. Additionally,
53 every channel whose first update was seen after the given timestamp is collected alongside its
54 announcement.
55
56 Finally, all channel update transitions are evaluated and collected into either a full or an
57 incremental update.
58
59 ## License
60
61 [Apache 2.0](LICENSE-APACHE.md) or [MIT](LICENSE-MIT.md), [at your option](LICENSE.md).