Skip to content

Commit

Permalink
json_getchannels: add public flag.
Browse files Browse the repository at this point in the history
Fixes: ElementsProject#509
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Jan 8, 2018
1 parent 7975a1c commit a8de8a3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ cli/lightning-cli fundchannel <node_id> <amount>
```

This opens a connection and, on top of that connection, then opens a channel.
The funding transaction needs 6 confirmations in order for the channel to be usable.
You can check the status of the channel using `cli/lightning-cli getpeers`, which after 1 confirmation should say that the status is in _Normal operation_.
After 6 confirmations you can use `cli/lightning-cli getchannels` to verify that the channel shows up in the list of open channels.
The funding transaction needs 1 confirmations in order for the channel to be usable, and 6 to be broadcast for others to use.
You can check the status of the channel using `cli/lightning-cli getpeers`, which after 1 confirmation should say that `state` is `CHANNELD_NORMAL`; after 6 confirmations you can use `cli/lightning-cli getchannels` to verify that the `public` field is now `true`.

### Receiving and receiving payments

Expand Down
1 change: 1 addition & 0 deletions gossipd/gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem
entries[num_chans].destination = n->out[j]->dst->id;
entries[num_chans].active = n->out[j]->active;
entries[num_chans].flags = n->out[j]->flags;
entries[num_chans].public = (n->out[j]->channel_update != NULL);
entries[num_chans].short_channel_id = n->out[j]->short_channel_id;
entries[num_chans].last_update_timestamp = n->out[j]->last_timestamp;
if (entries[num_chans].last_update_timestamp >= 0) {
Expand Down
1 change: 1 addition & 0 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static void json_getchannels_reply(struct subd *gossip, const u8 *reply,
&entries[i].short_channel_id));
json_add_num(response, "flags", entries[i].flags);
json_add_bool(response, "active", entries[i].active);
json_add_bool(response, "public", entries[i].public);
if (entries[i].last_update_timestamp >= 0) {
json_add_num(response, "last_update",
entries[i].last_update_timestamp);
Expand Down
2 changes: 2 additions & 0 deletions lightningd/gossip_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void fromwire_gossip_getchannels_entry(const u8 **pptr, size_t *max,
fromwire_pubkey(pptr, max, &entry->destination);
entry->active = fromwire_bool(pptr, max);
entry->flags = fromwire_u16(pptr, max);
entry->public = fromwire_bool(pptr, max);
entry->last_update_timestamp = fromwire_u64(pptr, max);
if (entry->last_update_timestamp >= 0) {
entry->base_fee_msat = fromwire_u32(pptr, max);
Expand All @@ -67,6 +68,7 @@ void towire_gossip_getchannels_entry(
towire_pubkey(pptr, &entry->destination);
towire_bool(pptr, entry->active);
towire_u16(pptr, entry->flags);
towire_bool(pptr, entry->public);
towire_u64(pptr, entry->last_update_timestamp);
if (entry->last_update_timestamp >= 0) {
towire_u32(pptr, entry->base_fee_msat);
Expand Down
1 change: 1 addition & 0 deletions lightningd/gossip_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct gossip_getchannels_entry {
bool active;
struct short_channel_id short_channel_id;
u16 flags;
bool public;
s64 last_update_timestamp; /* -1 means never */
/* These are only set if last_update_timestamp >= 0 */
u32 delay;
Expand Down
20 changes: 19 additions & 1 deletion tests/test_lightningd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,17 @@ def test_gossip_jsonrpc(self):
# Make sure we can route through the channel, will raise on failure
l1.rpc.getroute(l2.info['id'], 100, 1)

# Outgoing should be active, but not public.
channels = l1.rpc.getchannels()['channels']
assert len(channels) == 1
assert channels[0]['active'] == True
assert channels[0]['public'] == False

channels = l2.rpc.getchannels()['channels']
assert len(channels) == 1
assert channels[0]['active'] == True
assert channels[0]['public'] == False

# Now proceed to funding-depth and do a full gossip round
l1.bitcoin.generate_block(5)
# Could happen in either order.
Expand All @@ -1358,9 +1369,16 @@ def test_gossip_jsonrpc(self):
l1.daemon.wait_for_log('peer_in WIRE_CHANNEL_UPDATE')
l2.daemon.wait_for_log('peer_in WIRE_CHANNEL_UPDATE')

# Now should be active and public.
channels = l1.rpc.getchannels()['channels']
assert len(channels) == 2
wait_for(lambda: [c['active'] for c in channels] == [True, True])
assert [c['active'] for c in channels] == [True, True]
assert [c['public'] for c in channels] == [True, True]

channels = l2.rpc.getchannels()['channels']
assert len(channels) == 2
assert [c['active'] for c in channels] == [True, True]
assert [c['public'] for c in channels] == [True, True]

def ping_tests(self, l1, l2):
# 0-byte pong gives just type + length field.
Expand Down

0 comments on commit a8de8a3

Please sign in to comment.