mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
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>
This commit is contained in:
parent
9132a097b5
commit
63f22d70b5
8 changed files with 43 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <bitcoin/short_channel_id.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.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,
|
||||
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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue