From 37373f2c166c9a07dccbd7a888a8d85f43949cf8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 16 Feb 2018 09:00:58 +1030 Subject: [PATCH] wallet: provide better comments on wallet_first_blocknum. ZmnSCPxj queried the unilateral close case, so make that clearer. Christian raise concerns about existing channels, so make it clear what we're doing there too. Signed-off-by: Rusty Russell --- wallet/wallet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wallet/wallet.c b/wallet/wallet.c index 4fa5900b7..6795ee7c1 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -677,8 +677,7 @@ static bool wallet_ever_used(struct wallet *w) if (db_get_intvar(w->db, "bip32_max_index", 0) != 0) return true; - /* Or we could have had a channel terminate unilaterally, - * providing a UTXO. */ + /* Or if they do a unilateral close, the output to us provides a UTXO. */ stmt = db_query(__func__, w->db, "SELECT COUNT(*) FROM outputs WHERE commitment_point IS NOT NULL;"); sqlite3_step(stmt); @@ -688,6 +687,13 @@ static bool wallet_ever_used(struct wallet *w) return channel_utxos; } +/* We want the earlier of either: + * 1. The first channel we're still watching (it might have closed), + * 2. The last block we scanned for UTXO (might have new incoming payments) + * + * chaintopology actually subtracts another 100 blocks to make sure we + * catch chain forks. + */ u32 wallet_first_blocknum(struct wallet *w, u32 first_possible) { int err;