gossip: handle_get_update can just use get_channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-03-02 19:29:16 +10:30 committed by Christian Decker
parent a9b1d73148
commit 6bc634badf

View File

@ -709,51 +709,50 @@ static struct io_plan *peer_start_gossip(struct io_conn *conn, struct peer *peer
static void handle_get_update(struct peer *peer, const u8 *msg) static void handle_get_update(struct peer *peer, const u8 *msg)
{ {
struct short_channel_id schanid; struct short_channel_id scid;
struct node *us; struct routing_channel *chan;
size_t i;
const u8 *update; const u8 *update;
if (!fromwire_gossip_get_update(msg, &schanid)) { if (!fromwire_gossip_get_update(msg, &scid)) {
status_trace("peer %s sent bad gossip_get_update %s", status_trace("peer %s sent bad gossip_get_update %s",
type_to_string(trc, struct pubkey, &peer->id), type_to_string(trc, struct pubkey, &peer->id),
tal_hex(trc, msg)); tal_hex(trc, msg));
return; return;
} }
/* FIXME: Do direct scid lookup to get channel */ chan = get_channel(peer->daemon->rstate, &scid);
if (!chan) {
/* We want update than comes from our end. */ status_unusual("peer %s scid %s: unknown channel",
us = get_node(peer->daemon->rstate, &peer->daemon->id); type_to_string(trc, struct pubkey, &peer->id),
if (!us) { type_to_string(trc, struct short_channel_id,
status_trace("peer %s schanid %s but can't find ourselves", &scid));
type_to_string(trc, struct pubkey, &peer->id),
type_to_string(trc, struct short_channel_id,
&schanid));
update = NULL; update = NULL;
goto reply; } else {
}
for (i = 0; i < tal_count(us->channels); i++) {
struct node_connection *c; struct node_connection *c;
if (!structeq(&us->channels[i]->scid, &schanid))
continue;
c = connection_from(us, us->channels[i]); /* We want update than comes from our end. */
if (!c) if (pubkey_eq(&chan->nodes[0]->id, &peer->daemon->id))
update = NULL; c = chan->connections[0];
else else if (pubkey_eq(&chan->nodes[1]->id, &peer->daemon->id))
c = chan->connections[1];
else {
status_unusual("peer %s scid %s: not our channel?",
type_to_string(trc, struct pubkey,
&peer->id),
type_to_string(trc,
struct short_channel_id,
&scid));
c = NULL;
}
if (c)
update = c->channel_update; update = c->channel_update;
status_trace("peer %s schanid %s: %s update",
type_to_string(trc, struct pubkey, &peer->id),
type_to_string(trc, struct short_channel_id,
&schanid),
update ? "got" : "no");
goto reply;
} }
update = NULL; status_trace("peer %s schanid %s: %s update",
type_to_string(trc, struct pubkey, &peer->id),
type_to_string(trc, struct short_channel_id, &scid),
update ? "got" : "no");
reply:
msg = towire_gossip_get_update_reply(msg, update); msg = towire_gossip_get_update_reply(msg, update);
daemon_conn_send(peer->remote, take(msg)); daemon_conn_send(peer->remote, take(msg));
} }