mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
wallet: wrap missing last_processed_block handling in COMPAT_V052.
Our testing also reveals a bug: we start lightningd and shut it down before fully processing the blockchain, so we don't set last_processed_block. Fix that by setting it immediately once we have a block: worst case it goes backwards a little. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
328786ffeb
commit
9d9c1c3db6
@ -483,6 +483,10 @@ static void init_topo(struct bitcoind *bitcoind UNUSED,
|
||||
block_map_add(&topo->block_map, topo->root);
|
||||
topo->tip = topo->prev_tip = topo->root;
|
||||
|
||||
/* In case we don't get all the way to updates_complete */
|
||||
db_set_intvar(topo->bitcoind->ld->wallet->db,
|
||||
"last_processed_block", topo->tip->height);
|
||||
|
||||
io_break(topo);
|
||||
}
|
||||
|
||||
|
@ -720,6 +720,7 @@ bool wallet_channels_load_active(const tal_t *ctx, struct wallet *w)
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifdef COMPAT_V052
|
||||
/* Upgrade of db (or initial create): do we have anything to scan for? */
|
||||
static bool wallet_ever_used(struct wallet *w)
|
||||
{
|
||||
@ -740,6 +741,7 @@ static bool wallet_ever_used(struct wallet *w)
|
||||
|
||||
return channel_utxos;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* We want the earlier of either:
|
||||
* 1. The first channel we're still watching (it might have closed),
|
||||
@ -764,6 +766,8 @@ u32 wallet_first_blocknum(struct wallet *w, u32 first_possible)
|
||||
first_channel = UINT32_MAX;
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
#ifdef COMPAT_V052
|
||||
/* This field was missing in older databases. */
|
||||
first_utxo = db_get_intvar(w->db, "last_processed_block", 0);
|
||||
if (first_utxo == 0) {
|
||||
/* Don't know? New db, or upgraded. */
|
||||
@ -773,6 +777,9 @@ u32 wallet_first_blocknum(struct wallet *w, u32 first_possible)
|
||||
else
|
||||
first_utxo = UINT32_MAX;
|
||||
}
|
||||
#else
|
||||
first_utxo = db_get_intvar(w->db, "last_processed_block", UINT32_MAX);
|
||||
#endif
|
||||
|
||||
if (first_utxo < first_channel)
|
||||
return first_utxo;
|
||||
|
Loading…
Reference in New Issue
Block a user