Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
36 changes: 26 additions & 10 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 @@ -361,10 +372,14 @@ static void announce_channel(struct peer *peer)
cannounce = create_channel_announcement(peer, peer);
cupdate = create_channel_update(cannounce, 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)));
/* Tell gossipd to announce channel (it does node) */
if (!wire_sync_write(GOSSIP_FD,
take(towire_gossip_new_channel(peer,
cannounce,
cupdate))))
status_failed(STATUS_FAIL_GOSSIP_IO,
"Sending announce to gossipd: %s",
strerror(errno));
tal_free(cannounce);
}

Expand Down Expand Up @@ -2204,7 +2219,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 +2270,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 +2442,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!
*/
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