Skip to content

Commit

Permalink
listforwards: add created_index and updated_index fields.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON-RPC: `listforwards` fields `created_index` (old: `id`) and `updated_index`.
  • Loading branch information
rustyrussell committed Oct 28, 2023
1 parent de1e459 commit 1d8af90
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 88 deletions.
12 changes: 11 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@
"ListDatastore.datastore[]": 1
},
"ListforwardsForwards": {
"ListForwards.forwards[].created_index": 12,
"ListForwards.forwards[].fee_msat": 7,
"ListForwards.forwards[].in_channel": 1,
"ListForwards.forwards[].in_htlc_id": 10,
Expand All @@ -934,7 +935,8 @@
"ListForwards.forwards[].payment_hash": 6,
"ListForwards.forwards[].received_time": 4,
"ListForwards.forwards[].status": 3,
"ListForwards.forwards[].style": 9
"ListForwards.forwards[].style": 9,
"ListForwards.forwards[].updated_index": 13
},
"ListforwardsRequest": {
"ListForwards.in_channel": 2,
Expand Down Expand Up @@ -3570,6 +3572,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListForwards.forwards[].created_index": {
"added": "v23.11",
"deprecated": false
},
"ListForwards.forwards[].fee_msat": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down Expand Up @@ -3610,6 +3616,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListForwards.forwards[].updated_index": {
"added": "v23.11",
"deprecated": false
},
"ListForwards.in_channel": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down
2 changes: 2 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.

2 changes: 2 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.

4 changes: 4 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.

136 changes: 68 additions & 68 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,13 +1298,15 @@ def getroute2py(m):

def listforwards_forwards2py(m):
return remove_default({
"created_index": m.created_index, # PrimitiveField in generate_composite
"in_channel": m.in_channel, # PrimitiveField in generate_composite
"in_htlc_id": m.in_htlc_id, # PrimitiveField in generate_composite
"in_msat": amount2msat(m.in_msat), # PrimitiveField in generate_composite
"status": str(m.status), # EnumField in generate_composite
"received_time": m.received_time, # PrimitiveField in generate_composite
"out_channel": m.out_channel, # PrimitiveField in generate_composite
"out_htlc_id": m.out_htlc_id, # PrimitiveField in generate_composite
"updated_index": m.updated_index, # PrimitiveField in generate_composite
"style": str(m.style), # EnumField in generate_composite
"fee_msat": amount2msat(m.fee_msat), # PrimitiveField in generate_composite
"out_msat": amount2msat(m.out_msat), # PrimitiveField in generate_composite
Expand Down
4 changes: 3 additions & 1 deletion doc/lightning-listforwards.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ RETURN VALUE
[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, an object containing **forwards** is returned. It is an array of objects, where each object contains:

- **created\_index** (u64): 1-based index indicating order this forward was created in *(added v23.11)*
- **in\_channel** (short\_channel\_id): the channel that received the HTLC
- **in\_msat** (msat): the value of the incoming HTLC
- **status** (string): still ongoing, completed, failed locally, or failed after forwarding (one of "offered", "settled", "local\_failed", "failed")
- **received\_time** (number): the UNIX timestamp when this was received
- **in\_htlc\_id** (u64, optional): the unique HTLC id the sender gave this (not present if incoming channel was closed before ugprade to v22.11)
- **out\_channel** (short\_channel\_id, optional): the channel that the HTLC (trying to) forward to
- **out\_htlc\_id** (u64, optional): the unique HTLC id we gave this when sending (may be missing even if out\_channel is present, for old forwards before v22.11)
- **updated\_index** (u64, optional): 1-based index indicating order this forward was changed (only present if it has changed since creation) *(added v23.11)*
- **style** (string, optional): Either a legacy onion format or a modern tlv format (one of "legacy", "tlv")

If **out\_msat** is present:
Expand Down Expand Up @@ -64,4 +66,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:fb6b59740d52aee780678850445bdd58803b33c1df02c5794473ee87c23da35b)
[comment]: # ( SHA256STAMP:b08957fa97a9e574ea80570518551577e272552a29b60d5b1620f00bdfdfe225)
4 changes: 3 additions & 1 deletion doc/lightning-sql.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ The following tables are currently supported:
- `close_cause` (type `string`, sqltype `TEXT`)

- `forwards` indexed by `in_channel and in_htlc_id` (see lightning-listforwards(7))
- `created_index` (type `u64`, sqltype `INTEGER`)
- `in_channel` (type `short_channel_id`, sqltype `TEXT`)
- `in_htlc_id` (type `u64`, sqltype `INTEGER`)
- `in_msat` (type `msat`, sqltype `INTEGER`)
- `status` (type `string`, sqltype `TEXT`)
- `received_time` (type `number`, sqltype `REAL`)
- `out_channel` (type `short_channel_id`, sqltype `TEXT`)
- `out_htlc_id` (type `u64`, sqltype `INTEGER`)
- `updated_index` (type `u64`, sqltype `INTEGER`)
- `style` (type `string`, sqltype `TEXT`)
- `fee_msat` (type `msat`, sqltype `INTEGER`)
- `out_msat` (type `msat`, sqltype `INTEGER`)
Expand Down Expand Up @@ -518,4 +520,4 @@ RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:51935a8b2807867e97ecb077194090e55ce610a32120825c093c766d0292a6cb)
[comment]: # ( SHA256STAMP:f1434805992a6d428e96c93e2acde932d99da9cfbc91c9b543b3553b1af39c9b)
23 changes: 23 additions & 0 deletions doc/schemas/listforwards.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
"type": "object",
"additionalProperties": true,
"required": [
"created_index",
"in_channel",
"in_msat",
"status",
"received_time"
],
"properties": {
"created_index": {
"added": "v23.11",
"type": "u64",
"description": "1-based index indicating order this forward was created in"
},
"in_channel": {
"type": "short_channel_id",
"description": "the channel that received the HTLC"
Expand Down Expand Up @@ -52,6 +58,11 @@
"type": "u64",
"description": "the unique HTLC id we gave this when sending (may be missing even if out_channel is present, for old forwards before v22.11)"
},
"updated_index": {
"added": "v23.11",
"type": "u64",
"description": "1-based index indicating order this forward was changed (only present if it has changed since creation)"
},
"style": {
"type": "string",
"enum": [
Expand All @@ -76,6 +87,8 @@
"out_channel"
],
"properties": {
"created_index": {},
"updated_index": {},
"in_channel": {},
"in_htlc_id": {},
"in_msatoshi": {},
Expand All @@ -102,6 +115,8 @@
"additionalProperties": false,
"required": [],
"properties": {
"created_index": {},
"updated_index": {},
"in_channel": {},
"in_htlc_id": {},
"in_msatoshi": {},
Expand Down Expand Up @@ -134,6 +149,8 @@
"resolved_time"
],
"properties": {
"created_index": {},
"updated_index": {},
"in_channel": {},
"in_htlc_id": {},
"in_msatoshi": {},
Expand All @@ -158,6 +175,8 @@
"else": {
"additionalProperties": false,
"properties": {
"created_index": {},
"updated_index": {},
"in_channel": {},
"in_htlc_id": {},
"in_msatoshi": {},
Expand Down Expand Up @@ -192,6 +211,8 @@
"additionalProperties": false,
"required": [],
"properties": {
"created_index": {},
"updated_index": {},
"in_channel": {},
"in_htlc_id": {},
"in_msatoshi": {},
Expand Down Expand Up @@ -220,6 +241,8 @@
"additionalProperties": false,
"required": [],
"properties": {
"created_index": {},
"updated_index": {},
"in_channel": {},
"in_htlc_id": {},
"in_msatoshi": {},
Expand Down
6 changes: 6 additions & 0 deletions lightningd/forwards.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ void json_add_forwarding_object(struct json_stream *response,
{
json_object_start(response, fieldname);

/* We don't bother grabbing id from db on update. */
if (cur->created_index)
json_add_u64(response, "created_index", cur->created_index);
if (cur->updated_index)
json_add_u64(response, "updated_index", cur->updated_index);

/* Only for forward_event */
if (payment_hash)
json_add_sha256(response, "payment_hash", payment_hash);
Expand Down
3 changes: 3 additions & 0 deletions lightningd/forwards.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ enum forward_status {
};

struct forwarding {
u64 created_index;
/* zero means never updated */
u64 updated_index;
/* channel_out is all-zero if unknown. */
struct short_channel_id channel_in, channel_out;
/* htlc_id_out is NULL if unknown. */
Expand Down
16 changes: 12 additions & 4 deletions lightningd/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ static void forward_event_notification_serialize(struct json_stream *stream,
enum forward_status state,
enum onion_wire failcode,
struct timeabs *resolved_time,
enum forward_style forward_style)
enum forward_style forward_style,
u64 created_index,
u64 updated_index)
{
/* Here is more neat to initial a forwarding structure than
* to pass in a bunch of parameters directly*/
Expand Down Expand Up @@ -370,6 +372,8 @@ static void forward_event_notification_serialize(struct json_stream *stream,
cur->resolved_time = tal_steal(cur, resolved_time);
cur->forward_style = forward_style;
cur->htlc_id_in = in->key.id;
cur->created_index = created_index;
cur->updated_index = updated_index;

json_add_forwarding_object(stream, "forward_event",
cur, &in->payment_hash);
Expand All @@ -385,7 +389,9 @@ void notify_forward_event(struct lightningd *ld,
enum forward_status state,
enum onion_wire failcode,
struct timeabs *resolved_time,
enum forward_style forward_style)
enum forward_style forward_style,
u64 created_index,
u64 updated_index)
{
void (*serialize)(struct json_stream *,
const struct htlc_in *,
Expand All @@ -394,11 +400,13 @@ void notify_forward_event(struct lightningd *ld,
enum forward_status,
enum onion_wire,
struct timeabs *,
enum forward_style) = forward_event_notification_gen.serialize;
enum forward_style,
u64,
u64) = forward_event_notification_gen.serialize;

struct jsonrpc_notification *n
= jsonrpc_notification_start(NULL, forward_event_notification_gen.topic);
serialize(n->stream, in, scid_out, amount_out, state, failcode, resolved_time, forward_style);
serialize(n->stream, in, scid_out, amount_out, state, failcode, resolved_time, forward_style, created_index, updated_index);
jsonrpc_notification_end(n);
plugins_notify(ld->plugins, take(n));
}
Expand Down
4 changes: 3 additions & 1 deletion lightningd/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ void notify_forward_event(struct lightningd *ld,
enum forward_status state,
enum onion_wire failcode,
struct timeabs *resolved_time,
enum forward_style forward_style);
enum forward_style forward_style,
u64 created_index,
u64 updated_index);

void notify_sendpay_success(struct lightningd *ld,
const struct wallet_payment *payment);
Expand Down
15 changes: 14 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,29 +1392,38 @@ def test_forward_event_notification(node_factory, bitcoind, executor):
# First event won't have conclusion.
del expect['resolved_time']
del expect['out_htlc_id']
del expect['updated_index']
expect['status'] = 'offered'
assert plugin_stats[0] == expect
expect = stats[0].copy()
del expect['out_htlc_id']
# We don't bother populating created_index for updates.
del expect['created_index']
assert plugin_stats[1] == expect

expect = stats[1].copy()
del expect['resolved_time']
del expect['out_htlc_id']
del expect['updated_index']
expect['status'] = 'offered'
assert plugin_stats[2] == expect
expect = stats[1].copy()
del expect['out_htlc_id']
# We don't bother populating created_index for updates.
del expect['created_index']
assert plugin_stats[3] == expect

expect = stats[2].copy()
del expect['failcode']
del expect['failreason']
del expect['out_htlc_id']
del expect['updated_index']
expect['status'] = 'offered'
assert plugin_stats[4] == expect
expect = stats[2].copy()
del expect['out_htlc_id']
# We don't bother populating created_index for updates.
del expect['created_index']
assert plugin_stats[5] == expect


Expand Down Expand Up @@ -3534,7 +3543,9 @@ def test_sql(node_factory, bitcoind):
'type': 'string'}]},
'forwards': {
'indices': [['in_channel', 'in_htlc_id']],
'columns': [{'name': 'in_channel',
'columns': [{'name': 'created_index',
'type': 'u64'},
{'name': 'in_channel',
'type': 'short_channel_id'},
{'name': 'in_htlc_id',
'type': 'u64'},
Expand All @@ -3548,6 +3559,8 @@ def test_sql(node_factory, bitcoind):
'type': 'short_channel_id'},
{'name': 'out_htlc_id',
'type': 'u64'},
{'name': 'updated_index',
'type': 'u64'},
{'name': 'style',
'type': 'string'},
{'name': 'fee_msat',
Expand Down
4 changes: 3 additions & 1 deletion wallet/test/run-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ void notify_forward_event(struct lightningd *ld UNNEEDED,
enum forward_status state UNNEEDED,
enum onion_wire failcode UNNEEDED,
struct timeabs *resolved_time UNNEEDED,
enum forward_style forward_style UNNEEDED)
enum forward_style forward_style UNNEEDED,
u64 created_index UNNEEDED,
u64 updated_index UNNEEDED)
{ fprintf(stderr, "notify_forward_event called!\n"); abort(); }
/* Generated stub for onion_wire_name */
const char *onion_wire_name(int e UNNEEDED)
Expand Down
4 changes: 3 additions & 1 deletion wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,9 @@ void notify_forward_event(struct lightningd *ld UNNEEDED,
enum forward_status state UNNEEDED,
enum onion_wire failcode UNNEEDED,
struct timeabs *resolved_time UNNEEDED,
enum forward_style forward_style UNNEEDED)
enum forward_style forward_style UNNEEDED,
u64 created_index UNNEEDED,
u64 updated_index UNNEEDED)
{ fprintf(stderr, "notify_forward_event called!\n"); abort(); }
/* Generated stub for notify_invoice_payment */
void notify_invoice_payment(struct lightningd *ld UNNEEDED, struct amount_msat amount UNNEEDED,
Expand Down
Loading

0 comments on commit 1d8af90

Please sign in to comment.