# LDK Splicing Prototype
Note: Please feel free to add comments to this document! (login with github)

# About Splicing
Best starting point is Dusty Daemon's [lightningsplice.com](https://lightningsplice.com/) site.
**What is Splicing?**
Splicing can change the capacity of a channel, without closing it. It's possible to increase or decrease the capacity, by adding or removing some funds on-chain.
**Why Splicing?**
Splicing can be used for different goals. e.g.:
- For a routing node, splicing allows to increase the capacity of a well-performing channel (without closing it). It is even possible to move some funds to one channel to another in one go.
- For a LSP node -- wallet setup, the channel can be upgraded/downgraded as needed (alternative is to open an additional or close & reopen).
- For a LN + Onchain spending wallet experience it is possible to keep funds in LN, and send from it or receive to it on-chain using splicing (alternative is to keep them in separate 'pockets', or use Submarine Swap).
The main advantage is less on-chain operations (one instead of two in some use cases), but splicing also opens up new use cases (mentioned above).
The first implementation is/was in CLN, started by Dusty Daemon.
# Status of Splicing
## Specification
The splicing spec is quite mature, but not yet finalized. ([bolts PR #863](https://github.com/lightning/bolts/pull/863))
## Implementations
**Core Lightning**
CLN has released splicing implementation, experimental.
Released with `23.08` (Aug'23).
**Eclair/Phoenix (Acinq)**
Released, used in production, between their LSP node and the wallets. Not interoperable with other implementations.
(Versions: Lightning-kmp lib: version 1.5.0, Jul'23, Phoenix Android wallet release [2.0.0](https://github.com/ACINQ/phoenix/releases/tag/android-v2.0.0), Aug'23.)
# Splicing in [LDK](https://lightningdevkit.org/)
It is work-in-progress, on the 2023 Roadmap.
Tracking issue: https://github.com/lightningdevkit/rust-lightning/issues/1621
# News
- Nov 13: Splicing message definitions got merged (PR #2544)
- Oct 1: Phoenix iOS v2.0 released, bringing splicing to iOS as well.
- Aug 23: CLN splicing implementation released, release `23.08`.
- Aug 16: New Phoenix Android version 2.0 released, uses splicing internally.
- Aug 11: My [Nostr post on successful splice using ldk proto](https://primal.net/e/note1eae7aexsxajykslzz8xtn8tcn0mludsymfyert6cpr0v0sav3ajq5xtvcq)
- Jul'23: Client lib by Acinq, lightning-kmp, released with splicing support (v 1.5.0)
# LDK-Splicing prototype (by optout)
**Warning:** *This prototype is experimental code, using it will likely result in some funds lost!*
The current (`splicing-hapa2`) prototype is a rudimentary splicing implementation in LDK, aimed to be the basis for the final implementation.
Some of the simplifying assumptions:
- No quiscence is used/checked
- Happy path only, no complex combinations, no error scenarios
- TX negotiation messages are skipped, two simpler messages are used instead
**Repositories:**
- https://github.com/ldksplicing/ldk-spicing
- https://github.com/ldksplicing/ldk-sample
# Contact/Contribute
Please feel free to ask questions or give feedback:
- [Discord LDK channel](https://discord.gg/xaYE3pDQpm), channel #splicing (or #ldk-dev or #general)
- Nostr: optout@nostrplebs.com, [npub](https://primal.net/p/npub1kxgpwh80gp79j0chc925srk6rghw0akggduwau8fwdflslh9jvqqd3lecx)
- GitHub (repo links above)
# Prototype Details
## ldk-splicing
Contains the splice proto: required messages, new API `splice_channel`, and some events (e.g. `SpliceAcked`), and also a step-by-step functional test.
## ldk-sample
Exposes the splice functionality, through a new `splicein` command (`splicein <channel_id> <peer_pubkey> <add_amt_satoshis>`). Works on an existing channel, and adds some more funds to it.
## ldk-node
Currently not done, but it is planned to expose splicing functionality through ldk-node as well.
## Building modified LDK
- Clone https://github.com/ldksplicing/ldk-splicing
```
git clone https://github.com/ldksplicing/ldk-splicing
cd ldk-splicing
```
or alternatively you can use an existing LDK folder
```
cd rust-lightning
git remote add ldksplicing https://github.com/ldksplicing/ldk-splicing
git fetch ldksplicing
git checkout -b splicing -t ldksplicing/main
```
- Build it, simply with `cargo build`
- You can try or look a splicing use case test: `cargo test splic`
## Building modified `ldk-sample`
- Clone https://github.com/ldksplicing/ldk-splicing
```
git clone https://github.com/ldksplicing/ldk-sample
cd ldk-sample
```
- Modify `Cargo.toml` to point to locally built modified LDK.
Under `[dependencies]` replace the `lightning...` lines:
```
# To build against updated LDK built locally, you need to change the following 7 lines to the form:
# lightning = { path = "<RELATIVE_PATH_TO_LDK_FOLDER>/lightning", features = ["max_level_trace"] }
# instead of
# lightning = { version = "0.0.117", features = ["max_level_trace"] }
```
You need to do this for all lines (7 of them).
- Build: `cargo build`
- For running, you need a locally accessible Bitcoin Core node.
- Run: `cargo run <bitcoind-rpc-username>:<bitcoind-rpc-password>@<bitcoind-rpc-host>:<bitcoind-rpc-port> datadir1 19735 testnet`
After startup, type `help` command, you should see a `splicein` command:
```
COMMANDS:
Channels:
...
splicein <channel_id> <peer_pubkey> <add_amt_satoshis>
```
## End-to-end test between two `ldk-sample` instances
**Prerequisites:**
- A locally built modified LDK (`rust-lightning`); see above.
- A locally built modified `ldk-sample`, using modifed LDK; see above.
- a Bitcoin Core node on testnet, accessible through RPC, with a wallet loaded with some balance.
**Steps**
Start two shells (`S1:` and `S2:` indicate the shell):
```
S1: cd ldk-sample
S1: cargo run <bitcoind-rpc-username>:<bitcoind-rpc-password>@<bitcoind-rpc-host>:<bitcoind-rpc-port> datadir1 19735 testnet
S2: cd ldk-sample
S2: cargo run <bitcoind-rpc-username>:<bitcoind-rpc-password>@<bitcoind-rpc-host>:<bitcoind-rpc-port> datadir2 19745 testnet
--> note the 'Local Node ID' displayed
S1: openchannel <node-id-from-S2>@localhost:19745 8000
S1: listchannels
S1: splicein <channel-id-from-above> <node-id-from-S2> 2000
S1: listchannels
```
Sample output:
```
LDK startup successful. Enter "help" to view available commands. Press Ctrl-D to quit.
Local Node ID is 03b6d5..a0.
>
> openchannel 020ab1..5c@localhost:19745 3500
EVENT: initiated channel with peer 020ab1..5c.
EVENT: Channel 3a09ec..f3 with peer 020ab1..5c is pending awaiting funding lock-in!
EVENT: Channel 3a09ec..f3 with peer 020ab1..5c is ready to be used!
>
> listchannels
[
{
channel_id: 3a09ec..f3,
funding_txid: f2a439..3a,
peer_pubkey: 020ab1..5c,
is_channel_ready: true,
channel_value_satoshis: 3500,
},
]
>
> splicein 3a09ec..f3 020ab1..5c 2000
EVENT: initiated splice-in with add'l amount 2000 on channel 3a09ec..f3.
Debug SpliceAcked channel_id 3a09ec..f3 pre-post 3500 5500 curr funding f2a4397..3a 1
EVENT: Channel 3a09ec..f3 splicing tx created, from 3500 to 5500, txid ae8f28d4843f2d24ae0558b05841d2555ee70df0e404e7b37a18c85c56a6054a
>
> listchannels
[
{
channel_id: 3a09ec..f3,
funding_txid: ae8f28..4a,
peer_pubkey: 020ab1..5c,
is_channel_ready: false,
channel_value_satoshis: 5500,
},
]
>
> closechannel 3a09ec..f3 020ab1..5c
EVENT: initiating channel close
EVENT: Channel 3a09ec..f3 with counterparty 020ab1..5c closed due to: CooperativeClosure
>
> listchannels
[]
>
```