Browse Source

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>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
9ab28d1659
  1. 2
      lightningd/chaintopology.c
  2. 2
      wallet/wallet.c

2
lightningd/chaintopology.c

@ -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,

2
wallet/wallet.c

@ -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);
}

Loading…
Cancel
Save