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
|
|
|
|
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-06-03 20:22:25 +02:00
|
|
|
struct gossip_store *gossip_store_new(struct routing_state *rstate,
|
|
|
|
struct list_head *peers);
|
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
|
2019-06-12 01:25:07 +02:00
|
|
|
*
|
2019-10-08 03:11:24 +02:00
|
|
|
* Returns the last-modified time of the store, or 0 if it was created new.
|
2018-03-13 12:08:03 +01:00
|
|
|
*/
|
2019-10-08 03:11:24 +02:00
|
|
|
u32 gossip_store_load(struct routing_state *rstate, struct gossip_store *gs);
|
2018-03-13 12:08:03 +01:00
|
|
|
|
2019-06-03 20:05:25 +02:00
|
|
|
/**
|
|
|
|
* Add a private channel_update message to the gossip_store
|
|
|
|
*/
|
|
|
|
u64 gossip_store_add_private_update(struct gossip_store *gs, const u8 *update);
|
|
|
|
|
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)
|
2019-11-04 01:37:05 +01:00
|
|
|
* @gs: gossip store
|
|
|
|
* @gossip_msg: the gossip message to insert.
|
|
|
|
* @timestamp: the timestamp for filtering of this messsage.
|
|
|
|
* @push: true if this should be sent to peers despite any timestamp filters.
|
|
|
|
* @addendum: another message to append immediately after this
|
|
|
|
* (for appending amounts to channel_announcements for internal use).
|
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-11-04 01:37:05 +01:00
|
|
|
u32 timestamp, bool push, const u8 *addendum);
|
2019-05-16 21:55:17 +02:00
|
|
|
|
2018-03-25 18:23:10 +02:00
|
|
|
|
2018-03-28 12:54:09 +02:00
|
|
|
/**
|
2019-06-03 20:09:25 +02:00
|
|
|
* Delete the broadcast associated with this (if any).
|
|
|
|
*
|
|
|
|
* In developer mode, checks that type is correct.
|
2018-03-28 12:54:09 +02:00
|
|
|
*/
|
2019-06-03 20:09:25 +02:00
|
|
|
void gossip_store_delete(struct gossip_store *gs,
|
|
|
|
struct broadcastable *bcast,
|
|
|
|
int type);
|
2018-03-28 12:54:09 +02:00
|
|
|
|
2020-08-11 07:06:56 +02:00
|
|
|
/**
|
|
|
|
* Mark that the channel is about to be deleted, for convenience of
|
|
|
|
* others mapping the gossip_store.
|
|
|
|
*/
|
|
|
|
void gossip_store_mark_channel_deleted(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-06-03 20:05:25 +02:00
|
|
|
/**
|
|
|
|
* Direct store accessor: loads private gossip msg back from store.
|
|
|
|
*
|
|
|
|
* Caller must ensure offset != 0. Never returns NULL.
|
|
|
|
*/
|
|
|
|
const u8 *gossip_store_get_private_update(const tal_t *ctx,
|
|
|
|
struct gossip_store *gs,
|
|
|
|
u64 offset);
|
|
|
|
|
2019-06-03 20:22:25 +02:00
|
|
|
/* Exposed for dev-compact-gossip-store to force compaction. */
|
|
|
|
bool gossip_store_compact(struct gossip_store *gs);
|
2019-04-11 07:16:57 +02:00
|
|
|
|
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-06-03 20:22:25 +02:00
|
|
|
/* Callback inside gossipd when store is compacted */
|
|
|
|
void update_peers_broadcast_index(struct list_head *peers, u32 offset);
|
|
|
|
|
2018-03-26 02:05:34 +02:00
|
|
|
#endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_H */
|