diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 3907680f8..1fff03724 100644 --- a/lightningd/chaintopology.c +++ b/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);