Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeker autoconnect #7798

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ void peer_supplied_good_gossip(struct daemon *daemon,
peer->gossip_counter += amount;
}

/* Increase a peer's query_reply_counter, if peer not NULL */
void peer_supplied_query_response(struct daemon *daemon,
const struct node_id *source_peer,
size_t amount)
{
struct peer *peer;

if (!source_peer)
return;

peer = find_peer(daemon, source_peer);
if (!peer)
return;

peer->query_reply_counter += amount;
}

/* Queue a gossip message for the peer: connectd simply forwards it to
* the peer. */
void queue_peer_msg(struct daemon *daemon,
Expand Down Expand Up @@ -124,6 +141,7 @@ static void connectd_new_peer(struct daemon *daemon, const u8 *msg)
/* Populate the rest of the peer info. */
peer->daemon = daemon;
peer->gossip_counter = 0;
peer->query_reply_counter = 0;
peer->scid_queries = NULL;
peer->scid_query_idx = 0;
peer->scid_query_nodes = NULL;
Expand Down Expand Up @@ -618,6 +636,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE:
case WIRE_GOSSIPD_CONNECT_TO_PEER:
break;
}

Expand Down
10 changes: 9 additions & 1 deletion gossipd/gossipd.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ struct peer {
/* How much contribution have we made to gossip? */
size_t gossip_counter;

/* How much gossip have we sent in response to gossip queries? */
size_t query_reply_counter;

/* The two features gossip cares about (so far) */
bool gossip_queries_feature, initial_routing_sync_feature;

Expand Down Expand Up @@ -128,11 +131,16 @@ struct peer {
/* Search for a peer. */
struct peer *find_peer(struct daemon *daemon, const struct node_id *id);

/* This peer (may be NULL) gave is valid gossip. */
/* This peer (may be NULL) gave us valid gossip. */
void peer_supplied_good_gossip(struct daemon *daemon,
const struct node_id *source_peer,
size_t amount);

/* Increase peer's query_reply_counter, if peer not NULL */
void peer_supplied_query_response(struct daemon *daemon,
const struct node_id *source_peer,
size_t amount);

/* Get a random peer. NULL if no peers. */
struct peer *first_random_peer(struct daemon *daemon,
struct peer_node_id_map_iter *it);
Expand Down
6 changes: 6 additions & 0 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ subtypedata,peer_update,htlc_maximum_msat,amount_msat,
msgtype,gossipd_remote_channel_update,3010
msgdata,gossipd_remote_channel_update,source_node,?node_id,
msgdata,gossipd_remote_channel_update,peer_update,peer_update,

# Ask lightningd to connect to a peer.
msgtype,gossipd_connect_to_peer,3011
msgdata,gossipd_connect_to_peer,id,node_id,
msgdata,gossipd_connect_to_peer,num,u16,
msgdata,gossipd_connect_to_peer,addrs,wireaddr,num,
7 changes: 7 additions & 0 deletions gossipd/gossmap_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,15 @@ static const char *process_channel_update(const tal_t *ctx,
htlc_maximum_msat);
}

/* Used to evaluate gossip peers' performance */
peer_supplied_good_gossip(gm->daemon, source_peer, 1);

status_peer_debug(source_peer,
"Received channel_update for channel %s/%d now %s",
fmt_short_channel_id(tmpctx, scid),
dir,
channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE");

return NULL;
}

Expand Down Expand Up @@ -941,6 +945,9 @@ static void process_node_announcement(struct gossmap_manage *gm,
if (gossmap_node_announced(node))
gossip_store_del(gm->daemon->gs, node->nann_off, WIRE_NODE_ANNOUNCEMENT);

/* Used to evaluate gossip peers' performance */
peer_supplied_good_gossip(gm->daemon, source_peer, 1);

status_peer_debug(source_peer,
"Received node_announcement for node %s",
fmt_node_id(tmpctx, node_id));
Expand Down
2 changes: 1 addition & 1 deletion gossipd/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)

/* Credit peer for answering gossip, so seeker doesn't get upset:
* since scids are only 8 bytes, use a discount over normal gossip. */
peer_supplied_good_gossip(peer->daemon, &peer->id, tal_count(scids) / 20);
peer_supplied_query_response(peer->daemon, &peer->id, tal_count(scids) / 20);

/* Old code used to set this to 1 all the time; not setting it implies
* we're talking to an upgraded node. */
Expand Down
Loading
Loading