diff --git a/gossipd/gossip_generation.c b/gossipd/gossip_generation.c index 619090e89..c5022406d 100644 --- a/gossipd/gossip_generation.c +++ b/gossipd/gossip_generation.c @@ -394,547 +394,3 @@ void maybe_send_own_node_announce(struct daemon *daemon, bool startup) update_own_node_announcement(daemon, startup, false); } -/* Fast accessors for channel_update fields */ -static u8 *channel_flags_access(const u8 *channel_update) -{ - /* BOLT #7: - * 1. type: 258 (`channel_update`) - * 2. data: - * * [`signature`:`signature`] - * * [`chain_hash`:`chain_hash`] - * * [`short_channel_id`:`short_channel_id`] - * * [`u32`:`timestamp`] - * * [`byte`:`message_flags`] - * * [`byte`:`channel_flags`] - */ - /* Note: 2 bytes for `type` field */ - return cast_const(u8 *, &channel_update[2 + 64 + 32 + 8 + 4 + 1]); -} - -static u8 *timestamp_access(const u8 *channel_update) -{ - /* BOLT #7: - * 1. type: 258 (`channel_update`) - * 2. data: - * * [`signature`:`signature`] - * * [`chain_hash`:`chain_hash`] - * * [`short_channel_id`:`short_channel_id`] - * * [`u32`:`timestamp`] - * * [`byte`:`message_flags`] - * * [`byte`:`channel_flags`] - */ - /* Note: 2 bytes for `type` field */ - return cast_const(u8 *, &channel_update[2 + 64 + 32 + 8]); -} - -static bool is_disabled(const u8 *channel_update) -{ - return *channel_flags_access(channel_update) & ROUTING_FLAGS_DISABLED; -} - -static bool is_enabled(const u8 *channel_update) -{ - return !is_disabled(channel_update); -} - - -static u32 timestamp_for_update(struct daemon *daemon, - const u32 *prev_timestamp, - bool disable) -{ - u32 timestamp = gossip_time_now(daemon->rstate).ts.tv_sec; - - /* Create an unsigned channel_update: we backdate enables, so - * we can always send a disable in an emergency. */ - if (!disable) - timestamp -= GOSSIP_MIN_INTERVAL(daemon->rstate->dev_fast_gossip); - - if (prev_timestamp) { - /* Timestamps can't go backwards! */ - if (timestamp < *prev_timestamp) - timestamp = *prev_timestamp + 1; - - /* If we ever use set-based propagation, ensuring the toggle - * the lower bit in consecutive timestamps makes it more - * robust. */ - if ((timestamp & 1) == (*prev_timestamp & 1)) - timestamp++; - } - - return timestamp; -} - -static u8 *sign_and_timestamp_update(const tal_t *ctx, - struct daemon *daemon, - const struct chan *chan, - int direction, - u8 *unsigned_update TAKES) -{ - u8 *msg, *update; - be32 timestamp; - const u32 *prev_timestamp; - const struct half_chan *hc = &chan->half[direction]; - - if (is_halfchan_defined(hc)) - prev_timestamp = &hc->bcast.timestamp; - else - prev_timestamp = NULL; - - /* Get an appropriate timestamp */ - timestamp = cpu_to_be32(timestamp_for_update(daemon, - prev_timestamp, - is_disabled(unsigned_update))); - memcpy(timestamp_access(unsigned_update), ×tamp, sizeof(timestamp)); - - /* Note that we treat the hsmd as synchronous. This is simple (no - * callback hell)!, but may need to change to async if we ever want - * remote HSMs */ - if (!wire_sync_write(HSM_FD, - towire_hsmd_cupdate_sig_req(tmpctx, unsigned_update))) { - status_failed(STATUS_FAIL_HSM_IO, "Writing cupdate_sig_req: %s", - strerror(errno)); - } - - msg = wire_sync_read(tmpctx, HSM_FD); - if (!msg || !fromwire_hsmd_cupdate_sig_reply(ctx, msg, &update)) { - status_failed(STATUS_FAIL_HSM_IO, - "Reading cupdate_sig_req: %s", - strerror(errno)); - } - - if (taken(unsigned_update)) - tal_free(unsigned_update); - - /* Tell lightningd about this immediately (even if we're not actually - * applying it now). We choose not to send info about private - * channels, even in errors. */ - msg = towire_gossipd_got_local_channel_update(NULL, &chan->scid, - update); - daemon_conn_send(daemon->master, take(msg)); - - return update; -} - -static u8 *create_unsigned_update(const tal_t *ctx, - const struct short_channel_id *scid, - int direction, - bool enable, - u16 cltv_expiry_delta, - struct amount_msat htlc_minimum, - struct amount_msat htlc_maximum, - u32 fee_base_msat, - u32 fee_proportional_millionths, - bool public) -{ - secp256k1_ecdsa_signature dummy_sig; - u8 message_flags, channel_flags; - - /* So valgrind doesn't complain */ - memset(&dummy_sig, 0, sizeof(dummy_sig)); - - /* BOLT-f3a9f7f4e9e7a5a2997f3129e13d94090091846a #7: - * - * The `channel_flags` bitfield is used to indicate the direction of - * the channel: it identifies the node that this update originated - * from and signals various options concerning the channel. The - * following table specifies the meaning of its individual bits: - * - * | Bit Position | Name | Meaning | - * | ------------- | ----------- | -------------------------------- | - * | 0 | `direction` | Direction this update refers to. | - * | 1 | `disable` | Disable the channel. | - */ - channel_flags = direction; - if (!enable) - channel_flags |= ROUTING_FLAGS_DISABLED; - - /* BOLT #7: - * - * The `message_flags` bitfield is used to provide additional - * details about the message: - * - * | Bit Position | Name | - * | ------------- | ---------------| - * | 0 | `must_be_one` | - * | 1 | `dont_forward` | - */ - message_flags = ROUTING_OPT_HTLC_MAX_MSAT; - if (!public) - message_flags |= ROUTING_OPT_DONT_FORWARD; - - /* We create an update with a dummy signature and timestamp. */ - return towire_channel_update(ctx, - &dummy_sig, /* sig set later */ - &chainparams->genesis_blockhash, - scid, - 0, /* timestamp set later */ - message_flags, channel_flags, - cltv_expiry_delta, - htlc_minimum, - fee_base_msat, - fee_proportional_millionths, - htlc_maximum); -} - -static void apply_update(struct daemon *daemon, - const struct chan *chan, - int direction, - u8 *update TAKES) -{ - u8 *msg; - - msg = handle_channel_update(daemon->rstate, update, NULL, NULL, true); - if (msg) - status_failed(STATUS_FAIL_INTERNAL_ERROR, - "%s: rejected local channel update %s: %s", - __func__, - /* Normally we must not touch something taken() - * but we're in deep trouble anyway, and - * handle_channel_update only tal_steals onto - * tmpctx, so it's actually OK. */ - tal_hex(tmpctx, update), - tal_hex(tmpctx, msg)); -} - -static void sign_timestamp_and_apply_update(struct daemon *daemon, - const struct chan *chan, - int direction, - u8 *update TAKES) -{ - update = sign_and_timestamp_update(NULL, daemon, chan, direction, - update); - apply_update(daemon, chan, direction, take(update)); -} - -/* We don't want to thrash the gossip network, so we often defer sending an - * update. We track them here. */ -struct deferred_update { - /* Off daemon->deferred_updates (our leak detection needs this as - * first element in struct, because it's dumb!) */ - struct list_node list; - /* The daemon */ - struct daemon *daemon; - /* Channel it's for (and owner) */ - const struct chan *chan; - int direction; - /* Timer which will fire when it's time to apply. */ - struct oneshot *channel_update_timer; - /* The actual `update_channel` to apply */ - u8 *update; -}; - -static struct deferred_update *find_deferred_update(struct daemon *daemon, - const struct chan *chan) -{ - struct deferred_update *du; - - list_for_each(&daemon->deferred_updates, du, list) { - if (du->chan == chan) - return du; - } - return NULL; -} - -static void destroy_deferred_update(struct deferred_update *du) -{ - list_del(&du->list); -} - -static void apply_deferred_update(struct deferred_update *du) -{ - apply_update(du->daemon, du->chan, du->direction, take(du->update)); - tal_free(du); -} - -static void defer_update(struct daemon *daemon, - u32 delay, - const struct chan *chan, - int direction, - u8 *unsigned_update TAKES) -{ - struct deferred_update *du; - - /* Override any existing one */ - tal_free(find_deferred_update(daemon, chan)); - - /* If chan is gone, so are we. */ - du = tal(chan, struct deferred_update); - du->daemon = daemon; - du->chan = chan; - du->direction = direction; - du->update = sign_and_timestamp_update(du, daemon, chan, direction, - unsigned_update); - if (delay != 0xFFFFFFFF) - du->channel_update_timer = new_reltimer(&daemon->timers, du, - time_from_sec(delay), - apply_deferred_update, - du); - else - du->channel_update_timer = NULL; - list_add_tail(&daemon->deferred_updates, &du->list); - tal_add_destructor(du, destroy_deferred_update); -} - -/* If there is a pending update for this local channel, apply immediately. */ -static bool local_channel_update_latest(struct daemon *daemon, struct chan *chan) -{ - struct deferred_update *du; - - du = find_deferred_update(daemon, chan); - if (!du) - return false; - - /* Frees itself */ - apply_deferred_update(du); - return true; -} - -/* Get previous update. */ -static u8 *prev_update(const tal_t *ctx, - struct daemon *daemon, const struct chan *chan, int direction) -{ - u8 *prev; - - if (!is_halfchan_defined(&chan->half[direction])) - return NULL; - - prev = cast_const(u8 *, - gossip_store_get(tmpctx, daemon->rstate->gs, - chan->half[direction].bcast.index)); - - return prev; -} - -/* This is a refresh of a local channel (after 13 days). */ -void refresh_local_channel(struct daemon *daemon, - struct chan *chan, int direction) -{ - u16 cltv_expiry_delta; - struct amount_msat htlc_minimum, htlc_maximum; - u32 fee_base_msat, fee_proportional_millionths, timestamp; - u8 *prev, *update; - u8 message_flags, channel_flags; - secp256k1_ecdsa_signature signature; - struct bitcoin_blkid chain_hash; - struct short_channel_id short_channel_id; - - /* If there's a pending update, apply it and we're done. */ - if (local_channel_update_latest(daemon, chan)) - return; - - prev = prev_update(tmpctx, daemon, chan, direction); - if (!prev) - return; - - if (!fromwire_channel_update(prev, - &signature, &chain_hash, - &short_channel_id, ×tamp, - &message_flags, &channel_flags, - &cltv_expiry_delta, - &htlc_minimum, - &fee_base_msat, - &fee_proportional_millionths, - &htlc_maximum)) { - status_broken("Could not decode local channel_update %s!", - tal_hex(tmpctx, prev)); - return; - } - - /* BOLT-f3a9f7f4e9e7a5a2997f3129e13d94090091846a #7: - * - * The `channel_flags` bitfield is used to indicate the direction of - * the channel: it identifies the node that this update originated - * from and signals various options concerning the channel. The - * following table specifies the meaning of its individual bits: - * - * | Bit Position | Name | Meaning | - * | ------------- | ----------- | -------------------------------- | - * | 0 | `direction` | Direction this update refers to. | - * | 1 | `disable` | Disable the channel. | - */ - if (direction != (channel_flags & ROUTING_FLAGS_DIRECTION)) { - status_broken("Wrong channel direction %s!", - tal_hex(tmpctx, prev)); - return; - } - - /* Don't refresh disabled channels. */ - if (channel_flags & ROUTING_FLAGS_DISABLED) - return; - - update = create_unsigned_update(NULL, &short_channel_id, direction, - false, cltv_expiry_delta, - htlc_minimum, htlc_maximum, - fee_base_msat, - fee_proportional_millionths, - !(message_flags & ROUTING_OPT_DONT_FORWARD)); - sign_timestamp_and_apply_update(daemon, chan, direction, take(update)); -} - -/* channeld (via lightningd) asks us to update the local channel. */ -void handle_local_channel_update(struct daemon *daemon, const u8 *msg) -{ - struct node_id id; - struct short_channel_id scid; - bool enable; - u16 cltv_expiry_delta; - struct amount_msat htlc_minimum, htlc_maximum; - u32 fee_base_msat, fee_proportional_millionths; - struct chan *chan; - int direction; - u8 *unsigned_update; - const struct half_chan *hc; - bool public; - - if (!fromwire_gossipd_local_channel_update(msg, - &id, - &scid, - &enable, - &cltv_expiry_delta, - &htlc_minimum, - &fee_base_msat, - &fee_proportional_millionths, - &htlc_maximum, - &public)) { - master_badmsg(WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE, msg); - } - - chan = get_channel(daemon->rstate, &scid); - /* Can theoretically happen if channel just closed. */ - if (!chan) { - status_peer_debug(&id, "local_channel_update for unknown %s", - type_to_string(tmpctx, struct short_channel_id, - &scid)); - return; - } - - if (!local_direction(daemon->rstate, chan, &direction)) { - status_peer_broken(&id, "bad local_channel_update chan %s", - type_to_string(tmpctx, - struct short_channel_id, - &scid)); - return; - } - - unsigned_update = create_unsigned_update(tmpctx, &scid, direction, - enable, cltv_expiry_delta, - htlc_minimum, htlc_maximum, - fee_base_msat, - fee_proportional_millionths, - public); - - hc = &chan->half[direction]; - - /* Ignore duplicates. */ - if (is_halfchan_defined(hc) - && !cupdate_different(daemon->rstate->gs, hc, unsigned_update)) - return; - - /* Too early? Defer (don't worry if it's unannounced). */ - if (is_halfchan_defined(hc)) { - u32 now = time_now().ts.tv_sec; - u32 next_time = hc->bcast.timestamp - + GOSSIP_MIN_INTERVAL(daemon->rstate->dev_fast_gossip); - if (now < next_time) { - defer_update(daemon, next_time - now, - chan, direction, take(unsigned_update)); - return; - } - } - - sign_timestamp_and_apply_update(daemon, chan, direction, - take(unsigned_update)); -} - -/* Take update, set/unset disabled flag (and update timestamp). - */ -static void set_disable_flag(u8 *channel_update, bool disable) -{ - u8 *channel_flags = channel_flags_access(channel_update); - - if (disable) - *channel_flags |= ROUTING_FLAGS_DISABLED; - else - *channel_flags &= ~ROUTING_FLAGS_DISABLED; -} - -/* We don't immediately disable, to avoid flapping. */ -void local_disable_chan(struct daemon *daemon, const struct chan *chan, int direction) -{ - struct deferred_update *du; - u8 *update = prev_update(tmpctx, daemon, chan, direction); - if (!update) - return; - - du = find_deferred_update(daemon, chan); - - /* Will a deferred update disable it already? OK, nothing to do. */ - if (du && is_disabled(du->update)) - return; - - /* OK, we definitely don't want deferred update to re-enable! */ - tal_free(du); - - /* Is it already disabled? */ - if (is_disabled(update)) - return; - - /* This is deferred indefinitely (flushed if needed though) */ - set_disable_flag(update, true); - defer_update(daemon, 0xFFFFFFFF, chan, direction, take(update)); -} - -/* lightningd tells us it used the local channel update. */ -void handle_used_local_channel_update(struct daemon *daemon, const u8 *msg) -{ - struct short_channel_id scid; - struct chan *chan; - - if (!fromwire_gossipd_used_local_channel_update(msg, &scid)) - master_badmsg(WIRE_GOSSIPD_USED_LOCAL_CHANNEL_UPDATE, msg); - - chan = get_channel(daemon->rstate, &scid); - /* Might have closed in meantime, but v unlikely! */ - if (!chan) { - status_broken("used_local_channel_update on unknown %s", - type_to_string(tmpctx, struct short_channel_id, - &scid)); - return; - } - - /* This whole idea is racy: they might have used a *previous* update. - * But that's OK: the notification is an optimization to avoid - * broadcasting updates we never use (route flapping). In this case, - * we might broadcast a more recent update than the one we sent to a - * peer. */ - local_channel_update_latest(daemon, chan); -} - -void local_enable_chan(struct daemon *daemon, const struct chan *chan, int direction) -{ - struct deferred_update *du; - u8 *update = prev_update(tmpctx, daemon, chan, direction); - - - if (!update) - return; - - du = find_deferred_update(daemon, chan); - - /* Will a deferred update enable it? If so, apply immediately. */ - if (du && is_enabled(du->update)) { - apply_deferred_update(du); - return; - } - - /* OK, we definitely don't want deferred update to disable! */ - tal_free(du); - - /* Is it already enabled? */ - if (is_enabled(update)) - return; - - /* Apply this enabling update immediately. */ - set_disable_flag(update, false); - sign_timestamp_and_apply_update(daemon, chan, direction, take(update)); -} diff --git a/gossipd/gossip_generation.h b/gossipd/gossip_generation.h index b39cc158b..50d3bb527 100644 --- a/gossipd/gossip_generation.h +++ b/gossipd/gossip_generation.h @@ -35,20 +35,4 @@ bool nannounce_different(struct gossip_store *gs, /* Should we announce our own node? Called at strategic places. */ void maybe_send_own_node_announce(struct daemon *daemon, bool startup); -/* Disable this local channel (lazily) */ -void local_disable_chan(struct daemon *daemon, const struct chan *chan, int direction); - -/* Re-enable this local channel */ -void local_enable_chan(struct daemon *daemon, const struct chan *chan, int direction); - -/* This is a refresh of a local channel which is > 13 days old. */ -void refresh_local_channel(struct daemon *daemon, - struct chan *chan, int direction); - -/* channeld (via lightningd) asks us to update the local channel. */ -void handle_local_channel_update(struct daemon *daemon, const u8 *msg); - -/* lightningd tells us it used the last channel_update we sent. */ -void handle_used_local_channel_update(struct daemon *daemon, const u8 *msg); - #endif /* LIGHTNING_GOSSIPD_GOSSIP_GENERATION_H */ diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index fe4ad3617..7505aa02d 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -46,41 +46,6 @@ bool peer_node_id_eq(const struct peer *peer, const struct node_id *node_id) return node_id_eq(&peer->id, node_id); } -/*~ A channel consists of a `struct half_chan` for each direction, each of - * which has a `flags` word from the `channel_update`; bit 1 is - * ROUTING_FLAGS_DISABLED in the `channel_update`. But we also keep a local - * whole-channel flag which indicates it's not available; we use this when a - * peer disconnects, and generate a `channel_update` to tell the world lazily - * when someone asks. */ -static void peer_disable_channels(struct daemon *daemon, const struct node *node) -{ - /* If this peer had a channel with us, mark it disabled. */ - struct chan_map_iter i; - const struct chan *c; - - for (c = first_chan(node, &i); c; c = next_chan(node, &i)) { - int direction; - if (!local_direction(daemon->rstate, c, &direction)) - continue; - local_disable_chan(daemon, c, direction); - } -} - -/*~ This cancels the soft-disables when the peer reconnects. */ -static void peer_enable_channels(struct daemon *daemon, const struct node *node) -{ - /* If this peer had a channel with us, mark it disabled. */ - struct chan_map_iter i; - const struct chan *c; - - for (c = first_chan(node, &i); c; c = next_chan(node, &i)) { - int direction; - if (!local_direction(daemon->rstate, c, &direction)) - continue; - local_enable_chan(daemon, c, direction); - } -} - /*~ Destroy a peer, usually because the per-peer daemon has exited. * * Were you wondering why we call this "destroy_peer" and not "peer_destroy"? @@ -90,16 +55,10 @@ static void peer_enable_channels(struct daemon *daemon, const struct node *node) */ static void destroy_peer(struct peer *peer) { - struct node *node; - /* Remove it from the peers table */ - peer_node_id_map_del(peer->daemon->peers, peer);; - - /* If we have a channel with this peer, disable it. */ - node = get_node(peer->daemon->rstate, &peer->id); - if (node) - peer_disable_channels(peer->daemon, node); + peer_node_id_map_del(peer->daemon->peers, peer); + /* Sorry seeker, this one is gone. */ seeker_peer_gone(peer->daemon->seeker, peer); } @@ -301,26 +260,6 @@ static u8 *handle_node_announce(struct peer *peer, const u8 *msg) return err; } -static void handle_local_channel_announcement(struct daemon *daemon, const u8 *msg) -{ - u8 *cannouncement; - const u8 *err; - struct node_id id; - - if (!fromwire_gossipd_local_channel_announcement(msg, msg, - &id, - &cannouncement)) - master_badmsg(WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT, msg); - - err = handle_channel_announcement_msg(daemon, &id, cannouncement); - if (err) { - status_peer_broken(&id, "invalid local_channel_announcement %s (%s)", - tal_hex(tmpctx, msg), - tal_hex(tmpctx, err)); - } -} - - /* lightningd tells us it has discovered and verified new `remote_addr`. * We can use this to update our node announcement. */ static void handle_discovered_ip(struct daemon *daemon, const u8 *msg) @@ -433,7 +372,6 @@ static void dump_our_gossip(struct daemon *daemon, struct peer *peer) static void connectd_new_peer(struct daemon *daemon, const u8 *msg) { struct peer *peer = tal(daemon, struct peer); - struct node *node; if (!fromwire_gossipd_new_peer(msg, &peer->id, &peer->gossip_queries_feature)) { @@ -463,10 +401,6 @@ static void connectd_new_peer(struct daemon *daemon, const u8 *msg) peer_node_id_map_add(daemon->peers, peer); tal_add_destructor(peer, destroy_peer); - node = get_node(daemon->rstate, &peer->id); - if (node) - peer_enable_channels(daemon, node); - /* Send everything we know about our own channels */ dump_our_gossip(daemon, peer); @@ -659,58 +593,13 @@ handled: */ static void gossip_refresh_network(struct daemon *daemon) { - u64 now = gossip_time_now(daemon->rstate).ts.tv_sec; - s64 highwater; - struct node *n; - - /* Send out 1 day before deadline */ - highwater = now - (GOSSIP_PRUNE_INTERVAL(daemon->rstate->dev_fast_gossip) - - GOSSIP_BEFORE_DEADLINE(daemon->rstate->dev_fast_gossip_prune)); - /* Schedule next run now */ notleak(new_reltimer(&daemon->timers, daemon, time_from_sec(GOSSIP_PRUNE_INTERVAL(daemon->rstate->dev_fast_gossip_prune)/4), gossip_refresh_network, daemon)); - /* Find myself in the network */ - n = get_node(daemon->rstate, &daemon->id); - if (n) { - /* Iterate through all outgoing connection and check whether - * it's time to re-announce */ - struct chan_map_iter i; - struct chan *c; - - for (c = first_chan(n, &i); c; c = next_chan(n, &i)) { - struct half_chan *hc; - int direction; - - if (!local_direction(daemon->rstate, c, &direction)) - continue; - - hc = &c->half[direction]; - - if (!is_halfchan_defined(hc)) { - /* Connection is not announced yet, so don't even - * try to re-announce it */ - continue; - } - - if (hc->bcast.timestamp > highwater) { - /* No need to send a keepalive update message */ - continue; - } - - status_debug("Sending keepalive channel_update" - " for %s/%u", - type_to_string(tmpctx, - struct short_channel_id, - &c->scid), direction); - refresh_local_channel(daemon, c, direction); - } - } - - /* Now we've refreshed our channels, we can prune without clobbering - * them */ + /* Prune: I hope lightningd is keeping up with our own channel + * refreshes! */ route_prune(daemon->rstate); } @@ -1013,38 +902,6 @@ static void handle_outpoints_spent(struct daemon *daemon, const u8 *msg) } } -/*~ This is sent by lightningd when it kicks off 'closingd': we disable it - * in both directions. - * - * We'll leave it to handle_outpoint_spent to delete the channel from our view - * once the close gets confirmed. This avoids having strange states in which the - * channel is list in our peer list but won't be returned when listing public - * channels. This does not send out updates since that's triggered by the peer - * connection closing. - */ -static void handle_local_channel_close(struct daemon *daemon, const u8 *msg) -{ - struct short_channel_id scid; - struct chan *chan; - struct routing_state *rstate = daemon->rstate; - if (!fromwire_gossipd_local_channel_close(msg, &scid)) - master_badmsg(WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE, msg); - - chan = get_channel(rstate, &scid); - if (chan) { - int direction; - - if (!local_direction(rstate, chan, &direction)) { - status_broken("Non-local channel close %s", - type_to_string(tmpctx, - struct short_channel_id, - &scid)); - } else { - local_disable_chan(daemon, chan, direction); - } - } -} - /*~ This routine handles all the commands from lightningd. */ static struct io_plan *recv_req(struct io_conn *conn, const u8 *msg, @@ -1065,10 +922,6 @@ static struct io_plan *recv_req(struct io_conn *conn, handle_outpoints_spent(daemon, msg); goto done; - case WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE: - handle_local_channel_close(daemon, msg); - goto done; - case WIRE_GOSSIPD_NEW_BLOCKHEIGHT: new_blockheight(daemon, msg); goto done; @@ -1084,18 +937,6 @@ static struct io_plan *recv_req(struct io_conn *conn, case WIRE_GOSSIPD_GET_ADDRS: return handle_get_address(conn, daemon, msg); - case WIRE_GOSSIPD_USED_LOCAL_CHANNEL_UPDATE: - handle_used_local_channel_update(daemon, msg); - goto done; - - case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE: - handle_local_channel_update(daemon, msg); - goto done; - - case WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT: - handle_local_channel_announcement(daemon, msg); - goto done; - case WIRE_GOSSIPD_DISCOVERED_IP: handle_discovered_ip(daemon, msg); goto done; @@ -1133,7 +974,6 @@ static struct io_plan *recv_req(struct io_conn *conn, case WIRE_GOSSIPD_ADDGOSSIP_REPLY: case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY: case WIRE_GOSSIPD_GET_ADDRS_REPLY: - case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE: case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE: break; } diff --git a/gossipd/gossipd_wire.csv b/gossipd/gossipd_wire.csv index 7a72606cb..1f6dfdc8e 100644 --- a/gossipd/gossipd_wire.csv +++ b/gossipd/gossipd_wire.csv @@ -34,10 +34,6 @@ msgdata,gossipd_dev_set_time,dev_gossip_time,u32, msgtype,gossipd_dev_set_max_scids_encode_size,3030 msgdata,gossipd_dev_set_max_scids_encode_size,max,u32, -# gossipd->master: we're closing this channel. -msgtype,gossipd_local_channel_close,3027 -msgdata,gossipd_local_channel_close,short_channel_id,short_channel_id, - # Gossipd->master get this tx output please. msgtype,gossipd_get_txout,3018 msgdata,gossipd_get_txout,short_channel_id,short_channel_id, @@ -96,34 +92,6 @@ msgtype,gossipd_get_addrs_reply,3150 msgdata,gossipd_get_addrs_reply,num,u16, msgdata,gossipd_get_addrs_reply,addrs,wireaddr,num -# Tell master a local channel update (so it can serve errors). -msgtype,gossipd_got_local_channel_update,3151 -msgdata,gossipd_got_local_channel_update,scid,short_channel_id, -msgdata,gossipd_got_local_channel_update,len,u16, -msgdata,gossipd_got_local_channel_update,channel_update,u8,len - -# Send this channel_update. -msgtype,gossipd_local_channel_update,3004 -msgdata,gossipd_local_channel_update,id,node_id, -msgdata,gossipd_local_channel_update,short_channel_id,short_channel_id, -msgdata,gossipd_local_channel_update,enable,bool, -msgdata,gossipd_local_channel_update,cltv_expiry_delta,u16, -msgdata,gossipd_local_channel_update,htlc_minimum_msat,amount_msat, -msgdata,gossipd_local_channel_update,fee_base_msat,u32, -msgdata,gossipd_local_channel_update,fee_proportional_millionths,u32, -msgdata,gossipd_local_channel_update,htlc_maximum_msat,amount_msat, -msgdata,gossipd_local_channel_update,public,bool, - -# Send this channel_announcement -msgtype,gossipd_local_channel_announcement,3006 -msgdata,gossipd_local_channel_announcement,id,node_id, -msgdata,gossipd_local_channel_announcement,len,u16, -msgdata,gossipd_local_channel_announcement,cannounce,u8,len - -# Tell gossipd we used the channel update (in case it was deferred) -msgtype,gossipd_used_local_channel_update,3052 -msgdata,gossipd_used_local_channel_update,scid,short_channel_id, - # Tell gossipd we have verified a new public IP by the remote_addr feature msgtype,gossipd_discovered_ip,3009 msgdata,gossipd_discovered_ip,discovered_ip,wireaddr, diff --git a/gossipd/routing.c b/gossipd/routing.c index 1ad4905d0..548c63bc6 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -2022,6 +2022,11 @@ void route_prune(struct routing_state *rstate) || chan->half[0].bcast.timestamp < highwater || !is_halfchan_defined(&chan->half[1]) || chan->half[1].bcast.timestamp < highwater) { + if (local_direction(rstate, chan, NULL)) + status_unusual("Pruning local channel %s from gossip_store: not refreshed in over two weeks", + type_to_string(tmpctx, struct short_channel_id, + &chan->scid)); + status_debug( "Pruning channel %s from network view (ages %"PRIu64" and %"PRIu64"s)", type_to_string(tmpctx, struct short_channel_id, diff --git a/gossipd/test/run-check_node_announcement.c b/gossipd/test/run-check_node_announcement.c index a2635a50d..e4f61d5ab 100644 --- a/gossipd/test/run-check_node_announcement.c +++ b/gossipd/test/run-check_node_announcement.c @@ -24,18 +24,6 @@ bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED, const struct sha256 *h UNNEEDED, struct pubkey *next UNNEEDED) { fprintf(stderr, "blinding_next_pubkey called!\n"); abort(); } -/* Generated stub for daemon_conn_send */ -void daemon_conn_send(struct daemon_conn *dc UNNEEDED, const u8 *msg UNNEEDED) -{ fprintf(stderr, "daemon_conn_send called!\n"); abort(); } -/* Generated stub for fromwire_gossipd_local_channel_update */ -bool fromwire_gossipd_local_channel_update(const void *p UNNEEDED, struct node_id *id UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, bool *enable UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED, bool *public UNNEEDED) -{ fprintf(stderr, "fromwire_gossipd_local_channel_update called!\n"); abort(); } -/* Generated stub for fromwire_gossipd_used_local_channel_update */ -bool fromwire_gossipd_used_local_channel_update(const void *p UNNEEDED, struct short_channel_id *scid UNNEEDED) -{ fprintf(stderr, "fromwire_gossipd_used_local_channel_update called!\n"); abort(); } -/* Generated stub for fromwire_hsmd_cupdate_sig_reply */ -bool fromwire_hsmd_cupdate_sig_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **cu UNNEEDED) -{ fprintf(stderr, "fromwire_hsmd_cupdate_sig_reply called!\n"); abort(); } /* Generated stub for fromwire_hsmd_node_announcement_sig_reply */ bool fromwire_hsmd_node_announcement_sig_reply(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED) { fprintf(stderr, "fromwire_hsmd_node_announcement_sig_reply called!\n"); abort(); } @@ -46,20 +34,11 @@ struct node *get_node(struct routing_state *rstate UNNEEDED, /* Generated stub for gossip_time_now */ struct timeabs gossip_time_now(const struct routing_state *rstate UNNEEDED) { fprintf(stderr, "gossip_time_now called!\n"); abort(); } -/* Generated stub for handle_channel_update */ -u8 *handle_channel_update(struct routing_state *rstate UNNEEDED, const u8 *update TAKES UNNEEDED, - const struct node_id *source_peer TAKES UNNEEDED, - struct short_channel_id *unknown_scid UNNEEDED, - bool force UNNEEDED) -{ fprintf(stderr, "handle_channel_update called!\n"); abort(); } /* Generated stub for handle_node_announcement */ u8 *handle_node_announcement(struct routing_state *rstate UNNEEDED, const u8 *node_ann UNNEEDED, const struct node_id *source_peer TAKES UNNEEDED, bool *was_unknown UNNEEDED) { fprintf(stderr, "handle_node_announcement called!\n"); abort(); } -/* Generated stub for master_badmsg */ -void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg) -{ fprintf(stderr, "master_badmsg called!\n"); abort(); } /* Generated stub for new_reltimer_ */ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED, const tal_t *ctx UNNEEDED, @@ -79,12 +58,6 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } -/* Generated stub for towire_gossipd_got_local_channel_update */ -u8 *towire_gossipd_got_local_channel_update(const tal_t *ctx UNNEEDED, const struct short_channel_id *scid UNNEEDED, const u8 *channel_update UNNEEDED) -{ fprintf(stderr, "towire_gossipd_got_local_channel_update called!\n"); abort(); } -/* Generated stub for towire_hsmd_cupdate_sig_req */ -u8 *towire_hsmd_cupdate_sig_req(const tal_t *ctx UNNEEDED, const u8 *cu UNNEEDED) -{ fprintf(stderr, "towire_hsmd_cupdate_sig_req called!\n"); abort(); } /* Generated stub for towire_hsmd_node_announcement_sig_req */ u8 *towire_hsmd_node_announcement_sig_req(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED) { fprintf(stderr, "towire_hsmd_node_announcement_sig_req called!\n"); abort(); } diff --git a/gossipd/test/run-crc32_of_update.c b/gossipd/test/run-crc32_of_update.c index 28ba27f56..1516d5da6 100644 --- a/gossipd/test/run-crc32_of_update.c +++ b/gossipd/test/run-crc32_of_update.c @@ -28,9 +28,6 @@ bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED, const struct sha256 *h UNNEEDED, struct pubkey *next UNNEEDED) { fprintf(stderr, "blinding_next_pubkey called!\n"); abort(); } -/* Generated stub for daemon_conn_send */ -void daemon_conn_send(struct daemon_conn *dc UNNEEDED, const u8 *msg UNNEEDED) -{ fprintf(stderr, "daemon_conn_send called!\n"); abort(); } /* Generated stub for daemon_conn_wake */ void daemon_conn_wake(struct daemon_conn *dc UNNEEDED) { fprintf(stderr, "daemon_conn_wake called!\n"); abort(); } @@ -52,15 +49,6 @@ struct peer *first_random_peer(struct daemon *daemon UNNEEDED, /* Generated stub for fromwire_gossipd_dev_set_max_scids_encode_size */ bool fromwire_gossipd_dev_set_max_scids_encode_size(const void *p UNNEEDED, u32 *max UNNEEDED) { fprintf(stderr, "fromwire_gossipd_dev_set_max_scids_encode_size called!\n"); abort(); } -/* Generated stub for fromwire_gossipd_local_channel_update */ -bool fromwire_gossipd_local_channel_update(const void *p UNNEEDED, struct node_id *id UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, bool *enable UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED, bool *public UNNEEDED) -{ fprintf(stderr, "fromwire_gossipd_local_channel_update called!\n"); abort(); } -/* Generated stub for fromwire_gossipd_used_local_channel_update */ -bool fromwire_gossipd_used_local_channel_update(const void *p UNNEEDED, struct short_channel_id *scid UNNEEDED) -{ fprintf(stderr, "fromwire_gossipd_used_local_channel_update called!\n"); abort(); } -/* Generated stub for fromwire_hsmd_cupdate_sig_reply */ -bool fromwire_hsmd_cupdate_sig_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **cu UNNEEDED) -{ fprintf(stderr, "fromwire_hsmd_cupdate_sig_reply called!\n"); abort(); } /* Generated stub for fromwire_hsmd_node_announcement_sig_reply */ bool fromwire_hsmd_node_announcement_sig_reply(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED) { fprintf(stderr, "fromwire_hsmd_node_announcement_sig_reply called!\n"); abort(); } @@ -76,12 +64,6 @@ const u8 *gossip_store_get(const tal_t *ctx UNNEEDED, /* Generated stub for gossip_time_now */ struct timeabs gossip_time_now(const struct routing_state *rstate UNNEEDED) { fprintf(stderr, "gossip_time_now called!\n"); abort(); } -/* Generated stub for handle_channel_update */ -u8 *handle_channel_update(struct routing_state *rstate UNNEEDED, const u8 *update TAKES UNNEEDED, - const struct node_id *source_peer TAKES UNNEEDED, - struct short_channel_id *unknown_scid UNNEEDED, - bool force UNNEEDED) -{ fprintf(stderr, "handle_channel_update called!\n"); abort(); } /* Generated stub for handle_node_announcement */ u8 *handle_node_announcement(struct routing_state *rstate UNNEEDED, const u8 *node_ann UNNEEDED, const struct node_id *source_peer TAKES UNNEEDED, @@ -126,12 +108,6 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } -/* Generated stub for towire_gossipd_got_local_channel_update */ -u8 *towire_gossipd_got_local_channel_update(const tal_t *ctx UNNEEDED, const struct short_channel_id *scid UNNEEDED, const u8 *channel_update UNNEEDED) -{ fprintf(stderr, "towire_gossipd_got_local_channel_update called!\n"); abort(); } -/* Generated stub for towire_hsmd_cupdate_sig_req */ -u8 *towire_hsmd_cupdate_sig_req(const tal_t *ctx UNNEEDED, const u8 *cu UNNEEDED) -{ fprintf(stderr, "towire_hsmd_cupdate_sig_req called!\n"); abort(); } /* Generated stub for towire_hsmd_node_announcement_sig_req */ u8 *towire_hsmd_node_announcement_sig_req(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED) { fprintf(stderr, "towire_hsmd_node_announcement_sig_req called!\n"); abort(); } diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 36933141e..169de1a08 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -161,16 +161,12 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIPD_OUTPOINTS_SPENT: case WIRE_GOSSIPD_NEW_LEASE_RATES: case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE: - case WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE: case WIRE_GOSSIPD_DEV_MEMLEAK: case WIRE_GOSSIPD_DEV_COMPACT_STORE: case WIRE_GOSSIPD_DEV_SET_TIME: case WIRE_GOSSIPD_NEW_BLOCKHEIGHT: case WIRE_GOSSIPD_ADDGOSSIP: case WIRE_GOSSIPD_GET_ADDRS: - case WIRE_GOSSIPD_LOCAL_CHANNEL_ANNOUNCEMENT: - case WIRE_GOSSIPD_USED_LOCAL_CHANNEL_UPDATE: - case WIRE_GOSSIPD_LOCAL_CHANNEL_UPDATE: /* This is a reply, so never gets through to here. */ case WIRE_GOSSIPD_INIT_REPLY: case WIRE_GOSSIPD_DEV_MEMLEAK_REPLY: @@ -184,9 +180,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIPD_INIT_CUPDATE: handle_init_cupdate(gossip->ld, msg); break; - /* FIXME: remove from gossipd_wire.csv */ - case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE: - break; case WIRE_GOSSIPD_GET_TXOUT: get_txout(gossip, msg); break;