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/tutorials/building-a-node-with-ldk/connect-to-peers.md
+36-14Lines changed: 36 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
# Connect to Peers
2
2
3
-
In this section you'll learn how to join the lightning network.
3
+
In this section you'll learn how to join the lightning network.
4
4
5
5
Firstly we need to have the ability to do high performance I/O operations. LDK provides default implementations for initializing all of your networking needs. If you are using Rust, you can use our simple socket handling library `lightning_net_tokio`. In Kotlin/Java you can use the `NioPeerHandler` which uses Java's NIO I/O interface.
6
6
7
7
**What it's used for**: making peer connections, facilitating peer data to and from LDK
Connections to other peers are established with `PeerManager`. You'll need to know the pubkey and address of another node that you want as a peer. Once the connection is established and the handshake is complete, `PeerManager` will show the peer's pubkey in its list of peers.
let createChannelResults = channelManager.createChannel(
70
+
theirNetworkKey: pubKey,
71
+
channelValueSatoshis: amount,
72
+
pushMsat: pushMsat,
73
+
userChannelId: userId,
74
+
overrideConfig: userConfig
75
+
)
76
+
```
77
+
78
+
</template>
79
+
54
80
</CodeSwitcher>
55
81
56
82
# FundingGenerationReady Event Handling
57
83
58
-
At this point, an outbound channel has been initiated with your peer and it will appear in `ChannelManager::list_channels`. However, the channel is not yet funded. Once your peer accepts the channel, you will be notified with a `FundingGenerationReady` event. It's then your responsibility to construct the funding transaction and pass it to ChannelManager, which will broadcast it once it receives your channel counterparty's signature.
84
+
At this point, an outbound channel has been initiated with your peer and it will appear in `ChannelManager::list_channels`. However, the channel is not yet funded. Once your peer accepts the channel, you will be notified with a `FundingGenerationReady` event. It's then your responsibility to construct the funding transaction and pass it to ChannelManager, which will broadcast it once it receives your channel counterparty's signature.
59
85
60
86
::: tip Note
61
87
62
88
Remember that the funding transaction must only spend SegWit inputs.
After crafting the funding transaction you'll need to send it to the Bitcoin network where it will hopefully be mined and added to the blockchain. You'll need to watch this transaction and wait for a minimum of 6 confirmations before the channel is ready to use.
Remember if you are restarting and have open channels then you should [let LDK know about the latest channel state.](./setting-up-a-channel-manager/#sync-channelmonitors-and-channelmanager-to-chain-tip)
216
-
217
-
:::
276
+
<templatev-slot:swift>
218
277
278
+
```Swift
279
+
// Using BDK (Bitcoin Dev Kit) to broadcast a transaction via the esplora client
print("Failed to broadcast transaction: \(error.localizedDescription)")
292
+
}
293
+
}
294
+
}
295
+
```
219
296
297
+
</template>
220
298
299
+
</CodeSwitcher>
221
300
301
+
::: tip Keep LDK in sync
222
302
303
+
Remember if you are restarting and have open channels then you should [let LDK know about the latest channel state.](./setting-up-a-channel-manager/#sync-channelmonitors-and-channelmanager-to-chain-tip)
0 commit comments