Skip to content

Commit 8674880

Browse files
committed
channel: Directly send announcements and updates to gossipd
Signed-off-by: Christian Decker <[email protected]>
1 parent c30dcd8 commit 8674880

File tree

6 files changed

+8
-110
lines changed

6 files changed

+8
-110
lines changed

channeld/channel.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,16 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
367367

368368
static void announce_channel(struct peer *peer)
369369
{
370+
tal_t *tmpctx = tal_tmpctx(peer);
370371
u8 *cannounce, *cupdate;
371372

372-
cannounce = create_channel_announcement(peer, peer);
373-
cupdate = create_channel_update(cannounce, peer, false);
373+
cannounce = create_channel_announcement(tmpctx, peer);
374+
cupdate = create_channel_update(tmpctx, peer, false);
375+
376+
wire_sync_write(GOSSIP_FD, cannounce);
377+
wire_sync_write(GOSSIP_FD, cupdate);
374378

375-
/* Tell the master that we to announce channel (it does node) */
376-
wire_sync_write(MASTER_FD, take(towire_channel_announce(peer,
377-
cannounce,
378-
cupdate)));
379-
tal_free(cannounce);
379+
tal_free(tmpctx);
380380
}
381381

382382
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)
22152215
case WIRE_CHANNEL_INIT:
22162216
case WIRE_CHANNEL_OFFER_HTLC_REPLY:
22172217
case WIRE_CHANNEL_PING_REPLY:
2218-
case WIRE_CHANNEL_ANNOUNCE:
22192218
case WIRE_CHANNEL_SENDING_COMMITSIG:
22202219
case WIRE_CHANNEL_GOT_COMMITSIG:
22212220
case WIRE_CHANNEL_GOT_REVOKE:

channeld/channel_wire.csv

-7
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ channel_ping,,len,u16
109109
channel_ping_reply,1111
110110
channel_ping_reply,,totlen,u16
111111

112-
# Channeld tells the master to announce the channel (with first update)
113-
channel_announce,1012
114-
channel_announce,,announce_len,u16
115-
channel_announce,,announce,announce_len*u8
116-
channel_announce,,update_len,u16
117-
channel_announce,,update,update_len*u8
118-
119112
# When we receive funding_locked.
120113
channel_got_funding_locked,1019
121114
channel_got_funding_locked,,next_per_commit_point,struct pubkey

gossipd/gossip.c

-13
Original file line numberDiff line numberDiff line change
@@ -1284,15 +1284,6 @@ static struct io_plan *resolve_channel_req(struct io_conn *conn,
12841284
return daemon_conn_read_next(conn, &daemon->master);
12851285
}
12861286

1287-
static void handle_forwarded_msg(struct io_conn *conn, struct daemon *daemon, const u8 *msg)
1288-
{
1289-
u8 *payload;
1290-
if (!fromwire_gossip_forwarded_msg(msg, msg, NULL, &payload))
1291-
master_badmsg(WIRE_GOSSIP_FORWARDED_MSG, msg);
1292-
1293-
handle_gossip_msg(daemon, payload);
1294-
}
1295-
12961287
static struct io_plan *handshake_out_success(struct io_conn *conn,
12971288
const struct pubkey *id,
12981289
const struct wireaddr *addr,
@@ -1536,10 +1527,6 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
15361527
case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST:
15371528
return resolve_channel_req(conn, daemon, daemon->master.msg_in);
15381529

1539-
case WIRE_GOSSIP_FORWARDED_MSG:
1540-
handle_forwarded_msg(conn, daemon, daemon->master.msg_in);
1541-
return daemon_conn_read_next(conn, &daemon->master);
1542-
15431530
case WIRE_GOSSIPCTL_HAND_BACK_PEER:
15441531
return hand_back_peer(conn, daemon, master->msg_in);
15451532

gossipd/gossip_wire.csv

-6
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ gossip_resolve_channel_reply,3109
121121
gossip_resolve_channel_reply,,num_keys,u16
122122
gossip_resolve_channel_reply,,keys,num_keys*struct pubkey
123123

124-
# The main daemon forward some gossip message to gossipd, allows injecting
125-
# arbitrary gossip messages.
126-
gossip_forwarded_msg,3010
127-
gossip_forwarded_msg,,msglen,u16
128-
gossip_forwarded_msg,,msg,msglen*u8
129-
130124
# The main daemon asks for peers
131125
gossip_getpeers_request,3011
132126

lightningd/gossip_control.c

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
6666
case WIRE_GOSSIP_GETPEERS_REQUEST:
6767
case WIRE_GOSSIP_PING:
6868
case WIRE_GOSSIP_RESOLVE_CHANNEL_REQUEST:
69-
case WIRE_GOSSIP_FORWARDED_MSG:
7069
case WIRE_GOSSIPCTL_REACH_PEER:
7170
case WIRE_GOSSIPCTL_HAND_BACK_PEER:
7271
case WIRE_GOSSIPCTL_RELEASE_PEER:

lightningd/peer_control.c

+1-75
Original file line numberDiff line numberDiff line change
@@ -1599,81 +1599,10 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc,
15991599
tal_free(fc);
16001600
}
16011601

1602-
/* Create a node_announcement with the given signature. It may be NULL
1603-
* in the case we need to create a provisional announcement for the
1604-
* HSM to sign. This is typically called twice: once with the dummy
1605-
* signature to get it signed and a second time to build the full
1606-
* packet with the signature. The timestamp is handed in since that is
1607-
* the only thing that may change between the dummy creation and the
1608-
* call with a signature.*/
1609-
static u8 *create_node_announcement(const tal_t *ctx, struct lightningd *ld,
1610-
secp256k1_ecdsa_signature *sig,
1611-
u32 timestamp)
1612-
{
1613-
u8 *features = NULL;
1614-
u8 *addresses = tal_arr(ctx, u8, 0);
1615-
u8 *announcement;
1616-
size_t i;
1617-
if (!sig) {
1618-
sig = tal(ctx, secp256k1_ecdsa_signature);
1619-
memset(sig, 0, sizeof(*sig));
1620-
}
1621-
for (i = 0; i < tal_count(ld->wireaddrs); i++)
1622-
towire_wireaddr(&addresses, ld->wireaddrs+i);
1623-
1624-
announcement =
1625-
towire_node_announcement(ctx, sig, features, timestamp,
1626-
&ld->id, ld->rgb, (u8 *)ld->alias,
1627-
addresses);
1628-
return announcement;
1629-
}
1630-
16311602
/* We were informed by channeld that it announced the channel and sent
16321603
* an update, so we can now start sending a node_announcement. The
16331604
* first step is to build the provisional announcement and ask the HSM
16341605
* to sign it. */
1635-
static void peer_channel_announce(struct peer *peer, const u8 *msg)
1636-
{
1637-
struct lightningd *ld = peer->ld;
1638-
tal_t *tmpctx = tal_tmpctx(peer);
1639-
secp256k1_ecdsa_signature sig;
1640-
u8 *cannounce, *cupdate;
1641-
u8 *announcement, *wrappedmsg;
1642-
u32 timestamp = time_now().ts.tv_sec;
1643-
1644-
if (!fromwire_channel_announce(msg, msg, NULL, &cannounce, &cupdate)) {
1645-
peer_internal_error(peer, "bad fromwire_channel_announced %s",
1646-
tal_hex(peer, msg));
1647-
return;
1648-
}
1649-
1650-
msg = towire_hsm_node_announcement_sig_req(
1651-
tmpctx, create_node_announcement(tmpctx, ld, NULL, timestamp));
1652-
1653-
if (!wire_sync_write(ld->hsm_fd, take(msg)))
1654-
fatal("Could not write to HSM: %s", strerror(errno));
1655-
1656-
msg = hsm_sync_read(tmpctx, ld);
1657-
if (!fromwire_hsm_node_announcement_sig_reply(msg, NULL, &sig))
1658-
fatal("HSM returned an invalid node_announcement sig");
1659-
1660-
/* We got the signature for out provisional node_announcement back
1661-
* from the HSM, create the real announcement and forward it to
1662-
* gossipd so it can take care of forwarding it. */
1663-
announcement = create_node_announcement(tmpctx, ld, &sig, timestamp);
1664-
1665-
/* We have to send channel_announce before channel_update and
1666-
* node_announcement */
1667-
wrappedmsg = towire_gossip_forwarded_msg(tmpctx, cannounce);
1668-
subd_send_msg(ld->gossip, take(wrappedmsg));
1669-
1670-
wrappedmsg = towire_gossip_forwarded_msg(tmpctx, cupdate);
1671-
subd_send_msg(ld->gossip, take(wrappedmsg));
1672-
1673-
wrappedmsg = towire_gossip_forwarded_msg(tmpctx, announcement);
1674-
subd_send_msg(ld->gossip, take(wrappedmsg));
1675-
tal_free(tmpctx);
1676-
}
16771606

16781607
static void peer_got_funding_locked(struct peer *peer, const u8 *msg)
16791608
{
@@ -2022,9 +1951,6 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
20221951
case WIRE_CHANNEL_GOT_REVOKE:
20231952
peer_got_revoke(sd->peer, msg);
20241953
break;
2025-
case WIRE_CHANNEL_ANNOUNCE:
2026-
peer_channel_announce(sd->peer, msg);
2027-
break;
20281954
case WIRE_CHANNEL_GOT_FUNDING_LOCKED:
20291955
peer_got_funding_locked(sd->peer, msg);
20301956
break;
@@ -2419,7 +2345,7 @@ static unsigned int opening_negotiation_failed(struct subd *openingd,
24192345
/* We need the peer fd and gossip fd. */
24202346
if (tal_count(fds) == 0)
24212347
return 2;
2422-
2348+
24232349
if (!fromwire_opening_negotiation_failed(msg, msg, NULL,
24242350
&cs, &gossip_index, &err)) {
24252351
peer_internal_error(peer,

0 commit comments

Comments
 (0)