lightningd: cleanup, freeing jsonrpc in shutdown cannot trigger db write's anymore

since PR #3867 utxos are unreserved by height, destroy_utxos and
related functions are not used anymore so clean them up also

However free(ld->jsonrpc) still needs to happen before free(ld) because its
destructors need list_head pointers from ld
This commit is contained in:
Simon Vrouwe 2021-11-02 09:55:19 +02:00 committed by Rusty Russell
parent 5f69674faa
commit 63bd569bf6
4 changed files with 2 additions and 40 deletions

View File

@ -22,7 +22,7 @@ enum command_mode {
/* Context for a command (from JSON, but might outlive the connection!). */
/* FIXME: move definition into jsonrpc.c */
struct command {
/* Off json_cmd->commands */
/* Off list jcon->commands */
struct list_node list;
/* The global state */
struct lightningd *ld;

View File

@ -1193,12 +1193,8 @@ 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);
/* Cleanup JSON RPC separately: destructors assume some list_head * in ld */
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);

View File

@ -401,35 +401,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,

View File

@ -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.