MCPcopy Create free account
hub / github.com/ElementsProject/lightning / resolve_htlc_tx

Function resolve_htlc_tx

onchaind/onchaind.c:1062–1109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1060}
1061
1062static void resolve_htlc_tx(struct tracked_output ***outs,
1063 size_t out_index,
1064 const struct tx_parts *htlc_tx,
1065 size_t input_num,
1066 u32 tx_blockheight)
1067{
1068 struct tracked_output *out;
1069 struct amount_sat amt;
1070 struct amount_asset asset;
1071 struct bitcoin_outpoint outpoint;
1072 u8 *msg;
1073 u8 *wscript = bitcoin_wscript_htlc_tx(tmpctx, to_self_delay[LOCAL],
1074 &keyset->self_revocation_key,
1075 &keyset->self_delayed_payment_key);
1076
1077
1078 /* BOLT #5:
1079 *
1080 * - SHOULD resolve the HTLC-timeout transaction by spending it to
1081 * a convenient address...
1082 * - MUST wait until the `OP_CHECKSEQUENCEVERIFY` delay has passed
1083 * (as specified by the remote node's `open_channel`
1084 * `to_self_delay` field) before spending that HTLC-timeout
1085 * output.
1086 */
1087 outpoint.txid = htlc_tx->txid;
1088 outpoint.n = input_num;
1089
1090 asset = wally_tx_output_get_amount(htlc_tx->outputs[outpoint.n]);
1091 assert(amount_asset_is_main(&asset));
1092 amt = amount_asset_to_sat(&asset);
1093 out = new_tracked_output(outs, &outpoint,
1094 tx_blockheight,
1095 (*outs)[out_index]->resolved->tx_type,
1096 amt,
1097 DELAYED_OUTPUT_TO_US,
1098 NULL, NULL, NULL);
1099
1100 msg = towire_onchaind_spend_to_us(NULL,
1101 &outpoint, amt,
1102 to_self_delay[LOCAL],
1103 rel_blockheight(out, to_self_delay[LOCAL]),
1104 commit_num,
1105 wscript);
1106 propose_resolution_to_master(out, take(msg),
1107 rel_blockheight(out, to_self_delay[LOCAL]),
1108 OUR_DELAYED_RETURN_TO_WALLET);
1109}
1110
1111/* BOLT #5:
1112 *

Callers 1

output_spentFunction · 0.85

Calls 8

bitcoin_wscript_htlc_txFunction · 0.85
new_tracked_outputFunction · 0.85
rel_blockheightFunction · 0.85
amount_asset_is_mainFunction · 0.50
amount_asset_to_satFunction · 0.50

Tested by

no test coverage detected