mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +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:
@@ -5,6 +5,9 @@ struct queued_message {
|
|||||||
/* Broadcast index. */
|
/* Broadcast index. */
|
||||||
u64 index;
|
u64 index;
|
||||||
|
|
||||||
|
/* Timestamp, for filtering. */
|
||||||
|
u32 timestamp;
|
||||||
|
|
||||||
/* Serialized payload */
|
/* Serialized payload */
|
||||||
const u8 *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,
|
static struct queued_message *new_queued_message(const tal_t *ctx,
|
||||||
struct broadcast_state *bstate,
|
struct broadcast_state *bstate,
|
||||||
const u8 *payload,
|
const u8 *payload,
|
||||||
|
u32 timestamp,
|
||||||
u64 index)
|
u64 index)
|
||||||
{
|
{
|
||||||
struct queued_message *msg = tal(ctx, struct queued_message);
|
struct queued_message *msg = tal(ctx, struct queued_message);
|
||||||
|
assert(payload);
|
||||||
msg->payload = payload;
|
msg->payload = payload;
|
||||||
msg->index = index;
|
msg->index = index;
|
||||||
|
msg->timestamp = timestamp;
|
||||||
uintmap_add(&bstate->broadcasts, index, msg);
|
uintmap_add(&bstate->broadcasts, index, msg);
|
||||||
tal_add_destructor2(msg, destroy_queued_message, bstate);
|
tal_add_destructor2(msg, destroy_queued_message, bstate);
|
||||||
return msg;
|
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. */
|
/* 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)
|
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);
|
struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
||||||
|
|
||||||
/* Append a queued message for broadcast. Freeing the msg will remove it. */
|
/* 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.
|
/* Return the broadcast with index >= *last_index, and update *last_index.
|
||||||
* There's no broadcast with index 0. */
|
* 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,
|
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);
|
rstate->local_channel_announced |= is_local_channel(rstate, chan);
|
||||||
|
|
||||||
/* If we've been waiting for this, now we can announce node */
|
/* 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) {
|
if (!node->node_announcement_public) {
|
||||||
node->node_announcement_public = true;
|
node->node_announcement_public = true;
|
||||||
insert_broadcast(rstate->broadcasts,
|
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;
|
return true;
|
||||||
|
|
||||||
/* BOLT #7:
|
/* 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
|
* - MUST consider whether to send the `channel_announcement` after
|
||||||
* receiving the first corresponding `channel_update`.
|
* receiving the first corresponding `channel_update`.
|
||||||
*/
|
*/
|
||||||
if (!have_broadcast_announce)
|
if (!have_broadcast_announce)
|
||||||
add_channel_announce_to_broadcast(rstate, chan);
|
add_channel_announce_to_broadcast(rstate, chan, timestamp);
|
||||||
|
|
||||||
insert_broadcast(rstate->broadcasts,
|
insert_broadcast(rstate->broadcasts,
|
||||||
chan->half[direction].channel_update);
|
chan->half[direction].channel_update,
|
||||||
|
timestamp);
|
||||||
return true;
|
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. */
|
/* We might be waiting for channel_announce to be released. */
|
||||||
node->node_announcement_public = node_has_public_channels(node);
|
node->node_announcement_public = node_has_public_channels(node);
|
||||||
if (node->node_announcement_public)
|
if (node->node_announcement_public)
|
||||||
insert_broadcast(rstate->broadcasts, node->node_announcement);
|
insert_broadcast(rstate->broadcasts, node->node_announcement,
|
||||||
|
timestamp);
|
||||||
return true;
|
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)
|
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||||
/* Generated stub for insert_broadcast */
|
/* 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(); }
|
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||||
/* Generated stub for onion_type_name */
|
/* Generated stub for onion_type_name */
|
||||||
const char *onion_type_name(int e UNNEEDED)
|
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)
|
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||||
/* Generated stub for insert_broadcast */
|
/* 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(); }
|
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||||
/* Generated stub for onion_type_name */
|
/* Generated stub for onion_type_name */
|
||||||
const char *onion_type_name(int e UNNEEDED)
|
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)
|
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||||
/* Generated stub for insert_broadcast */
|
/* 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(); }
|
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||||
/* Generated stub for onion_type_name */
|
/* Generated stub for onion_type_name */
|
||||||
const char *onion_type_name(int e UNNEEDED)
|
const char *onion_type_name(int e UNNEEDED)
|
||||||
|
|||||||
Reference in New Issue
Block a user