Skip to content

Commit

Permalink
gossipd: advertize all our features in node_announcement.
Browse files Browse the repository at this point in the history
This preempts the acceptance of
lightning/bolts#666 but it's
clear that feature bits are going to be distinct, so this is safe to
do anyway.

See lightning/bolts#680

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Oct 3, 2019
1 parent b3a6279 commit 4e4d405
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Plugin: new notifications `sendpay_success` and `sendpay_failure`.
- Protocol: we now offer `option_gossip_queries_ex` for finegrained gossip control.
- Protocol: no longer ask for `initial_routing_sync` (only affects ancient peers).
- Protocol: nodes now announce features in `node_announcement` broadcasts.

### Changed

Expand Down
12 changes: 12 additions & 0 deletions common/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ u8 *get_offered_globalfeatures(const tal_t *ctx)
our_globalfeatures, ARRAY_SIZE(our_globalfeatures));
}

/* We currently advertize everything in node_announcement, except
* initial_routing_sync which the spec says not to (and we don't set
* any more anyway).
*
* FIXME: Add bolt ref when finalized!
*/
u8 *get_offered_nodefeatures(const tal_t *ctx)
{
return mkfeatures(ctx,
our_localfeatures, ARRAY_SIZE(our_localfeatures));
}

u8 *get_offered_localfeatures(const tal_t *ctx)
{
return mkfeatures(ctx,
Expand Down
1 change: 1 addition & 0 deletions common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bool features_supported(const u8 *globalfeatures, const u8 *localfeatures);
/* For sending our features: tal_count() returns length. */
u8 *get_offered_globalfeatures(const tal_t *ctx);
u8 *get_offered_localfeatures(const tal_t *ctx);
u8 *get_offered_nodefeatures(const tal_t *ctx);

/* Is this feature bit requested? (Either compulsory or optional) */
bool feature_offered(const u8 *features, size_t f);
Expand Down
2 changes: 1 addition & 1 deletion gossipd/gossip_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
towire_wireaddr(&addresses, &daemon->announcable[i]);

announcement =
towire_node_announcement(ctx, sig, daemon->globalfeatures, timestamp,
towire_node_announcement(ctx, sig, daemon->nodefeatures, timestamp,
&daemon->id, daemon->rgb, daemon->alias,
addresses);
return announcement;
Expand Down
3 changes: 2 additions & 1 deletion gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ static struct io_plan *gossip_init(struct io_conn *conn,

if (!fromwire_gossipctl_init(daemon, msg,
&chainparams,
&daemon->id, &daemon->globalfeatures,
&daemon->id,
&daemon->nodefeatures,
daemon->rgb,
daemon->alias,
&daemon->announcable,
Expand Down
4 changes: 2 additions & 2 deletions gossipd/gossipd.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct daemon {
/* Timers: we batch gossip, and also refresh announcements */
struct timers timers;

/* Global features to list in node_announcement. */
u8 *globalfeatures;
/* Features to list in node_announcement. */
u8 *nodefeatures;

/* Alias (not NUL terminated) and favorite color for node_announcement */
u8 alias[32];
Expand Down
2 changes: 1 addition & 1 deletion lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
tmpctx,
chainparams,
&ld->id,
get_offered_globalfeatures(tmpctx),
get_offered_nodefeatures(tmpctx),
ld->rgb,
ld->alias,
ld->announcable,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,8 +1403,8 @@ 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)['globalfeatures'] == peer1['globalfeatures']
assert only_one(nodes2)['globalfeatures'] == peer2['globalfeatures']
assert only_one(nodes1)['globalfeatures'] == peer1['localfeatures']
assert only_one(nodes2)['globalfeatures'] == peer2['localfeatures']

assert l1.rpc.getpeer(l2.info['id'])['localfeatures'] == lfeatures
assert l2.rpc.getpeer(l1.info['id'])['localfeatures'] == lfeatures
Expand Down
9 changes: 7 additions & 2 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fixtures import * # noqa: F401,F403
from fixtures import TEST_NETWORK
from lightning import RpcError
from utils import wait_for, TIMEOUT, only_one, sync_blockheight
from utils import wait_for, TIMEOUT, only_one, sync_blockheight, EXPERIMENTAL_FEATURES

import json
import logging
Expand Down Expand Up @@ -1012,6 +1012,11 @@ def test_node_reannounce(node_factory, bitcoind):
wait_for(lambda: 'alias' in only_one(l2.rpc.listnodes(l1.info['id'])['nodes']))
assert only_one(l2.rpc.listnodes(l1.info['id'])['nodes'])['alias'].startswith('JUNIORBEAM')

lfeatures = '28a2'

# Make sure it gets features correct.
assert only_one(l2.rpc.listnodes(l1.info['id'])['nodes'])['globalfeatures'] == lfeatures

l1.stop()
l1.daemon.opts['alias'] = 'SENIORBEAM'
# It won't update within 5 seconds, so sleep.
Expand Down Expand Up @@ -1429,7 +1434,7 @@ def test_gossip_store_compact_on_load(node_factory, bitcoind):
l2.restart()

wait_for(lambda: l2.daemon.is_in_log(r'gossip_store_compact_offline: [5-8] deleted, 9 copied'))
wait_for(lambda: l2.daemon.is_in_log(r'gossip_store: Read 1/4/2/0 cannounce/cupdate/nannounce/cdelete from store \(0 deleted\) in 1446 bytes'))
wait_for(lambda: l2.daemon.is_in_log(r'gossip_store: Read 1/4/2/0 cannounce/cupdate/nannounce/cdelete from store \(0 deleted\) in 1450 bytes'))


def test_gossip_announce_invalid_block(node_factory, bitcoind):
Expand Down

0 comments on commit 4e4d405

Please sign in to comment.