Browse Source

gossip: Don't ask bitcoind for outpoints we should know

Compares the `blocknum` in the `short_channel_id` with the range of blocks we
store in the database and abort if we should have known about it. Avoids
bombarding `bitcoind` with requests for channels that have already been spent or
were invalid in the first place.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
6298ce3b03
  1. 14
      lightningd/gossip_control.c

14
lightningd/gossip_control.c

@ -89,12 +89,15 @@ static void get_txout(struct subd *gossip, const u8 *msg)
{
struct short_channel_id *scid = tal(gossip, struct short_channel_id);
struct outpoint *op;
u32 blockheight;
struct chain_topology *topo = gossip->ld->topology;
if (!fromwire_gossip_get_txout(msg, scid))
fatal("Gossip gave bad GOSSIP_GET_TXOUT message %s",
tal_hex(msg, msg));
/* FIXME: Block less than 6 deep? */
blockheight = short_channel_id_blocknum(scid);
op = wallet_outpoint_for_scid(gossip->ld->wallet, scid, scid);
@ -103,8 +106,17 @@ static void get_txout(struct subd *gossip, const u8 *msg)
towire_gossip_get_txout_reply(
scid, scid, op->satoshis, op->scriptpubkey));
tal_free(scid);
} else if (blockheight >= topo->min_blockheight &&
blockheight <= topo->max_blockheight) {
/* We should have known about this outpoint since it is included
* in the range in the DB. The fact that we don't means that
* this is either a spent outpoint or an invalid one. Return a
* failure. */
subd_send_msg(gossip, take(towire_gossip_get_txout_reply(
NULL, scid, 0, NULL)));
tal_free(scid);
} else {
bitcoind_getoutput(gossip->ld->topology->bitcoind,
bitcoind_getoutput(topo->bitcoind,
short_channel_id_blocknum(scid),
short_channel_id_txnum(scid),
short_channel_id_outnum(scid),

Loading…
Cancel
Save