diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 1b09b6fc2..30f382c46 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -2007,6 +2007,7 @@ static struct io_plan *handle_outpoint_spent(struct io_conn *conn, * of the channel and the destructor takes care of unregistering * the channel */ tal_free(chan); + gossip_store_add_channel_delete(rstate->store, &scid); } return daemon_conn_read_next(conn, &daemon->master); @@ -2096,6 +2097,7 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master case WIRE_GOSSIP_STORE_CHANNEL_ANNOUNCEMENT: case WIRE_GOSSIP_STORE_CHANNEL_UPDATE: case WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT: + case WIRE_GOSSIP_STORE_CHANNEL_DELETE: break; } diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index 2bd3f533c..aaa89387a 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -88,6 +88,14 @@ void gossip_store_add_node_announcement(struct gossip_store *gs, tal_free(msg); } +void gossip_store_add_channel_delete(struct gossip_store *gs, + const struct short_channel_id *scid) +{ + u8 *msg = towire_gossip_store_channel_delete(NULL, scid); + gossip_store_append(gs, msg); + tal_free(msg); +} + bool gossip_store_read_next(struct routing_state *rstate, struct gossip_store *gs) { @@ -96,6 +104,7 @@ bool gossip_store_read_next(struct routing_state *rstate, u8 *msg, *gossip_msg; u64 satoshis; enum gossip_wire_type type; + struct short_channel_id scid; /* Did we already reach the end of the gossip_store? */ if (gs->read_pos == -1) @@ -135,6 +144,9 @@ bool gossip_store_read_next(struct routing_state *rstate, } else if(type == WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT) { fromwire_gossip_store_node_announcement(msg, msg, &gossip_msg); routing_add_node_announcement(rstate, gossip_msg); + } else if(type == WIRE_GOSSIP_STORE_CHANNEL_DELETE) { + fromwire_gossip_store_channel_delete(msg, &scid); + tal_free(get_channel(rstate, &scid)); } tal_free(msg); return true; diff --git a/gossipd/gossip_store.h b/gossipd/gossip_store.h index 9ab7e33d8..34bb205a1 100644 --- a/gossipd/gossip_store.h +++ b/gossipd/gossip_store.h @@ -3,6 +3,7 @@ #include "config.h" +#include #include #include #include @@ -44,4 +45,10 @@ void gossip_store_add_channel_update(struct gossip_store *gs, void gossip_store_add_node_announcement(struct gossip_store *gs, const u8 *gossip_msg); +/** + * Remember that we deleted a channel as a result of its outpoint being spent + */ +void gossip_store_add_channel_delete(struct gossip_store *gs, + const struct short_channel_id *scid); + #endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_H */ diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index c3e5775dd..7c807f005 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -242,3 +242,6 @@ gossip_store_channel_update,,update,len*u8 gossip_store_node_announcement,4098 gossip_store_node_announcement,,len,u16 gossip_store_node_announcement,,announcement,len*u8 + +gossip_store_channel_delete,4099 +gossip_store_channel_delete,,short_channel_id,struct short_channel_id diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 397e7565c..cc4f5e4b9 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -65,6 +65,9 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature * /* Generated stub for fromwire_gossip_store_channel_announcement */ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_announcement called!\n"); abort(); } +/* Generated stub for fromwire_gossip_store_channel_delete */ +bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_update */ bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); } @@ -108,6 +111,9 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, /* Generated stub for towire_gossip_store_channel_announcement */ u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, u64 satoshis UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_announcement called!\n"); abort(); } +/* Generated stub for towire_gossip_store_channel_delete */ +u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) +{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } /* Generated stub for towire_gossip_store_channel_update */ u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); } diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 372f5e7bb..3c220d20d 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -29,6 +29,9 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature * /* Generated stub for fromwire_gossip_store_channel_announcement */ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_announcement called!\n"); abort(); } +/* Generated stub for fromwire_gossip_store_channel_delete */ +bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_update */ bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); } @@ -72,6 +75,9 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, /* Generated stub for towire_gossip_store_channel_announcement */ u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, u64 satoshis UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_announcement called!\n"); abort(); } +/* Generated stub for towire_gossip_store_channel_delete */ +u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) +{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } /* Generated stub for towire_gossip_store_channel_update */ u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); } diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 9e34ac899..c042bccee 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -27,6 +27,9 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature * /* Generated stub for fromwire_gossip_store_channel_announcement */ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_announcement called!\n"); abort(); } +/* Generated stub for fromwire_gossip_store_channel_delete */ +bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) +{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_update */ bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); } @@ -70,6 +73,9 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, /* Generated stub for towire_gossip_store_channel_announcement */ u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, u64 satoshis UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_announcement called!\n"); abort(); } +/* Generated stub for towire_gossip_store_channel_delete */ +u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) +{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } /* Generated stub for towire_gossip_store_channel_update */ u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); } diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index ae6908622..c2bbefafc 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -153,6 +153,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIP_STORE_CHANNEL_ANNOUNCEMENT: case WIRE_GOSSIP_STORE_CHANNEL_UPDATE: case WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT: + case WIRE_GOSSIP_STORE_CHANNEL_DELETE: break; /* These are inter-daemon messages, not received by us */ case WIRE_GOSSIP_LOCAL_ADD_CHANNEL: