15
15
#define SQLITE_MAX_UINT 0x7FFFFFFFFFFFFFFF
16
16
#define DIRECTION_INCOMING 0
17
17
#define DIRECTION_OUTGOING 1
18
+ /* How many blocks must a UTXO entry be buried under to be considered old enough
19
+ * to prune? */
20
+ #define UTXO_PRUNE_DEPTH 144
18
21
19
22
static void outpointfilters_init (struct wallet * w )
20
23
{
@@ -1762,6 +1765,17 @@ bool wallet_network_check(struct wallet *w,
1762
1765
return true;
1763
1766
}
1764
1767
1768
+ /**
1769
+ * wallet_utxoset_prune -- Remove spent UTXO entries that are old
1770
+ */
1771
+ static void wallet_utxoset_prune (struct wallet * w , const u32 blockheight )
1772
+ {
1773
+ sqlite3_stmt * stmt ;
1774
+ stmt = db_prepare (w -> db , "DELETE FROM utxoset WHERE spendheight < ?" );
1775
+ sqlite3_bind_int (stmt , 1 , blockheight - UTXO_PRUNE_DEPTH );
1776
+ db_exec_prepared (w -> db , stmt );
1777
+ }
1778
+
1765
1779
void wallet_block_add (struct wallet * w , struct block * b )
1766
1780
{
1767
1781
sqlite3_stmt * stmt = db_prepare (w -> db ,
@@ -1776,6 +1790,9 @@ void wallet_block_add(struct wallet *w, struct block *b)
1776
1790
sqlite3_bind_null (stmt , 3 );
1777
1791
}
1778
1792
db_exec_prepared (w -> db , stmt );
1793
+
1794
+ /* Now cleanup UTXOs that we don't care about anymore */
1795
+ wallet_utxoset_prune (w , b -> height );
1779
1796
}
1780
1797
1781
1798
void wallet_block_remove (struct wallet * w , struct block * b )
0 commit comments