mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
wallet: delete peers with no channels.
ON DELETE CASCADE goes the other way: we should clean up peers with no channels from db. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
38a313af0d
commit
81ca1db347
@@ -181,7 +181,7 @@ static void free_peer(struct peer *peer, const char *why)
|
|||||||
command_fail(peer->opening_cmd, "%s", why);
|
command_fail(peer->opening_cmd, "%s", why);
|
||||||
peer->opening_cmd = NULL;
|
peer->opening_cmd = NULL;
|
||||||
}
|
}
|
||||||
wallet_channel_delete(peer->ld->wallet, peer->channel->id);
|
wallet_channel_delete(peer->ld->wallet, peer->channel->id, peer->dbid);
|
||||||
tal_free(peer);
|
tal_free(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -866,12 +866,22 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan)
|
|||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_channel_delete(struct wallet *w, u64 wallet_id)
|
void wallet_channel_delete(struct wallet *w, u64 wallet_id, u64 peer_dbid)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
stmt = db_prepare(w->db, "DELETE FROM channels WHERE id=?");
|
/* FIXME: The line to clean up if we're last channel for peer would
|
||||||
|
* be better as a trigger. */
|
||||||
|
stmt = db_prepare(w->db,
|
||||||
|
"DELETE FROM channels WHERE id=?");
|
||||||
sqlite3_bind_int64(stmt, 1, wallet_id);
|
sqlite3_bind_int64(stmt, 1, wallet_id);
|
||||||
db_exec_prepared(w->db, stmt);
|
db_exec_prepared(w->db, stmt);
|
||||||
|
|
||||||
|
stmt = db_prepare(w->db,
|
||||||
|
"DELETE FROM peers WHERE id = ? AND NOT EXISTS"
|
||||||
|
" (SELECT 1 FROM channels WHERE peer_id = ?)");
|
||||||
|
sqlite3_bind_int64(stmt, 1, peer_dbid);
|
||||||
|
sqlite3_bind_int64(stmt, 2, peer_dbid);
|
||||||
|
db_exec_prepared(w->db, stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
|
int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
|
||||||
|
|||||||
@@ -225,8 +225,10 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wallet_channel_delete -- After resolving a channel, forget about it
|
* wallet_channel_delete -- After resolving a channel, forget about it
|
||||||
|
*
|
||||||
|
* Deletes peer too if no more channels.
|
||||||
*/
|
*/
|
||||||
void wallet_channel_delete(struct wallet *w, u64 wallet_id);
|
void wallet_channel_delete(struct wallet *w, u64 wallet_id, u64 peer_dbid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wallet_channel_config_save -- Upsert a channel_config into the database
|
* wallet_channel_config_save -- Upsert a channel_config into the database
|
||||||
|
|||||||
Reference in New Issue
Block a user