wallet: only delete peer from db if it's unused.
This relaxes the assertion that it won't be used, and renames the function to be clear. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
98d425f1f4
commit
09011177a8
|
@ -130,7 +130,7 @@ static void delete_peer(struct peer *peer)
|
|||
/* If it only ever existed because of uncommitted channel, it won't
|
||||
* be in the database */
|
||||
if (peer->dbid != 0)
|
||||
wallet_peer_delete(peer->ld->wallet, peer->dbid);
|
||||
wallet_delete_peer_if_unused(peer->ld->wallet, peer->dbid);
|
||||
tal_free(peer);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ void maybe_delete_peer(struct peer *peer)
|
|||
if (peer->uncommitted_channel) {
|
||||
/* This isn't sufficient to keep it in db! */
|
||||
if (peer->dbid != 0) {
|
||||
wallet_peer_delete(peer->ld->wallet, peer->dbid);
|
||||
wallet_delete_peer_if_unused(peer->ld->wallet, peer->dbid);
|
||||
peer_dbid_map_del(peer->ld->peers_by_dbid, peer);
|
||||
peer->dbid = 0;
|
||||
}
|
||||
|
|
|
@ -821,6 +821,9 @@ void wallet_channeltxs_add(struct wallet *w UNNEEDED, struct channel *chan UNNEE
|
|||
const int type UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
|
||||
const u32 input_num UNNEEDED, const u32 blockheight UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_channeltxs_add called!\n"); abort(); }
|
||||
/* Generated stub for wallet_delete_peer_if_unused */
|
||||
void wallet_delete_peer_if_unused(struct wallet *w UNNEEDED, u64 peer_dbid UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_delete_peer_if_unused called!\n"); abort(); }
|
||||
/* Generated stub for wallet_htlcs_load_in_for_channel */
|
||||
bool wallet_htlcs_load_in_for_channel(struct wallet *wallet UNNEEDED,
|
||||
struct channel *chan UNNEEDED,
|
||||
|
@ -916,9 +919,6 @@ char *wallet_offer_find(const tal_t *ctx UNNEEDED,
|
|||
enum offer_status *status)
|
||||
|
||||
{ fprintf(stderr, "wallet_offer_find called!\n"); abort(); }
|
||||
/* Generated stub for wallet_peer_delete */
|
||||
void wallet_peer_delete(struct wallet *w UNNEEDED, u64 peer_dbid UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_peer_delete called!\n"); abort(); }
|
||||
/* Generated stub for wallet_state_change_get */
|
||||
struct state_change_entry *wallet_state_change_get(struct wallet *w UNNEEDED,
|
||||
const tal_t *ctx UNNEEDED,
|
||||
|
|
|
@ -2292,7 +2292,7 @@ void wallet_channel_close(struct wallet *w, u64 wallet_id)
|
|||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
void wallet_peer_delete(struct wallet *w, u64 peer_dbid)
|
||||
void wallet_delete_peer_if_unused(struct wallet *w, u64 peer_dbid)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
|
||||
|
@ -2301,8 +2301,11 @@ void wallet_peer_delete(struct wallet *w, u64 peer_dbid)
|
|||
db_bind_u64(stmt, 0, peer_dbid);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (db_step(stmt))
|
||||
fatal("We have channels using peer %"PRIu64, peer_dbid);
|
||||
if (db_step(stmt)) {
|
||||
db_col_ignore(stmt, "*");
|
||||
tal_free(stmt);
|
||||
return;
|
||||
}
|
||||
tal_free(stmt);
|
||||
|
||||
stmt = db_prepare_v2(w->db, SQL("DELETE FROM peers WHERE id=?"));
|
||||
|
|
|
@ -630,9 +630,9 @@ struct state_change_entry *wallet_state_change_get(struct wallet *w,
|
|||
u64 channel_id);
|
||||
|
||||
/**
|
||||
* wallet_peer_delete -- After no more channels in peer, forget about it
|
||||
* wallet_delete_peer_if_unused -- After no more channels in peer, forget about it
|
||||
*/
|
||||
void wallet_peer_delete(struct wallet *w, u64 peer_dbid);
|
||||
void wallet_delete_peer_if_unused(struct wallet *w, u64 peer_dbid);
|
||||
|
||||
/**
|
||||
* wallet_init_channels -- Loads active channels into peers
|
||||
|
|
Loading…
Reference in New Issue