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

Function handle_their_cheat

onchaind/onchaind.c:2610–2943  ·  view source on GitHub ↗

BOLT #5: * * If any node tries to cheat by broadcasting an outdated commitment * transaction (any previous commitment transaction besides the most current * one), the other node in the channel can use its revocation private key to * claim all the funds from the channel's original funding transaction. */

Source from the content-addressed store, hash-verified

2608 * claim all the funds from the channel's original funding transaction.
2609 */
2610static void handle_their_cheat(const struct tx_parts *tx,
2611 u32 tx_blockheight,
2612 const struct secret *revocation_preimage,
2613 const struct basepoints basepoints[NUM_SIDES],
2614 const enum side opener,
2615 struct tracked_output **outs)
2616{
2617 u8 **htlc_scripts;
2618 u8 *remote_wscript, *script[NUM_SIDES], *anchor[NUM_SIDES];
2619 struct keyset *ks;
2620 struct pubkey *k;
2621 size_t i;
2622 struct htlcs_info *htlcs_info;
2623
2624 htlcs_info = init_reply(tx,
2625 "Tracking their illegal close: taking all funds");
2626 onchain_annotate_txin(
2627 &tx->txid, 0, TX_CHANNEL_UNILATERAL | TX_CHANNEL_CHEAT | TX_THEIRS);
2628
2629 /* BOLT #5:
2630 *
2631 * Once a node discovers a commitment transaction for which *it* has a
2632 * revocation private key, the funding transaction output is *resolved*.
2633 */
2634 resolved_by_other(outs[0], &tx->txid, THEIR_REVOKED_UNILATERAL);
2635
2636 /* FIXME: Types. */
2637 BUILD_ASSERT(sizeof(struct secret) == sizeof(*revocation_preimage));
2638 remote_per_commitment_secret = tal_dup(tx, struct secret,
2639 (struct secret *)
2640 revocation_preimage);
2641
2642 /* Need tmpvar for non-const. */
2643 remote_per_commitment_point = k = tal(tx, struct pubkey);
2644 if (!pubkey_from_secret(remote_per_commitment_secret, k))
2645 status_failed(STATUS_FAIL_INTERNAL_ERROR,
2646 "Failed derive from per_commitment_secret %s",
2647 fmt_secret(tmpctx,
2648 remote_per_commitment_secret));
2649
2650 status_debug("Deriving keyset %"PRIu64
2651 ": per_commit_point=%s"
2652 " self_payment_basepoint=%s"
2653 " other_payment_basepoint=%s"
2654 " self_htlc_basepoint=%s"
2655 " other_htlc_basepoint=%s"
2656 " self_delayed_basepoint=%s"
2657 " other_revocation_basepoint=%s",
2658 commit_num,
2659 fmt_pubkey(tmpctx,
2660 remote_per_commitment_point),
2661 fmt_pubkey(tmpctx,
2662 &basepoints[REMOTE].payment),
2663 fmt_pubkey(tmpctx,
2664 &basepoints[LOCAL].payment),
2665 fmt_pubkey(tmpctx,
2666 &basepoints[REMOTE].htlc),
2667 fmt_pubkey(tmpctx,

Callers 1

mainFunction · 0.85

Calls 15

init_replyFunction · 0.85
resolved_by_otherFunction · 0.85
pubkey_from_secretFunction · 0.85
fmt_secretFunction · 0.85
fmt_pubkeyFunction · 0.85
scriptpubkey_p2wshFunction · 0.85
scriptpubkey_to_remoteFunction · 0.85
derive_htlc_scriptsFunction · 0.85
tal_hexFunction · 0.85
get_anchor_scriptpubkeysFunction · 0.85
tal_hexstrFunction · 0.85

Tested by

no test coverage detected