Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compulsory modern features, and open-by-channel-type APIs #6864

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
72c9282
lnprototest: update to origin/no-empty-channeltype for now.
rustyrussell Jan 23, 2024
520d098
docs: Fix missing escapes for underscores in multifundchannel docs
cdecker Jan 28, 2024
44098df
msggen: Make `ChannelTypeName` a native enum
cdecker Jan 28, 2024
d0dc014
lightningd: fix fd leak with check command on openchannel_init.
rustyrussell Jan 28, 2024
4a4a4de
lightningd: make option_data_loss_protect compulsory.
rustyrussell Jan 28, 2024
14a774c
lightningd: make option_gossip_queries compulsory.
rustyrussell Jan 28, 2024
d61fe89
openingd: correctly mark channel type zeroconf if negotiated and they…
rustyrussell Jan 28, 2024
3338d51
common: add param_channel_type helper.
rustyrussell Jan 28, 2024
5b6be37
common: channel_type_accept doesn't use `their_features`; remove para…
rustyrussell Jan 28, 2024
4b2fcca
fundchannel_start / openchannel_init: add a channel_type parameter to…
rustyrussell Jan 28, 2024
958693e
spenderp: add channel_type parameter to fundchannel / multifundchannel.
rustyrussell Jan 28, 2024
91ccc44
lightningd: add dev-any-channel-type to allow obsolete channel types.
rustyrussell Jan 28, 2024
13e6e38
lightningd: make option_static_remotekey compulsory.
rustyrussell Jan 28, 2024
ef14931
common: move json_add_channel_type from lightningd/
rustyrussell Jan 28, 2024
f80fdf7
dualopend: fix channel_type if we don't negotiate the default.
rustyrussell Jan 28, 2024
5bef40e
fundchannel_start & multifundchannel: add channel_type.
rustyrussell Jan 28, 2024
1022b5d
pytest: check that listpeerchannels gives the same channel type as re…
rustyrussell Jan 28, 2024
5241a03
openingd: make channel-type rejection message clearer.
rustyrussell Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,14 @@
"FetchInvoice.invoice": 1,
"FetchInvoice.next_period": 3
},
"FundchannelChannel_type": {
"FundChannel.channel_type.bits[]": 1,
"FundChannel.channel_type.names[]": 2
},
"FundchannelRequest": {
"FundChannel.amount": 1,
"FundChannel.announce": 3,
"FundChannel.channel_type[]": 14,
"FundChannel.close_to": 6,
"FundChannel.compact_lease": 8,
"FundChannel.feerate": 2,
Expand All @@ -753,6 +758,7 @@
},
"FundchannelResponse": {
"FundChannel.channel_id": 4,
"FundChannel.channel_type": 7,
"FundChannel.close_to": 5,
"FundChannel.mindepth": 6,
"FundChannel.outnum": 3,
Expand Down Expand Up @@ -3026,6 +3032,22 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"FundChannel.channel_type": {
"added": "v24.02",
"deprecated": false
},
"FundChannel.channel_type.bits[]": {
"added": "v24.02",
"deprecated": false
},
"FundChannel.channel_type.names[]": {
"added": "v24.02",
"deprecated": false
},
"FundChannel.channel_type[]": {
"added": "v24.02",
"deprecated": false
},
"FundChannel.close_to": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down
7 changes: 7 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cln-grpc/proto/primitives.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ message TlvEntry {
uint64 type = 1;
bytes value = 2;
}

message TlvStream {
repeated TlvEntry entries = 1;
}

enum ChannelTypeName {
static_remotekey_even = 0;
anchor_outputs_even = 1;
anchors_zero_fee_htlc_tx_even = 2;
scid_alias_even = 3;
zeroconf_even = 4;
}
16 changes: 16 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 74 additions & 11 deletions cln-rpc/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ pub enum HtlcState {
SENT_REMOVE_ACK_REVOCATION = 19,
}

#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
#[allow(non_camel_case_types)]
pub enum ChannelTypeName {
#[serde(rename = "static_remotekey/even")]
STATIC_REMOTEKEY_EVEN = 0,
#[serde(rename = "anchor_outputs/even")]
ANCHOR_OUTPUTS_EVEN = 1,
#[serde(rename = "anchors_zero_fee_htlc_tx/even")]
ANCHORS_ZERO_FEE_HTLC_TX_EVEN = 2,
#[serde(rename = "scid_alias/even")]
SCID_ALIAS_EVEN = 3,
#[serde(rename = "zeroconf/even")]
ZEROCONF_EVEN = 4,
}

#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
#[allow(non_camel_case_types)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -318,6 +333,31 @@ impl TryFrom<i32> for ChannelState {
}
}

impl From<i32> for ChannelTypeName {
fn from(value: i32) -> Self {
match value {
0 => ChannelTypeName::STATIC_REMOTEKEY_EVEN,
1 => ChannelTypeName::ANCHOR_OUTPUTS_EVEN,
2 => ChannelTypeName::ANCHORS_ZERO_FEE_HTLC_TX_EVEN,
3 => ChannelTypeName::SCID_ALIAS_EVEN,
4 => ChannelTypeName::ZEROCONF_EVEN,
o => panic!("Unmapped ChannelTypeName {}", o),
}
}
}

impl From<ChannelTypeName> for i32 {
fn from(value: ChannelTypeName) -> Self {
match value {
ChannelTypeName::STATIC_REMOTEKEY_EVEN => 0,
ChannelTypeName::ANCHOR_OUTPUTS_EVEN => 1,
ChannelTypeName::ANCHORS_ZERO_FEE_HTLC_TX_EVEN => 2,
ChannelTypeName::SCID_ALIAS_EVEN => 3,
ChannelTypeName::ZEROCONF_EVEN => 4,
}
}
}

impl From<i32> for HtlcState {
fn from(value: i32) -> Self {
match value {
Expand Down Expand Up @@ -470,13 +510,13 @@ impl TryFrom<&str> for Amount {

impl From<Amount> for String {
fn from(a: Amount) -> String {
// Best effort msat to sat conversion, for methods that accept
// sats but not msats
if a.msat % 1000 == 0 {
format!("{}sat", a.msat / 1000)
} else {
// Best effort msat to sat conversion, for methods that accept
// sats but not msats
if a.msat % 1000 == 0 {
format!("{}sat", a.msat / 1000)
} else {
format!("{}msat", a.msat)
}
}
}
}

Expand Down Expand Up @@ -553,6 +593,8 @@ impl Serialize for Feerate {

#[cfg(test)]
mod test {
use crate::model::responses::FundchannelResponse;

use super::*;

#[test]
Expand All @@ -564,11 +606,7 @@ mod test {

let tests = vec![
("{\"amount\": \"10msat\"}", Amount { msat: 10 }, "10msat"),
(
"{\"amount\": \"42sat\"}",
Amount { msat: 42_000 },
"42sat",
),
("{\"amount\": \"42sat\"}", Amount { msat: 42_000 }, "42sat"),
(
"{\"amount\": \"31337btc\"}",
Amount {
Expand Down Expand Up @@ -669,6 +707,31 @@ mod test {
let res = serde_json::to_string(&stream).unwrap();
assert_eq!(res, "{\"31337\":\"0102030405\",\"42\":\"\"}");
}

#[test]
fn test_fundchannel() {
let r = serde_json::json!({
"tx": "0000000000000000000000000000000000000000000000000000000000000000",
"txid": "0000000000000000000000000000000000000000000000000000000000000000",
"outnum": 0,
"channel_id": "0000000000000000000000000000000000000000000000000000000000000000",
"channel_type": {
"bits": [1, 3, 5],
"names": [
"static_remotekey/even",
"anchor_outputs/even",
"anchors_zero_fee_htlc_tx/even",
"scid_alias/even",
"zeroconf/even"
]
},
"close_to": "bc1qd23gerv2mn0qdecrmulsjsmkv8lz6t6m0770tg",
"mindepth": 1,
});

let p: FundchannelResponse = serde_json::from_value(r).unwrap();
assert_eq!(p.channel_type.unwrap().bits, Some(vec![1,3,5]));
}
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ COMMON_SRC_NOGEN := \
common/initial_commit_tx.c \
common/invoice_path_id.c \
common/iso4217.c \
common/json_channel_type.c \
common/json_filter.c \
common/json_param.c \
common/json_parse.c \
Expand Down
3 changes: 1 addition & 2 deletions common/channel_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ struct channel_type *channel_type_from(const tal_t *ctx,

struct channel_type *channel_type_accept(const tal_t *ctx,
const u8 *t,
const struct feature_set *our_features,
const u8 *their_features)
const struct feature_set *our_features)
{
struct channel_type *ctype, proposed;
/* Need to copy since we're going to blank variant bits for equality. */
Expand Down
3 changes: 1 addition & 2 deletions common/channel_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ bool channel_type_eq(const struct channel_type *a,
/* Return channel_type if this is acceptable, otherwise NULL */
struct channel_type *channel_type_accept(const tal_t *ctx,
const u8 *t,
const struct feature_set *our_features,
const u8 *their_features);
const struct feature_set *our_features);

/* Return an array of feature strings indicating channel type. */
const char **channel_type_name(const tal_t *ctx, const struct channel_type *t);
Expand Down
61 changes: 61 additions & 0 deletions common/json_channel_type.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "config.h"
#include <common/channel_type.h>
#include <common/json_channel_type.h>
#include <common/json_command.h>
#include <common/json_param.h>
#include <common/json_stream.h>

struct command_result *param_channel_type(struct command *cmd,
const char *name,
const char *buffer,
const jsmntok_t *tok,
struct channel_type **ctype)
{
u8 *features = tal_arr(NULL, u8, 0);
size_t i;
const jsmntok_t *t;

if (tok->type != JSMN_ARRAY) {
return command_fail_badparam(cmd, name, buffer, tok,
"must be an array");
}

json_for_each_arr(i, t, tok) {
u16 fbit;
if (!json_to_u16(buffer, t, &fbit))
return command_fail_badparam(cmd, name, buffer, t,
"must be a 16-bit integer");
set_feature_bit(&features, fbit);
}

*ctype = channel_type_from(cmd, take(features));
return NULL;
}

void json_add_channel_type(struct json_stream *response,
const char *fieldname,
const struct channel_type *channel_type)
{
const char **fnames;

json_object_start(response, fieldname);
json_add_channel_type_arr(response, "bits", channel_type);

json_array_start(response, "names");
fnames = channel_type_name(tmpctx, channel_type);
for (size_t i = 0; i < tal_count(fnames); i++)
json_add_string(response, NULL, fnames[i]);
json_array_end(response);
json_object_end(response);
}
void json_add_channel_type_arr(struct json_stream *response,
const char *fieldname,
const struct channel_type *ctype)
{
json_array_start(response, fieldname);
for (size_t i = 0; i < tal_bytelen(ctype->features)*8; i++) {
if (feature_is_set(ctype->features, i))
json_add_u32(response, NULL, i);
}
json_array_end(response);
}