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

Function steal_htlc_tx

onchaind/onchaind.c:1118–1161  ·  view source on GitHub ↗

BOLT #5: * * - MUST *resolve* the _remote node's HTLC-timeout transaction_ by spending it * using the revocation private key. * - MUST *resolve* the _remote node's HTLC-success transaction_ by spending it * using the revocation private key. */

Source from the content-addressed store, hash-verified

1116 * using the revocation private key.
1117 */
1118static void steal_htlc_tx(struct tracked_output *out,
1119 struct tracked_output ***outs,
1120 const struct tx_parts *htlc_tx,
1121 u32 htlc_tx_blockheight,
1122 enum tx_type htlc_tx_type,
1123 const struct bitcoin_outpoint *htlc_outpoint)
1124{
1125 struct tracked_output *htlc_out;
1126 struct amount_asset asset;
1127 struct amount_sat htlc_out_amt;
1128 const u8 *msg;
1129
1130 u8 *wscript = bitcoin_wscript_htlc_tx(htlc_tx, to_self_delay[REMOTE],
1131 &keyset->self_revocation_key,
1132 &keyset->self_delayed_payment_key);
1133
1134 asset = wally_tx_output_get_amount(htlc_tx->outputs[htlc_outpoint->n]);
1135 assert(amount_asset_is_main(&asset));
1136 htlc_out_amt = amount_asset_to_sat(&asset);
1137
1138 htlc_out = new_tracked_output(outs,
1139 htlc_outpoint, htlc_tx_blockheight,
1140 htlc_tx_type,
1141 htlc_out_amt,
1142 DELAYED_CHEAT_OUTPUT_TO_THEM,
1143 &out->htlc, wscript, NULL);
1144
1145 /* mark commitment tx htlc output as 'resolved by them' */
1146 resolved_by_other(out, &htlc_tx->txid, htlc_tx_type);
1147
1148 /* BOLT #3:
1149 *
1150 * To spend this via penalty, the remote node uses a witness stack
1151 * `<revocationsig> 1`
1152 */
1153 msg = towire_onchaind_spend_penalty(NULL,
1154 htlc_outpoint, htlc_out_amt,
1155 remote_per_commitment_secret,
1156 tal_dup(tmpctx, u8, &ONE),
1157 htlc_out->wscript);
1158
1159 /* Spend this immediately. */
1160 propose_immediate_resolution(htlc_out, take(msg), OUR_PENALTY_TX);
1161}
1162
1163static void onchain_annotate_txout(const struct bitcoin_outpoint *outpoint,
1164 enum wallet_tx_type type)

Callers 1

output_spentFunction · 0.85

Calls 8

bitcoin_wscript_htlc_txFunction · 0.85
new_tracked_outputFunction · 0.85
resolved_by_otherFunction · 0.85
amount_asset_is_mainFunction · 0.50
amount_asset_to_satFunction · 0.50

Tested by

no test coverage detected