Skip to content

Commit a5e7c5c

Browse files
author
Conor Okus
committed
Adds P2PGossip Sync docs
1 parent ff4eae2 commit a5e7c5c

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

docs/tutorials/building-a-node-with-ldk/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building a Node with LDK
22

3-
## Learn how to build a basic LDK node from scratch using LDK
3+
## Learn how to build a basic LDK node from scratch
44

55
::: tip Note
66
For an integrated example of an LDK node in Rust, see the [Sample Node](https://github.com/lightningdevkit/ldk-sample)

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

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ There are a few dependencies needed to get this working. Let's walk through sett
7070

7171
### Step 1. Initialize the `FeeEstimator`
7272

73+
**What it's used for:** estimating fees for on-chain transactions that LDK wants broadcasted.
74+
7375
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin'}">
7476
<template v-slot:rust>
7577

@@ -130,8 +132,6 @@ There are a few dependencies needed to get this working. Let's walk through sett
130132
</template>
131133
</CodeSwitcher>
132134

133-
**What it's used for:** estimating fees for on-chain transactions that LDK wants broadcasted.
134-
135135
**Implementation notes:**
136136
1. Fees must be returned in: satoshis per 1000 weight units
137137
2. Fees must be no smaller than 253 (equivalent to 1 satoshi/vbyte, rounded up)
@@ -342,7 +342,7 @@ retrieving fresh ones every time
342342
</template>
343343
</CodeSwitcher>
344344

345-
<CodeSwitcher :languages="{rust:'Using LDK Sample Filesystem Persistence Module'}">
345+
<CodeSwitcher :languages="{rust:'Using LDK Sample Filesystem Persistence Module in Rust'}">
346346
<template v-slot:rust>
347347

348348
```rust
@@ -985,4 +985,69 @@ Otherwise, you can use LDK's `Confirm` interface as in the examples above. The h
985985

986986
**Dependencies:**
987987
* `ChainMonitor`, set of `ChannelMonitor`s and their funding outpoints
988-
* Step 9 must be completed prior to this step
988+
* Step 9 must be completed prior to this step
989+
990+
### Step 11: Optional: Initialize the `P2PGossipSync`
991+
992+
**You must follow this step if:** you need LDK to provide routes for sending payments (i.e. you are *not* providing your own routes)
993+
994+
**What it's used for:** generating routes to send payments over
995+
996+
**Example:** initializing `P2PGossipSync`
997+
998+
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin'}">
999+
1000+
<template v-slot:rust>
1001+
1002+
```rust
1003+
let genesis = genesis_block(Network::Testnet).header.block_hash();
1004+
let network_graph_path = format!("{}/network_graph", ldk_data_dir.clone());
1005+
let network_graph = Arc::new(disk::read_network(Path::new(&network_graph_path), genesis, logger.clone()));
1006+
let gossip_sync = Arc::new(P2PGossipSync::new(
1007+
Arc::clone(&network_graph),
1008+
None::<Arc<dyn chain::Access + Send + Sync>>,
1009+
logger.clone(),
1010+
));
1011+
```
1012+
1013+
</template>
1014+
1015+
<template v-slot:java>
1016+
1017+
```java
1018+
Network network = Network.LDKNetwork_Testnet;
1019+
1020+
BestBlock genesisBlock = BestBlock.from_genesis(network);
1021+
final byte[] genesisBlockHash = genesisBlock.block_hash();
1022+
1023+
final byte[] serializedNetworkGraph = // Read network graph bytes from file
1024+
final NetworkGraph networkGraph = NetworkGraph.read(serializedNetworkGraph, logger);
1025+
final P2PGossipSync p2pGossip = P2PGossipSync.of(networkGraph, Option_AccessZ.none(), logger)
1026+
```
1027+
1028+
</template>
1029+
1030+
<template v-slot:kotlin>
1031+
1032+
```kotlin
1033+
val genesisBlock : BestBlock = BestBlock.from_genesis(Network.LDKNetwork_Testnet)
1034+
val genesisBlockHash : String = byteArrayToHex(genesisBlock.block_hash())
1035+
1036+
val serializedNetworkGraph = // Read network graph bytes from file
1037+
val networkGraph : NetworkGraph = NetworkGraph.read(serializedNetworkGraph, logger)
1038+
val p2pGossip : P2PGossipSync = P2PGossipSync.of(networkGraph, Option_AccessZ.none(), logger)
1039+
```
1040+
1041+
</template>
1042+
1043+
1044+
</CodeSwitcher>
1045+
1046+
1047+
**Implementation notes:** this struct is not required if you are providing your own routes. It will be used internally in `ChannelManager` to build a `NetworkGraph`. Other networking options are: `LDKNetwork_Bitcoin`, `LDKNetwork_Regtest` and `LDKNetwork_Testnet`
1048+
1049+
**Dependencies:** `Logger`
1050+
1051+
**Optional dependency:** `Access`, a source of chain information. Recommended to be able to verify channels before adding them to the internal network graph.
1052+
1053+
**References:** [Rust `P2PGossipSync` docs](https://docs.rs/lightning/*/lightning/routing/gossip/struct.P2PGossipSync.html), [`Access` docs](https://docs.rs/lightning/*/lightning/chain/trait.Access.html), [Java `P2PGossipSync` docs](https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/P2PGossipSync.java)

0 commit comments

Comments
 (0)