mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
wallet: delete channels in state OPENINGD.
Both when we forget about an opening peer, and at startup. We're going to be relying on this, and the next patch, as we refactor peer/channel handling to mirror the db. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
15eaf56d79
commit
38a313af0d
@ -181,6 +181,7 @@ static void free_peer(struct peer *peer, const char *why)
|
||||
command_fail(peer->opening_cmd, "%s", why);
|
||||
peer->opening_cmd = NULL;
|
||||
}
|
||||
wallet_channel_delete(peer->ld->wallet, peer->channel->id);
|
||||
tal_free(peer);
|
||||
}
|
||||
|
||||
@ -1268,7 +1269,6 @@ static void handle_irrevocably_resolved(struct peer *peer, const u8 *msg)
|
||||
free_htlcs(peer->ld, peer);
|
||||
|
||||
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");
|
||||
@ -2968,8 +2968,6 @@ static void process_dev_forget_channel(struct bitcoind *bitcoind UNUSED,
|
||||
json_add_txid(response, "funding_txid", forget->peer->funding_txid);
|
||||
json_object_end(response);
|
||||
|
||||
if (peer_persists(forget->peer))
|
||||
wallet_channel_delete(forget->cmd->ld->wallet, forget->peer->channel->id);
|
||||
free_peer(forget->peer, "dev-forget-channel called");
|
||||
|
||||
command_success(forget->cmd, response);
|
||||
|
@ -626,9 +626,16 @@ static const char *channel_fields =
|
||||
bool wallet_channels_load_active(const tal_t *ctx, struct wallet *w, struct list_head *peers)
|
||||
{
|
||||
bool ok = true;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
/* Get rid of OPENINGD entries; they don't last across reconnects */
|
||||
stmt = db_prepare(w->db, "DELETE FROM channels WHERE state=?");
|
||||
sqlite3_bind_int64(stmt, 1, OPENINGD);
|
||||
db_exec_prepared(w->db, stmt);
|
||||
|
||||
/* Channels are active if they have reached at least the
|
||||
* opening state and they are not marked as complete */
|
||||
sqlite3_stmt *stmt = db_query(
|
||||
stmt = db_query(
|
||||
__func__, w->db, "SELECT %s FROM channels WHERE state > %d AND state != %d;",
|
||||
channel_fields, OPENINGD, CLOSINGD_COMPLETE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user