From 9b429cdf4fab2c37757b7993493190439ef250ee Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Wed, 1 Apr 2020 21:51:20 -0500 Subject: [PATCH] coin moves: some additional htlc handling We record htlcs when they're fulfilled as 'withdrawals' that are onchain. This should make use of the payment_hash that we stashed. Additionally, if an htlc spend comes through that's not ours, it's probably them resolving our attempted cheat; we should allow it to proceed without bombing, and just do our accounting as necessary. It'll all come out in the wash. --- onchaind/onchaind.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 5c8f399cf..4698e889e 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -1199,12 +1199,26 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out, tx_type_name(out->tx_type), output_type_name(out->output_type)); - if (tal_count(witness_preimage) != sizeof(preimage)) + if (tal_count(witness_preimage) != sizeof(preimage)) { + /* It's possible something terrible happened and we broadcast + * an old commitment state, which they're now cleaning up. + * + * We stumble along. + */ + if (out->tx_type == OUR_UNILATERAL + && tal_count(witness_preimage) == PUBKEY_CMPR_LEN) { + status_unusual("Our cheat attempt failed, they're " + "taking our htlc out (%s)", + type_to_string(tmpctx, struct amount_sat, + &out->sat)); + return; + } status_failed(STATUS_FAIL_INTERNAL_ERROR, "%s/%s spent with bad witness length %zu", tx_type_name(out->tx_type), output_type_name(out->output_type), tal_count(witness_preimage)); + } memcpy(&preimage, witness_preimage, sizeof(preimage)); sha256(&sha, &preimage, sizeof(preimage)); ripemd160(&ripemd, &sha, sizeof(sha)); @@ -1455,6 +1469,8 @@ static void output_spent(const struct chainparams *chainparams, * output is considered *irrevocably resolved* */ ignore_output(out); + + record_htlc_fulfilled(&txid, out, false); onchain_annotate_txout( &spendertxid, out->outnum, TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS);