lightningd: add networkevents to wait API.
What changed, and why it matters
This commit adds a new 'networkevents' category to the existing 'wait' API, allowing users to subscribe to notifications about peer connection, ping, and disconnect events. It is a straightforward feature addition with no visible security defect.
No security action required; review as normal feature code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch extends the JSON-RPC wait subsystem to support ‘networkevents’ alongside existing subsystems like invoices, forwards, and channelmoves. It updates the schema definitions, the subsystem enum, and the response formatting logic. The C code also slightly refactors how details are emitted for newer subsystems and introduces a small helper convention for copying numeric values literally. There is no bug fix, bounds error, authentication change, or cryptographic modification.
Changed components
lightningd/wait.clightningd/wait.hdoc/schemas/wait.jsoncontrib/msggen/msggen/schema.jsonInspect captured patch +138 / −12
diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json
index 26b41277..ea392f40 100644
--- a/contrib/msggen/msggen/schema.json
+++ b/contrib/msggen/msggen/schema.json
@@ -34881,7 +34881,8 @@
" `forwards`: corresponding to `listforwards` (added in *v23.11*).",
" `htlcs`: corresponding to `listhtlcs` (added in *v25.05*).",
" `chainmoves`: corresponding to `listchainmoves` (added in *v25.09*).",
- " `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*)."
+ " `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*).",
+ " `networkevents`: corresponding to `listnetworkevents` (added in *v25.12*)."
],
"enum": [
"invoices",
@@ -34889,7 +34890,8 @@
"sendpays",
"htlcs",
"chainmoves",
- "channelmoves"
+ "channelmoves",
+ "networkevents"
]
},
"indexname": {
@@ -34928,7 +34930,8 @@
"sendpays",
"htlcs",
"chainmoves",
- "channelmoves"
+ "channelmoves",
+ "networkevents"
]
},
"created": {
@@ -34955,6 +34958,7 @@
"htlcs": {},
"chainmoves": {},
"channelmoves": {},
+ "networkevents": {},
"details": {}
},
"allOf": [
@@ -35504,6 +35508,62 @@
}
}
}
+ },
+ {
+ "if": {
+ "additionalProperties": true,
+ "properties": {
+ "subsystem": {
+ "type": "string",
+ "enum": [
+ "networkevents"
+ ]
+ }
+ }
+ },
+ "then": {
+ "additionalProperties": false,
+ "properties": {
+ "subsystem": {},
+ "created": {},
+ "updated": {},
+ "deleted": {},
+ "networkevents": {
+ "added": "v25.12",
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "created_index": {
+ "added": "v25.12",
+ "type": "u64",
+ "description": [
+ "The created_index of the record added/deleted"
+ ]
+ },
+ "type": {
+ "added": "v25.12",
+ "type": "string",
+ "enum": [
+ "connect",
+ "connect_fail",
+ "ping",
+ "disconnect"
+ ],
+ "description": [
+ "The kind of network event"
+ ]
+ },
+ "peer_id": {
+ "added": "v25.12",
+ "type": "pubkey",
+ "description": [
+ "The peer this network event was with"
+ ]
+ }
+ }
+ }
+ }
+ }
}
]
},
diff --git a/doc/schemas/wait.json b/doc/schemas/wait.json
index f5bb18b6..3f4f2b45 100644
--- a/doc/schemas/wait.json
+++ b/doc/schemas/wait.json
@@ -24,7 +24,8 @@
" `forwards`: corresponding to `listforwards` (added in *v23.11*).",
" `htlcs`: corresponding to `listhtlcs` (added in *v25.05*).",
" `chainmoves`: corresponding to `listchainmoves` (added in *v25.09*).",
- " `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*)."
+ " `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*).",
+ " `networkevents`: corresponding to `listnetworkevents` (added in *v25.12*)."
],
"enum": [
"invoices",
@@ -32,7 +33,8 @@
"sendpays",
"htlcs",
"chainmoves",
- "channelmoves"
+ "channelmoves",
+ "networkevents"
]
},
"indexname": {
@@ -71,7 +73,8 @@
"sendpays",
"htlcs",
"chainmoves",
- "channelmoves"
+ "channelmoves",
+ "networkevents"
]
},
"created": {
@@ -98,6 +101,7 @@
"htlcs": {},
"chainmoves": {},
"channelmoves": {},
+ "networkevents": {},
"details": {}
},
"allOf": [
@@ -647,6 +651,62 @@
}
}
}
+ },
+ {
+ "if": {
+ "additionalProperties": true,
+ "properties": {
+ "subsystem": {
+ "type": "string",
+ "enum": [
+ "networkevents"
+ ]
+ }
+ }
+ },
+ "then": {
+ "additionalProperties": false,
+ "properties": {
+ "subsystem": {},
+ "created": {},
+ "updated": {},
+ "deleted": {},
+ "networkevents": {
+ "added": "v25.12",
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "created_index": {
+ "added": "v25.12",
+ "type": "u64",
+ "description": [
+ "The created_index of the record added/deleted"
+ ]
+ },
+ "type": {
+ "added": "v25.12",
+ "type": "string",
+ "enum": [
+ "connect",
+ "connect_fail",
+ "ping",
+ "disconnect"
+ ],
+ "description": [
+ "The kind of network event"
+ ]
+ },
+ "peer_id": {
+ "added": "v25.12",
+ "type": "pubkey",
+ "description": [
+ "The peer this network event was with"
+ ]
+ }
+ }
+ }
+ }
+ }
}
]
},
diff --git a/lightningd/wait.c b/lightningd/wait.c
index a2b25297..b9390a74 100644
--- a/lightningd/wait.c
+++ b/lightningd/wait.c
@@ -26,6 +26,7 @@ static const char *subsystem_names[] = {
"htlcs",
"chainmoves",
"channelmoves",
+ "networkevents",
};
static const char *index_names[] = {
@@ -55,6 +56,7 @@ const char *wait_subsystem_name(enum wait_subsystem subsystem)
case WAIT_SUBSYSTEM_HTLCS:
case WAIT_SUBSYSTEM_CHAINMOVES:
case WAIT_SUBSYSTEM_CHANNELMOVES:
+ case WAIT_SUBSYSTEM_NETWORKEVENTS:
return subsystem_names[subsystem];
}
abort();
@@ -90,8 +92,8 @@ static void json_add_index(struct command *cmd,
return;
va_copy(ap2, *ap);
- /* "htlcs" never had details field: it came after! */
- if (subsystem != WAIT_SUBSYSTEM_HTLCS
+ /* "htlcs" etc never had details field: they came after! */
+ if (subsystem < WAIT_SUBSYSTEM_HTLCS
&& command_deprecated_out_ok(cmd, "details", "v25.05", "v26.06")) {
json_object_start(response, "details");
while ((name = va_arg(*ap, const char *)) != NULL) {
@@ -116,10 +118,13 @@ static void json_add_index(struct command *cmd,
if (!value)
continue;
- /* This is a hack! */
+ /* This is a hack! Means "copy in literally". */
if (name[0] == '=') {
- /* Copy in literally! */
- json_add_jsonstr(response, name + 1, value, strlen(value));
+ /* This is also a hack! Means "current value"*/
+ if (streq(value, ""))
+ json_add_u64(response, name + 1, val);
+ else
+ json_add_jsonstr(response, name + 1, value, strlen(value));
} else {
json_add_string(response, name, value);
}
diff --git a/lightningd/wait.h b/lightningd/wait.h
index da71b6c2..b248dd82 100644
--- a/lightningd/wait.h
+++ b/lightningd/wait.h
@@ -13,8 +13,9 @@ enum wait_subsystem {
WAIT_SUBSYSTEM_HTLCS,
WAIT_SUBSYSTEM_CHAINMOVES,
WAIT_SUBSYSTEM_CHANNELMOVES,
+ WAIT_SUBSYSTEM_NETWORKEVENTS,
};
-#define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_CHANNELMOVES+1)
+#define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_NETWORKEVENTS+1)
enum wait_index {
WAIT_INDEX_CREATED,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.