mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 07:34:21 +01:00
gossip: Cache txout query failures
If we asked `bitcoind` for a txout and it failed we were not storing that information anywhere, meaning that when we see the channel announcement the next time we'd be reaching out to `lightningd` and `bitcoind` again, just to see it fail again. This adds an in-memory cache for these failures so we can just ignore these the next time around. Fixes #2503 Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
6765423393
commit
f3c234529e
@@ -94,6 +94,7 @@ struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
rstate->local_channel_announced = false;
|
||||
list_head_init(&rstate->pending_cannouncement);
|
||||
uintmap_init(&rstate->chanmap);
|
||||
uintmap_init(&rstate->txout_failures);
|
||||
|
||||
rstate->pending_node_map = tal(ctx, struct pending_node_map);
|
||||
pending_node_map_init(rstate->pending_node_map);
|
||||
@@ -845,6 +846,18 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
|
||||
goto malformed;
|
||||
}
|
||||
|
||||
/* If a prior txout lookup failed there is little point it trying
|
||||
* again. Just drop the announcement and walk away whistling. Any non-0
|
||||
* result means this failed before. */
|
||||
if (uintmap_get(&rstate->txout_failures, pending->short_channel_id.u64)) {
|
||||
SUPERVERBOSE(
|
||||
"Ignoring channel_announcement of %s due to a prior txout "
|
||||
"query failure. The channel was likely closed on-chain.",
|
||||
type_to_string(tmpctx, struct short_channel_id,
|
||||
&pending->short_channel_id));
|
||||
goto ignored;
|
||||
}
|
||||
|
||||
/* Check if we know the channel already (no matter in what
|
||||
* state, we stop here if yes). */
|
||||
chan = get_channel(rstate, &pending->short_channel_id);
|
||||
@@ -993,6 +1006,7 @@ void handle_pending_cannouncement(struct routing_state *rstate,
|
||||
type_to_string(pending, struct short_channel_id,
|
||||
scid));
|
||||
tal_free(pending);
|
||||
uintmap_add(&rstate->txout_failures, scid->u64, true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1215,6 +1229,12 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If we dropped the matching announcement for this channel due to the
|
||||
* txout query failing, don't report failure, it's just too noisy on
|
||||
* mainnet */
|
||||
if (uintmap_get(&rstate->txout_failures, short_channel_id.u64))
|
||||
return NULL;
|
||||
|
||||
chan = get_channel(rstate, &short_channel_id);
|
||||
|
||||
/* Optimization: only check for pending if not public */
|
||||
|
||||
@@ -190,6 +190,10 @@ struct routing_state {
|
||||
|
||||
/* Has one of our own channels been announced? */
|
||||
bool local_channel_announced;
|
||||
|
||||
/* Cache for txout queries that failed. Allows us to skip failed
|
||||
* checks if we get another announcement for the same scid. */
|
||||
UINTMAP(bool) txout_failures;
|
||||
};
|
||||
|
||||
static inline struct chan *
|
||||
|
||||
Reference in New Issue
Block a user