Skip to content

Commit

Permalink
fundchannel_start / openchannel_init: add a channel_type parameter to…
Browse files Browse the repository at this point in the history
… force channel type.

And add request schemas for openchannel_init and fundchannel_start.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `fundchannel_start` and `openchannel_init` now take an optional `channel_type` parameter.
  • Loading branch information
rustyrussell committed Jan 29, 2024
1 parent a943a53 commit e749aeb
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 30 deletions.
6 changes: 4 additions & 2 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ def fundchannel(self, node_id, amount, feerate=None, announce=True,
return self.call("fundchannel", payload)

def fundchannel_start(self, node_id, amount, feerate=None, announce=True,
close_to=None, mindepth: Optional[int] = None):
close_to=None, mindepth: Optional[int] = None, channel_type=None):
"""
Start channel funding with {id} for {amount} satoshis
with feerate of {feerate} (uses default feerate if unset).
Expand All @@ -804,6 +804,7 @@ def fundchannel_start(self, node_id, amount, feerate=None, announce=True,
"announce": announce,
"close_to": close_to,
"mindepth": mindepth,
"channel_type": channel_type,
}
return self.call("fundchannel_start", payload)

Expand Down Expand Up @@ -1104,7 +1105,7 @@ def pay(self, bolt11, amount_msat=None, label=None, riskfactor=None,
}
return self.call("pay", payload)

def openchannel_init(self, node_id, channel_amount, psbt, feerate=None, funding_feerate=None, announce=True, close_to=None, request_amt=None, *args, **kwargs):
def openchannel_init(self, node_id, channel_amount, psbt, feerate=None, funding_feerate=None, announce=True, close_to=None, request_amt=None, channel_type=None):
"""Initiate an openchannel with a peer """
payload = {
"id": node_id,
Expand All @@ -1115,6 +1116,7 @@ def openchannel_init(self, node_id, channel_amount, psbt, feerate=None, funding_
"announce": announce,
"close_to": close_to,
"request_amt": request_amt,
"channel_type": channel_type,
}
return self.call("openchannel_init", payload)

Expand Down
17 changes: 16 additions & 1 deletion doc/lightning-fundchannel_start.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-fundchannel\_start -- Command for initiating channel establishment for
SYNOPSIS
--------

**fundchannel\_start** *id* *amount* [*feerate* *announce* *close\_to* *push\_msat*]
**fundchannel\_start** *id* *amount* [*feerate*] [*announce*] [*close\_to*] [*push\_msat*] [*channel\_type*]

DESCRIPTION
-----------
Expand Down Expand Up @@ -34,6 +34,21 @@ open. Note that this is a gift to the peer -- these satoshis are
added to the initial balance of the peer at channel start and are largely
unrecoverable once pushed.

*channel\_type* *(added v24.02)* is an array of bit numbers, representing the explicit
channel type to request. BOLT 2 defines the following value types:

```
The currently defined basic types are:
- no features (no bits set) `[]`
- `option_static_remotekey` (`[12]`)
- `option_anchor_outputs` and `option_static_remotekey` (`[20, 12]`)
- `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` ([22, 12])
Each basic type has the following variations allowed:
- `option_scid_alias` ([46])
- `option_zeroconf` ([50])
```

Note that the funding transaction MUST NOT be broadcast until after
channel establishment has been successfully completed by running
`fundchannel_complete`, as the commitment transactions for this channel
Expand Down
15 changes: 14 additions & 1 deletion doc/lightning-openchannel_init.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-openchannel\_init -- Command to initiate a channel to a peer
SYNOPSIS
--------

**openchannel\_init** *id* *amount* *initalpsbt* [*commitment\_feerate*] [*funding\_feerate*] [*announce*] [*close\_to*] [*request\_amt*] [*compact\_lease*]
**openchannel\_init** *id* *amount* *initalpsbt* [*commitment\_feerate*] [*funding\_feerate*] [*announce*] [*close\_to*] [*request\_amt*] [*compact\_lease*] [*channel\_type*]

DESCRIPTION
-----------
Expand Down Expand Up @@ -47,6 +47,19 @@ much liquidity into the channel. Must also pass in *compact\_lease*.
channel lease terms. If the peer's terms don't match this set, we will
fail to open the channel.

*channel\_type* *(added v24.02)* is an array of bit numbers, representing the explicit
channel type to request. BOLT 2 defines the following value types:

The currently defined basic types are:
- no features (no bits set) `[]`
- `option_static_remotekey` (`[12]`)
- `option_anchor_outputs` and `option_static_remotekey` (`[20, 12]`)
- `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` ([22, 12])

Each basic type has the following variations allowed:
- `option_scid_alias` ([46])
- `option_zeroconf` ([50])
```
RETURN VALUE
------------
Expand Down
43 changes: 43 additions & 0 deletions doc/schemas/fundchannel_start.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"id",
"amount"
],
"properties": {
"id": {
"type": "pubkey"
},
"amount": {
"type": "msat"
},
"feerate": {
"type": "feerate"
},
"announce": {
"type": "boolean"
},
"close_to": {
"type": "hex"
},
"push_msat": {
"type": "msat"
},
"mindepth": {
"type": "u32"
},
"reserve": {
"type": "msat"
},
"channel_type": {
"type": "array",
"description": "Each bit set in this channel_type",
"items": {
"type": "u32",
"description": "Bit number"
}
}
}
}
47 changes: 47 additions & 0 deletions doc/schemas/openchannel_init.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"id",
"amount",
"initialpsbt"
],
"properties": {
"id": {
"type": "pubkey"
},
"amount": {
"type": "msat"
},
"initialpsbt": {
"type": "string"
},
"commitment_feerate": {
"type": "feerate"
},
"funding_feerate": {
"type": "feerate"
},
"announce": {
"type": "boolean"
},
"close_to": {
"type": "hex"
},
"request_amt": {
"type": "msat"
},
"compact_lease": {
"type": "hex"
},
"channel_type": {
"type": "array",
"description": "Each bit set in this channel_type",
"items": {
"type": "u32",
"description": "Bit number"
}
}
}
}
1 change: 1 addition & 0 deletions lightningd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ LIGHTNINGD_COMMON_OBJS := \
common/invoice_path_id.o \
common/key_derive.o \
common/keyset.o \
common/json_channel_type.o \
common/json_filter.o \
common/json_param.o \
common/json_parse.o \
Expand Down
14 changes: 13 additions & 1 deletion lightningd/dual_open_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/blockheight_states.h>
#include <common/json_channel_type.h>
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/psbt_open.h>
Expand Down Expand Up @@ -3031,6 +3032,7 @@ static struct command_result *json_openchannel_init(struct command *cmd,
struct open_attempt *oa;
struct lease_rates *rates;
struct command_result *res;
struct channel_type *ctype;
int fds[2];

if (!param_check(cmd, buffer, params,
Expand All @@ -3043,6 +3045,7 @@ static struct command_result *json_openchannel_init(struct command *cmd,
p_opt("close_to", param_bitcoin_address, &our_upfront_shutdown_script),
p_opt_def("request_amt", param_sat, &request_amt, AMOUNT_SAT(0)),
p_opt("compact_lease", param_lease_hex, &rates),
p_opt("channel_type", param_channel_type, &ctype),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -3103,6 +3106,14 @@ static struct command_result *json_openchannel_init(struct command *cmd,
"by peer");
}

if (ctype &&
!channel_type_accept(tmpctx,
ctype->features,
cmd->ld->our_features)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"channel_type not supported");
}

/* BOLT #2:
* - if both nodes advertised `option_support_large_channel`:
* - MAY set `funding_satoshis` greater than or equal to 2^24 satoshi.
Expand Down Expand Up @@ -3194,6 +3205,7 @@ static struct command_result *json_openchannel_init(struct command *cmd,
NULL : request_amt,
get_block_height(cmd->ld->topology),
false,
ctype,
rates);

/* Start dualopend! */
Expand Down Expand Up @@ -3765,7 +3777,7 @@ static struct command_result *json_queryrates(struct command *cmd,
NULL : request_amt,
get_block_height(cmd->ld->topology),
true,
NULL);
NULL, NULL);

if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
return command_fail(cmd, FUND_MAX_EXCEEDED,
Expand Down
14 changes: 13 additions & 1 deletion lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <common/blockheight_states.h>
#include <common/configdir.h>
#include <common/fee_states.h>
#include <common/json_channel_type.h>
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/memleak.h>
Expand Down Expand Up @@ -1148,6 +1149,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
struct amount_msat *push_msat;
u32 *upfront_shutdown_script_wallet_index;
struct channel_id tmp_channel_id;
struct channel_type *ctype;

fc->cmd = cmd;
fc->cancels = tal_arr(fc, struct command *, 0);
Expand All @@ -1164,9 +1166,18 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
p_opt("push_msat", param_msat, &push_msat),
p_opt_def("mindepth", param_u32, &mindepth, cmd->ld->config.anchor_confirms),
p_opt("reserve", param_sat, &reserve),
p_opt("channel_type", param_channel_type, &ctype),
NULL))
return command_param_failed();

if (ctype &&
!channel_type_accept(tmpctx,
ctype->features,
cmd->ld->our_features)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"channel_type not supported");
}

if (push_msat && amount_msat_greater_sat(*push_msat, *amount))
return command_fail(cmd, FUND_CANNOT_AFFORD,
"Requested to push_msat of %s is greater than "
Expand Down Expand Up @@ -1307,7 +1318,8 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
unilateral_feerate(cmd->ld->topology, true),
&tmp_channel_id,
fc->channel_flags,
fc->uc->reserve);
fc->uc->reserve,
ctype);

if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
return command_fail(cmd, FUND_MAX_EXCEEDED,
Expand Down
8 changes: 7 additions & 1 deletion openingd/dualopend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,7 @@ static void opener_start(struct state *state, u8 *msg)
struct amount_sat *requested_lease;
size_t locktime;
u32 nonanchor_feerate, anchor_feerate;
struct channel_type *ctype;

if (!fromwire_dualopend_opener_init(state, msg,
&tx_state->psbt,
Expand All @@ -2965,6 +2966,7 @@ static void opener_start(struct state *state, u8 *msg)
&requested_lease,
&tx_state->blockheight,
&dry_run,
&ctype,
&expected_rates))
master_badmsg(WIRE_DUALOPEND_OPENER_INIT, msg);

Expand All @@ -2981,9 +2983,13 @@ static void opener_start(struct state *state, u8 *msg)
* - SHOULD NOT set it to a type containing a feature which was not
* negotiated.
*/
state->channel_type = default_channel_type(state,
if (ctype) {
state->channel_type = ctype;
} else {
state->channel_type = default_channel_type(state,
state->our_features,
state->their_features);
}
open_tlv->channel_type = state->channel_type->features;

/* Given channel type, which feerate do we use? */
Expand Down
1 change: 1 addition & 0 deletions openingd/dualopend_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ msgdata,dualopend_opener_init,channel_flags,u8,
msgdata,dualopend_opener_init,requested_sats,?amount_sat,
msgdata,dualopend_opener_init,blockheight,u32,
msgdata,dualopend_opener_init,dry_run,bool,
msgdata,dualopend_opener_init,channel_type,?channel_type,
# must go last because embedded tu32
msgdata,dualopend_opener_init,expected_rates,?lease_rates,

Expand Down
Loading

0 comments on commit e749aeb

Please sign in to comment.