From 73b378294393030e844c3ecf8b61907fb2f563c8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 27 Jul 2018 06:52:37 +0930 Subject: [PATCH] gossipd: send latest update in error message, even if delayed. We delay internally to reduce broadcastig route flap, but errors are a special case: we want to send the latest, otherwise we might send an old (non-disabled) update. Signed-off-by: Rusty Russell --- gossipd/gossip.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 79927fc57..b511684d4 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -162,6 +162,17 @@ struct peer { /* FIXME: Reorder */ static void peer_disable_channels(struct daemon *daemon, struct node *node); +static u8 *create_channel_update(const tal_t *ctx, + struct routing_state *rstate, + const struct chan *chan, + int direction, + bool disable, + u16 cltv_expiry_delta, + u64 htlc_minimum_msat, + u32 fee_base_msat, + u32 fee_proportional_millionths); +static struct local_update *find_local_update(struct daemon *daemon, + const struct short_channel_id *scid); static void destroy_peer(struct peer *peer) { @@ -937,6 +948,8 @@ static void handle_get_update(struct peer *peer, const u8 *msg) &scid)); update = NULL; } else { + struct local_update *l; + /* We want the update that comes from our end. */ if (pubkey_eq(&chan->nodes[0]->id, &peer->daemon->id)) update = chan->half[0].channel_update; @@ -950,8 +963,25 @@ static void handle_get_update(struct peer *peer, const u8 *msg) struct short_channel_id, &scid)); update = NULL; + goto out; } + + /* We might have a pending update which overrides: always send + * that now, since this is used to populate errors which should + * contain the latest information. */ + l = find_local_update(peer->daemon, &scid); + if (l) + update = create_channel_update(tmpctx, + rstate, + chan, l->direction, + l->disable, + l->cltv_delta, + l->htlc_minimum_msat, + l->fee_base_msat, + l->fee_proportional_millionths); } + +out: status_trace("peer %s schanid %s: %s update", type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct short_channel_id, &scid),