Browse Source

gossip: Store channel deletions so we don't re-add them on restart

If we only remember the actions that added channels then we'd restore them when
re-reading the gossip_store, so put a tombstone in there to remember to delete
it. These will be cleared upon re-writing the store since the announcements wont
be written anymore.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
63f22d70b5
  1. 2
      gossipd/gossip.c
  2. 12
      gossipd/gossip_store.c
  3. 7
      gossipd/gossip_store.h
  4. 3
      gossipd/gossip_wire.csv
  5. 6
      gossipd/test/run-bench-find_route.c
  6. 6
      gossipd/test/run-find_route-specific.c
  7. 6
      gossipd/test/run-find_route.c
  8. 1
      lightningd/gossip_control.c

2
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 * of the channel and the destructor takes care of unregistering
* the channel */ * the channel */
tal_free(chan); tal_free(chan);
gossip_store_add_channel_delete(rstate->store, &scid);
} }
return daemon_conn_read_next(conn, &daemon->master); 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_ANNOUNCEMENT:
case WIRE_GOSSIP_STORE_CHANNEL_UPDATE: case WIRE_GOSSIP_STORE_CHANNEL_UPDATE:
case WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT: case WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT:
case WIRE_GOSSIP_STORE_CHANNEL_DELETE:
break; break;
} }

12
gossipd/gossip_store.c

@ -88,6 +88,14 @@ void gossip_store_add_node_announcement(struct gossip_store *gs,
tal_free(msg); 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, bool gossip_store_read_next(struct routing_state *rstate,
struct gossip_store *gs) struct gossip_store *gs)
{ {
@ -96,6 +104,7 @@ bool gossip_store_read_next(struct routing_state *rstate,
u8 *msg, *gossip_msg; u8 *msg, *gossip_msg;
u64 satoshis; u64 satoshis;
enum gossip_wire_type type; enum gossip_wire_type type;
struct short_channel_id scid;
/* Did we already reach the end of the gossip_store? */ /* Did we already reach the end of the gossip_store? */
if (gs->read_pos == -1) 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) { } else if(type == WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT) {
fromwire_gossip_store_node_announcement(msg, msg, &gossip_msg); fromwire_gossip_store_node_announcement(msg, msg, &gossip_msg);
routing_add_node_announcement(rstate, 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); tal_free(msg);
return true; return true;

7
gossipd/gossip_store.h

@ -3,6 +3,7 @@
#include "config.h" #include "config.h"
#include <bitcoin/short_channel_id.h>
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <gossipd/routing.h> #include <gossipd/routing.h>
@ -44,4 +45,10 @@ void gossip_store_add_channel_update(struct gossip_store *gs,
void gossip_store_add_node_announcement(struct gossip_store *gs, void gossip_store_add_node_announcement(struct gossip_store *gs,
const u8 *gossip_msg); 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 */ #endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_H */

3
gossipd/gossip_wire.csv

@ -242,3 +242,6 @@ gossip_store_channel_update,,update,len*u8
gossip_store_node_announcement,4098 gossip_store_node_announcement,4098
gossip_store_node_announcement,,len,u16 gossip_store_node_announcement,,len,u16
gossip_store_node_announcement,,announcement,len*u8 gossip_store_node_announcement,,announcement,len*u8
gossip_store_channel_delete,4099
gossip_store_channel_delete,,short_channel_id,struct short_channel_id

Can't render this file because it has a wrong number of fields in line 6.

6
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 */ /* 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) 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(); } { 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 */ /* 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) 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(); } { 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 */ /* 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) 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(); } { 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 */ /* Generated stub for towire_gossip_store_channel_update */
u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) 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(); } { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); }

6
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 */ /* 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) 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(); } { 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 */ /* 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) 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(); } { 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 */ /* 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) 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(); } { 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 */ /* Generated stub for towire_gossip_store_channel_update */
u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) 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(); } { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); }

6
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 */ /* 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) 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(); } { 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 */ /* 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) 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(); } { 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 */ /* 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) 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(); } { 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 */ /* Generated stub for towire_gossip_store_channel_update */
u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) 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(); } { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); }

1
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_ANNOUNCEMENT:
case WIRE_GOSSIP_STORE_CHANNEL_UPDATE: case WIRE_GOSSIP_STORE_CHANNEL_UPDATE:
case WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT: case WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT:
case WIRE_GOSSIP_STORE_CHANNEL_DELETE:
break; break;
/* These are inter-daemon messages, not received by us */ /* These are inter-daemon messages, not received by us */
case WIRE_GOSSIP_LOCAL_ADD_CHANNEL: case WIRE_GOSSIP_LOCAL_ADD_CHANNEL:

Loading…
Cancel
Save