Browse Source

channel: Directly send announcements and updates to gossipd

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
a8a6d1d669
  1. 15
      channeld/channel.c
  2. 7
      channeld/channel_wire.csv
  3. 13
      gossipd/gossip.c
  4. 6
      gossipd/gossip_wire.csv
  5. 1
      lightningd/gossip_control.c
  6. 74
      lightningd/peer_control.c

15
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);
wire_sync_write(GOSSIP_FD, cannounce);
wire_sync_write(GOSSIP_FD, cupdate);
/* 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);
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:

7
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

Can't render this file because it has a wrong number of fields in line 2.

13
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);

6
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

Can't render this file because it has a wrong number of fields in line 5.

1
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:

74
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;

Loading…
Cancel
Save