Skip to content

Commit

Permalink
Use localfeatures and globalfeatures consistently.
Browse files Browse the repository at this point in the history
That's what BOLT #1 calls them; make it easier for people to grep.

Reported-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Sep 28, 2018
1 parent 15e8801 commit 41b0872
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 103 deletions.
30 changes: 16 additions & 14 deletions common/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include <ccan/array_size/array_size.h>
#include <wire/peer_wire.h>

static const u32 local_features[] = {
static const u32 our_localfeatures[] = {
LOCAL_DATA_LOSS_PROTECT,
LOCAL_INITIAL_ROUTING_SYNC,
LOCAL_GOSSIP_QUERIES
};

static const u32 global_features[] = {
static const u32 our_globalfeatures[] = {
};

/* BOLT #1:
Expand Down Expand Up @@ -46,14 +46,16 @@ static u8 *mkfeatures(const tal_t *ctx, const u32 *arr, size_t n)
return f;
}

u8 *get_offered_global_features(const tal_t *ctx)
u8 *get_offered_globalfeatures(const tal_t *ctx)
{
return mkfeatures(ctx, global_features, ARRAY_SIZE(global_features));
return mkfeatures(ctx,
our_globalfeatures, ARRAY_SIZE(our_globalfeatures));
}

u8 *get_offered_local_features(const tal_t *ctx)
u8 *get_offered_localfeatures(const tal_t *ctx)
{
return mkfeatures(ctx, local_features, ARRAY_SIZE(local_features));
return mkfeatures(ctx,
our_localfeatures, ARRAY_SIZE(our_localfeatures));
}

static bool feature_set(const u8 *features, size_t bit)
Expand Down Expand Up @@ -115,19 +117,19 @@ static bool all_supported_features(const u8 *bitmap,
return true;
}

bool features_supported(const u8 *gfeatures, const u8 *lfeatures)
bool features_supported(const u8 *globalfeatures, const u8 *localfeatures)
{
/* BIT 2 would logically be "compulsory initial_routing_sync", but
* that does not exist, so we special case it. */
if (feature_set(lfeatures,
if (feature_set(localfeatures,
COMPULSORY_FEATURE(LOCAL_INITIAL_ROUTING_SYNC)))
return false;

return all_supported_features(gfeatures,
global_features,
ARRAY_SIZE(global_features))
&& all_supported_features(lfeatures,
local_features,
ARRAY_SIZE(local_features));
return all_supported_features(globalfeatures,
our_globalfeatures,
ARRAY_SIZE(our_globalfeatures))
&& all_supported_features(localfeatures,
our_localfeatures,
ARRAY_SIZE(our_localfeatures));
}

6 changes: 3 additions & 3 deletions common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
/* Returns true if we're OK with all these offered features. */
bool features_supported(const u8 *gfeatures, const u8 *lfeatures);

/* For sending our features: tal_len() returns length. */
u8 *get_offered_global_features(const tal_t *ctx);
u8 *get_offered_local_features(const tal_t *ctx);
/* For sending our features: tal_count() returns length. */
u8 *get_offered_globalfeatures(const tal_t *ctx);
u8 *get_offered_localfeatures(const tal_t *ctx);

/* Is this feature bit requested? (Either compulsory or optional) */
bool feature_offered(const u8 *features, size_t f);
Expand Down
12 changes: 6 additions & 6 deletions common/test/run-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int main(void)
assert(features_supported(bits, bits));

/* We must support our own features. */
lf = get_offered_global_features(tmpctx);
gf = get_offered_global_features(tmpctx);
lf = get_offered_globalfeatures(tmpctx);
gf = get_offered_globalfeatures(tmpctx);
assert(features_supported(gf, lf));

/* We can add random odd features, no problem. */
Expand All @@ -89,15 +89,15 @@ int main(void)
assert(!features_supported(gf, bits));
} else {
assert(features_supported(gf, bits)
== feature_supported(i, local_features,
ARRAY_SIZE(local_features)));
== feature_supported(i, our_localfeatures,
ARRAY_SIZE(our_localfeatures)));
}

bits = tal_dup_arr(tmpctx, u8, gf, tal_count(gf), 0);
set_bit(&bits, i);
assert(features_supported(bits, lf)
== feature_supported(i, global_features,
ARRAY_SIZE(global_features)));
== feature_supported(i, our_globalfeatures,
ARRAY_SIZE(our_globalfeatures)));
}

wally_cleanup(0);
Expand Down
8 changes: 4 additions & 4 deletions connectd/connect_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
connectctl_init,2000
connectctl_init,,id,struct pubkey
connectctl_init,,gflen,u16
connectctl_init,,gfeatures,gflen*u8
connectctl_init,,globalfeatures,gflen*u8
connectctl_init,,lflen,u16
connectctl_init,,lfeatures,lflen*u8
connectctl_init,,localfeatures,lflen*u8
connectctl_init,,num_wireaddrs,u16
connectctl_init,,wireaddrs,num_wireaddrs*struct wireaddr_internal
connectctl_init,,listen_announce,num_wireaddrs*enum addr_listen_announce
Expand Down Expand Up @@ -55,9 +55,9 @@ connect_peer_connected,,id,struct pubkey
connect_peer_connected,,addr,struct wireaddr_internal
connect_peer_connected,,crypto_state,struct crypto_state
connect_peer_connected,,gflen,u16
connect_peer_connected,,gfeatures,gflen*u8
connect_peer_connected,,globalfeatures,gflen*u8
connect_peer_connected,,lflen,u16
connect_peer_connected,,lfeatures,lflen*u8
connect_peer_connected,,localfeatures,lflen*u8

# master -> connectd: peer has disconnected.
connectctl_peer_disconnected,2015
Expand Down
32 changes: 16 additions & 16 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,28 @@ static void connected_to_peer(struct daemon *daemon,
* it to forward gossip to/from the peer. The gossip daemon needs to know a
* few of the features of the peer and its id (for reporting).
*
* The 'lfeatures' refers to 'local features', which indicate the properties
* when you're connected to it like we are: there are also 'global features'
* The 'localfeatures' is a field in the `init` message, indicating properties
* when you're connected to it like we are: there are also 'globalfeatures'
* which specify requirements to route a payment through a node. */
static int get_gossipfd(struct daemon *daemon,
const struct pubkey *id,
const u8 *lfeatures)
const u8 *localfeatures)
{
bool gossip_queries_feature, initial_routing_sync, success;
u8 *msg;

/*~ The way features generally work is that both sides need to offer it;
* we always offer `gossip_queries`, but this check is explicit. */
gossip_queries_feature
= feature_offered(lfeatures, LOCAL_GOSSIP_QUERIES)
= feature_offered(localfeatures, LOCAL_GOSSIP_QUERIES)
&& feature_offered(daemon->localfeatures,
LOCAL_GOSSIP_QUERIES);

/*~ `initial_routing_sync is supported by every node, since it was in
* the initial lightning specification: it means the peer wants the
* backlog of existing gossip. */
initial_routing_sync
= feature_offered(lfeatures, LOCAL_INITIAL_ROUTING_SYNC);
= feature_offered(localfeatures, LOCAL_INITIAL_ROUTING_SYNC);

/*~ We do this communication sync, since gossipd is our friend and
* it's easier. If gossipd fails, we fail. */
Expand Down Expand Up @@ -331,7 +331,7 @@ struct peer_reconnected {
struct daemon *daemon;
struct pubkey id;
const u8 *peer_connected_msg;
const u8 *lfeatures;
const u8 *localfeatures;
};

/*~ For simplicity, lightningd only ever deals with a single connection per
Expand All @@ -350,7 +350,7 @@ static struct io_plan *retry_peer_connected(struct io_conn *conn,
* our temporary structure. */
plan = peer_connected(conn, pr->daemon, &pr->id,
take(pr->peer_connected_msg),
take(pr->lfeatures));
take(pr->localfeatures));
tal_free(pr);
return plan;
}
Expand All @@ -361,7 +361,7 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
struct daemon *daemon,
const struct pubkey *id,
const u8 *peer_connected_msg TAKES,
const u8 *lfeatures TAKES)
const u8 *localfeatures TAKES)
{
u8 *msg;
struct peer_reconnected *r;
Expand All @@ -379,13 +379,13 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
r->id = *id;

/*~ Note that tal_dup_arr() will do handle the take() of
* peer_connected_msg and lfeatures (turning it into a simply
* peer_connected_msg and localfeatures (turning it into a simply
* tal_steal() in those cases). */
r->peer_connected_msg
= tal_dup_arr(r, u8, peer_connected_msg,
tal_count(peer_connected_msg), 0);
r->lfeatures
= tal_dup_arr(r, u8, lfeatures, tal_count(lfeatures), 0);
r->localfeatures
= tal_dup_arr(r, u8, localfeatures, tal_count(localfeatures), 0);

/*~ ccan/io supports waiting on an address: in this case, the key in
* the peer set. When someone calls `io_wake()` on that address, it
Expand All @@ -400,22 +400,22 @@ struct io_plan *peer_connected(struct io_conn *conn,
struct daemon *daemon,
const struct pubkey *id,
const u8 *peer_connected_msg TAKES,
const u8 *lfeatures TAKES)
const u8 *localfeatures TAKES)
{
int gossip_fd;

if (pubkey_set_get(&daemon->peers, id))
return peer_reconnected(conn, daemon, id, peer_connected_msg,
lfeatures);
localfeatures);

/* We've successfully connected. */
connected_to_peer(daemon, conn, id);

gossip_fd = get_gossipfd(daemon, id, lfeatures);
gossip_fd = get_gossipfd(daemon, id, localfeatures);

/* We promised we'd take it by marking it TAKEN above; simply free it. */
if (taken(lfeatures))
tal_free(lfeatures);
if (taken(localfeatures))
tal_free(localfeatures);

/* If gossipd can't give us a file descriptor, we give up connecting. */
if (gossip_fd < 0)
Expand Down
27 changes: 14 additions & 13 deletions connectd/peer_exchange_initmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
struct peer *peer)
{
u8 *msg = cryptomsg_decrypt_body(peer, &peer->cs, peer->msg);
u8 *gfeatures, *lfeatures;
u8 *globalfeatures, *localfeatures;

if (!msg)
return io_close(conn);
Expand All @@ -49,7 +49,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
if (unlikely(is_unknown_msg_discardable(msg)))
return read_init(conn, peer);

if (!fromwire_init(peer, msg, &gfeatures, &lfeatures)) {
if (!fromwire_init(peer, msg, &globalfeatures, &localfeatures)) {
status_trace("peer %s bad fromwire_init '%s', closing",
type_to_string(tmpctx, struct pubkey, &peer->id),
tal_hex(tmpctx, msg));
Expand All @@ -65,28 +65,29 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
* - upon receiving unknown _even_ feature bits that are non-zero:
* - MUST fail the connection.
*/
if (!features_supported(gfeatures, lfeatures)) {
const u8 *global_features = get_offered_global_features(msg);
const u8 *local_features = get_offered_local_features(msg);
if (!features_supported(globalfeatures, localfeatures)) {
const u8 *our_globalfeatures = get_offered_globalfeatures(msg);
const u8 *our_localfeatures = get_offered_localfeatures(msg);
msg = towire_errorfmt(NULL, NULL, "Unsupported features %s/%s:"
" we only offer globalfeatures %s"
" and localfeatures %s",
tal_hex(msg, gfeatures),
tal_hex(msg, lfeatures),
tal_hex(msg, global_features),
tal_hex(msg, local_features));
tal_hex(msg, globalfeatures),
tal_hex(msg, localfeatures),
tal_hex(msg, our_globalfeatures),
tal_hex(msg, our_localfeatures));
msg = cryptomsg_encrypt_msg(NULL, &peer->cs, take(msg));
return io_write(conn, msg, tal_count(msg), io_close_cb, NULL);
}

/* Create message to tell master peer has connected. */
msg = towire_connect_peer_connected(NULL, &peer->id, &peer->addr,
&peer->cs, gfeatures, lfeatures);
&peer->cs,
globalfeatures, localfeatures);

/* Usually return io_close_taken_fd, but may wait for old peer to
* be disconnected if it's a reconnect. */
return peer_connected(conn, peer->daemon, &peer->id,
take(msg), take(lfeatures));
take(msg), take(localfeatures));
}

static struct io_plan *peer_init_hdr_received(struct io_conn *conn,
Expand Down Expand Up @@ -149,8 +150,8 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
* connection.
*/
peer->msg = towire_init(NULL,
get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx));
get_offered_globalfeatures(tmpctx),
get_offered_localfeatures(tmpctx));
status_peer_io(LOG_IO_OUT, peer->msg);
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));

Expand Down
10 changes: 5 additions & 5 deletions devtools/gossipwith.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ static struct io_plan *handshake_success(struct io_conn *conn,
{
u8 *msg;
struct crypto_state cs = *orig_cs;
u8 *local_features;
u8 *localfeatures;

if (initial_sync) {
local_features = tal(conn, u8);
local_features[0] = (1 << 3);
localfeatures = tal(conn, u8);
localfeatures[0] = (1 << 3);
} else
local_features = NULL;
localfeatures = NULL;

msg = towire_init(NULL, NULL, local_features);
msg = towire_init(NULL, NULL, localfeatures);

sync_crypto_write(&cs, conn->fd, take(msg));
/* Ignore their init message. */
Expand Down
6 changes: 3 additions & 3 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1393,16 +1393,16 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem

static void append_node(const struct gossip_getnodes_entry ***nodes,
const struct pubkey *nodeid,
const u8 *gfeatures,
const u8 *globalfeatures,
/* If non-NULL, contains more information */
const struct node *n)
{
struct gossip_getnodes_entry *new;

new = tal(*nodes, struct gossip_getnodes_entry);
new->nodeid = *nodeid;
new->global_features = tal_dup_arr(*nodes, u8, gfeatures,
tal_count(gfeatures), 0);
new->globalfeatures = tal_dup_arr(*nodes, u8, globalfeatures,
tal_count(globalfeatures), 0);
if (!n || n->last_timestamp < 0) {
new->last_timestamp = -1;
new->addresses = NULL;
Expand Down
4 changes: 2 additions & 2 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ int connectd_init(struct lightningd *ld)

msg = towire_connectctl_init(
tmpctx, &ld->id,
get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx), wireaddrs,
get_offered_globalfeatures(tmpctx),
get_offered_localfeatures(tmpctx), wireaddrs,
listen_announce,
ld->proxyaddr, ld->use_proxy_always || ld->pure_tor_setup,
allow_localhost, ld->config.use_dns,
Expand Down
4 changes: 2 additions & 2 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
msg = towire_gossipctl_init(
tmpctx, ld->config.broadcast_interval,
&get_chainparams(ld)->genesis_blockhash, &ld->id,
get_offered_global_features(tmpctx),
get_offered_globalfeatures(tmpctx),
ld->rgb,
ld->alias, ld->config.channel_update_interval,
ld->announcable);
Expand Down Expand Up @@ -207,7 +207,7 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
json_add_u64(response, "last_timestamp",
nodes[i]->last_timestamp);
json_add_hex_talarr(response, "global_features",
nodes[i]->global_features);
nodes[i]->globalfeatures);
json_array_start(response, "addresses");
for (j=0; j<tal_count(nodes[i]->addresses); j++) {
json_add_address(response, NULL, &nodes[i]->addresses[j]);
Expand Down

0 comments on commit 41b0872

Please sign in to comment.