Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c7f506

Browse files
author
Conor Okus
committed
Adds lightning-transaction-sync in favor of Confirm
1 parent 42646ad commit 8c7f506

File tree

1 file changed

+66
-28
lines changed

1 file changed

+66
-28
lines changed

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

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -931,16 +931,18 @@ _after_ the `ChannelMonitor`s and `ChannelManager` are synced to the chain tip (
931931
932932
### Sync `ChannelMonitor`s and `ChannelManager` to chain tip
933933
934-
**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
934+
**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.
935+
936+
There are 2 main options for synchronizing to chain on startup:
937+
938+
#### Full Blocks or BIP 157/158 (Compact Block Filters)
935939
936940
**Example:**
937941
938-
<CodeSwitcher :languages="{rust:'Rust', kotlin:'Kotlin', swift:'Swift'}">
942+
<CodeSwitcher :languages="{rust:'Rust'}">
939943
<template v-slot:rust>
940944
941945
```rust
942-
// Full Blocks or BIP 157/158
943-
944946
use lightning_block_sync::init;
945947
use lightning_block_sync::poll;
946948
use lightning_block_sync::UnboundedCache;
@@ -1006,17 +1008,74 @@ chain_tip = Some(
10061008
.await
10071009
.unwrap(),
10081010
);
1011+
```
1012+
1013+
</template>
1014+
1015+
</CodeSwitcher>
1016+
1017+
**Implementation notes:**
1018+
1019+
If you are connecting full blocks or using BIP 157/158, then it is recommended to use
1020+
LDK's [`lightning_block_sync`](https://docs.rs/lightning-block-sync/*/lightning_block_sync/) crate as in the example above: the high-level steps that must be done for both `ChannelManager` and each `ChannelMonitor` are as follows:
1021+
1022+
1. Get the last blockhash that each object saw.
1023+
- Receive the latest block hash when through [deserializtion](https://docs.rs/lightning/*/lightning/ln/channelmanager/struct.ChannelManagerReadArgs.html) of the `ChannelManager` via `read()`
1024+
- Each `ChannelMonitor`'s is in `channel_manager.channel_monitors`, as the 2nd element in each tuple
1025+
2. For each object, if its latest known blockhash has been reorged out of the chain, then disconnect blocks using `channel_manager.as_Listen().block_disconnected(..)` or `channel_monitor.block_disconnected(..)` until you reach the last common ancestor with the main chain.
1026+
3. For each object, reconnect blocks starting from the common ancestor until it gets to your best known chain tip using `channel_manager.as_Listen().block_connected(..)` and/or `channel_monitor.block_connected(..)`.
1027+
4. Call `channel_manager.chain_sync_completed(..)` to complete the initial sync process.
1028+
1029+
1030+
#### Electrum or Esplora
1031+
1032+
Alternatively, you can use LDK's [`lightning-transaction-sync`](https://docs.rs/lightning-transaction-sync/*/lightning_transaction_sync/) crate. This provides utilities for syncing LDK via the transaction-based [`Confirm`](https://docs.rs/lightning/*/lightning/chain/trait.Confirm.html)interface.
10091033

1034+
**Example:**
1035+
1036+
<CodeSwitcher :languages="{rust:'Rust', kotlin:'Kotlin', swift:'Swift'}">
1037+
<template v-slot:rust>
10101038

1011-
````
1039+
```rust
1040+
let tx_sync = Arc::new(EsploraSyncClient::new(
1041+
esplora_server_url,
1042+
Arc::clone(&some_logger),
1043+
));
1044+
1045+
let chain_monitor = Arc::new(ChainMonitor::new(
1046+
Some(Arc::clone(&tx_sync)),
1047+
Arc::clone(&some_broadcaster),
1048+
Arc::clone(&some_logger),
1049+
Arc::clone(&some_fee_estimator),
1050+
Arc::clone(&some_persister),
1051+
));
1052+
1053+
let channel_manager = Arc::new(ChannelManager::new(
1054+
Arc::clone(&some_fee_estimator),
1055+
Arc::clone(&chain_monitor),
1056+
Arc::clone(&some_broadcaster),
1057+
Arc::clone(&some_router),
1058+
Arc::clone(&some_logger),
1059+
Arc::clone(&some_entropy_source),
1060+
Arc::clone(&some_node_signer),
1061+
Arc::clone(&some_signer_provider),
1062+
user_config,
1063+
chain_params,
1064+
));
1065+
1066+
let confirmables = vec![
1067+
&*channel_manager as &(dyn Confirm + Sync + Send),
1068+
&*chain_monitor as &(dyn Confirm + Sync + Send),
1069+
];
1070+
1071+
tx_sync.sync(confirmables).unwrap();
1072+
```
10121073

10131074
</template>
10141075

10151076
<template v-slot:kotlin>
10161077

10171078
```java
1018-
// Electrum/Esplora
1019-
10201079
// Retrieve transaction IDs to check the chain for un-confirmation.
10211080
val relevantTxIdsFromChannelManager: Array<ByteArray> = channelManager .as_Confirm().get_relevant_txids()
10221081
val relevantTxIdsFromChannelManager: Array<ByteArray> = chainMonitor.as_Confirm().get_relevant_txids()
@@ -1062,8 +1121,6 @@ channelManagerConstructor.chain_sync_completed(customEventHandler);
10621121
<template v-slot:swift>
10631122

10641123
```Swift
1065-
// Electrum/Esplora
1066-
10671124
// Retrieve transaction IDs to check the chain for un-confirmation.
10681125
let relevantTxIds1 = channelManager?.asConfirm().getRelevantTxids() ?? []
10691126
let relevantTxIds2 = chainMonitor?.asConfirm().getRelevantTxids() ?? []
@@ -1118,25 +1175,6 @@ channelManagerConstructor.chainSyncCompleted(persister: channelManagerPersister)
11181175

11191176
</CodeSwitcher>
11201177

1121-
**Implementation notes:**
1122-
1123-
There are 2 main options for synchronizing to chain on startup:
1124-
1125-
**Full Blocks or BIP 157/158**
1126-
1127-
If you are connecting full blocks or using BIP 157/158, then it is recommended to use
1128-
LDK's `lightning_block_sync` crate as in the example above: the high-level steps that must be done for both `ChannelManager` and each `ChannelMonitor` are as follows:
1129-
1130-
1. Get the last blockhash that each object saw.
1131-
- Receive the latest block hash when through [deserializtion](https://docs.rs/lightning/*/lightning/ln/channelmanager/struct.ChannelManagerReadArgs.html) of the `ChannelManager` via `read()`
1132-
- Each `ChannelMonitor`'s is in `channel_manager.channel_monitors`, as the 2nd element in each tuple
1133-
2. For each object, if its latest known blockhash has been reorged out of the chain, then disconnect blocks using `channel_manager.as_Listen().block_disconnected(..)` or `channel_monitor.block_disconnected(..)` until you reach the last common ancestor with the main chain.
1134-
3. For each object, reconnect blocks starting from the common ancestor until it gets to your best known chain tip using `channel_manager.as_Listen().block_connected(..)` and/or `channel_monitor.block_connected(..)`.
1135-
4. Call `channel_manager.chain_sync_completed(..)` to complete the initial sync process.
1136-
1137-
**Electrum/Esplora**
1138-
1139-
Alternatively, you can use LDK's `lightning-transaction-sync` crate. This provides utilities for syncing LDK via the transaction-based `Confirm` interface.
11401178

11411179
### Optional: Initialize `P2PGossipSync or RapidGossipSync`
11421180

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /