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) {
status_unusual("peer %s scid %s: unknown channel",
type_to_string(trc, struct pubkey, &peer->id),
type_to_string(trc, struct short_channel_id,
&scid));
update = NULL;
} else {
struct node_connection *c;
/* We want update than comes from our end. */ /* We want update than comes from our end. */
us = get_node(peer->daemon->rstate, &peer->daemon->id); if (pubkey_eq(&chan->nodes[0]->id, &peer->daemon->id))
if (!us) { c = chan->connections[0];
status_trace("peer %s schanid %s but can't find ourselves", else if (pubkey_eq(&chan->nodes[1]->id, &peer->daemon->id))
type_to_string(trc, struct pubkey, &peer->id), c = chan->connections[1];
type_to_string(trc, struct short_channel_id, else {
&schanid)); status_unusual("peer %s scid %s: not our channel?",
update = NULL; type_to_string(trc, struct pubkey,
goto reply; &peer->id),
type_to_string(trc,
struct short_channel_id,
&scid));
c = NULL;
} }
for (i = 0; i < tal_count(us->channels); i++) { if (c)
struct node_connection *c;
if (!structeq(&us->channels[i]->scid, &schanid))
continue;
c = connection_from(us, us->channels[i]);
if (!c)
update = NULL;
else
update = c->channel_update; update = c->channel_update;
}
status_trace("peer %s schanid %s: %s update", status_trace("peer %s schanid %s: %s update",
type_to_string(trc, struct pubkey, &peer->id), type_to_string(trc, struct pubkey, &peer->id),
type_to_string(trc, struct short_channel_id, type_to_string(trc, struct short_channel_id, &scid),
&schanid),
update ? "got" : "no"); update ? "got" : "no");
goto reply;
}
update = NULL;
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));
} }