Browse Source

chaintopology: always cap max block to bitcoind's block height.

We only did this when we were first creating a wallet, or when we
asked for a relative rescan, not in the normal case!

Fixes: #1843
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
ab0fa7a1bd
  1. 16
      lightningd/chaintopology.c

16
lightningd/chaintopology.c

@ -568,22 +568,22 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
* go back to that height. This might be a new node catching up, or
* bitcoind is processing a reorg. */
if (blockcount < topo->max_blockheight) {
if (bitcoind->ld->config.rescan < 0) {
/* Absolute blockheight, but bitcoind's blockheight isn't there yet */
if (topo->max_blockheight == UINT32_MAX) {
/* Relative rescan, but we didn't know the blockheight */
/* Protect against underflow in subtraction.
* Possible in regtest mode. */
if (blockcount < 1)
if (blockcount < bitcoind->ld->config.rescan)
topo->max_blockheight = 0;
else
topo->max_blockheight = blockcount - 1;
} else if (topo->max_blockheight == UINT32_MAX) {
/* Relative rescan, but we didn't know the blockheight */
topo->max_blockheight = blockcount - bitcoind->ld->config.rescan;
} else {
/* Absolute blockheight, but bitcoind's blockheight isn't there yet */
/* Protect against underflow in subtraction.
* Possible in regtest mode. */
if (blockcount < bitcoind->ld->config.rescan)
if (blockcount < 1)
topo->max_blockheight = 0;
else
topo->max_blockheight = blockcount - bitcoind->ld->config.rescan;
topo->max_blockheight = blockcount - 1;
}
}

Loading…
Cancel
Save