@@ -2814,12 +2814,8 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
28142814void wallet_channel_close (struct wallet * w ,
28152815 const struct channel * chan )
28162816{
2817- /* We keep a couple of dependent tables around as well, such as the
2818- * channel_configs table, since that might help us debug some issues,
2819- * and it is rather limited in size. Tables that can grow quite
2820- * considerably and that are of limited use after channel closure will
2821- * be pruned as well. */
2822-
2817+ /* We keep the entry in the channel_configs table, since that might
2818+ * help us debug some issues, and it is rather limited in size. */
28232819 struct db_stmt * stmt ;
28242820
28252821 /* Delete entries from `channel_htlcs` */
@@ -2861,6 +2857,24 @@ void wallet_channel_close(struct wallet *w,
28612857 db_bind_u64 (stmt , chan -> dbid );
28622858 db_exec_prepared_v2 (take (stmt ));
28632859
2860+ /* Delete transaction annotations */
2861+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM transaction_annotations "
2862+ "WHERE channel=?" ));
2863+ db_bind_u64 (stmt , chan -> dbid );
2864+ db_exec_prepared_v2 (take (stmt ));
2865+
2866+ /* Delete feerates */
2867+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM channel_feerates "
2868+ "WHERE channel_id=?" ));
2869+ db_bind_u64 (stmt , chan -> dbid );
2870+ db_exec_prepared_v2 (take (stmt ));
2871+
2872+ /* Delete anchor information */
2873+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM local_anchors "
2874+ "WHERE channel_id=?" ));
2875+ db_bind_u64 (stmt , chan -> dbid );
2876+ db_exec_prepared_v2 (take (stmt ));
2877+
28642878 /* Set the channel to closed */
28652879 stmt = db_prepare_v2 (w -> db , SQL ("UPDATE channels "
28662880 "SET state=? "
@@ -2870,6 +2884,32 @@ void wallet_channel_close(struct wallet *w,
28702884 db_exec_prepared_v2 (take (stmt ));
28712885}
28722886
2887+ /* Completely unused channels get wiped entirely (we've already closed it above) */
2888+ void wallet_channel_delete (struct wallet * w , const struct channel * channel )
2889+ {
2890+ struct db_stmt * stmt ;
2891+
2892+ /* Delete channel configuration for both sides */
2893+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM channel_configs"
2894+ " WHERE id=? OR id=?" ));
2895+ db_bind_u64 (stmt , channel -> channel_info .their_config .id );
2896+ db_bind_u64 (stmt , channel -> our_config .id );
2897+ db_exec_prepared_v2 (stmt );
2898+
2899+ assert (db_count_changes (stmt ) == 2 );
2900+ tal_free (stmt );
2901+
2902+ stmt = db_prepare_v2 (w -> db , SQL ("DELETE FROM channels"
2903+ " WHERE state = ?"
2904+ " AND id=?" ));
2905+ db_bind_u64 (stmt , channel_state_in_db (CLOSED ));
2906+ db_bind_u64 (stmt , channel -> dbid );
2907+ db_exec_prepared_v2 (stmt );
2908+
2909+ assert (db_count_changes (stmt ) == 1 );
2910+ tal_free (stmt );
2911+ }
2912+
28732913void wallet_channel_inflight_cleanup_incomplete (struct wallet * w , u64 wallet_id )
28742914{
28752915 struct db_stmt * stmt ;
0 commit comments