Browse Source

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.
nifty/pset-pre
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
9b429cdf4f
  1. 18
      onchaind/onchaind.c

18
onchaind/onchaind.c

@ -1199,12 +1199,26 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out,
tx_type_name(out->tx_type), tx_type_name(out->tx_type),
output_type_name(out->output_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, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"%s/%s spent with bad witness length %zu", "%s/%s spent with bad witness length %zu",
tx_type_name(out->tx_type), tx_type_name(out->tx_type),
output_type_name(out->output_type), output_type_name(out->output_type),
tal_count(witness_preimage)); tal_count(witness_preimage));
}
memcpy(&preimage, witness_preimage, sizeof(preimage)); memcpy(&preimage, witness_preimage, sizeof(preimage));
sha256(&sha, &preimage, sizeof(preimage)); sha256(&sha, &preimage, sizeof(preimage));
ripemd160(&ripemd, &sha, sizeof(sha)); ripemd160(&ripemd, &sha, sizeof(sha));
@ -1455,6 +1469,8 @@ static void output_spent(const struct chainparams *chainparams,
* output is considered *irrevocably resolved* * output is considered *irrevocably resolved*
*/ */
ignore_output(out); ignore_output(out);
record_htlc_fulfilled(&txid, out, false);
onchain_annotate_txout( onchain_annotate_txout(
&spendertxid, out->outnum, &spendertxid, out->outnum,
TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS); TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS);

Loading…
Cancel
Save