Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@
"ipv6": 2,
"local socket": 0,
"torv2": 3,
"torv3": 4
"torv3": 4,
"websocket": 5
},
"PeerConnectDirection": {
"in": 0,
Expand Down
3 changes: 2 additions & 1 deletion cln-grpc/proto/node.proto

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

2 changes: 1 addition & 1 deletion cln-grpc/src/convert.rs

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

59 changes: 32 additions & 27 deletions cln-rpc/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,37 @@ pub struct ChannelOpenedNotification {
/// ['Direction of the connection']
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub enum ConnectDirection {
pub enum PeerConnectDirection {
#[serde(rename = "in")]
IN = 0,
#[serde(rename = "out")]
OUT = 1,
}

impl TryFrom<i32> for ConnectDirection {
impl TryFrom<i32> for PeerConnectDirection {
type Error = anyhow::Error;
fn try_from(c: i32) -> Result<ConnectDirection, anyhow::Error> {
fn try_from(c: i32) -> Result<PeerConnectDirection, anyhow::Error> {
match c {
0 => Ok(ConnectDirection::IN),
1 => Ok(ConnectDirection::OUT),
o => Err(anyhow::anyhow!("Unknown variant {} for enum ConnectDirection", o)),
0 => Ok(PeerConnectDirection::IN),
1 => Ok(PeerConnectDirection::OUT),
o => Err(anyhow::anyhow!("Unknown variant {} for enum PeerConnectDirection", o)),
}
}
}

impl ToString for ConnectDirection {
impl ToString for PeerConnectDirection {
fn to_string(&self) -> String {
match self {
ConnectDirection::IN => "IN",
ConnectDirection::OUT => "OUT",
PeerConnectDirection::IN => "IN",
PeerConnectDirection::OUT => "OUT",
}.to_string()
}
}

/// ['Type of connection (*torv2*/*torv3* only if **direction** is *out*)']
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub enum ConnectAddressType {
pub enum PeerConnectAddressType {
#[serde(rename = "local socket")]
LOCAL_SOCKET = 0,
#[serde(rename = "ipv4")]
Expand All @@ -85,30 +85,34 @@ pub enum ConnectAddressType {
TORV2 = 3,
#[serde(rename = "torv3")]
TORV3 = 4,
#[serde(rename = "websocket")]
WEBSOCKET = 5,
}

impl TryFrom<i32> for ConnectAddressType {
impl TryFrom<i32> for PeerConnectAddressType {
type Error = anyhow::Error;
fn try_from(c: i32) -> Result<ConnectAddressType, anyhow::Error> {
fn try_from(c: i32) -> Result<PeerConnectAddressType, anyhow::Error> {
match c {
0 => Ok(ConnectAddressType::LOCAL_SOCKET),
1 => Ok(ConnectAddressType::IPV4),
2 => Ok(ConnectAddressType::IPV6),
3 => Ok(ConnectAddressType::TORV2),
4 => Ok(ConnectAddressType::TORV3),
o => Err(anyhow::anyhow!("Unknown variant {} for enum ConnectAddressType", o)),
0 => Ok(PeerConnectAddressType::LOCAL_SOCKET),
1 => Ok(PeerConnectAddressType::IPV4),
2 => Ok(PeerConnectAddressType::IPV6),
3 => Ok(PeerConnectAddressType::TORV2),
4 => Ok(PeerConnectAddressType::TORV3),
5 => Ok(PeerConnectAddressType::WEBSOCKET),
o => Err(anyhow::anyhow!("Unknown variant {} for enum PeerConnectAddressType", o)),
}
}
}

impl ToString for ConnectAddressType {
impl ToString for PeerConnectAddressType {
fn to_string(&self) -> String {
match self {
ConnectAddressType::LOCAL_SOCKET => "LOCAL_SOCKET",
ConnectAddressType::IPV4 => "IPV4",
ConnectAddressType::IPV6 => "IPV6",
ConnectAddressType::TORV2 => "TORV2",
ConnectAddressType::TORV3 => "TORV3",
PeerConnectAddressType::LOCAL_SOCKET => "LOCAL_SOCKET",
PeerConnectAddressType::IPV4 => "IPV4",
PeerConnectAddressType::IPV6 => "IPV6",
PeerConnectAddressType::TORV2 => "TORV2",
PeerConnectAddressType::TORV3 => "TORV3",
PeerConnectAddressType::WEBSOCKET => "WEBSOCKET",
}.to_string()
}
}
Expand All @@ -123,13 +127,13 @@ pub struct ConnectAddress {
pub socket: Option<String>,
// Path `connect.address.type`
#[serde(rename = "type")]
pub item_type: ConnectAddressType,
pub item_type: PeerConnectAddressType,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ConnectNotification {
// Path `connect.direction`
pub direction: ConnectDirection,
pub direction: PeerConnectDirection,
pub address: ConnectAddress,
pub id: PublicKey,
}
Expand Down Expand Up @@ -190,14 +194,15 @@ impl ToString for ChannelStateChangedCause {
pub struct ChannelStateChangedNotification {
#[serde(skip_serializing_if = "Option::is_none")]
pub old_state: Option<ChannelState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub short_channel_id: Option<ShortChannelId>,
Comment on lines +197 to +198
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semver breaking change for cln-rpc.

// Path `channel_state_changed.cause`
pub cause: ChannelStateChangedCause,
// Path `channel_state_changed.new_state`
pub new_state: ChannelState,
pub channel_id: Sha256,
pub message: String,
pub peer_id: PublicKey,
pub short_channel_id: ShortChannelId,
pub timestamp: String,
}

Expand Down
8 changes: 7 additions & 1 deletion connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,13 @@ static void handle_pong_in(struct peer *peer, const u8 *msg)
/* Forward to gossipd */
static void handle_gossip_in(struct peer *peer, const u8 *msg)
{
u8 *gmsg = towire_gossipd_recv_gossip(NULL, &peer->id, msg);
u8 *gmsg;

/* We warn at 250000, drop at 500000 */
if (daemon_conn_queue_length(peer->daemon->gossipd) > 500000)
return;

gmsg = towire_gossipd_recv_gossip(NULL, &peer->id, msg);

/* gossipd doesn't log IO, so we log it here. */
status_peer_io(LOG_IO_IN, &peer->id, msg);
Expand Down
3 changes: 2 additions & 1 deletion contrib/msggen/msggen/gen/rpc/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from msggen.model import Service
from msggen.gen.generator import IGenerator
from msggen.gen.rpc.rust import gen_composite
from msggen.gen.grpc.util import notification_typename_overrides


class NotificationGenerator(IGenerator):
Expand Down Expand Up @@ -43,7 +44,7 @@ def generate(self, service: Service) -> None:
self.write("\n\n")

for notification in service.notifications:
_, resp_decl = gen_composite(notification.response, self.meta)
_, resp_decl = gen_composite(notification.response, self.meta, notification_typename_overrides)
self.write(resp_decl)

self.write("pub mod requests{\n")
Expand Down
45 changes: 25 additions & 20 deletions contrib/msggen/msggen/gen/rpc/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ def normalize_varname(field):
return field


def gen_field(field, meta):
def gen_field(field, meta, override=None):
if field.omit():
return ("", "")
if isinstance(field, CompositeField):
return gen_composite(field, meta)
return gen_composite(field, meta, override)
elif isinstance(field, EnumField):
return gen_enum(field, meta)
return gen_enum(field, meta, override)
elif isinstance(field, ArrayField):
return gen_array(field, meta)
return gen_array(field, meta, override)
elif isinstance(field, PrimitiveField):
return gen_primitive(field)
else:
raise TypeError(f"Unmanaged type {field}")


def gen_enum(e, meta):
def gen_enum(e, meta, override):
defi, decl = "", ""

if e.omit():
Expand All @@ -95,14 +95,21 @@ def gen_enum(e, meta):
if e.description != "":
decl += f"/// {e.description}\n"

if override is None:
message_name = e.typename.name
override = lambda x: x
typename = override(str(e.typename))
else:
typename = override(str(e.typename))
message_name = typename

if e.deprecated:
decl += "#[deprecated]\n"
decl += f"#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]\n#[allow(non_camel_case_types)]\npub enum {e.typename} {{\n"
decl += f"#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]\n#[allow(non_camel_case_types)]\npub enum {typename} {{\n"

m = meta["grpc-field-map"]
m2 = meta["grpc-enum-map"]

message_name = e.typename.name
assert not (message_name in m and message_name in m2)
if message_name in m:
m = m[message_name]
Expand Down Expand Up @@ -130,9 +137,9 @@ def gen_enum(e, meta):
# representation
decl += dedent(
f"""\
impl TryFrom<i32> for {e.typename} {{
impl TryFrom<i32> for {typename} {{
type Error = anyhow::Error;
fn try_from(c: i32) -> Result<{e.typename}, anyhow::Error> {{
fn try_from(c: i32) -> Result<{typename}, anyhow::Error> {{
match c {{
"""
)
Expand All @@ -141,16 +148,16 @@ def gen_enum(e, meta):
for v in sorted_variants:
norm = v.normalized()
# decl += f" #[serde(rename = \"{v}\")]\n"
decl += f" {m[str(v)]} => Ok({e.typename}::{norm}),\n"
decl += f" {m[str(v)]} => Ok({typename}::{norm}),\n"
else:
for i, v in enumerate(e.variants):
norm = v.normalized()
# decl += f" #[serde(rename = \"{v}\")]\n"
decl += f" {i} => Ok({e.typename}::{norm}),\n"
decl += f" {i} => Ok({typename}::{norm}),\n"

decl += dedent(
f"""\
o => Err(anyhow::anyhow!("Unknown variant {{}} for enum {e.typename}", o)),
o => Err(anyhow::anyhow!("Unknown variant {{}} for enum {typename}", o)),
}}
}}
}}
Expand All @@ -162,14 +169,14 @@ def gen_enum(e, meta):
# appear in the schemas.
decl += dedent(
f"""\
impl ToString for {e.typename} {{
impl ToString for {typename} {{
fn to_string(&self) -> String {{
match self {{
"""
)
for v in e.variants:
norm = v.normalized()
decl += f' {e.typename}::{norm} => "{norm}",\n'
decl += f' {typename}::{norm} => "{norm}",\n'
decl += dedent(
f"""\
}}.to_string()
Expand All @@ -179,8 +186,6 @@ def gen_enum(e, meta):
"""
)

typename = e.typename

if e.override() is not None:
decl = "" # No declaration if we have an override
typename = e.override()
Expand Down Expand Up @@ -220,10 +225,10 @@ def rename_if_necessary(original, name):
return f""


def gen_array(a, meta):
def gen_array(a, meta, override=None):
name = a.name.normalized().replace("[]", "")
logger.debug(f"Generating array field {a.name} -> {name} ({a.path})")
_, decl = gen_field(a.itemtype, meta)
_, decl = gen_field(a.itemtype, meta, override)

if a.override():
decl = "" # No declaration if we have an override
Expand Down Expand Up @@ -254,11 +259,11 @@ def gen_array(a, meta):
return (defi, decl)


def gen_composite(c, meta) -> Tuple[str, str]:
def gen_composite(c, meta, override=None) -> Tuple[str, str]:
logger.debug(f"Generating composite field {c.name} ({c.path})")
fields = []
for f in c.fields:
fields.append(gen_field(f, meta))
fields.append(gen_field(f, meta, override))
fields = sorted(fields)

r = "".join([f[1] for f in fields])
Expand Down
8 changes: 4 additions & 4 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35797,7 +35797,6 @@
"required": [
"peer_id",
"channel_id",
"short_channel_id",
"timestamp",
"new_state",
"cause",
Expand Down Expand Up @@ -35851,7 +35850,7 @@
"DUALOPEND_OPEN_COMMIT_READY"
],
"description": [
"The channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally.",
"The channel state, in particular \"CHANNELD_NORMAL\" and \"CHANNELD_AWAITING_SPLICE\" mean the channel can be used normally.",
"The deprecated value 'unknown' is also present for new channels: after v26.03 this field will be omitted instead."
],
"added": "pre-v0.10.1"
Expand All @@ -35875,7 +35874,7 @@
"DUALOPEND_OPEN_COMMIT_READY"
],
"description": [
"The channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
"The channel state, in particular \"CHANNELD_NORMAL\" and \"CHANNELD_AWAITING_SPLICE\" mean the channel can be used normally"
],
"added": "pre-v0.10.1"
},
Expand Down Expand Up @@ -35959,7 +35958,8 @@
"ipv4",
"ipv6",
"torv2",
"torv3"
"torv3",
"websocket"
],
"description": [
"Type of connection (*torv2*/*torv3* only if **direction** is *out*)"
Expand Down
Loading
Loading