You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/build_node.md
+86-48Lines changed: 86 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -18,27 +18,35 @@ shutdown checklist.
18
18
-[ ] Initialize the fee estimator
19
19
* What it's used for: estimating fees for on-chain transactions that LDK wants broadcasted.
20
20
* Dependencies: none
21
-
* Example fee estimator that always returns `253` satoshis:
21
+
22
+
Example fee estimator that always returns `253` satoshis:
22
23
```java
23
24
// FeeEstimatorInterface is a functional interface, so we can implement it with a lambda
24
25
final fee_estimator =FeeEstimator.new_impl((confirmation_target ->253));
25
26
```
26
-
Rather than using static fees, you'll want to fill in the lambda with fetching up-to-date fees from a source like bitcoin core or your own API endpoint.
27
+
Rather than using static fees, you'll want to fill in the lambda with fetching up-to-date fees from a source like bitcoin core or your own API endpoint.
27
28
-[ ] Initialize the logger
29
+
Example logger that prints to the console:
30
+
```java
31
+
// LoggerInterface is a functional interface, so we can implement it with a lambda
32
+
final logger =Logger.new_impl((String arg) ->System.out.println(arg));
33
+
```
28
34
-[ ] Initialize the transaction broadcaster
29
-
* What it's used for:
35
+
* What it's used for: broadcasting various lightning transactions
30
36
* Dependencies: none
31
37
* Example transaction broadcaster skeleton:
32
38
```java
39
+
// Note that the `tx` argument is a []byte type.
33
40
final tx_broadcaster =BroadcasterInterface.new_impl(tx -> {
34
41
// <insert code to actually broadcast the given transaction here>
35
42
});
36
43
```
37
44
-[ ] Initialize the channel data persister
38
-
* What it's used for:
45
+
* What it's used for: persisting crucial channel data in a timely manner
* What it's used for: monitoring the chain for lighting transactions that are relevant to our node, and broadcasting force close transactions if need be
56
64
* Dependencies: fee estimator, logger, transaction broadcaster, channel data persister
57
-
* Optional dependency: ChainSource
65
+
* Optional dependency: a chain filter that allows LDK to let you know what transactions you should filter blocks for. This is useful if you pre-filter blocks or use compact filters. Otherwise, LDK will need full blocks.
58
66
* Example:
59
67
```java
60
68
// The `null` here must be filled in with a struct if you are running a light client.
61
69
final chain_monitor =ChainMonitor.constructor_new(null, tx_broadcaster, logger, fee_estimator, persister);
62
70
```
63
-
-[ ] Fill in the chain monitor's channel monitor state if LDK is restarting
64
-
// TODO: add reading existing monitors from disk and handling replaying blocks, handling forks
65
71
-[ ] Initialize the keys manager
66
-
* What it's used for:
72
+
* What it's used for: providing keys for signing lightning transactions
67
73
* Dependencies: random bytes, the current bitcoin network
68
74
* Example:
69
75
```java
@@ -74,26 +80,71 @@ byte[] key_seed = new byte[32];
74
80
// * TODO document why the current time is part of the parameters
-[ ] If LDK is restarting, fill in the chain monitor's existing channel monitor state
84
+
* Dependencies: the keys manager
85
+
* If LDK is restarting and has existing channels, then it's very important to read its current channel state off of disk during the restart process.
86
+
* Equally important: when you read each channel monitor off of disk, it comes with a blockhash which was the last block the channel monitor saw. So it's very important to take this blockhash, and:
87
+
1. If the blockhash is on a fork that's no longer current to the chain, then first you need to disconnect blocks until the channel monitor gets to the common ancestor with the main chain
88
+
2. Else, you just need to connect recent blocks until the channel monitor is at the current chain tip.
89
+
Example of reading channel monitors from disk, where each channel monitor's file is named after its funding outpoint: // TODO matt plz check this
90
+
```java
91
+
// Initialize the HashMap where we'll store the channel monitors we read from disk.
Rust example of bringing a channel monitor up to chain tip: https://github.com/rust-bitcoin/rust-lightning/pull/763/files#diff-f457bab978fc8b89ad308d5195f99d7b65a4a6ba1673c5f164104b2dda9a0db6R251 where the channel monitor is the `chain_listener` parameter. See the linked function and the `find_fork` function within it.
77
117
-[ ] Initialize the router (which we call the `NetGraphMsgHandler`)
78
-
// TODO add reading router data from disk if restarting
118
+
// TODO add docs for reading router data from disk if restarting
79
119
* What it's used for:
80
120
* Dependencies: logger
81
121
* Optional dependency: source of chain information, recommended for light clients to be able to verify channels
82
122
* Example:
83
123
```java
84
-
// TODO: have the example include reading from disk OR starting a new one
85
124
final router =NetGraphMsgHandler.constructor_new(newbyte[32], null, logger);
86
125
```
87
126
-[ ] Initialize the channel manager
88
127
// TODO add stuff if we're restarting/reading from disk
89
-
* What it's used for:
90
-
* Dependencies:
91
-
* Optional dependency:
92
-
* Example:
128
+
* What it's used for: managing channel state
129
+
* Dependencies: keys manager, fee estimator, chain monitor, transaction broadcaster, logger, channel configuration info, and the set of channel monitors we read from disk in the previous step
130
+
Example of initializing a channel manager on a fresh node:
- [ ] Start a loop to handle the channel manager's generated events
134
162
// TODO add persisting the channel manager after handling each event
135
-
*What it's used for:
136
-
* Dependencies:
137
-
* Example:
163
+
* What it's used for: the channel manager and chain monitor generate events that must be handled by you, such as telling you when a payment has been successfully received or when a funding transaction is ready for broadcast.
0 commit comments