wallet: Forget channels that are irrevocably settled on-chain

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-01-23 14:48:09 +01:00 committed by Rusty Russell
parent f03dbde354
commit 9588c961bb
3 changed files with 14 additions and 1 deletions

View File

@ -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");

View File

@ -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)
{

View File

@ -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
*/