topology: Two off-by-one error when catching up with the blockchain

There are two very hard problems in software engineering:

 1. Off-by-one errors

In this case we were rolling back further than needed and we were starting the
catchup one block further than expected.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-04-05 18:09:46 +02:00 committed by Rusty Russell
parent 4da3d407b4
commit 9ab28d1659
2 changed files with 2 additions and 2 deletions

View File

@ -573,7 +573,7 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
/* Rollback to the given blockheight, so we start track
* correctly again */
wallet_blocks_rollback(topo->wallet, topo->first_blocknum - 1);
wallet_blocks_rollback(topo->wallet, topo->first_blocknum);
/* Get up to speed with topology. */
bitcoind_getblockhash(bitcoind, topo->first_blocknum,

View File

@ -2027,7 +2027,7 @@ void wallet_block_remove(struct wallet *w, struct block *b)
void wallet_blocks_rollback(struct wallet *w, u32 height)
{
sqlite3_stmt *stmt = db_prepare(w->db, "DELETE FROM blocks "
"WHERE height >= ?");
"WHERE height > ?");
sqlite3_bind_int(stmt, 1, height);
db_exec_prepared(w->db, stmt);
}