Skip to content

Commit e878b50

Browse files
committed
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 <[email protected]>
1 parent 0f2832e commit e878b50

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lightningd/gossip_control.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ static void gossipd_new_blockheight_reply(struct subd *gossipd,
222222

223223
/* Now, finally update getinfo's blockheight */
224224
gossipd->ld->gossip_blockheight = ptr2int(blockheight);
225+
226+
/* And use that to trim old entries in the UTXO set */
227+
wallet_utxoset_prune(gossipd->ld->wallet,
228+
gossipd->ld->gossip_blockheight);
225229
}
226230

227231
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)

wallet/wallet.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,7 +4198,7 @@ bool wallet_sanity_check(struct wallet *w)
41984198
/**
41994199
* wallet_utxoset_prune -- Remove spent UTXO entries that are old
42004200
*/
4201-
static void wallet_utxoset_prune(struct wallet *w, const u32 blockheight)
4201+
void wallet_utxoset_prune(struct wallet *w, u32 blockheight)
42024202
{
42034203
struct db_stmt *stmt;
42044204

@@ -4236,9 +4236,6 @@ void wallet_block_add(struct wallet *w, struct block *b)
42364236
db_bind_null(stmt);
42374237
}
42384238
db_exec_prepared_v2(take(stmt));
4239-
4240-
/* Now cleanup UTXOs that we don't care about anymore */
4241-
wallet_utxoset_prune(w, b->height);
42424239
}
42434240

42444241
void wallet_block_remove(struct wallet *w, struct block *b)

wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,9 @@ void wallet_utxoset_add(struct wallet *w,
11351135
const struct short_channel_id *
11361136
wallet_utxoset_get_spent(const tal_t *ctx, struct wallet *w, u32 blockheight);
11371137

1138+
/* Prune all UTXO entries spent (far) below this block height */
1139+
void wallet_utxoset_prune(struct wallet *w, u32 blockheight);
1140+
11381141
/**
11391142
* Retrieve all UTXO entries that were created at a given blockheight.
11401143
*/

0 commit comments

Comments
 (0)