Browse Source

chaintopology: fix 100 block subtraction.

We do a complicated dance because we don't know the current block
height before setting up the topology.

If we're starting at a particular block, we want to go back 100 blocks
before that to cover any reorgs.

If we're not (fresh startup), we still want to go back 100 blocks
because we don't bother handling a reorg which removes all the blocks
we know.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
bdd11e07fe
  1. 22
      lightningd/chaintopology.c

22
lightningd/chaintopology.c

@ -470,17 +470,18 @@ static void get_init_block(struct bitcoind *bitcoind,
static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
struct chain_topology *topo)
{
/* FIXME: Because we don't handle our root disappearing, we go
* 100 blocks back */
if (blockcount < 100)
blockcount = 0;
else
blockcount -= 100;
/* This happens if first_blocknum is UINTMAX-1 */
/* This can happen if bitcoind still syncing, or first_blocknum is MAX */
if (blockcount < topo->first_blocknum)
topo->first_blocknum = blockcount;
/* For fork protection (esp. because we don't handle our own first
* block getting reorged out), we always go 100 blocks further back
* than we need. */
if (topo->first_blocknum < 100)
topo->first_blocknum = 0;
else
topo->first_blocknum -= 100;
/* Get up to speed with topology. */
bitcoind_getblockhash(bitcoind, topo->first_blocknum,
get_init_block, topo);
@ -719,9 +720,8 @@ void setup_topology(struct chain_topology *topo,
memset(&topo->feerate, 0, sizeof(topo->feerate));
topo->timers = timers;
topo->poll_time = poll_time;
/* Start one before the block we are interested in (as we won't
* get notifications on txs in that block). */
topo->first_blocknum = first_blocknum - 1;
topo->first_blocknum = first_blocknum;
/* Make sure bitcoind is started, and ready */
wait_for_bitcoind(topo->bitcoind);

Loading…
Cancel
Save