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

Function handle_their_cheat

onchaind/onchaind.c:3076–3409  ·  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

3074 * claim all the funds from the channel's original funding transaction.
3075 */
3076static void handle_their_cheat(const struct tx_parts *tx,
3077 u32 tx_blockheight,
3078 const struct secret *revocation_preimage,
3079 const struct basepoints basepoints[NUM_SIDES],
3080 const enum side opener,
3081 struct tracked_output **outs)
3082{
3083 u8 **htlc_scripts;
3084 u8 *remote_wscript, *script[NUM_SIDES], *anchor[NUM_SIDES];
3085 struct keyset *ks;
3086 struct pubkey *k;
3087 size_t i;
3088 struct htlcs_info *htlcs_info;
3089
3090 htlcs_info = init_reply(tx,
3091 "Tracking their illegal close: taking all funds");
3092 onchain_annotate_txin(
3093 &tx->txid, 0, TX_CHANNEL_UNILATERAL | TX_CHANNEL_CHEAT | TX_THEIRS);
3094
3095 /* BOLT #5:
3096 *
3097 * Once a node discovers a commitment transaction for which *it* has a
3098 * revocation private key, the funding transaction output is *resolved*.
3099 */
3100 resolved_by_other(outs[0], &tx->txid, THEIR_REVOKED_UNILATERAL);
3101
3102 /* FIXME: Types. */
3103 BUILD_ASSERT(sizeof(struct secret) == sizeof(*revocation_preimage));
3104 remote_per_commitment_secret = tal_dup(tx, struct secret,
3105 (struct secret *)
3106 revocation_preimage);
3107
3108 /* Need tmpvar for non-const. */
3109 remote_per_commitment_point = k = tal(tx, struct pubkey);
3110 if (!pubkey_from_secret(remote_per_commitment_secret, k))
3111 status_failed(STATUS_FAIL_INTERNAL_ERROR,
3112 "Failed derive from per_commitment_secret %s",
3113 type_to_string(tmpctx, struct secret,
3114 remote_per_commitment_secret));
3115
3116 status_debug("Deriving keyset %"PRIu64
3117 ": per_commit_point=%s"
3118 " self_payment_basepoint=%s"
3119 " other_payment_basepoint=%s"
3120 " self_htlc_basepoint=%s"
3121 " other_htlc_basepoint=%s"
3122 " self_delayed_basepoint=%s"
3123 " other_revocation_basepoint=%s",
3124 commit_num,
3125 type_to_string(tmpctx, struct pubkey,
3126 remote_per_commitment_point),
3127 type_to_string(tmpctx, struct pubkey,
3128 &basepoints[REMOTE].payment),
3129 type_to_string(tmpctx, struct pubkey,
3130 &basepoints[LOCAL].payment),
3131 type_to_string(tmpctx, struct pubkey,
3132 &basepoints[REMOTE].htlc),
3133 type_to_string(tmpctx, struct pubkey,

Callers 1

mainFunction · 0.85

Calls 15

init_replyFunction · 0.85
resolved_by_otherFunction · 0.85
pubkey_from_secretFunction · 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
new_tracked_outputFunction · 0.85
ignore_outputFunction · 0.85
wally_tx_output_scripteqFunction · 0.85

Tested by

no test coverage detected