Skip to content

Commit

Permalink
freeing jsonrpc in shutdown cannot trigger db write's anymore
Browse files Browse the repository at this point in the history
since PR ElementsProject#3867 utxos are unreserved by height, destroy_utxos and
related functions are not used anymore so clean them up also

TODO: Can test_stop_pending_fundchannel be removed ?
  • Loading branch information
SimonVrouwe committed Nov 3, 2021
1 parent eb8f2b6 commit 5de34e6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 41 deletions.
7 changes: 0 additions & 7 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,13 +1194,6 @@ int main(int argc, char *argv[])
/* Tell plugins we're shutting down, closes the db for write access. */
shutdown_plugins(ld);

/* Clean up the JSON-RPC. This needs to happen in a DB transaction since
* it might actually be touching the DB in some destructors, e.g.,
* unreserving UTXOs (see #1737) */
db_begin_transaction(ld->wallet->db);
tal_free(ld->jsonrpc);
db_commit_transaction(ld->wallet->db);

/* Clean our our HTLC maps, since they use malloc. */
htlc_in_map_clear(&ld->htlcs_in);
htlc_out_map_clear(&ld->htlcs_out);
Expand Down
27 changes: 0 additions & 27 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,35 +398,8 @@ bool wallet_unreserve_output(struct wallet *w,
OUTPUT_STATE_AVAILABLE);
}

/**
* unreserve_utxo - Mark a reserved UTXO as available again
*/
static void unreserve_utxo(struct wallet *w, const struct utxo *unres)
{
if (!wallet_update_output_status(w, &unres->outpoint,
OUTPUT_STATE_RESERVED,
OUTPUT_STATE_AVAILABLE)) {
fatal("Unable to unreserve output");
}
}

/**
* destroy_utxos - Destructor for an array of pointers to utxo
*/
static void destroy_utxos(const struct utxo **utxos, struct wallet *w)
{
for (size_t i = 0; i < tal_count(utxos); i++)
unreserve_utxo(w, utxos[i]);
}

void wallet_persist_utxo_reservation(struct wallet *w, const struct utxo **utxos)
{
tal_del_destructor2(utxos, destroy_utxos, w);
}

void wallet_confirm_utxos(struct wallet *w, const struct utxo **utxos)
{
tal_del_destructor2(utxos, destroy_utxos, w);
for (size_t i = 0; i < tal_count(utxos); i++) {
if (!wallet_update_output_status(
w, &utxos[i]->outpoint,
Expand Down
7 changes: 0 additions & 7 deletions wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1411,13 +1411,6 @@ void add_unreleased_tx(struct wallet *w, struct unreleased_tx *utx);
/* These will touch the db, so need to be explicitly freed. */
void free_unreleased_txs(struct wallet *w);

/* wallet_persist_utxo_reservation - Removes destructor
*
* Persists the reservation in the database (until a restart)
* instead of clearing the reservation when the utxo object
* is destroyed */
void wallet_persist_utxo_reservation(struct wallet *w, const struct utxo **utxos);

/* wallet_unreserve_output - Unreserve a utxo
*
* We unreserve utxos so that they can be spent elsewhere.
Expand Down

0 comments on commit 5de34e6

Please sign in to comment.