Skip to content

Commit c568bd2

Browse files
rustyrussellendothermicdev
authored andcommitted
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 8df573d commit c568bd2

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
@@ -34881,15 +34881,17 @@
3488134881
" `forwards`: corresponding to `listforwards` (added in *v23.11*).",
3488234882
" `htlcs`: corresponding to `listhtlcs` (added in *v25.05*).",
3488334883
" `chainmoves`: corresponding to `listchainmoves` (added in *v25.09*).",
34884-
" `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*)."
34884+
" `channelmoves`: corresponding to `listchannelmoves` (added in *v25.09*).",
34885+
" `networkevents`: corresponding to `listnetworkevents` (added in *v25.12*)."
3488534886
],
3488634887
"enum": [
3488734888
"invoices",
3488834889
"forwards",
3488934890
"sendpays",
3489034891
"htlcs",
3489134892
"chainmoves",
34892-
"channelmoves"
34893+
"channelmoves",
34894+
"networkevents"
3489334895
]
3489434896
},
3489534897
"indexname": {
@@ -34928,7 +34930,8 @@
3492834930
"sendpays",
3492934931
"htlcs",
3493034932
"chainmoves",
34931-
"channelmoves"
34933+
"channelmoves",
34934+
"networkevents"
3493234935
]
3493334936
},
3493434937
"created": {
@@ -34955,6 +34958,7 @@
3495534958
"htlcs": {},
3495634959
"chainmoves": {},
3495734960
"channelmoves": {},
34961+
"networkevents": {},
3495834962
"details": {}
3495934963
},
3496034964
"allOf": [
@@ -35504,6 +35508,62 @@
3550435508
}
3550535509
}
3550635510
}
35511+
},
35512+
{
35513+
"if": {
35514+
"additionalProperties": true,
35515+
"properties": {
35516+
"subsystem": {
35517+
"type": "string",
35518+
"enum": [
35519+
"networkevents"
35520+
]
35521+
}
35522+
}
35523+
},
35524+
"then": {
35525+
"additionalProperties": false,
35526+
"properties": {
35527+
"subsystem": {},
35528+
"created": {},
35529+
"updated": {},
35530+
"deleted": {},
35531+
"networkevents": {
35532+
"added": "v25.12",
35533+
"type": "object",
35534+
"additionalProperties": false,
35535+
"properties": {
35536+
"created_index": {
35537+
"added": "v25.12",
35538+
"type": "u64",
35539+
"description": [
35540+
"The created_index of the record added/deleted"
35541+
]
35542+
},
35543+
"type": {
35544+
"added": "v25.12",
35545+
"type": "string",
35546+
"enum": [
35547+
"connect",
35548+
"connect_fail",
35549+
"ping",
35550+
"disconnect"
35551+
],
35552+
"description": [
35553+
"The kind of network event"
35554+
]
35555+
},
35556+
"peer_id": {
35557+
"added": "v25.12",
35558+
"type": "pubkey",
35559+
"description": [
35560+
"The peer this network event was with"
35561+
]
35562+
}
35563+
}
35564+
}
35565+
}
35566+
}
3550735567
}
3550835568
]
3550935569
},

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)