mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
gossipd: add timestamp to each broadcast message.
This lets us filter by timestamp. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
c633cbe2ee
commit
7a32637b5f
@ -5,6 +5,9 @@ struct queued_message {
|
||||
/* Broadcast index. */
|
||||
u64 index;
|
||||
|
||||
/* Timestamp, for filtering. */
|
||||
u32 timestamp;
|
||||
|
||||
/* Serialized payload */
|
||||
const u8 *payload;
|
||||
};
|
||||
@ -27,20 +30,25 @@ static void destroy_queued_message(struct queued_message *msg,
|
||||
static struct queued_message *new_queued_message(const tal_t *ctx,
|
||||
struct broadcast_state *bstate,
|
||||
const u8 *payload,
|
||||
u32 timestamp,
|
||||
u64 index)
|
||||
{
|
||||
struct queued_message *msg = tal(ctx, struct queued_message);
|
||||
assert(payload);
|
||||
msg->payload = payload;
|
||||
msg->index = index;
|
||||
msg->timestamp = timestamp;
|
||||
uintmap_add(&bstate->broadcasts, index, msg);
|
||||
tal_add_destructor2(msg, destroy_queued_message, bstate);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void insert_broadcast(struct broadcast_state *bstate, const u8 *payload)
|
||||
void insert_broadcast(struct broadcast_state *bstate,
|
||||
const u8 *payload, u32 timestamp)
|
||||
{
|
||||
/* Free payload, free index. */
|
||||
new_queued_message(payload, bstate, payload, bstate->next_index++);
|
||||
new_queued_message(payload, bstate, payload, timestamp,
|
||||
bstate->next_index++);
|
||||
}
|
||||
|
||||
const u8 *next_broadcast(struct broadcast_state *bstate, u64 *last_index)
|
||||
|
@ -17,7 +17,8 @@ struct broadcast_state {
|
||||
struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
||||
|
||||
/* Append a queued message for broadcast. Freeing the msg will remove it. */
|
||||
void insert_broadcast(struct broadcast_state *bstate, const u8 *msg);
|
||||
void insert_broadcast(struct broadcast_state *bstate, const u8 *msg,
|
||||
u32 timestamp);
|
||||
|
||||
/* Return the broadcast with index >= *last_index, and update *last_index.
|
||||
* There's no broadcast with index 0. */
|
||||
|
@ -614,9 +614,10 @@ static bool is_local_channel(const struct routing_state *rstate,
|
||||
}
|
||||
|
||||
static void add_channel_announce_to_broadcast(struct routing_state *rstate,
|
||||
struct chan *chan)
|
||||
struct chan *chan,
|
||||
u32 timestamp)
|
||||
{
|
||||
insert_broadcast(rstate->broadcasts, chan->channel_announce);
|
||||
insert_broadcast(rstate->broadcasts, chan->channel_announce, timestamp);
|
||||
rstate->local_channel_announced |= is_local_channel(rstate, chan);
|
||||
|
||||
/* If we've been waiting for this, now we can announce node */
|
||||
@ -627,7 +628,8 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
|
||||
if (!node->node_announcement_public) {
|
||||
node->node_announcement_public = true;
|
||||
insert_broadcast(rstate->broadcasts,
|
||||
node->node_announcement);
|
||||
node->node_announcement,
|
||||
node->last_timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -986,14 +988,17 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
||||
return true;
|
||||
|
||||
/* BOLT #7:
|
||||
* - MUST consider the `timestamp` of the `channel_announcement` to be
|
||||
* the `timestamp` of a corresponding `channel_update`.
|
||||
* - MUST consider whether to send the `channel_announcement` after
|
||||
* receiving the first corresponding `channel_update`.
|
||||
*/
|
||||
if (!have_broadcast_announce)
|
||||
add_channel_announce_to_broadcast(rstate, chan);
|
||||
add_channel_announce_to_broadcast(rstate, chan, timestamp);
|
||||
|
||||
insert_broadcast(rstate->broadcasts,
|
||||
chan->half[direction].channel_update);
|
||||
chan->half[direction].channel_update,
|
||||
timestamp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1204,7 +1209,8 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
|
||||
/* We might be waiting for channel_announce to be released. */
|
||||
node->node_announcement_public = node_has_public_channels(node);
|
||||
if (node->node_announcement_public)
|
||||
insert_broadcast(rstate->broadcasts, node->node_announcement);
|
||||
insert_broadcast(rstate->broadcasts, node->node_announcement,
|
||||
timestamp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,8 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for insert_broadcast */
|
||||
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED)
|
||||
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED,
|
||||
u32 timestamp UNNEEDED)
|
||||
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||
/* Generated stub for onion_type_name */
|
||||
const char *onion_type_name(int e UNNEEDED)
|
||||
|
@ -57,7 +57,8 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for insert_broadcast */
|
||||
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED)
|
||||
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED,
|
||||
u32 timestamp UNNEEDED)
|
||||
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||
/* Generated stub for onion_type_name */
|
||||
const char *onion_type_name(int e UNNEEDED)
|
||||
|
@ -55,7 +55,8 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for insert_broadcast */
|
||||
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED)
|
||||
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED,
|
||||
u32 timestamp UNNEEDED)
|
||||
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||
/* Generated stub for onion_type_name */
|
||||
const char *onion_type_name(int e UNNEEDED)
|
||||
|
Loading…
Reference in New Issue
Block a user