@@ -2812,12 +2812,8 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
28122812
28132813void wallet_channel_close (struct wallet * w , u64 wallet_id )
28142814{
2815- /* We keep a couple of dependent tables around as well, such as the
2816- * channel_configs table, since that might help us debug some issues,
2817- * and it is rather limited in size. Tables that can grow quite
2818- * considerably and that are of limited use after channel closure will
2819- * be pruned as well. */
2820-
2815+ /* We keep the entry in the channel_configs table, since that might
2816+ * help us debug some issues, and it is rather limited in size. */
28212817 struct db_stmt * stmt ;
28222818
28232819 /* Delete entries from `channel_htlcs` */
@@ -2855,6 +2851,24 @@ void wallet_channel_close(struct wallet *w, u64 wallet_id)
28552851 db_bind_u64 (stmt , wallet_id );
28562852 db_exec_prepared_v2 (take (stmt ));
28572853
2854+ /* Delete transaction annotations */
2855+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM transaction_annotations "
2856+ "WHERE channel=?" ));
2857+ db_bind_u64 (stmt , wallet_id );
2858+ db_exec_prepared_v2 (take (stmt ));
2859+
2860+ /* Delete feerates */
2861+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM channel_feerates "
2862+ "WHERE channel_id=?" ));
2863+ db_bind_u64 (stmt , wallet_id );
2864+ db_exec_prepared_v2 (take (stmt ));
2865+
2866+ /* Delete anchor information */
2867+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM local_anchors "
2868+ "WHERE channel_id=?" ));
2869+ db_bind_u64 (stmt , wallet_id );
2870+ db_exec_prepared_v2 (take (stmt ));
2871+
28582872 /* Set the channel to closed */
28592873 stmt = db_prepare_v2 (w -> db , SQL ("UPDATE channels "
28602874 "SET state=? "
@@ -2864,6 +2878,32 @@ void wallet_channel_close(struct wallet *w, u64 wallet_id)
28642878 db_exec_prepared_v2 (take (stmt ));
28652879}
28662880
2881+ /* Completely unused channels get wiped entirely (we've already closed it above) */
2882+ void wallet_channel_delete (struct wallet * w , const struct channel * channel )
2883+ {
2884+ struct db_stmt * stmt ;
2885+
2886+ /* Delete channel configuration for both sides */
2887+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM channel_configs"
2888+ " WHERE id=? OR id=?" ));
2889+ db_bind_u64 (stmt , channel -> channel_info .their_config .id );
2890+ db_bind_u64 (stmt , channel -> our_config .id );
2891+ db_exec_prepared_v2 (stmt );
2892+
2893+ assert (db_count_changes (stmt ) == 2 );
2894+ tal_free (stmt );
2895+
2896+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM channels"
2897+ " WHERE state = ?"
2898+ " AND id=?" ));
2899+ db_bind_u64 (stmt , channel_state_in_db (CLOSED ));
2900+ db_bind_u64 (stmt , channel -> dbid );
2901+ db_exec_prepared_v2 (stmt );
2902+
2903+ assert (db_count_changes (stmt ) == 1 );
2904+ tal_free (stmt );
2905+ }
2906+
28672907void wallet_channel_inflight_cleanup_incomplete (struct wallet * w , u64 wallet_id )
28682908{
28692909 struct db_stmt * stmt ;
0 commit comments