Skip to content

Commit 7ba6263

Browse files
committed
lightningd: add created_index and updated_index to listhtlcs.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: JSON-RPC: `listhtlcs` has `created_index` and `updated_index` fields.
1 parent 07c495e commit 7ba6263

File tree

14 files changed

+699
-585
lines changed

14 files changed

+699
-585
lines changed

.msggen.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,12 +2560,14 @@
25602560
},
25612561
"ListhtlcsHtlcs": {
25622562
"ListHtlcs.htlcs[].amount_msat": 4,
2563+
"ListHtlcs.htlcs[].created_index": 8,
25632564
"ListHtlcs.htlcs[].direction": 5,
25642565
"ListHtlcs.htlcs[].expiry": 3,
25652566
"ListHtlcs.htlcs[].id": 2,
25662567
"ListHtlcs.htlcs[].payment_hash": 6,
25672568
"ListHtlcs.htlcs[].short_channel_id": 1,
2568-
"ListHtlcs.htlcs[].state": 7
2569+
"ListHtlcs.htlcs[].state": 7,
2570+
"ListHtlcs.htlcs[].updated_index": 9
25692571
},
25702572
"ListhtlcsRequest": {
25712573
"ListHtlcs.id": 1
@@ -9583,6 +9585,10 @@
95839585
"added": "pre-v0.10.1",
95849586
"deprecated": null
95859587
},
9588+
"ListHtlcs.htlcs[].created_index": {
9589+
"added": "v25.05",
9590+
"deprecated": null
9591+
},
95869592
"ListHtlcs.htlcs[].direction": {
95879593
"added": "pre-v0.10.1",
95889594
"deprecated": null
@@ -9607,6 +9613,10 @@
96079613
"added": "pre-v0.10.1",
96089614
"deprecated": null
96099615
},
9616+
"ListHtlcs.htlcs[].updated_index": {
9617+
"added": "v25.05",
9618+
"deprecated": null
9619+
},
96109620
"ListHtlcs.id": {
96119621
"added": "pre-v0.10.1",
96129622
"deprecated": null

cln-grpc/proto/node.proto

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/msggen/msggen/schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21549,6 +21549,7 @@
2154921549
"type": "object",
2155021550
"additionalProperties": false,
2155121551
"required": [
21552+
"created_index",
2155221553
"short_channel_id",
2155321554
"id",
2155421555
"expiry",
@@ -21564,6 +21565,20 @@
2156421565
"The channel that contains/contained the HTLC."
2156521566
]
2156621567
},
21568+
"created_index": {
21569+
"added": "v25.05",
21570+
"type": "u64",
21571+
"description": [
21572+
"1-based index indicating order this htlc was created in."
21573+
]
21574+
},
21575+
"updated_index": {
21576+
"added": "v25.05",
21577+
"type": "u64",
21578+
"description": [
21579+
"1-based index indicating order this htlc was changed (only present if it has changed since creation)."
21580+
]
21581+
},
2156721582
"id": {
2156821583
"type": "u64",
2156921584
"description": [

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 572 additions & 572 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/pyln-testing/pyln/testing/grpc2py.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,10 +1715,12 @@ def listhtlcs_htlcs2py(m):
17151715
"direction": str(m.direction), # EnumField in generate_composite
17161716
"state": str(m.state), # EnumField in generate_composite
17171717
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
1718+
"created_index": m.created_index, # PrimitiveField in generate_composite
17181719
"expiry": m.expiry, # PrimitiveField in generate_composite
17191720
"id": m.id, # PrimitiveField in generate_composite
17201721
"payment_hash": hexlify(m.payment_hash), # PrimitiveField in generate_composite
17211722
"short_channel_id": m.short_channel_id, # PrimitiveField in generate_composite
1723+
"updated_index": m.updated_index, # PrimitiveField in generate_composite
17221724
})
17231725

17241726

doc/schemas/listhtlcs.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"type": "object",
3434
"additionalProperties": false,
3535
"required": [
36+
"created_index",
3637
"short_channel_id",
3738
"id",
3839
"expiry",
@@ -48,6 +49,20 @@
4849
"The channel that contains/contained the HTLC."
4950
]
5051
},
52+
"created_index": {
53+
"added": "v25.05",
54+
"type": "u64",
55+
"description": [
56+
"1-based index indicating order this htlc was created in."
57+
]
58+
},
59+
"updated_index": {
60+
"added": "v25.05",
61+
"type": "u64",
62+
"description": [
63+
"1-based index indicating order this htlc was changed (only present if it has changed since creation)."
64+
]
65+
},
5166
"id": {
5267
"type": "u64",
5368
"description": [

lightningd/peer_htlcs.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,7 @@ static struct command_result *json_listhtlcs(struct command *cmd,
31063106
struct channel *chan;
31073107
struct wallet_htlc_iter *i;
31083108
struct short_channel_id scid;
3109-
u64 htlc_id;
3109+
u64 htlc_id, created_index, updated_index;
31103110
int cltv_expiry;
31113111
enum side owner;
31123112
struct amount_msat msat;
@@ -3122,12 +3122,17 @@ static struct command_result *json_listhtlcs(struct command *cmd,
31223122
json_array_start(response, "htlcs");
31233123
for (i = wallet_htlcs_first(cmd, cmd->ld->wallet, chan,
31243124
&scid, &htlc_id, &cltv_expiry, &owner, &msat,
3125-
&payment_hash, &hstate);
3125+
&payment_hash, &hstate,
3126+
&created_index, &updated_index);
31263127
i;
31273128
i = wallet_htlcs_next(cmd->ld->wallet, i,
31283129
&scid, &htlc_id, &cltv_expiry, &owner, &msat,
3129-
&payment_hash, &hstate)) {
3130+
&payment_hash, &hstate,
3131+
&created_index, &updated_index)) {
31303132
json_object_start(response, NULL);
3133+
json_add_u64(response, "created_index", created_index);
3134+
if (updated_index != 0)
3135+
json_add_u64(response, "updated_index", updated_index);
31313136
json_add_short_channel_id(response, "short_channel_id", scid);
31323137
json_add_u64(response, "id", htlc_id);
31333138
json_add_u32(response, "expiry", cltv_expiry);

tests/test_connection.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4342,27 +4342,35 @@ def test_multichan(node_factory, executor, bitcoind):
43424342
assert l1htlcs == l1.rpc.listhtlcs(scid12)['htlcs']
43434343
assert l1htlcs == [{"short_channel_id": scid12,
43444344
"id": 0,
4345+
"created_index": 1,
4346+
"updated_index": 9,
43454347
"expiry": 117,
43464348
"direction": "out",
43474349
"amount_msat": Millisatoshi(100001001),
43484350
"payment_hash": inv1['payment_hash'],
43494351
"state": "RCVD_REMOVE_ACK_REVOCATION"},
43504352
{"short_channel_id": scid12,
43514353
"id": 1,
4354+
"created_index": 2,
4355+
"updated_index": 18,
43524356
"expiry": 117,
43534357
"direction": "out",
43544358
"amount_msat": Millisatoshi(100001001),
43554359
"payment_hash": inv2['payment_hash'],
43564360
"state": "RCVD_REMOVE_ACK_REVOCATION"},
43574361
{"short_channel_id": scid12,
43584362
"id": 2,
4363+
"created_index": 3,
4364+
"updated_index": 27,
43594365
"expiry": 135,
43604366
"direction": "out",
43614367
"amount_msat": Millisatoshi(100001001),
43624368
"payment_hash": inv3['payment_hash'],
43634369
"state": "RCVD_REMOVE_ACK_REVOCATION"},
43644370
{"short_channel_id": scid12,
43654371
"id": 3,
4372+
"created_index": 4,
4373+
"updated_index": 36,
43664374
"expiry": 135,
43674375
"direction": "out",
43684376
"amount_msat": Millisatoshi(100001001),
@@ -4373,7 +4381,16 @@ def test_multichan(node_factory, executor, bitcoind):
43734381
for h in l1htlcs:
43744382
h['direction'] = 'in'
43754383
h['state'] = 'SENT_REMOVE_ACK_REVOCATION'
4376-
assert l2.rpc.listhtlcs(scid12)['htlcs'] == l1htlcs
4384+
# These won't match!
4385+
del h['created_index']
4386+
del h['updated_index']
4387+
4388+
l2htlcs = l2.rpc.listhtlcs(scid12)['htlcs']
4389+
for h in l2htlcs:
4390+
del h['created_index']
4391+
del h['updated_index']
4392+
4393+
assert l2htlcs == l1htlcs
43774394

43784395

43794396
def test_mutual_reconnect_race(node_factory, executor, bitcoind):

0 commit comments

Comments
 (0)