Skip to content

Commit

Permalink
plugins/topology: add direction field to listchannels.
Browse files Browse the repository at this point in the history
It's a core concept in the spec which isn't directly exposed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `listchannels` added a `direction` field (0 or 1) as per gossip specification.
  • Loading branch information
rustyrussell authored and endothermicdev committed Jan 30, 2023
1 parent 611795b commit 9ab488f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@
"ListChannels.channels[].channel_flags": 7,
"ListChannels.channels[].delay": 12,
"ListChannels.channels[].destination": 2,
"ListChannels.channels[].direction": 16,
"ListChannels.channels[].features": 15,
"ListChannels.channels[].fee_per_millionth": 11,
"ListChannels.channels[].htlc_maximum_msat": 14,
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def listchannels_channels2py(m):
"source": hexlify(m.source), # PrimitiveField in generate_composite
"destination": hexlify(m.destination), # PrimitiveField in generate_composite
"short_channel_id": m.short_channel_id, # PrimitiveField in generate_composite
"direction": m.direction, # PrimitiveField in generate_composite
"public": m.public, # PrimitiveField in generate_composite
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"message_flags": m.message_flags, # PrimitiveField in generate_composite
Expand Down
3 changes: 2 additions & 1 deletion doc/lightning-listchannels.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ On success, an object containing **channels** is returned. It is an array of ob
- **source** (pubkey): the source node
- **destination** (pubkey): the destination node
- **short\_channel\_id** (short\_channel\_id): short channel id of channel
- **direction** (u32): direction (0 if source < destination, 1 otherwise).
- **public** (boolean): true if this is announced (otherwise it must be our channel)
- **amount\_msat** (msat): the total capacity of this channel (always a whole number of satoshis)
- **message\_flags** (u8): as defined by BOLT #7
Expand Down Expand Up @@ -79,4 +80,4 @@ Lightning RFC site
- BOLT \#7:
<https://github.com/lightning/bolts/blob/master/07-routing-gossip.md>

[comment]: # ( SHA256STAMP:d8d52272963a9ec4708fd3ae41585ddd8120bb5444c03219a7b728f0b2e09ec3)
[comment]: # ( SHA256STAMP:78f59780528ae5cd33c3607ed11b128cc94e1e0a5e2babd59cb99574a3f5f956)
5 changes: 5 additions & 0 deletions doc/schemas/listchannels.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"source",
"destination",
"short_channel_id",
"direction",
"public",
"amount_msat",
"message_flags",
Expand All @@ -40,6 +41,10 @@
"type": "short_channel_id",
"description": "short channel id of channel"
},
"direction": {
"type": "u32",
"description": "direction (0 if source < destination, 1 otherwise)."
},
"public": {
"type": "boolean",
"description": "true if this is announced (otherwise it must be our channel)"
Expand Down
1 change: 1 addition & 0 deletions plugins/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ static void json_add_halfchan(struct json_stream *response,
json_add_node_id(response, "source", &node_id[dir]);
json_add_node_id(response, "destination", &node_id[!dir]);
json_add_short_channel_id(response, "short_channel_id", &scid);
json_add_num(response, "direction", dir);
json_add_bool(response, "public", !c->private);

gossmap_chan_get_update_details(gossmap, c, dir,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,21 @@ def test_gossip_jsonrpc(node_factory):
channels2 = l2.rpc.listchannels(source=l1.info['id'])['channels']
assert only_one(channels1)['source'] == l1.info['id']
assert only_one(channels1)['destination'] == l2.info['id']
if l1.info['id'] > l2.info['id']:
assert only_one(channels1)['direction'] == 1
else:
assert only_one(channels1)['direction'] == 0
assert channels1 == channels2

# Test listchannels-by-destination
channels1 = l1.rpc.listchannels(destination=l1.info['id'])['channels']
channels2 = l2.rpc.listchannels(destination=l1.info['id'])['channels']
assert only_one(channels1)['destination'] == l1.info['id']
assert only_one(channels1)['source'] == l2.info['id']
if l2.info['id'] > l1.info['id']:
assert only_one(channels1)['direction'] == 1
else:
assert only_one(channels1)['direction'] == 0
assert channels1 == channels2

# Test only one of short_channel_id, source or destination can be supplied
Expand Down

0 comments on commit 9ab488f

Please sign in to comment.