| 2208 | } |
| 2209 | |
| 2210 | void wallet_channel_close(struct wallet *w, u64 wallet_id) |
| 2211 | { |
| 2212 | /* We keep a couple of dependent tables around as well, such as the |
| 2213 | * channel_configs table, since that might help us debug some issues, |
| 2214 | * and it is rather limited in size. Tables that can grow quite |
| 2215 | * considerably and that are of limited use after channel closure will |
| 2216 | * be pruned as well. */ |
| 2217 | |
| 2218 | struct db_stmt *stmt; |
| 2219 | |
| 2220 | /* Delete entries from `channel_htlcs` */ |
| 2221 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM channel_htlcs " |
| 2222 | "WHERE channel_id=?")); |
| 2223 | db_bind_u64(stmt, 0, wallet_id); |
| 2224 | db_exec_prepared_v2(take(stmt)); |
| 2225 | |
| 2226 | /* Delete entries from `htlc_sigs` */ |
| 2227 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM htlc_sigs " |
| 2228 | "WHERE channelid=?")); |
| 2229 | db_bind_u64(stmt, 0, wallet_id); |
| 2230 | db_exec_prepared_v2(take(stmt)); |
| 2231 | |
| 2232 | /* Delete entries from `htlc_sigs` */ |
| 2233 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM channeltxs " |
| 2234 | "WHERE channel_id=?")); |
| 2235 | db_bind_u64(stmt, 0, wallet_id); |
| 2236 | db_exec_prepared_v2(take(stmt)); |
| 2237 | |
| 2238 | /* Delete any entries from 'inflights' */ |
| 2239 | stmt = db_prepare_v2(w->db, |
| 2240 | SQL("DELETE FROM channel_funding_inflights " |
| 2241 | " WHERE channel_id=?")); |
| 2242 | db_bind_u64(stmt, 0, wallet_id); |
| 2243 | db_exec_prepared_v2(take(stmt)); |
| 2244 | |
| 2245 | /* Delete shachains */ |
| 2246 | stmt = db_prepare_v2(w->db, SQL("DELETE FROM shachains " |
| 2247 | "WHERE id IN (" |
| 2248 | " SELECT shachain_remote_id " |
| 2249 | " FROM channels " |
| 2250 | " WHERE channels.id=?" |
| 2251 | ")")); |
| 2252 | db_bind_u64(stmt, 0, wallet_id); |
| 2253 | db_exec_prepared_v2(take(stmt)); |
| 2254 | |
| 2255 | /* Set the channel to closed and disassociate with peer */ |
| 2256 | stmt = db_prepare_v2(w->db, SQL("UPDATE channels " |
| 2257 | "SET state=?, peer_id=? " |
| 2258 | "WHERE channels.id=?")); |
| 2259 | db_bind_u64(stmt, 0, CLOSED); |
| 2260 | db_bind_null(stmt, 1); |
| 2261 | db_bind_u64(stmt, 2, wallet_id); |
| 2262 | db_exec_prepared_v2(take(stmt)); |
| 2263 | } |
| 2264 | |
| 2265 | void wallet_peer_delete(struct wallet *w, u64 peer_dbid) |
| 2266 | { |
no test coverage detected