@@ -275,7 +275,7 @@ retrieving fresh ones every time
275
275
276
276
** References:** [ Rust ` BroadcasterInterface ` docs] ( https://docs.rs/lightning/*/lightning/chain/chaininterface/trait.BroadcasterInterface.html ) , [ Java ` BroadcasterInterface ` bindings] ( https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/BroadcasterInterface.java )
277
277
278
- ### Step 4. Initialize ` Persist `
278
+ ### Initialize ` Persist `
279
279
** What it's used for:** persisting ` ChannelMonitor ` s, which contain crucial channel data, in a timely manner
280
280
281
281
<CodeSwitcher :languages =" {rust:'Rust', java:'Java', kotlin:'Kotlin'} " >
@@ -311,49 +311,49 @@ retrieving fresh ones every time
311
311
<template v-slot:java >
312
312
313
313
``` java
314
- Persist persister = Persist . new_impl( new Persist . PersistInterface () {
314
+ class YourPersister implements Persist .PersistInterface {
315
315
@Override
316
- public Result_NoneChannelMonitorUpdateErrZ persist_new_channel (OutPoint id ,
317
- ChannelMonitor data ) {
318
- byte [] channel_monitor_bytes = data. write();
316
+ public Result_NoneChannelMonitorUpdateErrZ persist_new_channel (
317
+ OutPoint id , ChannelMonitor data ) {
318
+ byte [] channelMonitorBytes = data. write();
319
319
// <insert code to write these bytes to disk, keyed by `id`>
320
320
}
321
321
322
322
@Override
323
323
public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel (
324
324
OutPoint id , ChannelMonitorUpdate update , ChannelMonitor data ) {
325
- byte [] channel_monitor_bytes = data. write();
325
+ byte [] channelMonitorBytes = data. write();
326
326
// <insert code to update the `ChannelMonitor`'s file on disk with these
327
327
// new bytes, keyed by `id`>
328
328
}
329
- });
329
+ }
330
+
331
+ PersisterInterface persister = PersisterInterface . new_impl(new YourPersister ());
330
332
```
331
333
</template >
332
334
333
335
<template v-slot:kotlin >
334
336
335
337
``` kotlin
336
- object LDKPersister : Persist.PersistInterface {
338
+ object YourPersister : Persist.PersistInterface {
337
339
override fun persist_new_channel (
338
- id : OutPoint ? ,
339
- data : ChannelMonitor ? ,
340
- updateId : MonitorUpdateId ?
340
+ id : OutPoint ? , data : ChannelMonitor ? , updateId : MonitorUpdateId ?
341
341
): Result_NoneChannelMonitorUpdateErrZ ? {
342
342
val channelMonitorBytes = data.write()
343
343
// <insert code to write these bytes to disk, keyed by `id`>
344
344
}
345
345
346
346
override fun update_persisted_channel (
347
- id : OutPoint ? ,
348
- update : ChannelMonitorUpdate ? ,
349
- data : ChannelMonitor ? ,
347
+ id : OutPoint ? , update : ChannelMonitorUpdate ? , data : ChannelMonitor ? ,
350
348
updateId : MonitorUpdateId
351
349
): Result_NoneChannelMonitorUpdateErrZ ? {
352
350
val channelMonitorBytes = data.write()
353
351
// <insert code to update the `ChannelMonitor`'s file on disk with these
354
352
// new bytes, keyed by `id`>
355
353
}
356
354
}
355
+
356
+ val persister: Persist = Persist .new_impl(YourPersister )
357
357
```
358
358
359
359
</template >
@@ -418,7 +418,7 @@ inform LDK about these transactions/outputs in Step 14.
418
418
<template v-slot:java >
419
419
420
420
``` java
421
- Filter tx_filter = Filter . new_impl( new Filter . FilterInterface () {
421
+ class YourTxFilter implements Filter .FilterInterface {
422
422
@Override
423
423
public void register_tx (byte [] txid , byte [] script_pubkey ) {
424
424
// <insert code for you to watch for this transaction on-chain>
@@ -429,14 +429,16 @@ inform LDK about these transactions/outputs in Step 14.
429
429
// <insert code for you to watch for any transactions that spend this
430
430
// output on-chain>
431
431
}
432
- });
432
+ }
433
+
434
+ Filter txFilter = Filter . new_impl(YourTxFilter )
433
435
```
434
436
</template >
435
437
436
438
<template v-slot:kotlin >
437
439
438
440
``` kotlin
439
- object LDKTxFilter : Filter.FilterInterface {
441
+ object YourTxFilter : Filter.FilterInterface {
440
442
override fun register_tx (txid : ByteArray , script_pubkey : ByteArray ) {
441
443
// <insert code for you to watch for this transaction on-chain>
442
444
}
@@ -445,8 +447,9 @@ inform LDK about these transactions/outputs in Step 14.
445
447
// <insert code for you to watch for any transactions that spend this
446
448
// output on-chain>
447
449
}
448
- }
449
-
450
+ }
451
+
452
+ val txFilter: Filter = Filter .new_impl(YourTxFilter )
450
453
```
451
454
</template >
452
455
</CodeSwitcher >
@@ -457,7 +460,7 @@ inform LDK about these transactions/outputs in Step 14.
457
460
458
461
** References:** [ Rust ` Filter ` docs] ( https://docs.rs/lightning/*/lightning/chain/trait.Filter.html ) , [ Java ` Filter ` bindings] ( https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/Filter.java )
459
462
460
- ### Step 5. Initialize the ` ChainMonitor `
463
+ ### Initialize the ` ChainMonitor `
461
464
** What it's used for:** tracking one or more ` ChannelMonitor ` s and using them to monitor the chain for lighting transactions that are relevant to our node, and broadcasting transactions if need be.
462
465
463
466
<CodeSwitcher :languages =" {rust:'Rust', java:'Java', kotlin:'Kotlin'} " >
@@ -466,9 +469,7 @@ inform LDK about these transactions/outputs in Step 14.
466
469
``` rust
467
470
let filter : Option <Box <dyn Filter >> = // leave this as None or insert the Filter trait object
468
471
469
- let chain_monitor = ChainMonitor :: new (
470
- filter , & broadcaster , & logger , & fee_estimator , & persister
471
- );
472
+ let chain_monitor = ChainMonitor :: new (filter , & broadcaster , & logger , & fee_estimator , & persister );
472
473
```
473
474
</template >
474
475
@@ -477,9 +478,7 @@ inform LDK about these transactions/outputs in Step 14.
477
478
``` java
478
479
final filter = // leave this as `null` or insert the Filter object.
479
480
480
- final chain_monitor = ChainMonitor . of(filter, tx_broadcaster, logger,
481
- fee_estimator, persister);
482
-
481
+ final chainMonitor = ChainMonitor . of(filter, txBroadcaster, logger, feeEstimator, persister);
483
482
```
484
483
</template >
485
484
@@ -501,7 +500,7 @@ inform LDK about these transactions/outputs in Step 14.
501
500
502
501
** References:** [ Rust ` ChainMonitor ` docs] ( https://docs.rs/lightning/*/lightning/chain/chainmonitor/struct.ChainMonitor.html ) , [ Java ` ChainMonitor ` bindings] ( https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/ChainMonitor.java )
503
502
504
- ### Step 6. Initialize the ` KeysManager `
503
+ ### Initialize the ` KeysManager `
505
504
** What it's used for:** providing keys for signing Lightning transactions
506
505
507
506
<CodeSwitcher :languages =" {rust:'Rust', java:'Java', kotlin:'Kotlin'} " >
@@ -559,7 +558,8 @@ inform LDK about these transactions/outputs in Step 14.
559
558
560
559
``` kotlin
561
560
val keySeed = ByteArray (32 )
562
-
561
+ // <insert code to fill key_seed with random bytes OR if restarting, reload the
562
+ // seed from disk>
563
563
val keysManager = KeysManager .of(
564
564
keySeed,
565
565
System .currentTimeMillis() / 1000 ,
@@ -583,7 +583,7 @@ generation is unique across restarts.
583
583
584
584
** References:** [ Rust ` KeysManager ` docs] ( https://docs.rs/lightning/*/lightning/chain/keysinterface/struct.KeysManager.html ) , [ Java ` KeysManager ` bindings] ( https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/KeysManager.java )
585
585
586
- ### Step 7. Read ` ChannelMonitor ` state from disk
586
+ ### Read ` ChannelMonitor ` state from disk
587
587
588
588
** What it's used for:** if LDK is restarting and has at least 1 channel, its ` ChannelMonitor ` s will need to be (1) fed to the ` ChannelManager ` and (2) synced to chain.
589
589
@@ -608,19 +608,19 @@ generation is unique across restarts.
608
608
609
609
``` java
610
610
// Initialize the array where we'll store the `ChannelMonitor`s read from disk.
611
- final ArrayList channel_monitor_list = new ArrayList<> ();
611
+ final ArrayList channelMonitorList = new ArrayList<> ();
612
612
613
613
// For each monitor stored on disk, deserialize it and place it in
614
614
// `channel_monitors`.
615
615
for (... : monitor_files) {
616
- byte [] channel_monitor_bytes = // read the bytes from disk the same way you
617
- // wrote them in Step 4
618
- channel_monitor_list . add(channel_monitor_bytes );
616
+ byte [] channelMonitorBytes = // read the bytes from disk
617
+
618
+ channelMonitorList . add(channelMonitorBytes );
619
619
}
620
620
621
621
// Convert the ArrayList into an array so we can pass it to
622
622
// `ChannelManagerConstructor`.
623
- final byte [][] channel_monitors = (byte [][])channel_monitor_list . toArray(new byte [1 ][]);
623
+ final byte [][] channelMonitors = (byte [][])channelMonitorList . toArray(new byte [1 ][]);
624
624
625
625
```
626
626
</template >
@@ -646,7 +646,7 @@ generation is unique across restarts.
646
646
647
647
** References:** [ Rust ` load_outputs_to_watch ` docs] ( https://docs.rs/lightning/*/lightning/chain/channelmonitor/struct.ChannelMonitor.html#method.load_outputs_to_watch )
648
648
649
- ### Step 8. Initialize the ` ChannelManager `
649
+ ### Initialize the ` ChannelManager `
650
650
** What it's used for:** managing channel state
651
651
652
652
<CodeSwitcher :languages =" {rust:'Rust', java:'Java', kotlin:'Kotlin'} " >
@@ -706,21 +706,21 @@ generation is unique across restarts.
706
706
``` java
707
707
/* FRESH CHANNELMANAGER */
708
708
709
- int block_height = // <insert current chain tip height>;
710
- byte [] best_block_hash = // <insert current chain tip block hash>;
711
- ChannelManagerConstructor channel_manager_constructor = new ChannelManagerConstructor (
712
- Network . LDKNetwork_Bitcoin , UserConfig . default (), best_block_hash ,
713
- block_height, keys_manager . as_KeysInterface(), fee_estimator, chain_monitor ,
714
- router, tx_broadcaster , logger);
709
+ int bestBlockHeight = // <insert current chain tip height>;
710
+ byte [] bestBlockHash = // <insert current chain tip block hash>;
711
+ ChannelManagerConstructor channelManagerConstructor = new ChannelManagerConstructor (
712
+ Network . LDKNetwork_Bitcoin , UserConfig . default (), bestBlockHash ,
713
+ bestBlockHeight, keysManager . as_KeysInterface(), feeEstimator, chainMonitor ,
714
+ router, txBroadcaster , logger);
715
715
716
716
/* RESTARTING CHANNELMANAGER */
717
717
718
- byte [] serialized_channel_manager = // <insert bytes as written to disk in Step 4>
719
- ChannelManagerConstructor channel_manager_constructor = new ChannelManagerConstructor (
720
- serialized_channel_manager, channel_monitors, keys_manager . as_KeysInterface(),
721
- fee_estimator, chain_monitor , filter, router, tx_broadcaster , logger);
718
+ byte [] serializedChannelManager = // <insert bytes as written to disk in Step 4>
719
+ ChannelManagerConstructor channelManagerConstructor = new ChannelManagerConstructor (
720
+ serializedChannelManager, channelMonitors, keysManager . as_KeysInterface(),
721
+ feeEstimator, chainMonitor , filter, router, txBroadcaster , logger);
722
722
723
- final ChannelManager channel_manager = channel_manager_constructor . channel_manager;
723
+ final ChannelManager channelManager = channelManagerConstructor . channel_manager;
724
724
```
725
725
</template >
726
726
@@ -734,11 +734,11 @@ generation is unique across restarts.
734
734
serializedChannelManager,
735
735
channelMonitors,
736
736
userConfig,
737
- keysManager? .as_KeysInterface(),
737
+ keysManager.as_KeysInterface(),
738
738
feeEstimator,
739
739
chainMonitor,
740
740
txFilter,
741
- router!! .write(),
741
+ router.write(),
742
742
txBroadcaster,
743
743
logger
744
744
);
@@ -749,7 +749,7 @@ generation is unique across restarts.
749
749
userConfig,
750
750
latestBlockHash,
751
751
latestBlockHeight,
752
- keysManager? .as_KeysInterface(),
752
+ keysManager.as_KeysInterface(),
753
753
feeEstimator,
754
754
chainMonitor,
755
755
router,
@@ -762,14 +762,14 @@ generation is unique across restarts.
762
762
< / CodeSwitcher >
763
763
764
764
** Implementation notes: ** No methods should be called on `ChannelManager ` until
765
- * after* Step 9 .
765
+ * after* the ` ChannelMonitor `s and ` ChannelManager ` are synced to the chain tip (next step) .
766
766
767
767
** Dependencies : ** `KeysManager `, `FeeEstimator `, `ChainMonitor `, `BroadcasterInterface `, `Logger `
768
768
* If restarting: `ChannelMonitor `s and `ChannelManager ` bytes from Step 7 and Step 18 respectively
769
769
770
770
** References : ** [Rust `ChannelManager ` docs](https: // docs.rs/lightning/*/lightning/ln/channelmanager/struct.ChannelManager.html), [Java `ChannelManager` bindings](https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/ChannelManager.java)
771
771
772
- ### Step 9 . Sync `ChannelMonitor `s and `ChannelManager ` to chain tip
772
+ ### Sync `ChannelMonitor `s and `ChannelManager ` to chain tip
773
773
** What it' s used for:** this step is only necessary if you' re restarting and have open channels. This step ensures that LDK channel state is up- to- date with the bitcoin blockchain
774
774
775
775
** Example : **
@@ -953,58 +953,13 @@ Otherwise, you can use LDK's `Confirm` interface as in the examples above. The h
953
953
2 . Tell LDK what your best known block header and height is .
954
954
3 . Call `channel_manager_constructor.chain_sync_completed(.. )` to complete the initial sync process.
955
955
956
- ** More details about LDK ' s interfaces to provide chain info in Step 14**
957
-
958
956
** References : ** [Rust `Confirm ` docs](https: // docs.rs/lightning/*/lightning/chain/trait.Confirm.html), [Rust `Listen` docs](https://docs.rs/lightning/*/lightning/chain/trait.Listen.html), [Rust `lightning_block_sync` module docs](https://docs.rs/lightning-block-sync/*/lightning_block_sync/)
959
957
960
958
** Dependencies : ** `ChannelManager `, `ChainMonitor `, `ChannelMonitor `s
961
959
* If providing providing full blocks or BIP 157 / 158 : set of `ChannelMonitor `s
962
960
* If using Electrum : `ChainMonitor `
963
961
964
- ### Step 10. Give `ChannelMonitor`s to `ChainMonitor`
965
- **What it' s used for : ** `ChainMonitor ` is responsible for updating the `ChannelMonitor `s during LDK node operation.
966
-
967
- <CodeSwitcher : languages= "{rust: 'Rust ', java: 'Java ', kotlin: 'Kotlin '}">
968
- < template v- slot: rust>
969
-
970
- ```rust
971
- for (funding_outpoint, channel_monitor) in channel_monitors.drain(.. ) {
972
- chain_monitor.watch_channel(funding_outpoint, channel_monitor).unwrap();
973
- }
974
- ```
975
- < / template>
976
-
977
- < template v- slot: java>
978
-
979
- ```java
980
- long[] channel_monitors = chainMonitor.list_monitors()
981
-
982
- for (int k = 0 ; k < channel_monitors.length; k++ ) {
983
- Outpoint outpoint = channel_monitors[k];
984
- ChannelMonitor monitor = // Retrieve channel monitor saved in step 4
985
- chainMonitor.as_Watch().watch_channel(outPoint, monitor)
986
- }
987
- ```
988
- < / template>
989
-
990
- < template v- slot: kotlin>
991
-
992
- ```kotlin
993
- val channelMonitorlist = chainMonitor.list_monitors()
994
-
995
- list.iterator().forEach { outPoint ->
996
- val monitor = // Retrieve channel monitor saved in step 4
997
- chainMonitor.as_Watch().watch_channel(outPoint, monitor)
998
- }
999
- ```
1000
- < / template>
1001
- < / CodeSwitcher >
1002
-
1003
- ** Dependencies : **
1004
- * `ChainMonitor `, set of `ChannelMonitor `s and their funding outpoints
1005
- * Step 9 must be completed prior to this step
1006
-
1007
- ### Step 11 : Optional : Initialize the `P2PGossipSync `
962
+ ###Optional : Initialize the `P2PGossipSync `
1008
963
1009
964
** You must follow this step if : ** you need LDK to provide routes for sending payments (i.e. you are * not * providing your own routes)
1010
965
0 commit comments