2018-03-22 11:36:25 +01:00
|
|
|
#ifndef LIGHTNING_CHANNELD_COMMIT_TX_H
|
|
|
|
#define LIGHTNING_CHANNELD_COMMIT_TX_H
|
2017-02-07 02:44:22 +01:00
|
|
|
#include "config.h"
|
2017-08-29 06:12:04 +02:00
|
|
|
#include <channeld/channeld_htlc.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/initial_commit_tx.h>
|
2017-02-07 02:44:22 +01:00
|
|
|
|
2017-08-18 06:43:53 +02:00
|
|
|
struct keyset;
|
2017-02-07 02:44:22 +01:00
|
|
|
|
2017-02-21 05:45:28 +01:00
|
|
|
/**
|
|
|
|
* commit_tx_num_untrimmed: how many of these htlc outputs will commit tx have?
|
|
|
|
* @htlcs: tal_arr of HTLCs
|
|
|
|
* @feerate_per_kw: feerate to use
|
2019-02-21 04:45:55 +01:00
|
|
|
* @dust_limit: dust limit below which to trim outputs.
|
2020-08-13 19:47:02 +02:00
|
|
|
* @option_anchor_outputs: does option_anchor_outputs apply to this channel?
|
2017-02-21 05:45:28 +01:00
|
|
|
* @side: from which side's point of view
|
2020-08-14 03:30:41 +02:00
|
|
|
* @option_anchor_outputs: does option_anchor_outputs apply to this channel?
|
2017-02-21 05:45:28 +01:00
|
|
|
*
|
|
|
|
* We need @side because HTLC fees are different for offered and
|
|
|
|
* received HTLCs.
|
|
|
|
*/
|
|
|
|
size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
|
2019-02-21 04:45:55 +01:00
|
|
|
u32 feerate_per_kw,
|
|
|
|
struct amount_sat dust_limit,
|
2020-08-13 19:47:02 +02:00
|
|
|
bool option_anchor_outputs,
|
2017-02-21 05:45:28 +01:00
|
|
|
enum side side);
|
|
|
|
|
2021-09-28 21:12:01 +02:00
|
|
|
/**
|
|
|
|
* commit_tx_amount_trimmed: what's the sum of trimmed htlc amounts?
|
|
|
|
* @htlcs: tal_arr of HTLCs
|
|
|
|
* @feerate_per_kw: feerate to use
|
|
|
|
* @dust_limit: dust limit below which to trim outputs.
|
|
|
|
* @option_anchor_outputs: does option_anchor_outputs apply to this channel?
|
|
|
|
* @side: from which side's point of view
|
|
|
|
* @amt: returned, total value trimmed from this commitment
|
|
|
|
*
|
|
|
|
* We need @side because HTLC fees are different for offered and
|
|
|
|
* received HTLCs.
|
|
|
|
*
|
|
|
|
* Returns false if unable to calculate amount trimmed.
|
|
|
|
*/
|
|
|
|
bool commit_tx_amount_trimmed(const struct htlc **htlcs,
|
|
|
|
u32 feerate_per_kw,
|
|
|
|
struct amount_sat dust_limit,
|
|
|
|
bool option_anchor_outputs,
|
|
|
|
enum side side,
|
|
|
|
struct amount_msat *amt);
|
2017-02-21 05:45:28 +01:00
|
|
|
/**
|
|
|
|
* commit_tx: create (unsigned) commitment tx to spend the funding tx output
|
|
|
|
* @ctx: context to allocate transaction and @htlc_map from.
|
2021-10-13 05:45:36 +02:00
|
|
|
* @funding, @funding_sats: funding outpoint and amount
|
2020-08-13 19:46:02 +02:00
|
|
|
* @local_funding_key, @remote_funding_key: keys for funding input.
|
2019-09-09 18:11:24 +02:00
|
|
|
* @opener: is the LOCAL or REMOTE paying the fee?
|
2017-08-18 06:43:53 +02:00
|
|
|
* @keyset: keys derived for this commit tx.
|
2017-02-21 05:45:28 +01:00
|
|
|
* @feerate_per_kw: feerate to use
|
2019-02-21 04:45:55 +01:00
|
|
|
* @dust_limit: dust limit below which to trim outputs.
|
|
|
|
* @self_pay: amount to pay directly to self
|
|
|
|
* @other_pay: amount to pay directly to the other side
|
2017-02-21 05:45:28 +01:00
|
|
|
* @htlcs: tal_arr of htlcs committed by transaction (some may be trimmed)
|
2018-10-22 06:17:24 +02:00
|
|
|
* @htlc_map: outputed map of outnum->HTLC (NULL for direct outputs).
|
2017-02-21 05:45:28 +01:00
|
|
|
* @obscured_commitment_number: number to encode in commitment transaction
|
2020-05-07 02:43:34 +02:00
|
|
|
* @direct_outputs: If non-NULL, fill with pointers to the direct (non-HTLC) outputs (or NULL if none).
|
2020-08-13 19:47:02 +02:00
|
|
|
* @option_anchor_outputs: does option_anchor_outputs apply to this channel?
|
2017-02-21 05:45:28 +01:00
|
|
|
* @side: side to generate commitment transaction for.
|
2020-08-14 03:30:41 +02:00
|
|
|
* @option_anchor_outputs: does option_anchor_outputs apply to this channel?
|
2017-02-21 05:45:28 +01:00
|
|
|
*
|
|
|
|
* We need to be able to generate the remote side's tx to create signatures,
|
|
|
|
* but the BOLT is expressed in terms of generating our local commitment
|
|
|
|
* transaction, so we carefully use the terms "self" and "other" here.
|
|
|
|
*/
|
2017-02-07 02:44:22 +01:00
|
|
|
struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *funding,
|
|
|
|
struct amount_sat funding_sats,
|
2020-08-13 19:46:02 +02:00
|
|
|
const struct pubkey *local_funding_key,
|
|
|
|
const struct pubkey *remote_funding_key,
|
2019-09-09 18:11:24 +02:00
|
|
|
enum side opener,
|
2017-02-07 02:44:22 +01:00
|
|
|
u16 to_self_delay,
|
2021-06-22 23:49:04 +02:00
|
|
|
u32 lease_expiry,
|
|
|
|
u32 blockheight,
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct keyset *keyset,
|
2017-11-21 04:33:22 +01:00
|
|
|
u32 feerate_per_kw,
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat dust_limit,
|
|
|
|
struct amount_msat self_pay,
|
|
|
|
struct amount_msat other_pay,
|
2017-02-07 02:44:22 +01:00
|
|
|
const struct htlc **htlcs,
|
2017-02-07 02:44:22 +01:00
|
|
|
const struct htlc ***htlcmap,
|
2020-05-07 02:43:34 +02:00
|
|
|
struct wally_tx_output *direct_outputs[NUM_SIDES],
|
2017-02-21 05:45:28 +01:00
|
|
|
u64 obscured_commitment_number,
|
2020-08-13 19:47:02 +02:00
|
|
|
bool option_anchor_outputs,
|
2017-02-21 05:45:28 +01:00
|
|
|
enum side side);
|
2017-08-18 06:43:53 +02:00
|
|
|
|
2018-03-22 11:36:25 +01:00
|
|
|
#endif /* LIGHTNING_CHANNELD_COMMIT_TX_H */
|