Skip to content

Commit 8c2aaa7

Browse files
committed
lightningd: add networkevents to wait API.
Changelog-Added: JSON-RPC: `wait` now has `networkevents` subsystem. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent f15ff11 commit 8c2aaa7

File tree

4 files changed

+138
-12
lines changed

4 files changed

+138
-12
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34860,15 +34860,17 @@
3486034860
" `forwards`: corresponding to `listforwards` (added in *v23.11*).",
3486134861
" `htlcs`: corresponding to `listhtlcs` (added in *v25.05*).",
3486234862
" `chainmoves`: corresponding to `listchainmoves` (added in *v25.09*).",
34863-
" `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*)."
34863+
" `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*).",
34864+
" `networkevents`: corresponding to `listnetworkevents` (added in *v25.12*)."
3486434865
],
3486534866
"enum": [
3486634867
"invoices",
3486734868
"forwards",
3486834869
"sendpays",
3486934870
"htlcs",
3487034871
"chainmoves",
34871-
"channelmoves"
34872+
"channelmoves",
34873+
"networkevents"
3487234874
]
3487334875
},
3487434876
"indexname": {
@@ -34907,7 +34909,8 @@
3490734909
"sendpays",
3490834910
"htlcs",
3490934911
"chainmoves",
34910-
"channelmoves"
34912+
"channelmoves",
34913+
"networkevents"
3491134914
]
3491234915
},
3491334916
"created": {
@@ -34934,6 +34937,7 @@
3493434937
"htlcs": {},
3493534938
"chainmoves": {},
3493634939
"channelmoves": {},
34940+
"networkevents": {},
3493734941
"details": {}
3493834942
},
3493934943
"allOf": [
@@ -35483,6 +35487,62 @@
3548335487
}
3548435488
}
3548535489
}
35490+
},
35491+
{
35492+
"if": {
35493+
"additionalProperties": true,
35494+
"properties": {
35495+
"subsystem": {
35496+
"type": "string",
35497+
"enum": [
35498+
"networkevents"
35499+
]
35500+
}
35501+
}
35502+
},
35503+
"then": {
35504+
"additionalProperties": false,
35505+
"properties": {
35506+
"subsystem": {},
35507+
"created": {},
35508+
"updated": {},
35509+
"deleted": {},
35510+
"networkevents": {
35511+
"added": "v25.12",
35512+
"type": "object",
35513+
"additionalProperties": false,
35514+
"properties": {
35515+
"created_index": {
35516+
"added": "v25.12",
35517+
"type": "u64",
35518+
"description": [
35519+
"The created_index of the record added/deleted"
35520+
]
35521+
},
35522+
"type": {
35523+
"added": "v25.12",
35524+
"type": "string",
35525+
"enum": [
35526+
"connect",
35527+
"connect_fail",
35528+
"ping",
35529+
"disconnect"
35530+
],
35531+
"description": [
35532+
"The kind of network event"
35533+
]
35534+
},
35535+
"peer_id": {
35536+
"added": "v25.12",
35537+
"type": "pubkey",
35538+
"description": [
35539+
"The peer this network event was with"
35540+
]
35541+
}
35542+
}
35543+
}
35544+
}
35545+
}
3548635546
}
3548735547
]
3548835548
},

doc/schemas/wait.json

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
" `forwards`: corresponding to `listforwards` (added in *v23.11*).",
2525
" `htlcs`: corresponding to `listhtlcs` (added in *v25.05*).",
2626
" `chainmoves`: corresponding to `listchainmoves` (added in *v25.09*).",
27-
" `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*)."
27+
" `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*).",
28+
" `networkevents`: corresponding to `listnetworkevents` (added in *v25.12*)."
2829
],
2930
"enum": [
3031
"invoices",
3132
"forwards",
3233
"sendpays",
3334
"htlcs",
3435
"chainmoves",
35-
"channelmoves"
36+
"channelmoves",
37+
"networkevents"
3638
]
3739
},
3840
"indexname": {
@@ -71,7 +73,8 @@
7173
"sendpays",
7274
"htlcs",
7375
"chainmoves",
74-
"channelmoves"
76+
"channelmoves",
77+
"networkevents"
7578
]
7679
},
7780
"created": {
@@ -98,6 +101,7 @@
98101
"htlcs": {},
99102
"chainmoves": {},
100103
"channelmoves": {},
104+
"networkevents": {},
101105
"details": {}
102106
},
103107
"allOf": [
@@ -647,6 +651,62 @@
647651
}
648652
}
649653
}
654+
},
655+
{
656+
"if": {
657+
"additionalProperties": true,
658+
"properties": {
659+
"subsystem": {
660+
"type": "string",
661+
"enum": [
662+
"networkevents"
663+
]
664+
}
665+
}
666+
},
667+
"then": {
668+
"additionalProperties": false,
669+
"properties": {
670+
"subsystem": {},
671+
"created": {},
672+
"updated": {},
673+
"deleted": {},
674+
"networkevents": {
675+
"added": "v25.12",
676+
"type": "object",
677+
"additionalProperties": false,
678+
"properties": {
679+
"created_index": {
680+
"added": "v25.12",
681+
"type": "u64",
682+
"description": [
683+
"The created_index of the record added/deleted"
684+
]
685+
},
686+
"type": {
687+
"added": "v25.12",
688+
"type": "string",
689+
"enum": [
690+
"connect",
691+
"connect_fail",
692+
"ping",
693+
"disconnect"
694+
],
695+
"description": [
696+
"The kind of network event"
697+
]
698+
},
699+
"peer_id": {
700+
"added": "v25.12",
701+
"type": "pubkey",
702+
"description": [
703+
"The peer this network event was with"
704+
]
705+
}
706+
}
707+
}
708+
}
709+
}
650710
}
651711
]
652712
},

lightningd/wait.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static const char *subsystem_names[] = {
2626
"htlcs",
2727
"chainmoves",
2828
"channelmoves",
29+
"networkevents",
2930
};
3031

3132
static const char *index_names[] = {
@@ -55,6 +56,7 @@ const char *wait_subsystem_name(enum wait_subsystem subsystem)
5556
case WAIT_SUBSYSTEM_HTLCS:
5657
case WAIT_SUBSYSTEM_CHAINMOVES:
5758
case WAIT_SUBSYSTEM_CHANNELMOVES:
59+
case WAIT_SUBSYSTEM_NETWORKEVENTS:
5860
return subsystem_names[subsystem];
5961
}
6062
abort();
@@ -90,8 +92,8 @@ static void json_add_index(struct command *cmd,
9092
return;
9193

9294
va_copy(ap2, *ap);
93-
/* "htlcs" never had details field: it came after! */
94-
if (subsystem != WAIT_SUBSYSTEM_HTLCS
95+
/* "htlcs" etc never had details field: they came after! */
96+
if (subsystem < WAIT_SUBSYSTEM_HTLCS
9597
&& command_deprecated_out_ok(cmd, "details", "v25.05", "v26.06")) {
9698
json_object_start(response, "details");
9799
while ((name = va_arg(*ap, const char *)) != NULL) {
@@ -116,10 +118,13 @@ static void json_add_index(struct command *cmd,
116118
if (!value)
117119
continue;
118120

119-
/* This is a hack! */
121+
/* This is a hack! Means "copy in literally". */
120122
if (name[0] == '=') {
121-
/* Copy in literally! */
122-
json_add_jsonstr(response, name + 1, value, strlen(value));
123+
/* This is also a hack! Means "current value"*/
124+
if (streq(value, ""))
125+
json_add_u64(response, name + 1, val);
126+
else
127+
json_add_jsonstr(response, name + 1, value, strlen(value));
123128
} else {
124129
json_add_string(response, name, value);
125130
}

lightningd/wait.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ enum wait_subsystem {
1313
WAIT_SUBSYSTEM_HTLCS,
1414
WAIT_SUBSYSTEM_CHAINMOVES,
1515
WAIT_SUBSYSTEM_CHANNELMOVES,
16+
WAIT_SUBSYSTEM_NETWORKEVENTS,
1617
};
17-
#define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_CHANNELMOVES+1)
18+
#define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_NETWORKEVENTS+1)
1819

1920
enum wait_index {
2021
WAIT_INDEX_CREATED,

0 commit comments

Comments
 (0)