lightningd: only trim old UTXO entries after gossipd acks block.

If it gets really far behind, then we restart, it could miss some.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-11-13 13:24:28 +10:30
parent 20a41fd798
commit a4847b5af4
3 changed files with 8 additions and 4 deletions

View file

@ -222,6 +222,10 @@ static void gossipd_new_blockheight_reply(struct subd *gossipd,
/* Now, finally update getinfo's blockheight */
gossipd->ld->gossip_blockheight = ptr2int(blockheight);
/* And use that to trim old entries in the UTXO set */
wallet_utxoset_prune(gossipd->ld->wallet,
gossipd->ld->gossip_blockheight);
}
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)

View file

@ -4198,7 +4198,7 @@ bool wallet_sanity_check(struct wallet *w)
/**
* wallet_utxoset_prune -- Remove spent UTXO entries that are old
*/
static void wallet_utxoset_prune(struct wallet *w, const u32 blockheight)
void wallet_utxoset_prune(struct wallet *w, u32 blockheight)
{
struct db_stmt *stmt;
@ -4236,9 +4236,6 @@ void wallet_block_add(struct wallet *w, struct block *b)
db_bind_null(stmt);
}
db_exec_prepared_v2(take(stmt));
/* Now cleanup UTXOs that we don't care about anymore */
wallet_utxoset_prune(w, b->height);
}
void wallet_block_remove(struct wallet *w, struct block *b)

View file

@ -1135,6 +1135,9 @@ void wallet_utxoset_add(struct wallet *w,
const struct short_channel_id *
wallet_utxoset_get_spent(const tal_t *ctx, struct wallet *w, u32 blockheight);
/* Prune all UTXO entries spent (far) below this block height */
void wallet_utxoset_prune(struct wallet *w, u32 blockheight);
/**
* Retrieve all UTXO entries that were created at a given blockheight.
*/