From 9588c961bbe31f643c18b5cbd4e9c878d3b24f65 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 23 Jan 2018 14:48:09 +0100 Subject: [PATCH] wallet: Forget channels that are irrevocably settled on-chain Signed-off-by: Christian Decker --- lightningd/peer_control.c | 2 +- wallet/wallet.c | 8 ++++++++ wallet/wallet.h | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4bf2f4e55..f509a0ae8 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1244,8 +1244,8 @@ static void handle_irrevocably_resolved(struct peer *peer, const u8 *msg) /* FIXME: Implement check_htlcs to ensure no dangling hout->in ptrs! */ free_htlcs(peer->ld, peer); - /* FIXME: Remove peer from db. */ log_info(peer->log, "onchaind complete, forgetting peer"); + wallet_channel_delete(peer->ld->wallet, peer->channel->id); /* This will also free onchaind. */ free_peer(peer, "onchaind complete, forgetting peer"); diff --git a/wallet/wallet.c b/wallet/wallet.c index 9634dd6ec..02c0f326c 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -836,6 +836,14 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan, tal_free(tmpctx); } +void wallet_channel_delete(struct wallet *w, u64 wallet_id) +{ + sqlite3_stmt *stmt; + stmt = db_prepare(w->db, "DELETE FROM channels WHERE id=?"); + sqlite3_bind_int64(stmt, 1, wallet_id); + db_exec_prepared(w->db, stmt); +} + int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx, u64 *total_satoshi) { diff --git a/wallet/wallet.h b/wallet/wallet.h index 0f26a468c..f1794d873 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -215,6 +215,11 @@ bool wallet_shachain_load(struct wallet *wallet, u64 id, void wallet_channel_save(struct wallet *w, struct wallet_channel *chan, u32 current_block_height); +/** + * wallet_channel_delete -- After resolving a channel, forget about it + */ +void wallet_channel_delete(struct wallet *w, u64 wallet_id); + /** * wallet_channel_config_save -- Upsert a channel_config into the database */