Skip to content

Commit 6febc84

Browse files
author
Conor Okus
committed
Removes channel_watch instructions
1 parent 29ab742 commit 6febc84

File tree

1 file changed

+52
-97
lines changed

1 file changed

+52
-97
lines changed

docs/tutorials/building-a-node-with-ldk/setting-up-a-channel-manager.md

Lines changed: 52 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ retrieving fresh ones every time
275275

276276
**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)
277277

278-
### Step 4. Initialize `Persist`
278+
### Initialize `Persist`
279279
**What it's used for:** persisting `ChannelMonitor`s, which contain crucial channel data, in a timely manner
280280

281281
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin'}">
@@ -311,49 +311,49 @@ retrieving fresh ones every time
311311
<template v-slot:java>
312312

313313
```java
314-
Persist persister = Persist.new_impl(new Persist.PersistInterface() {
314+
class YourPersister implements Persist.PersistInterface {
315315
@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();
319319
// <insert code to write these bytes to disk, keyed by `id`>
320320
}
321321

322322
@Override
323323
public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(
324324
OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data) {
325-
byte[] channel_monitor_bytes = data.write();
325+
byte[] channelMonitorBytes = data.write();
326326
// <insert code to update the `ChannelMonitor`'s file on disk with these
327327
// new bytes, keyed by `id`>
328328
}
329-
});
329+
}
330+
331+
PersisterInterface persister = PersisterInterface.new_impl(new YourPersister());
330332
```
331333
</template>
332334

333335
<template v-slot:kotlin>
334336

335337
```kotlin
336-
object LDKPersister: Persist.PersistInterface {
338+
object YourPersister: Persist.PersistInterface {
337339
override fun persist_new_channel(
338-
id: OutPoint?,
339-
data: ChannelMonitor?,
340-
updateId: MonitorUpdateId?
340+
id: OutPoint?, data: ChannelMonitor?, updateId: MonitorUpdateId?
341341
): Result_NoneChannelMonitorUpdateErrZ? {
342342
val channelMonitorBytes = data.write()
343343
// <insert code to write these bytes to disk, keyed by `id`>
344344
}
345345

346346
override fun update_persisted_channel(
347-
id: OutPoint?,
348-
update: ChannelMonitorUpdate?,
349-
data: ChannelMonitor?,
347+
id: OutPoint?, update: ChannelMonitorUpdate?, data: ChannelMonitor?,
350348
updateId: MonitorUpdateId
351349
): Result_NoneChannelMonitorUpdateErrZ? {
352350
val channelMonitorBytes = data.write()
353351
// <insert code to update the `ChannelMonitor`'s file on disk with these
354352
// new bytes, keyed by `id`>
355353
}
356354
}
355+
356+
val persister: Persist = Persist.new_impl(YourPersister)
357357
```
358358

359359
</template>
@@ -418,7 +418,7 @@ inform LDK about these transactions/outputs in Step 14.
418418
<template v-slot:java>
419419

420420
```java
421-
Filter tx_filter = Filter.new_impl(new Filter.FilterInterface() {
421+
class YourTxFilter implements Filter.FilterInterface {
422422
@Override
423423
public void register_tx(byte[] txid, byte[] script_pubkey) {
424424
// <insert code for you to watch for this transaction on-chain>
@@ -429,14 +429,16 @@ inform LDK about these transactions/outputs in Step 14.
429429
// <insert code for you to watch for any transactions that spend this
430430
// output on-chain>
431431
}
432-
});
432+
}
433+
434+
Filter txFilter = Filter.new_impl(YourTxFilter)
433435
```
434436
</template>
435437

436438
<template v-slot:kotlin>
437439

438440
```kotlin
439-
object LDKTxFilter : Filter.FilterInterface {
441+
object YourTxFilter : Filter.FilterInterface {
440442
override fun register_tx(txid: ByteArray, script_pubkey: ByteArray) {
441443
// <insert code for you to watch for this transaction on-chain>
442444
}
@@ -445,8 +447,9 @@ inform LDK about these transactions/outputs in Step 14.
445447
// <insert code for you to watch for any transactions that spend this
446448
// output on-chain>
447449
}
448-
}
449-
450+
}
451+
452+
val txFilter: Filter = Filter.new_impl(YourTxFilter)
450453
```
451454
</template>
452455
</CodeSwitcher>
@@ -457,7 +460,7 @@ inform LDK about these transactions/outputs in Step 14.
457460

458461
**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)
459462

460-
### Step 5. Initialize the `ChainMonitor`
463+
### Initialize the `ChainMonitor`
461464
**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.
462465

463466
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin'}">
@@ -466,9 +469,7 @@ inform LDK about these transactions/outputs in Step 14.
466469
```rust
467470
let filter: Option<Box<dyn Filter>> = // leave this as None or insert the Filter trait object
468471

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);
472473
```
473474
</template>
474475

@@ -477,9 +478,7 @@ inform LDK about these transactions/outputs in Step 14.
477478
```java
478479
final filter = // leave this as `null` or insert the Filter object.
479480

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);
483482
```
484483
</template>
485484

@@ -501,7 +500,7 @@ inform LDK about these transactions/outputs in Step 14.
501500

502501
**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)
503502

504-
### Step 6. Initialize the `KeysManager`
503+
### Initialize the `KeysManager`
505504
**What it's used for:** providing keys for signing Lightning transactions
506505

507506
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin'}">
@@ -559,7 +558,8 @@ inform LDK about these transactions/outputs in Step 14.
559558

560559
```kotlin
561560
val keySeed = ByteArray(32)
562-
561+
// <insert code to fill key_seed with random bytes OR if restarting, reload the
562+
// seed from disk>
563563
val keysManager = KeysManager.of(
564564
keySeed,
565565
System.currentTimeMillis() / 1000,
@@ -583,7 +583,7 @@ generation is unique across restarts.
583583

584584
**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)
585585

586-
### Step 7. Read `ChannelMonitor` state from disk
586+
### Read `ChannelMonitor` state from disk
587587

588588
**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.
589589

@@ -608,19 +608,19 @@ generation is unique across restarts.
608608

609609
```java
610610
// 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<>();
612612

613613
// For each monitor stored on disk, deserialize it and place it in
614614
// `channel_monitors`.
615615
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);
619619
}
620620

621621
// Convert the ArrayList into an array so we can pass it to
622622
// `ChannelManagerConstructor`.
623-
final byte[][] channel_monitors = (byte[][])channel_monitor_list.toArray(new byte[1][]);
623+
final byte[][] channelMonitors = (byte[][])channelMonitorList.toArray(new byte[1][]);
624624

625625
```
626626
</template>
@@ -646,7 +646,7 @@ generation is unique across restarts.
646646

647647
**References:** [Rust `load_outputs_to_watch` docs](https://docs.rs/lightning/*/lightning/chain/channelmonitor/struct.ChannelMonitor.html#method.load_outputs_to_watch)
648648

649-
### Step 8. Initialize the `ChannelManager`
649+
### Initialize the `ChannelManager`
650650
**What it's used for:** managing channel state
651651

652652
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin'}">
@@ -706,21 +706,21 @@ generation is unique across restarts.
706706
```java
707707
/* FRESH CHANNELMANAGER */
708708

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);
715715

716716
/* RESTARTING CHANNELMANAGER */
717717

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);
722722

723-
final ChannelManager channel_manager = channel_manager_constructor.channel_manager;
723+
final ChannelManager channelManager = channelManagerConstructor.channel_manager;
724724
```
725725
</template>
726726

@@ -734,11 +734,11 @@ generation is unique across restarts.
734734
serializedChannelManager,
735735
channelMonitors,
736736
userConfig,
737-
keysManager?.as_KeysInterface(),
737+
keysManager.as_KeysInterface(),
738738
feeEstimator,
739739
chainMonitor,
740740
txFilter,
741-
router!!.write(),
741+
router.write(),
742742
txBroadcaster,
743743
logger
744744
);
@@ -749,7 +749,7 @@ generation is unique across restarts.
749749
userConfig,
750750
latestBlockHash,
751751
latestBlockHeight,
752-
keysManager?.as_KeysInterface(),
752+
keysManager.as_KeysInterface(),
753753
feeEstimator,
754754
chainMonitor,
755755
router,
@@ -762,14 +762,14 @@ generation is unique across restarts.
762762
</CodeSwitcher>
763763

764764
**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).
766766

767767
**Dependencies:** `KeysManager`, `FeeEstimator`, `ChainMonitor`, `BroadcasterInterface`, `Logger`
768768
* If restarting: `ChannelMonitor`s and `ChannelManager` bytes from Step 7 and Step 18 respectively
769769

770770
**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)
771771

772-
### Step 9. Sync `ChannelMonitor`s and `ChannelManager` to chain tip
772+
### Sync `ChannelMonitor`s and `ChannelManager` to chain tip
773773
**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
774774

775775
**Example:**
@@ -953,58 +953,13 @@ Otherwise, you can use LDK's `Confirm` interface as in the examples above. The h
953953
2. Tell LDK what your best known block header and height is.
954954
3. Call `channel_manager_constructor.chain_sync_completed(..)` to complete the initial sync process.
955955

956-
**More details about LDK's interfaces to provide chain info in Step 14**
957-
958956
**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/)
959957

960958
**Dependencies:** `ChannelManager`, `ChainMonitor`, `ChannelMonitor`s
961959
* If providing providing full blocks or BIP 157/158: set of `ChannelMonitor`s
962960
* If using Electrum: `ChainMonitor`
963961

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`
1008963

1009964
**You must follow this step if:** you need LDK to provide routes for sending payments (i.e. you are *not* providing your own routes)
1010965

0 commit comments

Comments
 (0)