gossipd: don't accept forwarding short_channel_ids we don't own.

Gossipd provided a generic "get endpoints of this scid" and we only
use it in one place: to look up htlc forwards.  But lightningd just
assumed that one would be us.

Instead, provide a simpler API which only returns the peer node
if any, and now we handle it much more gracefully.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-10-15 15:27:22 +10:30
parent 030fe1ce53
commit 3991425111
5 changed files with 35 additions and 49 deletions

View File

@@ -93,13 +93,12 @@ gossip_query_channel_range_reply,,scids,num*struct short_channel_id
gossip_dev_set_max_scids_encode_size,3030
gossip_dev_set_max_scids_encode_size,,max,u32
# Given a short_channel_id, return the endpoints
gossip_resolve_channel_request,3009
gossip_resolve_channel_request,,channel_id,struct short_channel_id
# Given a short_channel_id, return the other endpoint (or none if DNE)
gossip_get_channel_peer,3009
gossip_get_channel_peer,,channel_id,struct short_channel_id
gossip_resolve_channel_reply,3109
gossip_resolve_channel_reply,,num_keys,u16
gossip_resolve_channel_reply,,keys,num_keys*struct pubkey
gossip_get_channel_peer_reply,3109
gossip_get_channel_peer_reply,,peer_id,?struct pubkey
# Channel daemon can ask for updates for a specific channel, for sending
# errors. Must be distinct from WIRE_CHANNEL_ANNOUNCEMENT etc. gossip msgs!
1 #include <common/cryptomsg.h>
93 gossip_get_update_reply,,update,len*u8 # Gossipd can tell channeld etc about gossip to fwd.
94 # Gossipd can tell channeld etc about gossip to fwd. gossip_send_gossip,3016
95 gossip_send_gossip,3016 gossip_send_gossip,,len,u16
96 gossip_send_gossip,,len,u16 gossip_send_gossip,,gossip,len*u8
97 gossip_send_gossip,,gossip,len*u8 # Both sides have seen the funding tx being locked, but we have not
98 # Both sides have seen the funding tx being locked, but we have not # yet reached the announcement depth. So we add the channel locally so
99 # yet reached the announcement depth. So we add the channel locally so # we (and peer) can update it already.
100 # we (and peer) can update it already. gossip_local_add_channel,3017
101 gossip_local_add_channel,3017 gossip_local_add_channel,,short_channel_id,struct short_channel_id
gossip_local_add_channel,,short_channel_id,struct short_channel_id
102 gossip_local_add_channel,,remote_node_id,struct pubkey
103 gossip_local_add_channel,,satoshis,u64
104 gossip_local_channel_update,3026

View File

@@ -1846,32 +1846,32 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
return daemon_conn_read_next(master->conn, master);
}
static struct io_plan *resolve_channel_req(struct io_conn *conn,
struct daemon *daemon, const u8 *msg)
static struct io_plan *get_channel_peer(struct io_conn *conn,
struct daemon *daemon, const u8 *msg)
{
struct short_channel_id scid;
struct chan *chan;
struct pubkey *keys;
const struct pubkey *key;
int direction;
if (!fromwire_gossip_resolve_channel_request(msg, &scid))
master_badmsg(WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST, msg);
if (!fromwire_gossip_get_channel_peer(msg, &scid))
master_badmsg(WIRE_GOSSIP_GET_CHANNEL_PEER, msg);
chan = get_channel(daemon->rstate, &scid);
if (!chan) {
status_trace("Failed to resolve channel %s",
type_to_string(tmpctx, struct short_channel_id, &scid));
keys = NULL;
key = NULL;
} else if (local_direction(daemon, chan, &direction)) {
key = &chan->nodes[!direction]->id;
} else {
keys = tal_arr(msg, struct pubkey, 2);
keys[0] = chan->nodes[0]->id;
keys[1] = chan->nodes[1]->id;
status_trace("Resolved channel %s %s<->%s",
type_to_string(tmpctx, struct short_channel_id, &scid),
type_to_string(tmpctx, struct pubkey, &keys[0]),
type_to_string(tmpctx, struct pubkey, &keys[1]));
status_trace("Resolved channel %s was not local",
type_to_string(tmpctx, struct short_channel_id,
&scid));
key = NULL;
}
daemon_conn_send(&daemon->master,
take(towire_gossip_resolve_channel_reply(NULL, keys)));
take(towire_gossip_get_channel_peer_reply(NULL, key)));
return daemon_conn_read_next(conn, &daemon->master);
}
@@ -2000,8 +2000,8 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_GETCHANNELS_REQUEST:
return getchannels_req(conn, daemon, daemon->master.msg_in);
case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST:
return resolve_channel_req(conn, daemon, daemon->master.msg_in);
case WIRE_GOSSIP_GET_CHANNEL_PEER:
return get_channel_peer(conn, daemon, daemon->master.msg_in);
case WIRE_GOSSIP_GET_TXOUT_REPLY:
return handle_txout_reply(conn, daemon, master->msg_in);
@@ -2057,7 +2057,7 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_PING_REPLY:
case WIRE_GOSSIP_SCIDS_REPLY:
case WIRE_GOSSIP_QUERY_CHANNEL_RANGE_REPLY:
case WIRE_GOSSIP_RESOLVE_CHANNEL_REPLY:
case WIRE_GOSSIP_GET_CHANNEL_PEER_REPLY:
case WIRE_GOSSIP_GET_INCOMING_CHANNELS_REPLY:
case WIRE_GOSSIP_GET_UPDATE:
case WIRE_GOSSIP_GET_UPDATE_REPLY: