Revert "broadcast: don't reorder channel_announce when we get the real one."

This reverts commit f293ff0a6a.
This commit is contained in:
Christian Decker 2017-12-21 12:26:58 +01:00
parent ab620c5068
commit 1b28220b64
6 changed files with 19 additions and 49 deletions

View File

@ -1,4 +1,3 @@
#include <ccan/mem/mem.h>
#include <gossipd/broadcast.h>
struct broadcast_state *new_broadcast_state(tal_t *ctx)
@ -22,48 +21,28 @@ static struct queued_message *new_queued_message(tal_t *ctx,
return msg;
}
/* Returns 0 for not-found */
static u64 find_broadcast(const struct broadcast_state *bstate,
const int type, const u8 *tag)
{
struct queued_message *msg;
u64 index;
/* FIXME: Use a hash */
for (msg = uintmap_first(&bstate->broadcasts, &index);
msg;
msg = uintmap_after(&bstate->broadcasts, &index)) {
if (msg->type == type
&& memeq(msg->tag, tal_len(msg->tag), tag, tal_len(tag)))
return index;
}
return 0;
}
void queue_broadcast(struct broadcast_state *bstate,
const int type,
const u8 *tag,
const u8 *payload,
bool replace_inplace)
const u8 *payload)
{
struct queued_message *msg;
u64 index;
/* Remove any tag&type collisions */
index = find_broadcast(bstate, type, tag);
if (index == 0)
replace_inplace = false;
else
tal_free(uintmap_del(&bstate->broadcasts, index));
for (msg = uintmap_first(&bstate->broadcasts, &index);
msg;
msg = uintmap_after(&bstate->broadcasts, &index)) {
if (msg->type == type && memcmp(msg->tag, tag, tal_count(tag)) == 0) {
uintmap_del(&bstate->broadcasts, index);
tal_free(msg);
}
}
/* Now add the message to the queue */
msg = new_queued_message(bstate, type, tag, payload);
if (replace_inplace) {
uintmap_add(&bstate->broadcasts, index, msg);
} else {
uintmap_add(&bstate->broadcasts, bstate->next_index, msg);
bstate->next_index += 1;
}
uintmap_add(&bstate->broadcasts, bstate->next_index, msg);
bstate->next_index += 1;
}
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index)

View File

@ -29,13 +29,11 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx);
/* Queue a new message to be broadcast and replace any outdated
* broadcast. Replacement is done by comparing the `type` and the
* `tag`, if both match the old message is dropped from the queue. The
* new message is added to the top of the broadcast queue, unless
* replace_inplace is set, in which case it replaces the old (if any) */
* new message is added to the top of the broadcast queue. */
void queue_broadcast(struct broadcast_state *bstate,
const int type,
const u8 *tag,
const u8 *payload,
bool replace_inplace);
const u8 *payload);
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index);

View File

@ -565,9 +565,6 @@ bool handle_channel_announcement(
c1 = get_connection_by_scid(rstate, &short_channel_id, 1);
forward = !c0 || !c1 || !c0->channel_announcement || !c1->channel_announcement;
/* FIXME: What should we do if this channel_announce is completely
* different from previous? eg. different nodes? We would have to
* clear out the old announce and all updates... */
add_channel_direction(rstate, &node_id_1, &node_id_2, &short_channel_id,
sigfail ? NULL : serialized);
add_channel_direction(rstate, &node_id_2, &node_id_1, &short_channel_id,
@ -584,7 +581,7 @@ bool handle_channel_announcement(
u8 *tag = tal_arr(tmpctx, u8, 0);
towire_short_channel_id(&tag, &short_channel_id);
queue_broadcast(rstate->broadcasts, WIRE_CHANNEL_ANNOUNCEMENT,
tag, serialized, true);
tag, serialized);
tal_free(tmpctx);
return local;
@ -680,7 +677,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
queue_broadcast(rstate->broadcasts,
WIRE_CHANNEL_UPDATE,
tag,
serialized, false);
serialized);
tal_free(c->channel_update);
c->channel_update = tal_steal(c, serialized);
@ -786,8 +783,7 @@ void handle_node_announcement(
queue_broadcast(rstate->broadcasts,
WIRE_NODE_ANNOUNCEMENT,
tag,
serialized,
false);
serialized);
tal_free(node->node_announcement);
node->node_announcement = tal_steal(node, serialized);
tal_free(tmpctx);

View File

@ -67,8 +67,7 @@ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED,
bool replace_inplace UNNEEDED)
const u8 *payload UNNEEDED)
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
/* Generated stub for towire_pubkey */
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)

View File

@ -38,8 +38,7 @@ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED,
bool replace_inplace UNNEEDED)
const u8 *payload UNNEEDED)
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
/* Generated stub for towire_pubkey */
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)

View File

@ -31,8 +31,7 @@ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED,
bool replace_inplace UNNEEDED)
const u8 *payload UNNEEDED)
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
/* Generated stub for towire_pubkey */
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)