Skip to content

Commit d55fc06

Browse files
V1 complete minus more links in guide
1 parent e8fe207 commit d55fc06

File tree

12 files changed

+267
-58
lines changed

12 files changed

+267
-58
lines changed

docs/custom_blockdata.md renamed to docs/blockdata.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: custom_blockdata
2+
id: blockdata
33
title: Blockchain Data
44
---
55

docs/build_node.md

Lines changed: 120 additions & 45 deletions
Large diffs are not rendered by default.

docs/custom_key_mgmt.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/getting_started.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,55 @@
22
id: getting_started
33
title: Getting Started
44
---
5+
import useBaseUrl from '@docusaurus/useBaseUrl';
56

6-
TODO
7+
## Introduction
8+
9+
This guide will give an entrypoint to LDK as a whole, an introduction to the architecture of LDK and what
10+
batteries need to be plugged into it to get it working. These batteries
11+
can be supplied by the user or by one of LDK's sample modules.
12+
13+
## How To Use These Docs
14+
"Getting Started" + "Overview" provide an introduction to the architecture and
15+
design philosophy of LDK.
16+
17+
"Build a Node: Checklist" walks through how to specifically integrate LDK into
18+
your application, as well as documentation for what features are currently available
19+
and not available for LDK in Java. "Opening a Channel" is a follow-up to "Build a Node"
20+
that walks through an example of opening a channel with LDK.
21+
22+
"Key Management", "Spending On-Chain Funds", and "Block Data" dive into more depth on their topics.
23+
24+
Throughout these docs, if any piece of code is used or mentioned, the most in-depth docs can be
25+
found by searching [the Rust docs](https://docs.rs/lightning/0.0.12/lightning/index.html).
26+
27+
## Architecture
28+
<img alt="LDK Architecture" src={useBaseUrl('img/ldk_arch.svg')} />
29+
30+
The big blue box in the center contains all of LDK's core objects.
31+
32+
The green boxes and Data Storage are all of LDK's batteries that must be provided.
33+
34+
## LDK Batteries
35+
36+
This section will be updated as support for LDK batteries changes.
37+
* Networking (lightning-net-tokio in the diagram)
38+
* Sample modules are available in [Rust](https://github.com/rust-bitcoin/rust-lightning/tree/main/lightning-net-tokio) and [Java](https://github.com/lightningdevkit/ldk-garbagecollected/tree/main/src/main/java/org/ldk/batteries)
39+
* KeysManager
40+
* LDK supplies an implementation called [KeysManager](https://docs.rs/lightning/0.0.10/lightning/chain/keysinterface/struct.KeysManager.html)
41+
* Data storage
42+
* sample module is available in [Rust](https://github.com/rust-bitcoin/rust-lightning/tree/main/lightning-persister)
43+
* BlockSource
44+
* sample module is almost available in [Rust](https://github.com/rust-bitcoin/rust-lightning/pull/763)
45+
* Randomness
46+
* currently only supplied by the user
47+
* FeeEstimator
48+
* currently only supplied by the user
49+
* TxFilter
50+
* currently only supplied by the user
51+
* TxBroadcaster
52+
* currently only supplied by the user
53+
54+
EventHandler in the diagram is not so much a necessary LDK battery, but instead
55+
refers to the fact that LDK generates events that the user should handle (e.g.
56+
the `PaymentReceived` event).

docs/key_mgmt.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
id: key_mgmt
3+
title: Key Management
4+
---
5+
Relevant reference: https://docs.rs/lightning/0.0.12/lightning/chain/keysinterface/struct.KeysManager.html
6+
7+
LDK Private Key Information is primarily provided through the `chain::keysinterface::KeysInterface` trait. It includes a few basic methods to get public and private key information, as well as a method to get an instance of a second trait which provides per-channel information - `chain::keysinterface::ChannelKeys`. While a custom `KeysInterface` implementation allows simple flexibility to control derivation of private keys, `ChannelKeys` focuses on signing lightning transactions and is primarily useful if you want to store private key material on a separate device which enforces lightning protocol details.
8+
A simple implementation of `KeysInterface` is provided in the form of `chain::keysinterface::KeysManager`, see its documentation for more details on its key derivation. It uses `chain::keysinterface::InMemoryChannelKeys` for channel signing, which is likely an appropriate signer for custom `KeysInterface` implementations as well.
9+
A `KeysManager` can be constructed simply with only a 32-byte seed and some integers which ensure uniqueness across restarts (defined as `starting_time_secs` and `starting_time_nanos`).
10+
```rust
11+
let mut random_32_bytes = [0; 32];
12+
// Fill in random_32_bytes with secure random data, or, on restart, reload the seed from disk.
13+
let start_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
14+
let keys_interface_impl = lightning::chain::keysinterface::KeysManager::new(random_32-bytes, bitcoin::network::constants::Network::Bitcoin, start_time.as_secs(), start_time.subsec_nanos());
15+
```

docs/onchain_funds.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
id: onchain_funds
3+
title: "Spending On-chain Funds"
4+
---
5+
Relevant reference: search for any structs or methods mentioned in this article [here](https://docs.rs/lightning/0.0.12/lightning/index.html).
6+
7+
When a channel has been closed and some outputs on chain are spendable only by us, LDK provides a `util::events::Event::SpendableOutputs` event in return from `ChannelMonitor::get_and_clear_pending_events()`. It contains a list of `chain::keysinterface::SpendableOutputDescriptor` objects which describe the output and provide all necessary information to spend it. `ChannelKeys` objects provide a unique id via the `key_derivation_params` function, who's value is provided back to you in the `SpendableOutputs` objects. For users of a `KeysManager` object, you can re-construct the `InMemoryChannelKeys` object using this information and fetch the relevant private keys from that. A `SpendableOutputDescriptor::StaticOutput` element does not have this information as the output is sent to an output which used only `KeysInterface` data, not per-channel data.

docs/open_channel.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
id: open_channel
3+
title: "Opening a Channel with LDK"
4+
---
5+
6+
## Prerequisites
7+
See "Build a Node: Checklist" for preparing LDK to open a channel. This guide
8+
is a follow-up.
9+
10+
## Overview
11+
This guide is more of a walkthrough of a code snippet that shows the steps to
12+
open a channel with LDK.
13+
14+
```java
15+
// <insert code to connect to peer via NioPeerHandler.connect(byte[] their_node_id, SocketAddress remote)>
16+
17+
// Create the initial channel and make sure the result is successful.
18+
[]byte peer_node_pubkey = <peer node pubkey bytes>;
19+
Result_NoneAPIErrorZ create_channel_result = channel_manager.create_channel(
20+
peer_node_pubkey, 10000, 1000, 42, null);
21+
assert create_channel_result instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK;
22+
23+
// Ensure this generates a FundingGenerationReady event and that its fields are
24+
// sane.
25+
nio_peer_handler.check_events();
26+
Event[] events = channel_manager_events.get_and_clear_pending_events();
27+
assert events.length == 1;
28+
assert events[0] instanceof Event.FundingGenerationReady;
29+
assert ((Event.FundingGenerationReady) events[0]).channel_value_satoshis == 10000;
30+
assert ((Event.FundingGenerationReady) events[0]).user_channel_id == 42;
31+
byte[] funding_spk = ((Event.FundingGenerationReady) events[0]).output_script;
32+
assert funding_spk.length == 34 && funding_spk[0] == 0 && funding_spk[1] == 32; // P2WSH
33+
34+
// Generate the funding transaction for the channel based on the channel amount
35+
NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
36+
Transaction funding_tx = new Transaction(bitcoinj_net);
37+
funding_tx.addInput(new TransactionInput(bitcoinj_net, funding, new byte[0]));
38+
funding_tx.getInputs().get(0).setWitness(new TransactionWitness(2)); // Make sure we don't complain about lack of witness
39+
funding_tx.getInput(0).getWitness().setPush(0, new byte[]{0x1});
40+
funding_tx.addOutput(Coin.SATOSHI.multiply(10000), new Script(funding_spk));
41+
42+
// Give the funding transaction back to the channel manager.
43+
byte[] chan_id = ((Event.FundingGenerationReady) events[0]).temporary_channel_id;
44+
channel_manager.funding_transaction_generated(chan_id, OutPoint.constructor_new(
45+
funding_tx.getTxId().getReversedBytes(), (short) 0));
46+
47+
// Ensure that the funding transaction is then broadcasted.
48+
nio_peer_handler.check_events();
49+
events = channel_manager_events.get_and_clear_pending_events();
50+
assert events.length == 1;
51+
assert events[0] instanceof Event.FundingBroadcastSafe;
52+
assert ((Event.FundingBroadcastSafe) events[0]).user_channel_id == 42;
53+
54+
// Wait until a few blocks are mined, and then the channel is now open
55+
```

docs/overview.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ title: Overview
44
slug: /
55
---
66

7-
TODO
7+
LDK is a flexible lightning implementation with supporting batteries (or modules).
8+
The core lightning implementation is Rust-Lightning.
9+
10+
See the Rust-Lightning `README` for more overview: https://github.com/rust-bitcoin/rust-lightning
File renamed without changes.

docs/references.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ id: references
33
title: References
44
---
55

6-
TODO
6+
* Rust documentation: https://docs.rs/lightning/0.0.12/lightning/index.html
7+
These provide the most searchable and comprehensive documentation on LDK.
8+
If you're using Java and want more information on any method/struct/etc., searching
9+
the Rust docs for the Rust version of that struct/method is your best bet.
710

8-
API docs, current sample node partial implementations
11+
* Rust sample node: https://github.com/TheBlueMatt/rust-lightning-bitcoinrpc
12+
While this node is a little outdated, it's still a very useful reference for how to construct
13+
a lightning node using LDK.
14+
15+
* Swift LDK documentation: https://github.com/arik-so/SwiftLightning/tree/master/Documentation
16+
These docs are mainly geared towards how Swift could call LDK C bindings directly, but still may
17+
provide a useful overview of Rust Lightning in the context of language bindings.

sidebars.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
someSidebar: {
3-
'Lightning Development Kit': ['overview', 'getting_started', 'use_cases', 'language_bindings', 'references'],
4-
Guides: ['build_node', 'custom_persist', 'custom_key_mgmt', 'custom_blockdata'],
3+
'Lightning Development Kit': ['overview', 'getting_started', 'use_cases', 'references'],
4+
Guides: ['build_node', 'open_channel', 'key_mgmt', 'blockdata'],
55
},
66
};

static/img/ldk_arch.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)