mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
gossipd: handle channel_update while we're still checking channel_announce.
We only need to keep one. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
db30411ba5
commit
96ed75d8b2
1 changed files with 35 additions and 3 deletions
|
@ -41,6 +41,9 @@ struct pending_cannouncement {
|
||||||
|
|
||||||
/* The raw bits */
|
/* The raw bits */
|
||||||
const u8 *announce;
|
const u8 *announce;
|
||||||
|
|
||||||
|
/* A deferred update, if we received one while waiting for this */
|
||||||
|
const u8 *update;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct node_map *empty_node_map(const tal_t *ctx)
|
static struct node_map *empty_node_map(const tal_t *ctx)
|
||||||
|
@ -526,6 +529,7 @@ const struct short_channel_id *handle_channel_announcement(
|
||||||
secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2;
|
secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2;
|
||||||
|
|
||||||
pending = tal(rstate, struct pending_cannouncement);
|
pending = tal(rstate, struct pending_cannouncement);
|
||||||
|
pending->update = NULL;
|
||||||
pending->announce = tal_dup_arr(pending, u8,
|
pending->announce = tal_dup_arr(pending, u8,
|
||||||
announce, tal_len(announce), 0);
|
announce, tal_len(announce), 0);
|
||||||
|
|
||||||
|
@ -581,6 +585,7 @@ const struct short_channel_id *handle_channel_announcement(
|
||||||
status_trace("Received channel_announcement for channel %s", tag);
|
status_trace("Received channel_announcement for channel %s", tag);
|
||||||
tal_free(tag);
|
tal_free(tag);
|
||||||
|
|
||||||
|
/* FIXME: Handle duplicates as per BOLT #7 */
|
||||||
list_add_tail(&rstate->pending_cannouncement, &pending->list);
|
list_add_tail(&rstate->pending_cannouncement, &pending->list);
|
||||||
return &pending->short_channel_id;
|
return &pending->short_channel_id;
|
||||||
}
|
}
|
||||||
|
@ -670,10 +675,31 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
|
||||||
local = pubkey_eq(&pending->node_id_1, &rstate->local_id) ||
|
local = pubkey_eq(&pending->node_id_1, &rstate->local_id) ||
|
||||||
pubkey_eq(&pending->node_id_2, &rstate->local_id);
|
pubkey_eq(&pending->node_id_2, &rstate->local_id);
|
||||||
|
|
||||||
|
/* Did we have an update waiting? If so, apply now. */
|
||||||
|
if (pending->update)
|
||||||
|
handle_channel_update(rstate, pending->update);
|
||||||
|
|
||||||
tal_free(pending);
|
tal_free(pending);
|
||||||
return local && forward;
|
return local && forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return true if this is an update to a pending announcement (and queue it) */
|
||||||
|
static bool update_to_pending(struct routing_state *rstate,
|
||||||
|
const struct short_channel_id *scid,
|
||||||
|
const u8 *update)
|
||||||
|
{
|
||||||
|
struct pending_cannouncement *pending;
|
||||||
|
|
||||||
|
pending = find_pending_cannouncement(rstate, scid);
|
||||||
|
if (!pending)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* FIXME: should compare timestamps! */
|
||||||
|
tal_free(pending->update);
|
||||||
|
pending->update = tal_dup_arr(pending, u8, update, tal_len(update), 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void handle_channel_update(struct routing_state *rstate, const u8 *update)
|
void handle_channel_update(struct routing_state *rstate, const u8 *update)
|
||||||
{
|
{
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
|
@ -721,9 +747,15 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
|
||||||
c = get_connection_by_scid(rstate, &short_channel_id, flags & 0x1);
|
c = get_connection_by_scid(rstate, &short_channel_id, flags & 0x1);
|
||||||
|
|
||||||
if (!c) {
|
if (!c) {
|
||||||
status_trace("Ignoring update for unknown channel %s",
|
if (update_to_pending(rstate, &short_channel_id, serialized)) {
|
||||||
type_to_string(trc, struct short_channel_id,
|
status_trace("Deferring update for pending channel %s",
|
||||||
&short_channel_id));
|
type_to_string(trc, struct short_channel_id,
|
||||||
|
&short_channel_id));
|
||||||
|
} else {
|
||||||
|
status_trace("Ignoring update for unknown channel %s",
|
||||||
|
type_to_string(trc, struct short_channel_id,
|
||||||
|
&short_channel_id));
|
||||||
|
}
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
return;
|
return;
|
||||||
} else if (c->last_timestamp >= timestamp) {
|
} else if (c->last_timestamp >= timestamp) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue