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

Function penalty_tx_create

channeld/watchtower.c:14–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12static const u8 ONE = 0x1;
13
14const struct bitcoin_tx *
15penalty_tx_create(const tal_t *ctx,
16 const struct channel *channel,
17 u32 penalty_feerate,
18 u32 *final_index,
19 struct ext_key *final_ext_key,
20 u8 *final_scriptpubkey,
21 const struct secret *revocation_preimage,
22 const struct bitcoin_txid *commitment_txid,
23 s16 to_them_outnum, struct amount_sat to_them_sats,
24 int hsm_fd)
25{
26 u8 *wscript;
27 struct bitcoin_tx *tx;
28 struct keyset keyset;
29 size_t weight;
30 const u8 *msg;
31 struct amount_sat fee, min_out, amt;
32 struct bitcoin_signature sig;
33 u32 locktime = 0;
34 bool option_static_remotekey = channel_has(channel, OPT_STATIC_REMOTEKEY);
35 u8 **witness;
36 u32 remote_to_self_delay = channel->config[REMOTE].to_self_delay;
37 const struct amount_sat dust_limit = channel->config[LOCAL].dust_limit;
38 BUILD_ASSERT(sizeof(struct secret) == sizeof(*revocation_preimage));
39 const struct secret remote_per_commitment_secret = *revocation_preimage;
40 struct pubkey remote_per_commitment_point;
41 const struct basepoints *basepoints = channel->basepoints;
42 struct bitcoin_outpoint outpoint;
43
44 if (to_them_outnum == -1 ||
45 amount_sat_less_eq(to_them_sats, dust_limit)) {
46 status_debug(
47 "Cannot create penalty transaction because there "
48 "is no non-dust to_them output in the commitment.");
49 return NULL;
50 }
51
52 outpoint.txid = *commitment_txid;
53 outpoint.n = to_them_outnum;
54
55 if (!pubkey_from_secret(&remote_per_commitment_secret, &remote_per_commitment_point))
56 status_failed(STATUS_FAIL_INTERNAL_ERROR,
57 "Failed derive from per_commitment_secret %s",
58 fmt_secret(tmpctx, &remote_per_commitment_secret));
59
60 if (!derive_keyset(&remote_per_commitment_point,
61 &basepoints[REMOTE],
62 &basepoints[LOCAL],
63 option_static_remotekey,
64 &keyset))
65 status_failed(STATUS_FAIL_INTERNAL_ERROR,
66 "Failed deriving keyset");
67
68 /* FIXME: csv_lock */
69 wscript = bitcoin_wscript_to_local(tmpctx, remote_to_self_delay, 1,
70 &keyset.self_revocation_key,
71 &keyset.self_delayed_payment_key);

Callers 1

got_revoke_msgFunction · 0.85

Calls 15

amount_sat_less_eqFunction · 0.85
pubkey_from_secretFunction · 0.85
fmt_secretFunction · 0.85
bitcoin_wscript_to_localFunction · 0.85
bitcoin_tx_add_inputFunction · 0.85
bitcoin_tx_add_outputFunction · 0.85
tal_bytelenFunction · 0.85
bitcoin_tx_weightFunction · 0.85
elements_tx_overheadFunction · 0.85
amount_sat_lessFunction · 0.85

Tested by

no test coverage detected