mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
Revert "broadcast: don't reorder channel_announce when we get the real one."
This reverts commit f293ff0a6a.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
#include <ccan/mem/mem.h>
|
|
||||||
#include <gossipd/broadcast.h>
|
#include <gossipd/broadcast.h>
|
||||||
|
|
||||||
struct broadcast_state *new_broadcast_state(tal_t *ctx)
|
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;
|
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,
|
void queue_broadcast(struct broadcast_state *bstate,
|
||||||
const int type,
|
const int type,
|
||||||
const u8 *tag,
|
const u8 *tag,
|
||||||
const u8 *payload,
|
const u8 *payload)
|
||||||
bool replace_inplace)
|
|
||||||
{
|
{
|
||||||
struct queued_message *msg;
|
struct queued_message *msg;
|
||||||
u64 index;
|
u64 index;
|
||||||
|
|
||||||
/* Remove any tag&type collisions */
|
/* Remove any tag&type collisions */
|
||||||
index = find_broadcast(bstate, type, tag);
|
for (msg = uintmap_first(&bstate->broadcasts, &index);
|
||||||
if (index == 0)
|
msg;
|
||||||
replace_inplace = false;
|
msg = uintmap_after(&bstate->broadcasts, &index)) {
|
||||||
else
|
if (msg->type == type && memcmp(msg->tag, tag, tal_count(tag)) == 0) {
|
||||||
tal_free(uintmap_del(&bstate->broadcasts, index));
|
uintmap_del(&bstate->broadcasts, index);
|
||||||
|
tal_free(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Now add the message to the queue */
|
/* Now add the message to the queue */
|
||||||
msg = new_queued_message(bstate, type, tag, payload);
|
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);
|
uintmap_add(&bstate->broadcasts, bstate->next_index, msg);
|
||||||
bstate->next_index += 1;
|
bstate->next_index += 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index)
|
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index)
|
||||||
|
|||||||
@@ -29,13 +29,11 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
|||||||
/* Queue a new message to be broadcast and replace any outdated
|
/* Queue a new message to be broadcast and replace any outdated
|
||||||
* broadcast. Replacement is done by comparing the `type` and the
|
* broadcast. Replacement is done by comparing the `type` and the
|
||||||
* `tag`, if both match the old message is dropped from the queue. 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
|
* new message is added to the top of the broadcast queue. */
|
||||||
* replace_inplace is set, in which case it replaces the old (if any) */
|
|
||||||
void queue_broadcast(struct broadcast_state *bstate,
|
void queue_broadcast(struct broadcast_state *bstate,
|
||||||
const int type,
|
const int type,
|
||||||
const u8 *tag,
|
const u8 *tag,
|
||||||
const u8 *payload,
|
const u8 *payload);
|
||||||
bool replace_inplace);
|
|
||||||
|
|
||||||
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index);
|
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index);
|
||||||
|
|
||||||
|
|||||||
@@ -565,9 +565,6 @@ bool handle_channel_announcement(
|
|||||||
c1 = get_connection_by_scid(rstate, &short_channel_id, 1);
|
c1 = get_connection_by_scid(rstate, &short_channel_id, 1);
|
||||||
forward = !c0 || !c1 || !c0->channel_announcement || !c1->channel_announcement;
|
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,
|
add_channel_direction(rstate, &node_id_1, &node_id_2, &short_channel_id,
|
||||||
sigfail ? NULL : serialized);
|
sigfail ? NULL : serialized);
|
||||||
add_channel_direction(rstate, &node_id_2, &node_id_1, &short_channel_id,
|
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);
|
u8 *tag = tal_arr(tmpctx, u8, 0);
|
||||||
towire_short_channel_id(&tag, &short_channel_id);
|
towire_short_channel_id(&tag, &short_channel_id);
|
||||||
queue_broadcast(rstate->broadcasts, WIRE_CHANNEL_ANNOUNCEMENT,
|
queue_broadcast(rstate->broadcasts, WIRE_CHANNEL_ANNOUNCEMENT,
|
||||||
tag, serialized, true);
|
tag, serialized);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
return local;
|
return local;
|
||||||
@@ -680,7 +677,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
queue_broadcast(rstate->broadcasts,
|
queue_broadcast(rstate->broadcasts,
|
||||||
WIRE_CHANNEL_UPDATE,
|
WIRE_CHANNEL_UPDATE,
|
||||||
tag,
|
tag,
|
||||||
serialized, false);
|
serialized);
|
||||||
|
|
||||||
tal_free(c->channel_update);
|
tal_free(c->channel_update);
|
||||||
c->channel_update = tal_steal(c, serialized);
|
c->channel_update = tal_steal(c, serialized);
|
||||||
@@ -786,8 +783,7 @@ void handle_node_announcement(
|
|||||||
queue_broadcast(rstate->broadcasts,
|
queue_broadcast(rstate->broadcasts,
|
||||||
WIRE_NODE_ANNOUNCEMENT,
|
WIRE_NODE_ANNOUNCEMENT,
|
||||||
tag,
|
tag,
|
||||||
serialized,
|
serialized);
|
||||||
false);
|
|
||||||
tal_free(node->node_announcement);
|
tal_free(node->node_announcement);
|
||||||
node->node_announcement = tal_steal(node, serialized);
|
node->node_announcement = tal_steal(node, serialized);
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct
|
|||||||
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
|
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
|
||||||
const int type UNNEEDED,
|
const int type UNNEEDED,
|
||||||
const u8 *tag UNNEEDED,
|
const u8 *tag UNNEEDED,
|
||||||
const u8 *payload UNNEEDED,
|
const u8 *payload UNNEEDED)
|
||||||
bool replace_inplace UNNEEDED)
|
|
||||||
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
|
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
|
||||||
/* Generated stub for towire_pubkey */
|
/* Generated stub for towire_pubkey */
|
||||||
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct
|
|||||||
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
|
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
|
||||||
const int type UNNEEDED,
|
const int type UNNEEDED,
|
||||||
const u8 *tag UNNEEDED,
|
const u8 *tag UNNEEDED,
|
||||||
const u8 *payload UNNEEDED,
|
const u8 *payload UNNEEDED)
|
||||||
bool replace_inplace UNNEEDED)
|
|
||||||
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
|
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
|
||||||
/* Generated stub for towire_pubkey */
|
/* Generated stub for towire_pubkey */
|
||||||
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct
|
|||||||
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
|
void queue_broadcast(struct broadcast_state *bstate UNNEEDED,
|
||||||
const int type UNNEEDED,
|
const int type UNNEEDED,
|
||||||
const u8 *tag UNNEEDED,
|
const u8 *tag UNNEEDED,
|
||||||
const u8 *payload UNNEEDED,
|
const u8 *payload UNNEEDED)
|
||||||
bool replace_inplace UNNEEDED)
|
|
||||||
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
|
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
|
||||||
/* Generated stub for towire_pubkey */
|
/* Generated stub for towire_pubkey */
|
||||||
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
||||||
|
|||||||
Reference in New Issue
Block a user