From a8a6d1d66954cee2a23c30860e9ca04c793626c0 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 12 Dec 2017 23:25:50 +0100 Subject: [PATCH] channel: Directly send announcements and updates to gossipd Signed-off-by: Christian Decker --- channeld/channel.c | 15 ++++---- channeld/channel_wire.csv | 7 ---- gossipd/gossip.c | 13 ------- gossipd/gossip_wire.csv | 6 --- lightningd/gossip_control.c | 1 - lightningd/peer_control.c | 76 +------------------------------------ 6 files changed, 8 insertions(+), 110 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 33e873099..cf0e8324b 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -367,16 +367,16 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg) static void announce_channel(struct peer *peer) { + tal_t *tmpctx = tal_tmpctx(peer); u8 *cannounce, *cupdate; - cannounce = create_channel_announcement(peer, peer); - cupdate = create_channel_update(cannounce, peer, false); + cannounce = create_channel_announcement(tmpctx, peer); + cupdate = create_channel_update(tmpctx, peer, false); - /* Tell the master that we to announce channel (it does node) */ - wire_sync_write(MASTER_FD, take(towire_channel_announce(peer, - cannounce, - cupdate))); - tal_free(cannounce); + wire_sync_write(GOSSIP_FD, cannounce); + wire_sync_write(GOSSIP_FD, cupdate); + + tal_free(tmpctx); } static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg) @@ -2215,7 +2215,6 @@ static void req_in(struct peer *peer, const u8 *msg) case WIRE_CHANNEL_INIT: case WIRE_CHANNEL_OFFER_HTLC_REPLY: case WIRE_CHANNEL_PING_REPLY: - case WIRE_CHANNEL_ANNOUNCE: case WIRE_CHANNEL_SENDING_COMMITSIG: case WIRE_CHANNEL_GOT_COMMITSIG: case WIRE_CHANNEL_GOT_REVOKE: diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index bf49cdf0f..5aff8d4e0 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -109,13 +109,6 @@ channel_ping,,len,u16 channel_ping_reply,1111 channel_ping_reply,,totlen,u16 -# Channeld tells the master to announce the channel (with first update) -channel_announce,1012 -channel_announce,,announce_len,u16 -channel_announce,,announce,announce_len*u8 -channel_announce,,update_len,u16 -channel_announce,,update,update_len*u8 - # When we receive funding_locked. channel_got_funding_locked,1019 channel_got_funding_locked,,next_per_commit_point,struct pubkey diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 709105b2b..172a0f9cc 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1284,15 +1284,6 @@ static struct io_plan *resolve_channel_req(struct io_conn *conn, return daemon_conn_read_next(conn, &daemon->master); } -static void handle_forwarded_msg(struct io_conn *conn, struct daemon *daemon, const u8 *msg) -{ - u8 *payload; - if (!fromwire_gossip_forwarded_msg(msg, msg, NULL, &payload)) - master_badmsg(WIRE_GOSSIP_FORWARDED_MSG, msg); - - handle_gossip_msg(daemon, payload); -} - static struct io_plan *handshake_out_success(struct io_conn *conn, const struct pubkey *id, const struct wireaddr *addr, @@ -1536,10 +1527,6 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST: return resolve_channel_req(conn, daemon, daemon->master.msg_in); - case WIRE_GOSSIP_FORWARDED_MSG: - handle_forwarded_msg(conn, daemon, daemon->master.msg_in); - return daemon_conn_read_next(conn, &daemon->master); - case WIRE_GOSSIPCTL_HAND_BACK_PEER: return hand_back_peer(conn, daemon, master->msg_in); diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 2f4651663..e5149503b 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -121,12 +121,6 @@ gossip_resolve_channel_reply,3109 gossip_resolve_channel_reply,,num_keys,u16 gossip_resolve_channel_reply,,keys,num_keys*struct pubkey -# The main daemon forward some gossip message to gossipd, allows injecting -# arbitrary gossip messages. -gossip_forwarded_msg,3010 -gossip_forwarded_msg,,msglen,u16 -gossip_forwarded_msg,,msg,msglen*u8 - # The main daemon asks for peers gossip_getpeers_request,3011 diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 2e9a66d62..9b4eeee03 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -66,7 +66,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIP_GETPEERS_REQUEST: case WIRE_GOSSIP_PING: case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST: - case WIRE_GOSSIP_FORWARDED_MSG: case WIRE_GOSSIPCTL_REACH_PEER: case WIRE_GOSSIPCTL_HAND_BACK_PEER: case WIRE_GOSSIPCTL_RELEASE_PEER: diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index c32dcd634..992c5aa91 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1599,81 +1599,10 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc, tal_free(fc); } -/* Create a node_announcement with the given signature. It may be NULL - * in the case we need to create a provisional announcement for the - * HSM to sign. This is typically called twice: once with the dummy - * signature to get it signed and a second time to build the full - * packet with the signature. The timestamp is handed in since that is - * the only thing that may change between the dummy creation and the - * call with a signature.*/ -static u8 *create_node_announcement(const tal_t *ctx, struct lightningd *ld, - secp256k1_ecdsa_signature *sig, - u32 timestamp) -{ - u8 *features = NULL; - u8 *addresses = tal_arr(ctx, u8, 0); - u8 *announcement; - size_t i; - if (!sig) { - sig = tal(ctx, secp256k1_ecdsa_signature); - memset(sig, 0, sizeof(*sig)); - } - for (i = 0; i < tal_count(ld->wireaddrs); i++) - towire_wireaddr(&addresses, ld->wireaddrs+i); - - announcement = - towire_node_announcement(ctx, sig, features, timestamp, - &ld->id, ld->rgb, (u8 *)ld->alias, - addresses); - return announcement; -} - /* We were informed by channeld that it announced the channel and sent * an update, so we can now start sending a node_announcement. The * first step is to build the provisional announcement and ask the HSM * to sign it. */ -static void peer_channel_announce(struct peer *peer, const u8 *msg) -{ - struct lightningd *ld = peer->ld; - tal_t *tmpctx = tal_tmpctx(peer); - secp256k1_ecdsa_signature sig; - u8 *cannounce, *cupdate; - u8 *announcement, *wrappedmsg; - u32 timestamp = time_now().ts.tv_sec; - - if (!fromwire_channel_announce(msg, msg, NULL, &cannounce, &cupdate)) { - peer_internal_error(peer, "bad fromwire_channel_announced %s", - tal_hex(peer, msg)); - return; - } - - msg = towire_hsm_node_announcement_sig_req( - tmpctx, create_node_announcement(tmpctx, ld, NULL, timestamp)); - - if (!wire_sync_write(ld->hsm_fd, take(msg))) - fatal("Could not write to HSM: %s", strerror(errno)); - - msg = hsm_sync_read(tmpctx, ld); - if (!fromwire_hsm_node_announcement_sig_reply(msg, NULL, &sig)) - fatal("HSM returned an invalid node_announcement sig"); - - /* We got the signature for out provisional node_announcement back - * from the HSM, create the real announcement and forward it to - * gossipd so it can take care of forwarding it. */ - announcement = create_node_announcement(tmpctx, ld, &sig, timestamp); - - /* We have to send channel_announce before channel_update and - * node_announcement */ - wrappedmsg = towire_gossip_forwarded_msg(tmpctx, cannounce); - subd_send_msg(ld->gossip, take(wrappedmsg)); - - wrappedmsg = towire_gossip_forwarded_msg(tmpctx, cupdate); - subd_send_msg(ld->gossip, take(wrappedmsg)); - - wrappedmsg = towire_gossip_forwarded_msg(tmpctx, announcement); - subd_send_msg(ld->gossip, take(wrappedmsg)); - tal_free(tmpctx); -} static void peer_got_funding_locked(struct peer *peer, const u8 *msg) { @@ -2021,9 +1950,6 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) case WIRE_CHANNEL_GOT_REVOKE: peer_got_revoke(sd->peer, msg); break; - case WIRE_CHANNEL_ANNOUNCE: - peer_channel_announce(sd->peer, msg); - break; case WIRE_CHANNEL_GOT_FUNDING_LOCKED: peer_got_funding_locked(sd->peer, msg); break; @@ -2418,7 +2344,7 @@ static unsigned int opening_negotiation_failed(struct subd *openingd, /* We need the peer fd and gossip fd. */ if (tal_count(fds) == 0) return 2; - + if (!fromwire_opening_negotiation_failed(msg, msg, NULL, &cs, &gossip_index, &err)) { peer_internal_error(peer,