mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
channel: Directly send announcements and updates to gossipd
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
32a96973a5
commit
a8a6d1d669
@ -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:
|
||||
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
|
@ -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:
|
||||
|
@ -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…
Reference in New Issue
Block a user