| 3082 | } |
| 3083 | |
| 3084 | void wallet_channel_close(struct wallet *w, |
| 3085 | const struct channel *chan) |
| 3086 | { |
| 3087 | /* We keep the entry in the channel_configs table, since that might |
| 3088 | * help us debug some issues, and it is rather limited in size. We |
| 3089 | * also keep shachains: it's limited and we can use it for sending |
| 3090 | * reestablish messages with enough information for nodes with lost |
| 3091 | * dbs to recover. */ |
| 3092 | struct db_stmt *stmt; |
| 3093 | u64 new_move_id; |
| 3094 | u64 htlcs; |
| 3095 | |
| 3096 | /* The channel_htlcs table is quite large, and deleting it can take a |
| 3097 | * while. So we do that on next restart by calling |
| 3098 | * wallet_delete_old_htlcs. But update delete count in case anyone |
| 3099 | * is watching. */ |
| 3100 | stmt = db_prepare_v2(w->db, SQL("SELECT COUNT(*) FROM channel_htlcs " |
| 3101 | "WHERE channel_id=?")); |
| 3102 | db_bind_u64(stmt, chan->dbid); |
| 3103 | db_query_prepared(stmt); |
| 3104 | db_step(stmt); |
| 3105 | |
| 3106 | htlcs = db_col_u64(stmt, "COUNT(*)"); |
| 3107 | if (htlcs != 0) |
| 3108 | htlcs_index_deleted(w->ld, chan, htlcs); |
| 3109 | tal_free(stmt); |
| 3110 | |
| 3111 | /* Delete entries from `htlc_sigs` */ |
| 3112 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM htlc_sigs " |
| 3113 | "WHERE channelid=?")); |
| 3114 | db_bind_u64(stmt, chan->dbid); |
| 3115 | db_exec_prepared_v2(take(stmt)); |
| 3116 | |
| 3117 | /* Delete entries from `htlc_sigs` */ |
| 3118 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM channeltxs " |
| 3119 | "WHERE channel_id=?")); |
| 3120 | db_bind_u64(stmt, chan->dbid); |
| 3121 | db_exec_prepared_v2(take(stmt)); |
| 3122 | |
| 3123 | /* Delete any entries from 'inflights' */ |
| 3124 | stmt = db_prepare_v2(w->db, |
| 3125 | SQL("DELETE FROM channel_funding_inflights " |
| 3126 | " WHERE channel_id=?")); |
| 3127 | db_bind_u64(stmt, chan->dbid); |
| 3128 | db_exec_prepared_v2(take(stmt)); |
| 3129 | |
| 3130 | /* Delete transaction annotations */ |
| 3131 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM transaction_annotations " |
| 3132 | "WHERE channel=?")); |
| 3133 | db_bind_u64(stmt, chan->dbid); |
| 3134 | db_exec_prepared_v2(take(stmt)); |
| 3135 | |
| 3136 | /* Delete feerates */ |
| 3137 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_feerates " |
| 3138 | "WHERE channel_id=?")); |
| 3139 | db_bind_u64(stmt, chan->dbid); |
| 3140 | db_exec_prepared_v2(take(stmt)); |
| 3141 |
no test coverage detected