core-lightning/gossipd/broadcast.h
Rusty Russell 6b9069ee28 broadcast: don't keep payload pointer.
If we need the payload, pull it from the gossip store.

MCP results from 5 runs, min-max(mean +/- stddev):
	store_load_msec:30189-52561(39416.4+/-8.8e+03)
	vsz_kb:1812904
	store_rewrite_sec:21.390000-27.070000(23.596+/-2.4)
	listnodes_sec:1.120000-1.230000(1.176+/-0.044)
	listchannels_sec:38.900000-50.580000(44.716+/-3.9)
	routing_sec:45.080000-48.160000(46.814+/-1.1)
	peer_write_all_sec:58.780000-87.150000(72.278+/-9.7)

MCP notable changes from previous patch (>1 stddev):
	-vsz_kb:2288784
	+vsz_kb:1812904
	-store_rewrite_sec:38.060000-39.130000(38.426+/-0.39)
	+store_rewrite_sec:21.390000-27.070000(23.596+/-2.4)
	-listnodes_sec:0.750000-0.850000(0.794+/-0.042)
	+listnodes_sec:1.120000-1.230000(1.176+/-0.044)
	-listchannels_sec:30.740000-31.760000(31.096+/-0.35)
	+listchannels_sec:38.900000-50.580000(44.716+/-3.9)
	-routing_sec:29.600000-33.560000(30.472+/-1.5)
	+routing_sec:45.080000-48.160000(46.814+/-1.1)
	-peer_write_all_sec:49.220000-52.690000(50.892+/-1.3)
	+peer_write_all_sec:58.780000-87.150000(72.278+/-9.7)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-11 18:31:34 -07:00

72 lines
2.2 KiB
C

#ifndef LIGHTNING_GOSSIPD_BROADCAST_H
#define LIGHTNING_GOSSIPD_BROADCAST_H
#include "config.h"
#include <ccan/intmap/intmap.h>
#include <ccan/list/list.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
/* Common functionality to implement staggered broadcasts with replacement. */
struct routing_state;
/* This is nested inside a node, chan or half_chan; rewriting the store can
* cause it to change! */
struct broadcastable {
/* This is also the offset within the gossip_store; even with 1M
* channels we still have a factor of 8 before this wraps. */
u32 index;
u32 timestamp;
};
struct broadcast_state {
UINTMAP(struct broadcastable *) broadcasts;
size_t count;
struct gossip_store *gs;
};
static inline void broadcastable_init(struct broadcastable *bcast)
{
bcast->index = 0;
}
struct broadcast_state *new_broadcast_state(struct routing_state *rstate,
struct gossip_store *gs);
/* Append a queued message for broadcast. Must be explicitly deleted.
* Also adds it to the gossip store. */
void insert_broadcast(struct broadcast_state **bstate,
const u8 *msg,
struct broadcastable *bcast);
/* Add to broadcast, but not store: for gossip store compaction. */
void insert_broadcast_nostore(struct broadcast_state *bstate,
struct broadcastable *bcast);
/* Delete a broadcast: not usually needed, since destructor does it */
void broadcast_del(struct broadcast_state *bstate,
struct broadcastable *bcast);
/* Return the next broadcastable entry; doesn't load it. */
struct broadcastable *next_broadcast_raw(struct broadcast_state *bstate,
u32 *last_index);
/* Return the broadcast with index >= *last_index, timestamp >= min and <= max
* and update *last_index.
* There's no broadcast with index 0. */
const u8 *next_broadcast(const tal_t *ctx,
struct broadcast_state *bstate,
u32 timestamp_min, u32 timestamp_max,
u32 *last_index);
/* index of last entry. */
u64 broadcast_final_index(const struct broadcast_state *bstate);
/* Returns b if all OK, otherwise aborts if abortstr non-NULL, otherwise returns
* NULL. */
struct broadcast_state *broadcast_state_check(struct broadcast_state *b,
const char *abortstr);
#endif /* LIGHTNING_GOSSIPD_BROADCAST_H */