2017-08-28 18:02:01 +02:00
|
|
|
/* This represents a channel with no HTLCs: all that's required for openingd. */
|
|
|
|
#ifndef LIGHTNING_COMMON_INITIAL_CHANNEL_H
|
|
|
|
#define LIGHTNING_COMMON_INITIAL_CHANNEL_H
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-05-07 02:51:43 +02:00
|
|
|
#include <bitcoin/tx.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/channel_config.h>
|
2020-09-09 09:20:53 +02:00
|
|
|
#include <common/channel_id.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/derive_basepoints.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <common/htlc.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
|
|
|
|
struct signature;
|
|
|
|
struct added_htlc;
|
|
|
|
struct failed_htlc;
|
|
|
|
struct fulfilled_htlc;
|
|
|
|
|
|
|
|
/* View from each side */
|
|
|
|
struct channel_view {
|
|
|
|
/* How much is owed to each side (includes pending changes) */
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat owed[NUM_SIDES];
|
2017-08-28 18:02:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct channel {
|
2020-09-09 09:20:53 +02:00
|
|
|
|
|
|
|
/* The id for this channel */
|
|
|
|
struct channel_id cid;
|
|
|
|
|
2017-08-28 18:02:01 +02:00
|
|
|
/* Funding txid and output. */
|
2021-10-13 05:45:36 +02:00
|
|
|
struct bitcoin_outpoint funding;
|
2017-08-28 18:02:01 +02:00
|
|
|
|
|
|
|
/* Keys used to spend funding tx. */
|
|
|
|
struct pubkey funding_pubkey[NUM_SIDES];
|
|
|
|
|
2019-02-21 04:45:55 +01:00
|
|
|
/* satoshis in from commitment tx */
|
2021-10-13 05:45:36 +02:00
|
|
|
struct amount_sat funding_sats;
|
2017-08-28 18:02:01 +02:00
|
|
|
|
2019-02-26 17:57:19 +01:00
|
|
|
/* confirmations needed for locking funding */
|
|
|
|
u32 minimum_depth;
|
|
|
|
|
2017-08-28 18:02:01 +02:00
|
|
|
/* Who is paying fees. */
|
2019-09-09 18:11:24 +02:00
|
|
|
enum side opener;
|
2017-08-28 18:02:01 +02:00
|
|
|
|
|
|
|
/* Limits and settings on this channel. */
|
2018-11-21 04:12:03 +01:00
|
|
|
struct channel_config config[NUM_SIDES];
|
2017-08-28 18:02:01 +02:00
|
|
|
|
|
|
|
/* Basepoints for deriving keys. */
|
|
|
|
struct basepoints basepoints[NUM_SIDES];
|
|
|
|
|
|
|
|
/* Mask for obscuring the encoding of the commitment number. */
|
|
|
|
u64 commitment_number_obscurer;
|
|
|
|
|
|
|
|
/* All live HTLCs for this channel */
|
|
|
|
struct htlc_map *htlcs;
|
|
|
|
|
2019-12-12 15:07:53 +01:00
|
|
|
/* Fee changes, some which may be in transit */
|
|
|
|
struct fee_states *fee_states;
|
|
|
|
|
2021-06-22 20:25:59 +02:00
|
|
|
/* Blockheight changes, some which may be in transit
|
|
|
|
* (option_will_fund)*/
|
|
|
|
struct height_states *blockheight_states;
|
|
|
|
|
2017-08-28 18:02:01 +02:00
|
|
|
/* What it looks like to each side. */
|
|
|
|
struct channel_view view[NUM_SIDES];
|
2018-09-06 18:44:47 +02:00
|
|
|
|
2021-09-09 07:25:23 +02:00
|
|
|
/* Features which apply to this channel. */
|
|
|
|
struct channel_type *type;
|
2021-06-16 19:56:36 +02:00
|
|
|
|
2021-09-08 02:06:14 +02:00
|
|
|
/* Are we using big channels? */
|
|
|
|
bool option_wumbo;
|
|
|
|
|
2021-06-16 19:56:36 +02:00
|
|
|
/* When the lease expires for the funds in this channel */
|
|
|
|
u32 lease_expiry;
|
2017-08-28 18:02:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* new_initial_channel: Given initial fees and funding, what is initial state?
|
|
|
|
* @ctx: tal context to allocate return value from.
|
2020-09-09 09:20:53 +02:00
|
|
|
* @cid: The channel's id.
|
2021-10-13 05:45:36 +02:00
|
|
|
* @funding: The commitment transaction id/outnum
|
2019-02-26 17:57:19 +01:00
|
|
|
* @minimum_depth: The minimum confirmations needed for funding transaction.
|
2021-06-22 20:25:59 +02:00
|
|
|
* @height_states: The blockheight update states.
|
|
|
|
* @lease_expiry: Block the lease expires.
|
2021-10-13 05:45:36 +02:00
|
|
|
* @funding_sats: The commitment transaction amount.
|
2017-08-28 18:02:01 +02:00
|
|
|
* @local_msatoshi: The amount for the local side (remainder goes to remote)
|
2019-12-12 15:07:53 +01:00
|
|
|
* @fee_states: The fee update states.
|
2017-08-28 18:02:01 +02:00
|
|
|
* @local: local channel configuration
|
|
|
|
* @remote: remote channel configuration
|
|
|
|
* @local_basepoints: local basepoints.
|
|
|
|
* @remote_basepoints: remote basepoints.
|
|
|
|
* @local_fundingkey: local funding key
|
|
|
|
* @remote_fundingkey: remote funding key
|
2021-09-09 07:25:23 +02:00
|
|
|
* @type: type for this channel
|
2021-09-08 02:06:14 +02:00
|
|
|
* @option_wumbo: has peer currently negotiated wumbo?
|
2019-09-09 18:11:24 +02:00
|
|
|
* @opener: which side initiated it.
|
2017-08-28 18:02:01 +02:00
|
|
|
*
|
|
|
|
* Returns channel, or NULL if malformed.
|
|
|
|
*/
|
|
|
|
struct channel *new_initial_channel(const tal_t *ctx,
|
2020-09-09 09:20:53 +02:00
|
|
|
const struct channel_id *cid,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *funding,
|
2019-02-26 17:57:19 +01:00
|
|
|
u32 minimum_depth,
|
2021-06-22 20:25:59 +02:00
|
|
|
const struct height_states *height_states TAKES,
|
2021-06-16 19:56:36 +02:00
|
|
|
u32 lease_expiry,
|
2021-10-13 05:45:36 +02:00
|
|
|
struct amount_sat funding_sats,
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat local_msatoshi,
|
2019-12-12 15:07:53 +01:00
|
|
|
const struct fee_states *fee_states TAKES,
|
2017-08-28 18:02:01 +02:00
|
|
|
const struct channel_config *local,
|
|
|
|
const struct channel_config *remote,
|
|
|
|
const struct basepoints *local_basepoints,
|
|
|
|
const struct basepoints *remote_basepoints,
|
|
|
|
const struct pubkey *local_funding_pubkey,
|
|
|
|
const struct pubkey *remote_funding_pubkey,
|
2021-09-09 07:25:23 +02:00
|
|
|
const struct channel_type *type TAKES,
|
2021-09-08 02:06:14 +02:00
|
|
|
bool option_wumbo,
|
2019-09-09 18:11:24 +02:00
|
|
|
enum side opener);
|
2017-08-28 18:02:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* initial_channel_tx: Get the current commitment tx for the *empty* channel.
|
|
|
|
* @ctx: tal context to allocate return value from.
|
|
|
|
* @wscript: wscripts for the commitment tx.
|
|
|
|
* @channel: The channel to evaluate
|
|
|
|
* @per_commitment_point: Per-commitment point to determine keys
|
|
|
|
* @side: which side to get the commitment transaction for
|
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).
|
2019-04-03 10:20:36 +02:00
|
|
|
* @err_reason: When NULL is returned, this will point to a human readable reason.
|
2017-08-28 18:02:01 +02:00
|
|
|
*
|
2018-03-18 05:41:32 +01:00
|
|
|
* Returns the unsigned initial commitment transaction for @side, or NULL
|
|
|
|
* if the channel size was insufficient to cover fees or reserves.
|
2017-08-28 18:02:01 +02:00
|
|
|
*/
|
|
|
|
struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
|
|
|
const u8 **wscript,
|
|
|
|
const struct channel *channel,
|
|
|
|
const struct pubkey *per_commitment_point,
|
2019-04-03 10:20:36 +02:00
|
|
|
enum side side,
|
2020-05-07 02:43:34 +02:00
|
|
|
struct wally_tx_output *direct_outputs[NUM_SIDES],
|
2019-04-03 10:20:36 +02:00
|
|
|
char** err_reason);
|
2017-08-28 18:02:01 +02:00
|
|
|
|
2019-12-12 15:05:53 +01:00
|
|
|
/**
|
|
|
|
* channel_feerate: Get fee rate for this side of channel.
|
|
|
|
* @channel: The channel
|
|
|
|
* @side: the side
|
|
|
|
*/
|
|
|
|
u32 channel_feerate(const struct channel *channel, enum side side);
|
|
|
|
|
2021-06-22 23:47:33 +02:00
|
|
|
/**
|
|
|
|
* channel_blockheight: Get blockheight for this side of channel.
|
|
|
|
* @channel: The channel
|
|
|
|
* @side: the side
|
|
|
|
*/
|
|
|
|
u32 channel_blockheight(const struct channel *channel, enum side side);
|
|
|
|
|
2021-10-08 01:40:30 +02:00
|
|
|
/* What can we upgrade to? (Returns NULL if none). */
|
|
|
|
struct channel_type *channel_upgradable_type(const tal_t *ctx,
|
|
|
|
const struct channel *channel);
|
2021-06-04 07:13:47 +02:00
|
|
|
|
2021-10-08 01:40:30 +02:00
|
|
|
/* What channel type do we want? */
|
2021-06-04 07:13:47 +02:00
|
|
|
struct channel_type *channel_desired_type(const tal_t *ctx,
|
|
|
|
const struct channel *channel);
|
2021-06-04 07:13:47 +02:00
|
|
|
|
2021-09-09 07:25:23 +02:00
|
|
|
/* Convenience for querying channel->type */
|
|
|
|
bool channel_has(const struct channel *channel, int feature);
|
2023-06-26 01:07:21 +02:00
|
|
|
|
|
|
|
/* Convenience for querying either anchor_outputs or anchors_zero_fee_htlc_tx */
|
|
|
|
bool channel_has_anchors(const struct channel *channel);
|
|
|
|
|
2017-08-28 18:02:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */
|