From 8c7f50622d7390e283d8c0d51f92f6ffca99ba9a Mon Sep 17 00:00:00 2001 From: Conor Okus Date: Tue, 13 Feb 2024 22:17:40 -0500 Subject: [PATCH 1/3] Adds lightning-transaction-sync in favor of Confirm --- .../setting-up-a-channel-manager.md | 94 +++++++++++++------ 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/docs/building-a-node-with-ldk/setting-up-a-channel-manager.md b/docs/building-a-node-with-ldk/setting-up-a-channel-manager.md index 59f681bb6..753b13bcf 100644 --- a/docs/building-a-node-with-ldk/setting-up-a-channel-manager.md +++ b/docs/building-a-node-with-ldk/setting-up-a-channel-manager.md @@ -931,16 +931,18 @@ _after_ the `ChannelMonitor`s and `ChannelManager` are synced to the chain tip ( ### Sync `ChannelMonitor`s and `ChannelManager` to chain tip -**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 +**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. + +There are 2 main options for synchronizing to chain on startup: + +#### Full Blocks or BIP 157/158 (Compact Block Filters) **Example:** - + + + + +**Implementation notes:** + +If you are connecting full blocks or using BIP 157/158, then it is recommended to use +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: + +1. Get the last blockhash that each object saw. + - Receive the latest block hash when through [deserializtion](https://docs.rs/lightning/*/lightning/ln/channelmanager/struct.ChannelManagerReadArgs.html) of the `ChannelManager` via `read()` + - Each `ChannelMonitor`'s is in `channel_manager.channel_monitors`, as the 2nd element in each tuple +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. +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(..)`. +4. Call `channel_manager.chain_sync_completed(..)` to complete the initial sync process. + + +#### Electrum or Esplora + +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. +**Example:** + + +