channel: Directly send announcements and updates to gossipd

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2017-12-12 23:25:50 +01:00 committed by Rusty Russell
parent 32a96973a5
commit a8a6d1d669
6 changed files with 8 additions and 110 deletions

View File

@ -367,16 +367,16 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
static void announce_channel(struct peer *peer) static void announce_channel(struct peer *peer)
{ {
tal_t *tmpctx = tal_tmpctx(peer);
u8 *cannounce, *cupdate; u8 *cannounce, *cupdate;
cannounce = create_channel_announcement(peer, peer); cannounce = create_channel_announcement(tmpctx, peer);
cupdate = create_channel_update(cannounce, peer, false); cupdate = create_channel_update(tmpctx, peer, false);
/* Tell the master that we to announce channel (it does node) */ wire_sync_write(GOSSIP_FD, cannounce);
wire_sync_write(MASTER_FD, take(towire_channel_announce(peer, wire_sync_write(GOSSIP_FD, cupdate);
cannounce,
cupdate))); tal_free(tmpctx);
tal_free(cannounce);
} }
static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg) 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_INIT:
case WIRE_CHANNEL_OFFER_HTLC_REPLY: case WIRE_CHANNEL_OFFER_HTLC_REPLY:
case WIRE_CHANNEL_PING_REPLY: case WIRE_CHANNEL_PING_REPLY:
case WIRE_CHANNEL_ANNOUNCE:
case WIRE_CHANNEL_SENDING_COMMITSIG: case WIRE_CHANNEL_SENDING_COMMITSIG:
case WIRE_CHANNEL_GOT_COMMITSIG: case WIRE_CHANNEL_GOT_COMMITSIG:
case WIRE_CHANNEL_GOT_REVOKE: case WIRE_CHANNEL_GOT_REVOKE:

View File

@ -109,13 +109,6 @@ channel_ping,,len,u16
channel_ping_reply,1111 channel_ping_reply,1111
channel_ping_reply,,totlen,u16 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. # When we receive funding_locked.
channel_got_funding_locked,1019 channel_got_funding_locked,1019
channel_got_funding_locked,,next_per_commit_point,struct pubkey channel_got_funding_locked,,next_per_commit_point,struct pubkey

1 # Received and sent funding_locked
109 channel_got_funding_locked,,next_per_commit_point,struct pubkey channel_sending_commitsig,,num_changed,u16
110 # When we send a commitment_signed message, tell master. channel_sending_commitsig,,changed,num_changed*struct changed_htlc
111 channel_sending_commitsig,1020 channel_sending_commitsig,,commit_sig,secp256k1_ecdsa_signature
channel_sending_commitsig,,commitnum,u64
channel_sending_commitsig,,feerate,u32
# SENT_ADD_COMMIT, SENT_REMOVE_ACK_COMMIT, SENT_ADD_ACK_COMMIT, SENT_REMOVE_COMMIT
channel_sending_commitsig,,num_changed,u16
channel_sending_commitsig,,changed,num_changed*struct changed_htlc
channel_sending_commitsig,,commit_sig,secp256k1_ecdsa_signature
channel_sending_commitsig,,num_htlc_sigs,u16
112 channel_sending_commitsig,,htlc_sigs,num_htlc_sigs*secp256k1_ecdsa_signature channel_sending_commitsig,,num_htlc_sigs,u16
113 # Wait for reply, to make sure it's on disk before we send commit. channel_sending_commitsig,,htlc_sigs,num_htlc_sigs*secp256k1_ecdsa_signature
114 channel_sending_commitsig_reply,1120 # Wait for reply, to make sure it's on disk before we send commit.

View File

@ -1284,15 +1284,6 @@ static struct io_plan *resolve_channel_req(struct io_conn *conn,
return daemon_conn_read_next(conn, &daemon->master); 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, static struct io_plan *handshake_out_success(struct io_conn *conn,
const struct pubkey *id, const struct pubkey *id,
const struct wireaddr *addr, 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: case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST:
return resolve_channel_req(conn, daemon, daemon->master.msg_in); 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: case WIRE_GOSSIPCTL_HAND_BACK_PEER:
return hand_back_peer(conn, daemon, master->msg_in); return hand_back_peer(conn, daemon, master->msg_in);

View File

@ -121,12 +121,6 @@ gossip_resolve_channel_reply,3109
gossip_resolve_channel_reply,,num_keys,u16 gossip_resolve_channel_reply,,num_keys,u16
gossip_resolve_channel_reply,,keys,num_keys*struct pubkey 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 # The main daemon asks for peers
gossip_getpeers_request,3011 gossip_getpeers_request,3011

1 #include <common/cryptomsg.h>
121 gossip_get_update_reply,,len,u16 gossip_send_gossip,,len,u16
122 gossip_get_update_reply,,update,len*u8 gossip_send_gossip,,gossip,len*u8
123
gossip_send_gossip,3016
gossip_send_gossip,,gossip_index,u64
gossip_send_gossip,,len,u16
gossip_send_gossip,,gossip,len*u8
124
125
126

View File

@ -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_GETPEERS_REQUEST:
case WIRE_GOSSIP_PING: case WIRE_GOSSIP_PING:
case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST: case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST:
case WIRE_GOSSIP_FORWARDED_MSG:
case WIRE_GOSSIPCTL_REACH_PEER: case WIRE_GOSSIPCTL_REACH_PEER:
case WIRE_GOSSIPCTL_HAND_BACK_PEER: case WIRE_GOSSIPCTL_HAND_BACK_PEER:
case WIRE_GOSSIPCTL_RELEASE_PEER: case WIRE_GOSSIPCTL_RELEASE_PEER:

View File

@ -1599,81 +1599,10 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc,
tal_free(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 /* We were informed by channeld that it announced the channel and sent
* an update, so we can now start sending a node_announcement. The * an update, so we can now start sending a node_announcement. The
* first step is to build the provisional announcement and ask the HSM * first step is to build the provisional announcement and ask the HSM
* to sign it. */ * 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) 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: case WIRE_CHANNEL_GOT_REVOKE:
peer_got_revoke(sd->peer, msg); peer_got_revoke(sd->peer, msg);
break; break;
case WIRE_CHANNEL_ANNOUNCE:
peer_channel_announce(sd->peer, msg);
break;
case WIRE_CHANNEL_GOT_FUNDING_LOCKED: case WIRE_CHANNEL_GOT_FUNDING_LOCKED:
peer_got_funding_locked(sd->peer, msg); peer_got_funding_locked(sd->peer, msg);
break; break;
@ -2418,7 +2344,7 @@ static unsigned int opening_negotiation_failed(struct subd *openingd,
/* We need the peer fd and gossip fd. */ /* We need the peer fd and gossip fd. */
if (tal_count(fds) == 0) if (tal_count(fds) == 0)
return 2; return 2;
if (!fromwire_opening_negotiation_failed(msg, msg, NULL, if (!fromwire_opening_negotiation_failed(msg, msg, NULL,
&cs, &gossip_index, &err)) { &cs, &gossip_index, &err)) {
peer_internal_error(peer, peer_internal_error(peer,