Browse Source

lightningd/chaintopology: use plugin for tip polling

travis-debug
darosior 5 years ago
committed by Rusty Russell
parent
commit
ca7c1f8bc8
  1. 25
      lightningd/chaintopology.c

25
lightningd/chaintopology.c

@ -742,15 +742,22 @@ static void remove_tip(struct chain_topology *topo)
tal_free(b);
}
static void have_new_block(struct bitcoind *bitcoind UNUSED,
static void get_new_block(struct bitcoind *bitcoind,
struct bitcoin_blkid *blkid,
struct bitcoin_block *blk,
struct chain_topology *topo)
{
if (!blkid && !blk) {
/* No such block, we're done. */
updates_complete(topo);
return;
}
assert(blkid && blk);
/* Annotate all transactions with the chainparams */
for (size_t i = 0; i < tal_count(blk->tx); i++)
blk->tx[i]->chainparams = chainparams;
/* Unexpected predecessor? Free predecessor, refetch it. */
if (!bitcoin_blkid_eq(&topo->tip->blkid, &blk->hdr.prev_hash))
remove_tip(topo);
@ -761,21 +768,9 @@ static void have_new_block(struct bitcoind *bitcoind UNUSED,
try_extend_tip(topo);
}
static void get_new_block(struct bitcoind *bitcoind,
const struct bitcoin_blkid *blkid,
struct chain_topology *topo)
{
if (!blkid) {
/* No such block, we're done. */
updates_complete(topo);
return;
}
bitcoind_getrawblock(bitcoind, blkid, have_new_block, topo);
}
static void try_extend_tip(struct chain_topology *topo)
{
bitcoind_getblockhash(topo->bitcoind, topo->tip->height + 1,
bitcoind_getrawblockbyheight(topo->bitcoind, topo->tip->height + 1,
get_new_block, topo);
}

Loading…
Cancel
Save