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

No next lookup via gossipd #3547

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions gossipd/gossip_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ msgdata,gossip_ping_reply,totlen,u16,
msgtype,gossip_dev_set_max_scids_encode_size,3030
msgdata,gossip_dev_set_max_scids_encode_size,max,u32,

# Given a short_channel_id, return the other endpoint (or none if DNE)
msgtype,gossip_get_channel_peer,3009
msgdata,gossip_get_channel_peer,channel_id,short_channel_id,

msgtype,gossip_get_channel_peer_reply,3109
msgdata,gossip_get_channel_peer_reply,peer_id,?node_id,
msgdata,gossip_get_channel_peer_reply,stripped_update_len,u16,
msgdata,gossip_get_channel_peer_reply,stripped_update,u8,stripped_update_len
# Given a short_channel_id, return the latest (stripped) update for error msg.
msgtype,gossip_get_stripped_cupdate,3010
msgdata,gossip_get_stripped_cupdate,channel_id,short_channel_id,

msgtype,gossip_get_stripped_cupdate_reply,3110
msgdata,gossip_get_stripped_cupdate_reply,stripped_update_len,u16,
msgdata,gossip_get_stripped_cupdate_reply,stripped_update,u8,stripped_update_len

# gossipd->master: we're closing this channel.
msgtype,gossip_local_channel_close,3027
Expand Down
22 changes: 10 additions & 12 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,28 +1335,26 @@ static struct io_plan *dev_gossip_set_time(struct io_conn *conn,
}
#endif /* DEVELOPER */

/*~ lightningd: so, tell me about this channel, so we can forward to it. */
static struct io_plan *get_channel_peer(struct io_conn *conn,
struct daemon *daemon, const u8 *msg)
/*~ lightningd: so, get me the latest update for this local channel,
* so I can include it in an error message. */
static struct io_plan *get_stripped_cupdate(struct io_conn *conn,
struct daemon *daemon, const u8 *msg)
{
struct short_channel_id scid;
struct local_chan *local_chan;
const struct node_id *key;
const u8 *stripped_update;

if (!fromwire_gossip_get_channel_peer(msg, &scid))
master_badmsg(WIRE_GOSSIP_GET_CHANNEL_PEER, msg);
if (!fromwire_gossip_get_stripped_cupdate(msg, &scid))
master_badmsg(WIRE_GOSSIP_GET_STRIPPED_CUPDATE, msg);

local_chan = local_chan_map_get(&daemon->rstate->local_chan_map, &scid);
if (!local_chan) {
status_debug("Failed to resolve local channel %s",
type_to_string(tmpctx, struct short_channel_id, &scid));
key = NULL;
stripped_update = NULL;
} else {
const struct half_chan *hc;

key = &local_chan->chan->nodes[!local_chan->direction]->id;
/* Since we're going to use it, make sure it's up-to-date. */
refresh_local_channel(daemon, local_chan, false);

Expand All @@ -1372,7 +1370,7 @@ static struct io_plan *get_channel_peer(struct io_conn *conn,
stripped_update = NULL;
}
daemon_conn_send(daemon->master,
take(towire_gossip_get_channel_peer_reply(NULL, key,
take(towire_gossip_get_stripped_cupdate_reply(NULL,
stripped_update)));
return daemon_conn_read_next(conn, daemon->master);
}
Expand Down Expand Up @@ -1571,8 +1569,8 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIP_GETCHANNELS_REQUEST:
return getchannels_req(conn, daemon, msg);

case WIRE_GOSSIP_GET_CHANNEL_PEER:
return get_channel_peer(conn, daemon, msg);
case WIRE_GOSSIP_GET_STRIPPED_CUPDATE:
return get_stripped_cupdate(conn, daemon, msg);

case WIRE_GOSSIP_GET_TXOUT_REPLY:
return handle_txout_reply(conn, daemon, msg);
Expand Down Expand Up @@ -1620,7 +1618,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIP_GETROUTE_REPLY:
case WIRE_GOSSIP_GETCHANNELS_REPLY:
case WIRE_GOSSIP_PING_REPLY:
case WIRE_GOSSIP_GET_CHANNEL_PEER_REPLY:
case WIRE_GOSSIP_GET_STRIPPED_CUPDATE_REPLY:
case WIRE_GOSSIP_GET_INCOMING_CHANNELS_REPLY:
case WIRE_GOSSIP_GET_TXOUT:
case WIRE_GOSSIP_DEV_MEMLEAK_REPLY:
Expand Down
17 changes: 16 additions & 1 deletion lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
= tal_steal(channel, remote_upfront_shutdown_script);
channel->option_static_remotekey = option_static_remotekey;
channel->forgets = tal_arr(channel, struct command *, 0);
channel->stripped_update = NULL;

list_add_tail(&peer->channels, &channel->list);
tal_add_destructor(channel, destroy_channel);
Expand Down Expand Up @@ -329,6 +328,22 @@ struct channel *active_channel_by_id(struct lightningd *ld,
return peer_active_channel(peer);
}

struct channel *active_channel_by_scid(struct lightningd *ld,
const struct short_channel_id *scid)
{
struct peer *p;
struct channel *chan;
list_for_each(&ld->peers, p, list) {
list_for_each(&p->channels, chan, list) {
if (channel_active(chan)
&& chan->scid
&& short_channel_id_eq(scid, chan->scid))
return chan;
}
}
return NULL;
}

struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid)
{
struct peer *p;
Expand Down
6 changes: 3 additions & 3 deletions lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ struct channel {

/* Any commands trying to forget us. */
struct command **forgets;

/* Lastest channel_update from gossipd, if any: type stripped! */
const u8 *stripped_update;
};

struct channel *new_channel(struct peer *peer, u64 dbid,
Expand Down Expand Up @@ -217,6 +214,9 @@ struct channel *active_channel_by_id(struct lightningd *ld,

struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid);

struct channel *active_channel_by_scid(struct lightningd *ld,
const struct short_channel_id *scid);

void channel_set_last_tx(struct channel *channel,
struct bitcoin_tx *tx,
const struct bitcoin_signature *sig,
Expand Down
4 changes: 2 additions & 2 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIP_GETROUTE_REQUEST:
case WIRE_GOSSIP_GETCHANNELS_REQUEST:
case WIRE_GOSSIP_PING:
case WIRE_GOSSIP_GET_CHANNEL_PEER:
case WIRE_GOSSIP_GET_STRIPPED_CUPDATE:
case WIRE_GOSSIP_GET_TXOUT_REPLY:
case WIRE_GOSSIP_OUTPOINT_SPENT:
case WIRE_GOSSIP_PAYMENT_FAILURE:
Expand All @@ -154,10 +154,10 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIP_GETNODES_REPLY:
case WIRE_GOSSIP_GETROUTE_REPLY:
case WIRE_GOSSIP_GETCHANNELS_REPLY:
case WIRE_GOSSIP_GET_CHANNEL_PEER_REPLY:
case WIRE_GOSSIP_GET_INCOMING_CHANNELS_REPLY:
case WIRE_GOSSIP_DEV_MEMLEAK_REPLY:
case WIRE_GOSSIP_DEV_COMPACT_STORE_REPLY:
case WIRE_GOSSIP_GET_STRIPPED_CUPDATE_REPLY:
break;

case WIRE_GOSSIP_PING_REPLY:
Expand Down
7 changes: 5 additions & 2 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ static void shutdown_subdaemons(struct lightningd *ld)
/*~ The three "global" daemons, which we shutdown explicitly: we
* give them 10 seconds to exit gracefully before killing them. */
ld->connectd = subd_shutdown(ld->connectd, 10);
ld->gossip = subd_shutdown(ld->gossip, 10);
ld->hsm = subd_shutdown(ld->hsm, 10);

/* Now we free all the HTLCs */
free_htlcs(ld, NULL);
Expand Down Expand Up @@ -547,6 +545,11 @@ static void shutdown_subdaemons(struct lightningd *ld)
tal_free(p);
}

/*~ Now they're all dead, we can stop gossipd: doing it before HTLCs is
* problematic because local_fail_in_htlc_needs_update() asks gossipd */
ld->gossip = subd_shutdown(ld->gossip, 10);
ld->hsm = subd_shutdown(ld->hsm, 10);

/*~ Commit the transaction. Note that the db is actually
* single-threaded, so commits never fail and we don't need
* spin-and-retry logic everywhere. */
Expand Down
4 changes: 3 additions & 1 deletion lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,13 @@ static const u8 *send_onion(const tal_t *ctx, struct lightningd *ld,
{
const u8 *onion;
unsigned int base_expiry;
bool dont_care_about_channel_update;
base_expiry = get_block_height(ld->topology) + 1;
onion = serialize_onionpacket(tmpctx, packet);
return send_htlc_out(ctx, channel, first_hop->amount,
base_expiry + first_hop->delay,
payment_hash, partid, onion, NULL, hout);
payment_hash, partid, onion, NULL, hout,
&dont_care_about_channel_update);
}

/* destination/route_channels/route_nodes are NULL (and path_secrets may be NULL)
Expand Down
12 changes: 4 additions & 8 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,14 +1199,10 @@ command_find_channel(struct command *cmd,
tok->end - tok->start,
buffer + tok->start);
} else if (json_to_short_channel_id(buffer, tok, &scid)) {
list_for_each(&ld->peers, peer, list) {
*channel = peer_active_channel(peer);
if (!*channel)
continue;
if ((*channel)->scid
&& (*channel)->scid->u64 == scid.u64)
return NULL;
}
*channel = active_channel_by_scid(ld, &scid);
if (*channel)
return NULL;

return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Short channel ID not found: '%.*s'",
tok->end - tok->start,
Expand Down
Loading