Skip to content

Let gossipd automatically announce the node when a local channel_announcement is queued #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
98b1a66
gossip: Remove HSM_FD from handshake
cdecker Nov 24, 2017
37e9d14
routing: Make routing_state aware of its own ID
cdecker Dec 2, 2017
4c13032
opts: Change alias to be u8*, better matches the unicode nature
cdecker Nov 24, 2017
7427c8a
gossip: Passing alias, color and wireaddrs through to gossipd
cdecker Nov 24, 2017
abe9192
routing: Return boolean from handle_channel_announcement
cdecker Nov 24, 2017
dfc5a6e
routing: Add local and sigfail to trace when receiving cannounce
cdecker Dec 2, 2017
aa67236
gossip: Forward when we don't have a valid node_announcement yet
cdecker Dec 4, 2017
88218a0
routing: Do not set an empty channel_announcement if none is given
cdecker Dec 4, 2017
c1b4f41
json_fund_channel: give more details than "peer died".
rustyrussell Dec 5, 2017
e99f69e
subd: add transaction to subd exit corner case.
rustyrussell Dec 5, 2017
6793efe
wireaddr: marshal empty address properly.
rustyrussell Dec 5, 2017
139774c
openingd: return to master for more gossip when negotiation fails.
rustyrussell Dec 6, 2017
c984fb2
openingd: handle ERROR packets (if other end fails negotiation).
rustyrussell Dec 6, 2017
6889fe7
test_lightningd: add test for funding failures.
rustyrussell Dec 6, 2017
616bc26
daemon_conn: helper to release daemon_conn.
rustyrussell Dec 6, 2017
06a0188
gossipd: split peer structure to clearly separate local and remote fi…
rustyrussell Dec 6, 2017
62634e9
Makefile: make gossipd objects depend correctly on its own headers.
rustyrussell Dec 11, 2017
c552fa8
subd: if a required daemon exits, wait instead of killing it.
rustyrussell Dec 11, 2017
b9eddbe
gossipd: don't hand length to route code, it's implied.
rustyrussell Dec 11, 2017
09151fd
gossipd: hand back peer, don't hand a new peer.
rustyrussell Dec 11, 2017
a4512ea
gossipd: don't increment broadcast_index until *after* message sent.
rustyrussell Dec 11, 2017
2a2902b
gossipd: hand out gossip_index to other daemons.
rustyrussell Dec 11, 2017
a22d341
pytest: Fix a flaky channel_reenable test
cdecker Dec 12, 2017
c787e51
channel: Directly send announcements and updates to gossipd
cdecker Dec 12, 2017
234b412
pytest: Minor cleanup
cdecker Dec 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions channeld/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ struct peer {
u8 channel_flags;

bool announce_depth_reached;

/* Where we got up to in gossip broadcasts. */
u64 gossip_index;
};

static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
Expand All @@ -176,15 +179,23 @@ static void *tal_arr_append_(void **p, size_t size)

static void gossip_in(struct peer *peer, const u8 *msg)
{
u16 type = fromwire_peektype(msg);
u8 *gossip;
u16 type;

if (!fromwire_gossip_send_gossip(msg, msg, NULL,
&peer->gossip_index, &gossip))
status_failed(STATUS_FAIL_GOSSIP_IO,
"Got bad message from gossipd: %s",
tal_hex(msg, msg));
type = fromwire_peektype(gossip);

if (type == WIRE_CHANNEL_ANNOUNCEMENT || type == WIRE_CHANNEL_UPDATE ||
type == WIRE_NODE_ANNOUNCEMENT)
msg_enqueue(&peer->peer_out, msg);
msg_enqueue(&peer->peer_out, gossip);
else
status_failed(STATUS_FAIL_GOSSIP_IO,
"Got bad message from gossipd: %s",
tal_hex(msg, msg));
"Got bad message type %s from gossipd: %s",
wire_type_name(type), tal_hex(msg, msg));
}

static void send_announcement_signatures(struct peer *peer)
Expand Down Expand Up @@ -356,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)
Expand Down Expand Up @@ -2204,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:
Expand Down Expand Up @@ -2256,6 +2266,7 @@ static void init_channel(struct peer *peer)
&peer->feerate_min, &peer->feerate_max,
&peer->their_commit_sig,
&peer->cs,
&peer->gossip_index,
&funding_pubkey[REMOTE],
&points[REMOTE].revocation,
&points[REMOTE].payment,
Expand Down Expand Up @@ -2427,7 +2438,8 @@ static void send_shutdown_complete(struct peer *peer)
/* Now we can tell master shutdown is complete. */
wire_sync_write(MASTER_FD,
take(towire_channel_shutdown_complete(peer,
&peer->cs)));
&peer->cs,
peer->gossip_index)));
fdpass_send(MASTER_FD, PEER_FD);
fdpass_send(MASTER_FD, GOSSIP_FD);
close(MASTER_FD);
Expand Down
9 changes: 2 additions & 7 deletions channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ channel_init,,feerate_min,u32
channel_init,,feerate_max,u32
channel_init,,first_commit_sig,secp256k1_ecdsa_signature
channel_init,,crypto_state,struct crypto_state
channel_init,,gossip_index,u64
channel_init,,remote_fundingkey,struct pubkey
channel_init,,remote_revocation_basepoint,struct pubkey
channel_init,,remote_payment_basepoint,struct pubkey
Expand Down Expand Up @@ -108,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
Expand Down Expand Up @@ -183,6 +177,7 @@ channel_got_shutdown,,scriptpubkey,scriptpubkey_len*u8
# Shutdown is complete, ready for closing negotiation. + peer_fd & gossip_fd.
channel_shutdown_complete,1025
channel_shutdown_complete,,crypto_state,struct crypto_state
channel_shutdown_complete,,gossip_index,u64

# Re-enable commit timer.
channel_dev_reenable_commit,1026
Expand Down
6 changes: 4 additions & 2 deletions closingd/closing.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ int main(int argc, char *argv[])
secp256k1_ecdsa_signature sig;
bool reconnected;
u64 next_index[NUM_SIDES], revocations_received;
u64 gossip_index;

if (argc == 2 && streq(argv[1], "--version")) {
printf("%s\n", version());
Expand All @@ -184,7 +185,7 @@ int main(int argc, char *argv[])

msg = wire_sync_read(ctx, REQ_FD);
if (!fromwire_closing_init(ctx, msg, NULL,
&cs, &seed,
&cs, &gossip_index, &seed,
&funding_txid, &funding_txout,
&funding_satoshi,
&funding_pubkey[REMOTE],
Expand Down Expand Up @@ -473,7 +474,8 @@ int main(int argc, char *argv[])
}

/* We're done! */
wire_sync_write(REQ_FD, take(towire_closing_complete(ctx)));
wire_sync_write(REQ_FD,
take(towire_closing_complete(ctx, gossip_index)));
tal_free(ctx);

return 0;
Expand Down
2 changes: 2 additions & 0 deletions closingd/closing_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Begin! (passes peer fd, gossipd-client fd)
closing_init,2001
closing_init,,crypto_state,struct crypto_state
closing_init,,gossip_index,u64
closing_init,,seed,struct privkey
closing_init,,funding_txid,struct sha256_double
closing_init,,funding_txout,u16
Expand Down Expand Up @@ -33,3 +34,4 @@ closing_received_signature_reply,2102

# Negotiations complete, we're exiting.
closing_complete,2004
closing_complete,,gossip_index,u64
6 changes: 6 additions & 0 deletions common/daemon_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
io_set_finish(conn, finish, dc);
}

void daemon_conn_clear(struct daemon_conn *dc)
{
io_set_finish(dc->conn, NULL, NULL);
io_close(dc->conn);
}

void daemon_conn_send(struct daemon_conn *dc, const u8 *msg)
{
msg_enqueue(&dc->out, msg);
Expand Down
10 changes: 10 additions & 0 deletions common/daemon_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
struct io_plan *(*daemon_conn_recv)(
struct io_conn *, struct daemon_conn *),
void (*finish)(struct io_conn *, struct daemon_conn *));

/**
* daemon_conn_clear - discard a daemon conn without triggering finish.
* @dc: the daemon_conn to clean up.
*
* This is used by gossipd when a peer is handed back, and we no longer
* want to deal with it via daemon_conn. @dc must not be used after this!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could return NULL like tal_free so calls would look like this:

dc = daemon_conn_clear(dc)

to signal that the dc has been taken care of. The only call for daemon_conn_clear is directly followed by a tal_free on the daemon_conn anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes, but as you say it's only got one caller, so maybe overkill.

*/
void daemon_conn_clear(struct daemon_conn *dc);

/**
* daemon_conn_send - Enqueue an outgoing message to be sent
*/
Expand Down
4 changes: 4 additions & 0 deletions common/wireaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr)

void towire_wireaddr(u8 **pptr, const struct wireaddr *addr)
{
if (!addr || addr->type == ADDR_TYPE_PADDING) {
towire_u8(pptr, ADDR_TYPE_PADDING);
return;
}
towire_u8(pptr, addr->type);
towire(pptr, addr->addr, addr->addrlen);
towire_u16(pptr, addr->port);
Expand Down
1 change: 1 addition & 0 deletions common/wireaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct wireaddr {
u16 port;
};

/* Inserts a single ADDR_TYPE_PADDING if addr is NULL */
void towire_wireaddr(u8 **pptr, const struct wireaddr *addr);
bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr);
#endif /* LIGHTNING_COMMON_WIREADDR_H */
2 changes: 1 addition & 1 deletion gossipd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GOSSIPD_COMMON_OBJS := \
hsmd/gen_hsm_client_wire.o \
lightningd/gossip_msg.o

$(LIGHTNINGD_GOSSIP_OBJS) $(LIGHTNINGD_GOSSIP_CLIENT_OBJS): $(LIGHTNINGD_HEADERS)
$(LIGHTNINGD_GOSSIP_OBJS) $(LIGHTNINGD_GOSSIP_CLIENT_OBJS): $(LIGHTNINGD_HEADERS) $(LIGHTNINGD_GOSSIP_HEADERS)

$(LIGHTNINGD_GOSSIP_CONTROL_OBJS) : $(LIGHTNINGD_GOSSIP_CONTROL_HEADERS)

Expand Down
16 changes: 8 additions & 8 deletions gossipd/broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ void queue_broadcast(struct broadcast_state *bstate,
const u8 *payload)
{
struct queued_message *msg;
u64 index = 0;
u64 index;

/* Remove any tag&type collisions */
while (true) {
msg = next_broadcast_message(bstate, &index);
if (msg == NULL)
break;
else if (msg->type == type && memcmp(msg->tag, tag, tal_count(tag)) == 0) {
for (msg = uintmap_first(&bstate->broadcasts, &index);
msg;
msg = uintmap_after(&bstate->broadcasts, &index)) {
if (msg->type == type && memcmp(msg->tag, tag, tal_count(tag)) == 0) {
uintmap_del(&bstate->broadcasts, index);
tal_free(msg);
}
Expand All @@ -45,7 +45,7 @@ void queue_broadcast(struct broadcast_state *bstate,
bstate->next_index += 1;
}

struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 *last_index)
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index)
{
return uintmap_after(&bstate->broadcasts, last_index);
return uintmap_after(&bstate->broadcasts, &last_index);
}
2 changes: 1 addition & 1 deletion gossipd/broadcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ void queue_broadcast(struct broadcast_state *bstate,
const u8 *tag,
const u8 *payload);

struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 *last_index);
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index);

#endif /* LIGHTNING_LIGHTNINGD_GOSSIP_BROADCAST_H */
Loading