gossip: Use the utxoset to shortcircuit the txout lookup

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-03-05 23:16:24 +01:00 committed by Rusty Russell
parent 387ba76920
commit cb4ba9bf4f

View file

@ -81,6 +81,7 @@ static void got_txout(struct bitcoind *bitcoind,
static void get_txout(struct subd *gossip, const u8 *msg) static void get_txout(struct subd *gossip, const u8 *msg)
{ {
struct short_channel_id *scid = tal(gossip, struct short_channel_id); struct short_channel_id *scid = tal(gossip, struct short_channel_id);
struct outpoint *op;
if (!fromwire_gossip_get_txout(msg, scid)) if (!fromwire_gossip_get_txout(msg, scid))
fatal("Gossip gave bad GOSSIP_GET_TXOUT message %s", fatal("Gossip gave bad GOSSIP_GET_TXOUT message %s",
@ -88,11 +89,19 @@ static void get_txout(struct subd *gossip, const u8 *msg)
/* FIXME: Block less than 6 deep? */ /* FIXME: Block less than 6 deep? */
bitcoind_getoutput(gossip->ld->topology->bitcoind, op = wallet_outpoint_for_scid(gossip->ld->wallet, scid, scid);
short_channel_id_blocknum(scid),
short_channel_id_txnum(scid), if (op) {
short_channel_id_outnum(scid), subd_send_msg(gossip, towire_gossip_get_txout_reply(
got_txout, scid); scid, scid, op->scriptpubkey));
tal_free(scid);
} else {
bitcoind_getoutput(gossip->ld->topology->bitcoind,
short_channel_id_blocknum(scid),
short_channel_id_txnum(scid),
short_channel_id_outnum(scid),
got_txout, scid);
}
} }
static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)