Skip to content

Commit

Permalink
peer: Wrap the HTLC out destructor in a DB transaction
Browse files Browse the repository at this point in the history
Changelog-Fixed: peer: Fixed a crash when a connection is lost outside of a DB transaction
  • Loading branch information
cdecker committed Oct 29, 2021
1 parent 305e456 commit 7f47315
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ static void handle_localpay(struct htlc_in *hin,
*/
static void destroy_hout_subd_died(struct htlc_out *hout)
{
struct db *db = hout->key.channel->peer->ld->wallet->db;
/* Under some circumstances we may need to start a DB
* transaction and commit it here again. This is the case when
* we're getting called from the destructor chain. */
bool have_tx =
db_in_transaction(db);
log_debug(hout->key.channel->log,
"Failing HTLC %"PRIu64" due to peer death",
hout->key.id);
Expand All @@ -531,8 +537,14 @@ static void destroy_hout_subd_died(struct htlc_out *hout)
assert(hout->hstate == SENT_ADD_HTLC);
hout->hstate = RCVD_REMOVE_HTLC;

if (!have_tx)
db_begin_transaction(db);

fail_out_htlc(hout, "Outgoing subdaemon died",
take(towire_temporary_channel_failure(NULL, NULL)));

if (!have_tx)
db_commit_transaction(db);
}

/* This is where channeld gives us the HTLC id, and also reports if it
Expand Down

0 comments on commit 7f47315

Please sign in to comment.