From 9455331575b56718a289ea200395d864683568e3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 28 Sep 2018 12:54:25 +0930 Subject: [PATCH] json: use bolt naming for features arrays in listnodes, listpeers. Deprecate the old names. Signed-off-by: Rusty Russell --- CHANGELOG.md | 1 + lightningd/gossip_control.c | 5 ++++- lightningd/peer_control.c | 11 ++++++++--- tests/test_connection.py | 16 ++++++++-------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc9b73af..c972c84b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Note: You should always set `allow-deprecated-apis=false` to test for changes. - JSON RPC: `listchannels`' `flags` field. This has been split into two fields, see Added. +- JSON RPC: `global_features` and `local_features` fields: use `globalfeatures` and `localfeatures` as per BOLT #1. ### Removed diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index e7584a889..06c31237b 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -206,8 +206,11 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply, nodes[i]->color, ARRAY_SIZE(nodes[i]->color)); json_add_u64(response, "last_timestamp", nodes[i]->last_timestamp); - json_add_hex_talarr(response, "global_features", + json_add_hex_talarr(response, "globalfeatures", nodes[i]->globalfeatures); + if (deprecated_apis) + json_add_hex_talarr(response, "global_features", + nodes[i]->globalfeatures); json_array_start(response, "addresses"); for (j=0; jaddresses); j++) { json_add_address(response, NULL, &nodes[i]->addresses[j]); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 2477278a1..b0a8caca5 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -679,10 +679,15 @@ static void json_add_peer(struct lightningd *ld, struct wireaddr_internal, &p->addr)); json_array_end(response); - json_add_hex_talarr(response, "global_features", + if (deprecated_apis) { + json_add_hex_talarr(response, "global_features", + p->globalfeatures); + json_add_hex_talarr(response, "local_features", + p->localfeatures); + } + json_add_hex_talarr(response, "globalfeatures", p->globalfeatures); - - json_add_hex_talarr(response, "local_features", + json_add_hex_talarr(response, "localfeatures", p->localfeatures); } diff --git a/tests/test_connection.py b/tests/test_connection.py index deb4d1a6d..b4a56c7c0 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -991,8 +991,8 @@ def test_peerinfo(node_factory, bitcoind): # Gossiping but no node announcement yet assert l1.rpc.getpeer(l2.info['id'])['connected'] assert len(l1.rpc.getpeer(l2.info['id'])['channels']) == 0 - assert l1.rpc.getpeer(l2.info['id'])['local_features'] == '8a' - assert l1.rpc.getpeer(l2.info['id'])['global_features'] == '' + assert l1.rpc.getpeer(l2.info['id'])['localfeatures'] == '8a' + assert l1.rpc.getpeer(l2.info['id'])['globalfeatures'] == '' # Fund a channel to force a node announcement chan = l1.fund_channel(l2, 10**6) @@ -1006,18 +1006,18 @@ def test_peerinfo(node_factory, bitcoind): nodes2 = l2.rpc.listnodes(l2.info['id'])['nodes'] peer1 = l1.rpc.getpeer(l2.info['id']) peer2 = l2.rpc.getpeer(l1.info['id']) - assert only_one(nodes1)['global_features'] == peer1['global_features'] - assert only_one(nodes2)['global_features'] == peer2['global_features'] + assert only_one(nodes1)['globalfeatures'] == peer1['globalfeatures'] + assert only_one(nodes2)['globalfeatures'] == peer2['globalfeatures'] - assert l1.rpc.getpeer(l2.info['id'])['local_features'] == '8a' - assert l2.rpc.getpeer(l1.info['id'])['local_features'] == '8a' + assert l1.rpc.getpeer(l2.info['id'])['localfeatures'] == '8a' + assert l2.rpc.getpeer(l1.info['id'])['localfeatures'] == '8a' # If it reconnects after db load, it should know features. l1.restart() wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected']) wait_for(lambda: l2.rpc.getpeer(l1.info['id'])['connected']) - assert l1.rpc.getpeer(l2.info['id'])['local_features'] == '8a' - assert l2.rpc.getpeer(l1.info['id'])['local_features'] == '8a' + assert l1.rpc.getpeer(l2.info['id'])['localfeatures'] == '8a' + assert l2.rpc.getpeer(l1.info['id'])['localfeatures'] == '8a' # Close the channel to forget the peer with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):