channeld: Code to implement splicing

Update the lightningd <-> channeld interface with lots of new commands to needed to facilitate spicing.

Implement the channeld splicing protocol leveraging the interactivetx protocol.

Implement lightningd’s channel_control to support channeld in its splicing efforts.

Changelog-Added: Added the features to enable splicing & resizing of active channels.
This commit is contained in:
Dusty Daemon
2023-07-27 14:37:52 -07:00
committed by Rusty Russell
parent ebd0a3fd69
commit 4628e3ace8
88 changed files with 4560 additions and 644 deletions

View File

@@ -59,7 +59,8 @@ TEST_CHECK_DBSTMTS=[0|1] - When running blackbox tests, this will
Note: Only SQLite3.
TEST_DB_PROVIDER=[sqlite3|postgres] - Selects the database to use when running
blackbox tests.
EXPERIMENTAL_DUAL_FUND=[0|1] - Enable dual-funding tests.
EXPERIMENTAL_DUAL_FUND=[0|1] - Enable dual-funding tests.
EXPERIMENTAL_SPLICING=[0|1] - Enable splicing tests.
```
#### Troubleshooting

View File

@@ -131,6 +131,7 @@ Core Lightning Documentation
lightning-signinvoice <lightning-signinvoice.7.md>
lightning-signmessage <lightning-signmessage.7.md>
lightning-signpsbt <lightning-signpsbt.7.md>
lightning-splice_init <lightning-splice_init.7.md>
lightning-sql <lightning-sql.7.md>
lightning-staticbackup <lightning-staticbackup.7.md>
lightning-stop <lightning-stop.7.md>

View File

@@ -120,6 +120,9 @@ On success, an object is returned, containing:
- **experimental-dual-fund** (object, optional):
- **set** (boolean): `true` if set in config or cmdline
- **source** (string): source of configuration setting
- **experimental-splicing** (object, optional) *(added v23.08)*:
- **set** (boolean): `true` if set in config or cmdline
- **source** (string): source of configuration setting
- **experimental-onion-messages** (object, optional):
- **set** (boolean): `true` if set in config or cmdline
- **source** (string): source of configuration setting
@@ -298,6 +301,7 @@ On success, an object is returned, containing:
- **wallet** (string, optional): `wallet` field from config or cmdline default **deprecated, removal in v24.05**
- **large-channels** (boolean, optional): `large-channels` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-dual-fund** (boolean, optional): `experimental-dual-fund` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-splicing** (boolean, optional): `experimental-splicing` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-onion-messages** (boolean, optional): `experimental-onion-messages` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-offers** (boolean, optional): `experimental-offers` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-shutdown-wrong-funding** (boolean, optional): `experimental-shutdown-wrong-funding` field from config or cmdline, or default **deprecated, removal in v24.05**
@@ -467,4 +471,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:a40882cad0d889aa736a2932250102be43ae7e62b3d2429b26e0961e4c315f7b)
[comment]: # ( SHA256STAMP:8e7ec36b820cb17ecfc3066802bb07e159fffdd8dfe049d092b8f3b804e05588)

View File

@@ -26,7 +26,7 @@ On success, an object containing **channels** is returned. It is an array of ob
- **peer\_id** (pubkey): Node Public key
- **peer\_connected** (boolean): A boolean flag that is set to true if the peer is online
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "CHANNELD\_AWAITING\_SPLICE")
- **opener** (string): Who initiated the channel (one of "local", "remote")
- **features** (array of strings):
- BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_anchors\_zero\_fee\_htlc\_tx", "option\_scid\_alias", "option\_zeroconf")
@@ -49,11 +49,12 @@ On success, an object containing **channels** is returned. It is an array of ob
- **last\_feerate** (string, optional): For inflight opens, the most recent feerate used on the channel open
- **next\_feerate** (string, optional): For inflight opens, the next feerate we'll use for the channel open
- **next\_fee\_step** (u32, optional): For inflight opens, the next feerate step we'll use for the channel open
- **inflight** (array of objects, optional): Current candidate funding transactions (only for dual-funding):
- **inflight** (array of objects, optional): Current candidate funding transactions:
- **funding\_txid** (txid): ID of the funding transaction
- **funding\_outnum** (u32): The 0-based output number of the funding transaction which opens the channel
- **feerate** (string): The feerate for this funding transaction in per-1000-weight, with "kpw" appended
- **total\_funding\_msat** (msat): total amount in the channel
- **splice\_amount** (integer): The amouont of sats we're splicing in or out *(added v23.08)*
- **our\_funding\_msat** (msat): amount we have in the channel
- **scratch\_txid** (txid): The commitment transaction txid we would use if we went onchain now
- **close\_to** (hex, optional): scriptPubkey which we have to close to if we mutual close
@@ -195,4 +196,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>
[comment]: # ( SHA256STAMP:c530e39c9144b5fbef0f6474170865095bd7b4c48e6378fdb7f9a7697b909473)
[comment]: # ( SHA256STAMP:dade32248bd309f2514a237cb71be6ddbe12220e1b6899693a032b45b7980a01)

View File

@@ -89,6 +89,7 @@ On success, an object containing **peers** is returned. It is an array of objec
- **feerate** (string): The feerate for this funding transaction in per-1000-weight, with "kpw" appended
- **total\_funding\_msat** (msat): total amount in the channel
- **our\_funding\_msat** (msat): amount we have in the channel
- **splice\_amount** (integer): The amouont of sats we're splicing in or out *(added v23.08)*
- **scratch\_txid** (txid): The commitment transaction txid we would use if we went onchain now
- **close\_to** (hex, optional): scriptPubkey which we have to close to if we mutual close
- **private** (boolean, optional): if False, we will not announce this channel
@@ -398,4 +399,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightning/bolts/blob/master/09-features.md>
[comment]: # ( SHA256STAMP:c0d0cc8f083168fd76caa2430a7c7d27d72a5273c55fb14b0efcbcb7a87274f4)
[comment]: # ( SHA256STAMP:d75b5070288f26a39df39831212f40c397f1389e7c1765f22829d3f3389a56aa)

View File

@@ -0,0 +1,82 @@
lightning-splice\_init -- Command to initiate a channel to a peer
=====================================================================
SYNOPSIS
--------
**(WARNING: experimental-splicing only)**
**splice\_init** *channel\_id* *relative\_amount* [*initalpsbt*] [*feerate\_per\_kw*] [*force\_feerate*]
DESCRIPTION
-----------
`splice_init` is a low level RPC command which initiates a channel splice for a
given channel specified by `channel_id`.
*channel\_id* is the channel id of the channel to be spliced.
*relative\_amount* is a positive or negative amount of satoshis to add or
subtract from the channel.
*initalpsbt* is the (optional) base 64 encoded PSBT to begin with. If not
specified, one will be generated automatically.
*feerate\_per\_kw* is the miner fee we promise our peer to pay for our side of
the splice transaction. It is calculated by `feerate_per_kw` *
our\_bytes\_in\_splice\_tx / 1000.
*force\_feerate* is a boolean flag. By default splices will fail if the fee
provided looks too high. This is to protect against accidentally setting your
fee higher than intended. Set `force_feerate` to true to skip this saftey check.
Here is an example set of splice commands that will splice in 100,000 sats to
the first channel that comes out of `listpeerchannels`. The example assumes
you already have at least one confirmed channel.
```shell
RESULT=$(lightning-cli listpeerchannels)
CHANNEL_ID=$(echo $RESULT| jq -r ".channels[0].channel_id")
echo $RESULT
RESULT=$(lightning-cli fundpsbt -k satoshi=100000sat feerate=urgent startweight=800 excess_as_change=true)
INITIALPSBT=$(echo $RESULT | jq -r ".psbt")
echo $RESULT
RESULT=$(lightning-cli splice_init $CHANNEL_ID 100000 $INITIALPSBT)
PSBT=$(echo $RESULT | jq -r ".psbt")
echo $RESULT
RESULT=$(lightning-cli splice_update $CHANNEL_ID $PSBT)
PSBT=$(echo $RESULT | jq -r ".psbt")
echo $RESULT
RESULT=$(lightning-cli signpsbt $PSBT)
PSBT=$(echo $RESULT | jq -r ".signed_psbt")
echo $RESULT
lightning-cli splice_signed $CHANNEL_ID $PSBT
```
RETURN VALUE
------------
[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, an object is returned, containing:
- **psbt** (string): the (incomplete) PSBT of the splice transaction
[comment]: # (GENERATE-FROM-SCHEMA-END)
SEE ALSO
--------
AUTHOR
------
@dusty\_daemon
RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:40121e2e7b0db8c99de12b4fd086f58f63e0d6643b9da1c1697a34dd5057454e)

View File

@@ -271,6 +271,7 @@ The following tables are currently supported:
- `funding_outnum` (type `u32`, sqltype `INTEGER`)
- `feerate` (type `string`, sqltype `TEXT`)
- `total_funding_msat` (type `msat`, sqltype `INTEGER`)
- `splice_amount` (type `integer`, sqltype `INTEGER`)
- `our_funding_msat` (type `msat`, sqltype `INTEGER`)
- `scratch_txid` (type `txid`, sqltype `BLOB`)
- `close_to` (type `hex`, sqltype `BLOB`)
@@ -513,4 +514,4 @@ RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:094d94f4d2cfd8e8bdc99be8b692100d3cbd70ab3c297ed8e191c8d4a0f9b6a7)
[comment]: # ( SHA256STAMP:2f77078555f16a9dbee5f068d4d0ba18727aeb378be674cd96bf7c1554a74ce5)

View File

@@ -712,6 +712,16 @@ about whether to add funds or not to a proposed channel is handled
automatically by a plugin that implements the appropriate logic for
your needs. The default behavior is to not contribute funds.
* **experimental-splicing**
Specifying this enables support for the splicing protocol ([bolt][bolt] #863),
allowing both parties to dynamically adjust the size a channel. These changes
can be built interactively using PSBT and combined with other channel actions
including dual fund, additional channel splices, or generic transaction activity.
The operations will be bundled into a single transaction. The channel will remain
active while awaiting splice confirmation, however you can only spend the smaller
of the prior channel balance and the new one.
* **experimental-websocket-port**=*PORT*
Specifying this enables support for accepting incoming WebSocket

View File

@@ -402,6 +402,25 @@
}
}
},
"experimental-splicing": {
"added": "v23.08",
"type": "object",
"additionalProperties": false,
"required": [
"set",
"source"
],
"properties": {
"set": {
"type": "boolean",
"description": "`true` if set in config or cmdline"
},
"source": {
"type": "string",
"description": "source of configuration setting"
}
}
},
"experimental-onion-messages": {
"type": "object",
"additionalProperties": false,
@@ -1449,6 +1468,11 @@
"type": "boolean",
"description": "`experimental-dual-fund` field from config or cmdline, or default"
},
"experimental-splicing": {
"deprecated": "v23.08",
"type": "boolean",
"description": "`experimental-splicing` field from config or cmdline, or default"
},
"experimental-onion-messages": {
"deprecated": "v23.08",
"type": "boolean",

View File

@@ -41,7 +41,8 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"CHANNELD_AWAITING_SPLICE"
],
"description": "the channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
},
@@ -146,7 +147,7 @@
},
"inflight": {
"type": "array",
"description": "Current candidate funding transactions (only for dual-funding)",
"description": "Current candidate funding transactions",
"items": {
"type": "object",
"additionalProperties": false,
@@ -155,6 +156,7 @@
"funding_outnum",
"feerate",
"total_funding_msat",
"splice_amount",
"our_funding_msat",
"scratch_txid"
],
@@ -175,6 +177,11 @@
"type": "msat",
"description": "total amount in the channel"
},
"splice_amount": {
"type": "integer",
"added": "v23.08",
"description": "The amouont of sats we're splicing in or out"
},
"our_funding_msat": {
"type": "msat",
"description": "amount we have in the channel"

View File

@@ -273,6 +273,7 @@
"feerate",
"total_funding_msat",
"our_funding_msat",
"splice_amount",
"scratch_txid"
],
"properties": {
@@ -296,6 +297,11 @@
"type": "msat",
"description": "amount we have in the channel"
},
"splice_amount": {
"type": "integer",
"added": "v23.08",
"description": "The amouont of sats we're splicing in or out"
},
"scratch_txid": {
"type": "txid",
"description": "The commitment transaction txid we would use if we went onchain now"