2018-03-26 02:05:34 +02:00
|
|
|
#ifndef LIGHTNING_GOSSIPD_GOSSIP_STORE_H
|
|
|
|
#define LIGHTNING_GOSSIPD_GOSSIP_STORE_H
|
2018-03-13 12:08:03 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-03-28 12:54:09 +02:00
|
|
|
#include <bitcoin/short_channel_id.h>
|
2018-03-13 12:08:03 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
2018-03-23 17:34:11 +01:00
|
|
|
#include <gossipd/routing.h>
|
2018-03-13 12:08:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gossip_store -- On-disk storage related information
|
|
|
|
*/
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
struct broadcast_state;
|
2018-03-13 12:08:03 +01:00
|
|
|
struct gossip_store;
|
2018-03-23 17:34:11 +01:00
|
|
|
struct routing_state;
|
2018-03-13 12:08:03 +01:00
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
struct gossip_store *gossip_store_new(struct routing_state *rstate);
|
2018-03-13 12:08:03 +01:00
|
|
|
|
|
|
|
/**
|
2018-04-11 01:03:35 +02:00
|
|
|
* Load the initial gossip store, if any.
|
2018-03-13 12:08:03 +01:00
|
|
|
*
|
2018-04-11 01:03:35 +02:00
|
|
|
* @param rstate The routing state to load init.
|
2018-03-13 12:08:03 +01:00
|
|
|
* @param gs The `gossip_store` to read from
|
|
|
|
*/
|
2018-04-11 01:03:35 +02:00
|
|
|
void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs);
|
2018-03-13 12:08:03 +01:00
|
|
|
|
2018-03-23 17:34:11 +01:00
|
|
|
/**
|
2019-05-16 21:55:17 +02:00
|
|
|
* Add a gossip message to the gossip_store (and optional addendum)
|
2018-03-23 17:34:11 +01:00
|
|
|
*/
|
2019-05-04 07:53:12 +02:00
|
|
|
u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg,
|
2019-05-16 21:55:17 +02:00
|
|
|
const u8 *addendum);
|
|
|
|
|
2018-03-25 18:23:10 +02:00
|
|
|
|
2018-03-28 12:54:09 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
/**
|
|
|
|
* Direct store accessor: loads gossip msg back from store.
|
|
|
|
*
|
|
|
|
* Caller must ensure offset != 0. Never returns NULL.
|
|
|
|
*/
|
|
|
|
const u8 *gossip_store_get(const tal_t *ctx,
|
|
|
|
struct gossip_store *gs,
|
|
|
|
u64 offset);
|
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
/**
|
|
|
|
* If we need to compact the gossip store, do so.
|
|
|
|
* @gs: the gossip store.
|
|
|
|
* @bs: a pointer to the broadcast state: replaced if we compact it.
|
2019-04-11 07:16:57 +02:00
|
|
|
* @offset: the change in the store, if any.
|
|
|
|
*
|
2019-05-04 07:53:13 +02:00
|
|
|
* If return value is true, caller must update peers.
|
2019-04-10 09:31:29 +02:00
|
|
|
*/
|
2019-05-04 07:53:13 +02:00
|
|
|
bool gossip_store_maybe_compact(struct gossip_store *gs,
|
2019-04-11 07:16:57 +02:00
|
|
|
struct broadcast_state **bs,
|
|
|
|
u32 *offset);
|
2019-04-10 09:31:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Expose for dev-compact-gossip-store to force compaction. */
|
|
|
|
bool gossip_store_compact(struct gossip_store *gs,
|
2019-04-11 07:16:57 +02:00
|
|
|
struct broadcast_state **bs,
|
|
|
|
u32 *offset);
|
|
|
|
|
2019-05-04 07:53:13 +02:00
|
|
|
/**
|
|
|
|
* Get a readonly fd for the gossip_store.
|
|
|
|
* @gs: the gossip store.
|
|
|
|
*
|
|
|
|
* Returns -1 on failure, and sets errno.
|
|
|
|
*/
|
|
|
|
int gossip_store_readonly_fd(struct gossip_store *gs);
|
2019-04-11 07:16:57 +02:00
|
|
|
|
2019-05-29 06:35:47 +02:00
|
|
|
/* FIXME: Remove */
|
|
|
|
bool gossip_store_loading(const struct gossip_store *gs);
|
|
|
|
|
2018-03-26 02:05:34 +02:00
|
|
|
#endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_H */
|