mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
db, inflights: add method to remove any 'dangling' inflights
When we reconnect, if we get a note from the peer that they dont know about a pending inflight, we need to be able to clean it up so we can restart/re-negotiate a new RBF etc. This adds a cleanup method to remove any inflights for a channel without a last_tx (commitment tx)
This commit is contained in:
parent
72e2e37222
commit
95c7345515
4 changed files with 38 additions and 0 deletions
|
@ -97,6 +97,23 @@ void delete_channel(struct channel *channel STEALS)
|
|||
maybe_delete_peer(peer);
|
||||
}
|
||||
|
||||
bool maybe_cleanup_last_inflight(struct channel *channel)
|
||||
{
|
||||
struct channel_inflight *inflight;
|
||||
inflight = channel_current_inflight(channel);
|
||||
if (!inflight)
|
||||
return false;
|
||||
|
||||
if (inflight->last_tx)
|
||||
return false;
|
||||
|
||||
/* Remove from database */
|
||||
wallet_channel_inflight_cleanup_incomplete(
|
||||
channel->peer->ld->wallet, channel->dbid);
|
||||
tal_free(inflight);
|
||||
return true;
|
||||
}
|
||||
|
||||
void get_channel_basepoints(struct lightningd *ld,
|
||||
const struct node_id *peer_id,
|
||||
const u64 dbid,
|
||||
|
|
|
@ -404,6 +404,9 @@ void inflight_set_last_tx(struct channel_inflight *inflight,
|
|||
struct bitcoin_tx *last_tx STEALS,
|
||||
const struct bitcoin_signature last_sig);
|
||||
|
||||
/* If the last inflight has no commitment tx, remove it */
|
||||
bool maybe_cleanup_last_inflight(struct channel *channel);
|
||||
|
||||
/* Given a txid, find an inflight channel stub. Returns NULL if none found */
|
||||
struct channel_inflight *channel_inflight_find(struct channel *channel,
|
||||
const struct bitcoin_txid *txid);
|
||||
|
|
|
@ -2606,6 +2606,18 @@ void wallet_channel_close(struct wallet *w, u64 wallet_id)
|
|||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
void wallet_channel_inflight_cleanup_incomplete(struct wallet *w, u64 wallet_id)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
|
||||
/* Delete any incomplete entries from 'inflights' */
|
||||
stmt = db_prepare_v2(w->db,
|
||||
SQL("DELETE FROM channel_funding_inflights "
|
||||
" WHERE channel_id=? AND last_tx IS NULL"));
|
||||
db_bind_u64(stmt, wallet_id);
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
void wallet_delete_peer_if_unused(struct wallet *w, u64 peer_dbid)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
|
|
|
@ -626,6 +626,12 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight);
|
|||
void wallet_inflight_save(struct wallet *w,
|
||||
struct channel_inflight *inflight);
|
||||
|
||||
/**
|
||||
* Remove any channel inflights that are incomplete.
|
||||
*/
|
||||
void wallet_channel_inflight_cleanup_incomplete(struct wallet *w,
|
||||
u64 wallet_id);
|
||||
|
||||
/**
|
||||
* Remove all the inflights from a channel. Also cleans up
|
||||
* the channel's inflight list
|
||||
|
|
Loading…
Add table
Reference in a new issue