2018-02-12 11:10:46 +01:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_CHANNEL_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_CHANNEL_H
|
|
|
|
#include "config.h"
|
2020-09-09 09:20:53 +02:00
|
|
|
#include <common/channel_id.h>
|
2021-09-09 07:29:35 +02:00
|
|
|
#include <common/channel_type.h>
|
2022-06-24 02:48:18 +02:00
|
|
|
#include <common/scb_wiregen.h>
|
2021-01-20 02:07:04 +01:00
|
|
|
#include <common/tx_roles.h>
|
2021-09-16 07:00:42 +02:00
|
|
|
#include <common/utils.h>
|
2018-02-19 02:06:14 +01:00
|
|
|
#include <lightningd/channel_state.h>
|
2018-02-12 11:10:46 +01:00
|
|
|
#include <wallet/wallet.h>
|
|
|
|
|
2020-09-09 09:20:53 +02:00
|
|
|
struct channel_id;
|
2018-02-19 02:06:02 +01:00
|
|
|
struct uncommitted_channel;
|
2020-09-11 22:28:15 +02:00
|
|
|
struct wally_psbt;
|
2018-02-19 02:06:02 +01:00
|
|
|
|
2018-02-23 06:53:44 +01:00
|
|
|
struct billboard {
|
|
|
|
/* Status information to display on listpeers */
|
|
|
|
const char *permanent[CHANNEL_STATE_MAX+1];
|
|
|
|
const char *transient;
|
|
|
|
};
|
|
|
|
|
2021-02-04 22:14:44 +01:00
|
|
|
struct funding_info {
|
2021-10-13 05:45:36 +02:00
|
|
|
struct bitcoin_outpoint outpoint;
|
2021-02-04 22:14:44 +01:00
|
|
|
u32 feerate;
|
|
|
|
struct amount_sat total_funds;
|
|
|
|
|
|
|
|
/* Our original funds, in funding amount */
|
|
|
|
struct amount_sat our_funds;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct channel_inflight {
|
|
|
|
/* Inside channel->inflights. */
|
|
|
|
struct list_node list;
|
|
|
|
|
|
|
|
/* Channel context */
|
|
|
|
struct channel *channel;
|
|
|
|
|
|
|
|
/* Funding info */
|
|
|
|
const struct funding_info *funding;
|
|
|
|
struct wally_psbt *funding_psbt;
|
|
|
|
bool remote_tx_sigs;
|
2021-03-16 01:44:36 +01:00
|
|
|
bool tx_broadcast;
|
2021-02-04 22:14:44 +01:00
|
|
|
|
|
|
|
/* Commitment tx and sigs */
|
|
|
|
struct bitcoin_tx *last_tx;
|
|
|
|
struct bitcoin_signature last_sig;
|
2021-06-17 03:28:18 +02:00
|
|
|
|
|
|
|
/* Channel lease infos */
|
|
|
|
u32 lease_expiry;
|
|
|
|
secp256k1_ecdsa_signature *lease_commit_sig;
|
|
|
|
u32 lease_chan_max_msat;
|
|
|
|
u16 lease_chan_max_ppt;
|
2021-06-22 20:25:59 +02:00
|
|
|
u32 lease_blockheight_start;
|
2021-12-08 18:42:07 +01:00
|
|
|
|
|
|
|
/* We save this data so we can do nice accounting;
|
|
|
|
* on the channel we slot it into the 'push' field */
|
|
|
|
struct amount_msat lease_fee;
|
2021-02-04 22:14:44 +01:00
|
|
|
};
|
|
|
|
|
2021-01-20 02:07:04 +01:00
|
|
|
struct open_attempt {
|
|
|
|
/* on uncommitted_channel struct */
|
|
|
|
struct channel *channel;
|
|
|
|
struct channel_config our_config;
|
|
|
|
enum tx_role role;
|
2021-03-09 22:14:08 +01:00
|
|
|
bool aborted;
|
2021-01-20 02:07:04 +01:00
|
|
|
|
|
|
|
/* On funding_channel struct */
|
|
|
|
struct command *cmd;
|
|
|
|
struct amount_sat funding;
|
|
|
|
const u8 *our_upfront_shutdown_script;
|
2022-03-22 21:27:29 +01:00
|
|
|
|
|
|
|
/* First msg to send to dualopend (to make it create channel) */
|
|
|
|
const u8 *open_msg;
|
2021-01-20 02:07:04 +01:00
|
|
|
};
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
struct channel {
|
|
|
|
/* Inside peer->channels. */
|
|
|
|
struct list_node list;
|
|
|
|
|
|
|
|
/* Peer context */
|
|
|
|
struct peer *peer;
|
|
|
|
|
2021-02-04 22:14:44 +01:00
|
|
|
/* Inflight channel opens */
|
|
|
|
struct list_head inflights;
|
|
|
|
|
2021-01-20 02:07:04 +01:00
|
|
|
/* Open attempt */
|
|
|
|
struct open_attempt *open_attempt;
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
/* Database ID: 0 == not in db yet */
|
|
|
|
u64 dbid;
|
|
|
|
|
2021-01-20 02:09:38 +01:00
|
|
|
/* Populated by new_unsaved_channel */
|
|
|
|
u64 unsaved_dbid;
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
/* Error message (iff in error state) */
|
|
|
|
u8 *error;
|
|
|
|
|
|
|
|
/* Their shachain. */
|
|
|
|
struct wallet_shachain their_shachain;
|
|
|
|
|
|
|
|
/* What's happening. */
|
2018-02-19 02:06:14 +01:00
|
|
|
enum channel_state state;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
|
|
|
/* Which side offered channel? */
|
2019-09-09 18:11:24 +02:00
|
|
|
enum side opener;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
|
|
|
/* Is there a single subdaemon responsible for us? */
|
|
|
|
struct subd *owner;
|
|
|
|
|
|
|
|
/* History */
|
|
|
|
struct log *log;
|
2018-02-23 06:53:44 +01:00
|
|
|
struct billboard billboard;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
|
|
|
/* Channel flags from opening message. */
|
|
|
|
u8 channel_flags;
|
|
|
|
|
|
|
|
/* Our channel config. */
|
|
|
|
struct channel_config our_config;
|
|
|
|
|
|
|
|
/* Minimum funding depth (specified by us if they fund). */
|
|
|
|
u32 minimum_depth;
|
|
|
|
|
2022-06-02 01:39:53 +02:00
|
|
|
/* Depth of the funding TX as reported by the txout
|
|
|
|
* watch. Only used while we're in state
|
|
|
|
* CHANNELD_AWAITING_LOCKING, afterwards the watches do not
|
|
|
|
* trigger anymore. */
|
|
|
|
u32 depth;
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
/* Tracking commitment transaction numbers. */
|
|
|
|
u64 next_index[NUM_SIDES];
|
|
|
|
u64 next_htlc_id;
|
|
|
|
|
2021-10-13 05:45:36 +02:00
|
|
|
/* Funding outpoint and amount */
|
|
|
|
struct bitcoin_outpoint funding;
|
|
|
|
struct amount_sat funding_sats;
|
2019-09-30 23:47:16 +02:00
|
|
|
|
|
|
|
/* Our original funds, in funding amount */
|
|
|
|
struct amount_sat our_funds;
|
|
|
|
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat push;
|
2018-02-12 11:10:46 +01:00
|
|
|
bool remote_funding_locked;
|
|
|
|
/* Channel if locked locally. */
|
|
|
|
struct short_channel_id *scid;
|
|
|
|
|
2022-04-22 12:57:01 +02:00
|
|
|
/* Alias used for option_zeroconf, or option_scid_alias, if
|
|
|
|
* present. LOCAL are all the alias we told the peer about and
|
|
|
|
* REMOTE is one of the aliases we got from the peer and we'll
|
|
|
|
* use in a routehint. */
|
|
|
|
struct short_channel_id *alias[NUM_SIDES];
|
|
|
|
|
2020-09-09 09:20:53 +02:00
|
|
|
struct channel_id cid;
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
/* Amount going to us, not counting unfinished HTLCs; if we have one. */
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat our_msat;
|
2018-03-31 02:21:13 +02:00
|
|
|
/* Statistics for min and max our_msatoshi. */
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat msat_to_us_min;
|
|
|
|
struct amount_msat msat_to_us_max;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
2018-02-19 02:06:12 +01:00
|
|
|
/* Last tx they gave us. */
|
2018-02-12 11:10:46 +01:00
|
|
|
struct bitcoin_tx *last_tx;
|
2019-06-07 11:38:20 +02:00
|
|
|
enum wallet_tx_type last_tx_type;
|
2018-12-03 00:15:06 +01:00
|
|
|
struct bitcoin_signature last_sig;
|
2020-08-13 19:45:02 +02:00
|
|
|
const struct bitcoin_signature *last_htlc_sigs;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
2018-02-19 02:06:12 +01:00
|
|
|
/* Keys for channel */
|
|
|
|
struct channel_info channel_info;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
2020-09-17 03:58:59 +02:00
|
|
|
/* Fee status */
|
|
|
|
const struct fee_states *fee_states;
|
|
|
|
|
2021-06-22 20:25:59 +02:00
|
|
|
/* Height states (option_will_fund, update_blockheight) */
|
|
|
|
const struct height_states *blockheight_states;
|
|
|
|
|
2018-07-23 04:23:02 +02:00
|
|
|
/* Our local basepoints */
|
|
|
|
struct basepoints local_basepoints;
|
|
|
|
|
|
|
|
/* Our funding tx pubkey. */
|
|
|
|
struct pubkey local_funding_pubkey;
|
|
|
|
|
2019-10-15 03:08:33 +02:00
|
|
|
/* scriptpubkey for shutdown, if applicable. */
|
|
|
|
const u8 *shutdown_scriptpubkey[NUM_SIDES];
|
2018-03-07 01:06:07 +01:00
|
|
|
/* Address for any final outputs */
|
|
|
|
u64 final_key_idx;
|
2018-02-12 11:10:46 +01:00
|
|
|
|
2020-01-03 14:08:29 +01:00
|
|
|
/* Amount to give up on each step of the closing fee negotiation. */
|
|
|
|
u64 closing_fee_negotiation_step;
|
|
|
|
|
|
|
|
/* Whether closing_fee_negotiation_step is in satoshi or %. */
|
|
|
|
u8 closing_fee_negotiation_step_unit;
|
|
|
|
|
2021-03-15 21:25:41 +01:00
|
|
|
/* optional wrong_funding for mutual close */
|
|
|
|
const struct bitcoin_outpoint *shutdown_wrong_funding;
|
|
|
|
|
2021-09-08 06:41:46 +02:00
|
|
|
/* optional feerate min/max for mutual close */
|
|
|
|
u32 *closing_feerate_range;
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
/* Reestablishment stuff: last sent commit and revocation details. */
|
|
|
|
bool last_was_revoke;
|
|
|
|
struct changed_htlc *last_sent_commit;
|
|
|
|
|
|
|
|
/* Blockheight at creation, scans for funding confirmations
|
|
|
|
* will start here */
|
2018-05-06 11:05:49 +02:00
|
|
|
u32 first_blocknum;
|
2018-04-03 09:19:39 +02:00
|
|
|
|
|
|
|
/* Feerate range */
|
|
|
|
u32 min_possible_feerate, max_possible_feerate;
|
2018-04-26 06:51:01 +02:00
|
|
|
|
2018-08-17 07:06:35 +02:00
|
|
|
/* Do we have an "impossible" future per_commitment_point from
|
|
|
|
* peer via option_data_loss_protect? */
|
2018-08-17 07:06:36 +02:00
|
|
|
const struct pubkey *future_per_commitment_point;
|
2019-02-21 01:01:33 +01:00
|
|
|
|
2022-03-21 01:58:54 +01:00
|
|
|
/* Min/max htlc amount allowed in channel. */
|
|
|
|
struct amount_msat htlc_minimum_msat, htlc_maximum_msat;
|
2022-03-21 01:58:23 +01:00
|
|
|
|
2019-02-21 01:01:33 +01:00
|
|
|
/* Feerate per channel */
|
|
|
|
u32 feerate_base, feerate_ppm;
|
2022-03-21 01:58:23 +01:00
|
|
|
|
2022-03-21 01:58:27 +01:00
|
|
|
/* But allow these feerates/htlcs up until this time. */
|
2021-09-23 04:42:47 +02:00
|
|
|
struct timeabs old_feerate_timeout;
|
|
|
|
u32 old_feerate_base, old_feerate_ppm;
|
2022-03-21 01:58:54 +01:00
|
|
|
struct amount_msat old_htlc_minimum_msat, old_htlc_maximum_msat;
|
2019-05-01 00:57:09 +02:00
|
|
|
|
|
|
|
/* If they used option_upfront_shutdown_script. */
|
|
|
|
const u8 *remote_upfront_shutdown_script;
|
2019-09-10 04:22:27 +02:00
|
|
|
|
2021-06-04 07:13:47 +02:00
|
|
|
/* At what commit numbers does `option_static_remotekey` apply? */
|
|
|
|
u64 static_remotekey_start[NUM_SIDES];
|
2019-08-24 23:06:08 +02:00
|
|
|
|
2021-09-09 07:29:35 +02:00
|
|
|
/* What features apply to this channel? */
|
|
|
|
const struct channel_type *type;
|
2020-08-13 19:41:02 +02:00
|
|
|
|
2019-08-24 23:06:08 +02:00
|
|
|
/* Any commands trying to forget us. */
|
|
|
|
struct command **forgets;
|
2020-08-05 07:30:56 +02:00
|
|
|
|
|
|
|
/* Our position in the round-robin list. */
|
2020-09-08 06:57:53 +02:00
|
|
|
u64 rr_number;
|
2020-09-10 21:43:40 +02:00
|
|
|
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
/* the one that initiated a bilateral close, NUM_SIDES if unknown. */
|
|
|
|
enum side closer;
|
|
|
|
|
|
|
|
/* Last known state_change cause */
|
|
|
|
enum state_change state_change_cause;
|
2020-11-24 01:54:56 +01:00
|
|
|
|
|
|
|
/* Outstanding command for this channel, v2 only */
|
|
|
|
struct command *openchannel_signed_cmd;
|
2021-06-17 03:28:18 +02:00
|
|
|
|
|
|
|
/* Block lease expires at, zero is no lease */
|
|
|
|
u32 lease_expiry;
|
|
|
|
|
|
|
|
/* Lease commitment, useful someone breaks their promise
|
|
|
|
* wrt channel fees */
|
|
|
|
secp256k1_ecdsa_signature *lease_commit_sig;
|
|
|
|
|
|
|
|
/* Lease commited maximum channel fee base msat */
|
|
|
|
u32 lease_chan_max_msat;
|
|
|
|
/* Lease commited max part per thousandth channel fee (ppm * 1000) */
|
|
|
|
u16 lease_chan_max_ppt;
|
2022-01-24 20:58:52 +01:00
|
|
|
|
|
|
|
/* Latest channel_update, for use in error messages. */
|
|
|
|
u8 *channel_update;
|
2022-06-24 02:48:18 +02:00
|
|
|
|
|
|
|
/* `Channel-shell` of this channel
|
|
|
|
* (Minimum information required to backup this channel). */
|
|
|
|
struct scb_chan *scb;
|
2018-02-12 11:10:46 +01:00
|
|
|
};
|
|
|
|
|
2022-07-16 06:49:29 +02:00
|
|
|
bool channel_is_connected(const struct channel *channel);
|
|
|
|
|
2021-01-20 02:09:38 +01:00
|
|
|
/* For v2 opens, a channel that has not yet been committed/saved to disk */
|
|
|
|
struct channel *new_unsaved_channel(struct peer *peer,
|
|
|
|
u32 feerate_base,
|
|
|
|
u32 feerate_ppm);
|
|
|
|
|
2021-01-20 02:07:04 +01:00
|
|
|
struct open_attempt *new_channel_open_attempt(struct channel *channel);
|
|
|
|
|
2018-02-19 02:06:14 +01:00
|
|
|
struct channel *new_channel(struct peer *peer, u64 dbid,
|
|
|
|
/* NULL or stolen */
|
2020-04-15 08:52:36 +02:00
|
|
|
struct wallet_shachain *their_shachain STEALS,
|
2018-02-19 02:06:14 +01:00
|
|
|
enum channel_state state,
|
2019-09-09 18:11:24 +02:00
|
|
|
enum side opener,
|
2018-02-19 02:06:14 +01:00
|
|
|
/* NULL or stolen */
|
2020-04-15 08:52:36 +02:00
|
|
|
struct log *log STEALS,
|
2018-02-23 06:53:44 +01:00
|
|
|
const char *transient_billboard TAKES,
|
2018-02-19 02:06:14 +01:00
|
|
|
u8 channel_flags,
|
|
|
|
const struct channel_config *our_config,
|
|
|
|
u32 minimum_depth,
|
|
|
|
u64 next_index_local,
|
|
|
|
u64 next_index_remote,
|
|
|
|
u64 next_htlc_id,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *funding,
|
|
|
|
struct amount_sat funding_sats,
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat push,
|
2019-09-30 23:47:16 +02:00
|
|
|
struct amount_sat our_funds,
|
2018-02-19 02:06:14 +01:00
|
|
|
bool remote_funding_locked,
|
|
|
|
/* NULL or stolen */
|
2020-04-15 08:52:36 +02:00
|
|
|
struct short_channel_id *scid STEALS,
|
2022-04-22 12:57:01 +02:00
|
|
|
struct short_channel_id *alias_local STEALS,
|
|
|
|
struct short_channel_id *alias_remote STEALS,
|
2020-09-09 09:20:53 +02:00
|
|
|
struct channel_id *cid,
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat our_msatoshi,
|
|
|
|
struct amount_msat msatoshi_to_us_min,
|
|
|
|
struct amount_msat msatoshi_to_us_max,
|
2020-04-15 08:52:36 +02:00
|
|
|
struct bitcoin_tx *last_tx STEALS,
|
2018-12-03 00:15:06 +01:00
|
|
|
const struct bitcoin_signature *last_sig,
|
2018-02-19 02:06:14 +01:00
|
|
|
/* NULL or stolen */
|
2020-08-13 19:45:02 +02:00
|
|
|
const struct bitcoin_signature *last_htlc_sigs STEALS,
|
2018-02-19 02:06:14 +01:00
|
|
|
const struct channel_info *channel_info,
|
2020-09-17 03:58:59 +02:00
|
|
|
const struct fee_states *fee_states TAKES,
|
2018-02-19 02:06:14 +01:00
|
|
|
/* NULL or stolen */
|
2020-04-15 08:52:36 +02:00
|
|
|
u8 *remote_shutdown_scriptpubkey STEALS,
|
2019-10-15 03:08:33 +02:00
|
|
|
const u8 *local_shutdown_scriptpubkey,
|
2018-03-07 01:06:07 +01:00
|
|
|
u64 final_key_idx,
|
2018-02-19 02:06:14 +01:00
|
|
|
bool last_was_revoke,
|
|
|
|
/* NULL or stolen */
|
2020-04-15 08:52:36 +02:00
|
|
|
struct changed_htlc *last_sent_commit STEALS,
|
2018-04-03 09:19:39 +02:00
|
|
|
u32 first_blocknum,
|
|
|
|
u32 min_possible_feerate,
|
2018-04-26 06:51:01 +02:00
|
|
|
u32 max_possible_feerate,
|
2018-07-23 04:23:02 +02:00
|
|
|
const struct basepoints *local_basepoints,
|
2018-08-17 07:06:36 +02:00
|
|
|
const struct pubkey *local_funding_pubkey,
|
2019-02-21 01:01:33 +01:00
|
|
|
const struct pubkey *future_per_commitment_point,
|
|
|
|
u32 feerate_base,
|
2019-05-01 00:57:09 +02:00
|
|
|
u32 feerate_ppm,
|
|
|
|
/* NULL or stolen */
|
2020-04-15 08:52:36 +02:00
|
|
|
const u8 *remote_upfront_shutdown_script STEALS,
|
2021-06-04 07:13:47 +02:00
|
|
|
u64 local_static_remotekey_start,
|
|
|
|
u64 remote_static_remotekey_start,
|
2021-09-09 07:29:35 +02:00
|
|
|
const struct channel_type *type STEALS,
|
2020-10-28 11:46:17 +01:00
|
|
|
enum side closer,
|
2021-03-15 21:25:41 +01:00
|
|
|
enum state_change reason,
|
|
|
|
/* NULL or stolen */
|
2021-06-17 03:28:18 +02:00
|
|
|
const struct bitcoin_outpoint *shutdown_wrong_funding STEALS,
|
2021-06-22 20:25:59 +02:00
|
|
|
const struct height_states *height_states TAKES,
|
2021-06-17 03:28:18 +02:00
|
|
|
u32 lease_expiry,
|
|
|
|
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
|
|
|
|
u32 lease_chan_max_msat,
|
2022-03-21 01:58:23 +01:00
|
|
|
u16 lease_chan_max_ppt,
|
2022-03-21 01:58:54 +01:00
|
|
|
struct amount_msat htlc_minimum_msat,
|
2022-03-21 01:58:23 +01:00
|
|
|
struct amount_msat htlc_maximum_msat);
|
2018-02-14 02:53:04 +01:00
|
|
|
|
2021-02-04 22:14:44 +01:00
|
|
|
/* new_inflight - Create a new channel_inflight for a channel */
|
|
|
|
struct channel_inflight *
|
|
|
|
new_inflight(struct channel *channel,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *funding_outpoint,
|
2021-02-04 22:14:44 +01:00
|
|
|
u32 funding_feerate,
|
2021-10-13 05:45:36 +02:00
|
|
|
struct amount_sat funding_sat,
|
2021-02-04 22:14:44 +01:00
|
|
|
struct amount_sat our_funds,
|
|
|
|
struct wally_psbt *funding_psbt STEALS,
|
|
|
|
struct bitcoin_tx *last_tx STEALS,
|
2021-06-17 03:28:18 +02:00
|
|
|
const struct bitcoin_signature last_sig,
|
|
|
|
const u32 lease_expiry,
|
|
|
|
const secp256k1_ecdsa_signature *lease_commit_sig,
|
|
|
|
const u32 lease_chan_max_msat,
|
2021-06-22 20:25:59 +02:00
|
|
|
const u16 lease_chan_max_ppt,
|
2021-12-08 18:42:07 +01:00
|
|
|
const u32 lease_blockheight_start,
|
|
|
|
const struct amount_msat lease_fee);
|
2021-02-04 22:14:44 +01:00
|
|
|
|
2021-01-07 20:03:06 +01:00
|
|
|
/* Given a txid, find an inflight channel stub. Returns NULL if none found */
|
|
|
|
struct channel_inflight *channel_inflight_find(struct channel *channel,
|
|
|
|
const struct bitcoin_txid *txid);
|
|
|
|
|
2021-02-19 19:44:36 +01:00
|
|
|
/* What's the most recent inflight for this channel? */
|
|
|
|
struct channel_inflight *
|
|
|
|
channel_current_inflight(const struct channel *channel);
|
|
|
|
|
|
|
|
/* What's the last feerate used for a funding tx on this channel? */
|
|
|
|
u32 channel_last_funding_feerate(const struct channel *channel);
|
|
|
|
|
2020-04-15 08:52:36 +02:00
|
|
|
void delete_channel(struct channel *channel STEALS);
|
2018-02-12 11:10:46 +01:00
|
|
|
|
|
|
|
const char *channel_state_name(const struct channel *channel);
|
2018-02-19 02:06:14 +01:00
|
|
|
const char *channel_state_str(enum channel_state state);
|
2018-02-12 11:10:46 +01:00
|
|
|
|
2019-07-25 04:47:34 +02:00
|
|
|
void channel_set_owner(struct channel *channel, struct subd *owner);
|
2018-02-12 11:13:04 +01:00
|
|
|
|
2018-02-12 11:13:04 +01:00
|
|
|
/* Channel has failed, but can try again. */
|
2019-11-01 00:38:00 +01:00
|
|
|
void channel_fail_reconnect(struct channel *channel,
|
|
|
|
const char *fmt, ...) PRINTF_FMT(2,3);
|
2019-07-26 04:11:18 +02:00
|
|
|
/* Channel has failed, but can try again after a minute. */
|
2019-11-01 00:38:00 +01:00
|
|
|
void channel_fail_reconnect_later(struct channel *channel,
|
|
|
|
const char *fmt,...) PRINTF_FMT(2,3);
|
2019-07-26 04:11:18 +02:00
|
|
|
|
2018-02-12 11:13:04 +01:00
|
|
|
/* Channel has failed, give up on it. */
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
void channel_fail_permanent(struct channel *channel,
|
|
|
|
enum state_change reason,
|
|
|
|
const char *fmt,
|
|
|
|
...);
|
2019-08-26 20:31:25 +02:00
|
|
|
/* Forget the channel. This is only used for the case when we "receive" error
|
|
|
|
* during CHANNELD_AWAITING_LOCKIN if we are "fundee". */
|
|
|
|
void channel_fail_forget(struct channel *channel, const char *fmt, ...);
|
2018-02-12 11:13:04 +01:00
|
|
|
/* Permanent error, but due to internal problems, not peer. */
|
|
|
|
void channel_internal_error(struct channel *channel, const char *fmt, ...);
|
|
|
|
|
2021-02-16 20:23:53 +01:00
|
|
|
/* Clean up any in-progress commands for a channel */
|
|
|
|
void channel_cleanup_commands(struct channel *channel, const char *why);
|
|
|
|
|
2018-02-12 11:13:04 +01:00
|
|
|
void channel_set_state(struct channel *channel,
|
2018-02-19 02:06:14 +01:00
|
|
|
enum channel_state old_state,
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
enum channel_state state,
|
|
|
|
enum state_change reason,
|
|
|
|
char *why);
|
|
|
|
|
|
|
|
const char *channel_change_state_reason_str(enum state_change reason);
|
2018-02-12 11:13:04 +01:00
|
|
|
|
2022-03-22 23:59:20 +01:00
|
|
|
/* Find a channel which is not onchain, if any: sets *others if there
|
|
|
|
* is more than one. */
|
|
|
|
struct channel *peer_any_active_channel(struct peer *peer, bool *others);
|
json-invoice: add routeboost, warnings.
We split json_invoice(), as it now needs to round-trip to the gossipd,
and uniqueness checks need to happen *after* gossipd replies to avoid
a race.
For every candidate channel gossipd gives us, we check that it's in
state NORMAL (not shutting down, not still waiting for lockin), that
it's connected, and that it has capacity. We then choose one with
probability weighted by excess capacity, so larger channels are more
likely.
As a side effect of this, we can tell if an invoice is unpayble (no
channels have sufficient incoming capacity) or difficuly (no *online*
channels have sufficient capacity), so we add those warnings.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-09-27 07:29:17 +02:00
|
|
|
|
2022-03-22 23:59:20 +01:00
|
|
|
/* Find a channel which is not yet saved to disk */
|
|
|
|
struct channel *peer_any_unsaved_channel(struct peer *peer, bool *others);
|
2021-01-22 01:55:23 +01:00
|
|
|
|
2018-04-05 18:33:14 +02:00
|
|
|
struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid);
|
|
|
|
|
2021-01-07 19:42:47 +01:00
|
|
|
struct channel *any_channel_by_scid(struct lightningd *ld,
|
|
|
|
const struct short_channel_id *scid);
|
2020-02-27 05:26:36 +01:00
|
|
|
|
2021-01-20 01:55:59 +01:00
|
|
|
/* Get channel by channel_id */
|
2020-09-17 22:28:46 +02:00
|
|
|
struct channel *channel_by_cid(struct lightningd *ld,
|
2021-01-20 01:55:59 +01:00
|
|
|
const struct channel_id *cid);
|
2020-09-17 22:28:46 +02:00
|
|
|
|
2021-06-14 23:09:51 +02:00
|
|
|
/* Find this channel within peer */
|
|
|
|
struct channel *find_channel_by_id(const struct peer *peer,
|
|
|
|
const struct channel_id *cid);
|
|
|
|
|
2022-03-22 23:59:20 +01:00
|
|
|
/* Find this channel within peer */
|
|
|
|
struct channel *find_channel_by_scid(const struct peer *peer,
|
|
|
|
const struct short_channel_id *scid);
|
|
|
|
|
2022-04-28 17:55:15 +02:00
|
|
|
/* Find a channel by its alias, either local or remote. */
|
|
|
|
struct channel *find_channel_by_alias(const struct peer *peer,
|
|
|
|
const struct short_channel_id *alias,
|
|
|
|
enum side side);
|
|
|
|
|
2018-02-12 11:13:04 +01:00
|
|
|
void channel_set_last_tx(struct channel *channel,
|
|
|
|
struct bitcoin_tx *tx,
|
2019-05-28 18:06:39 +02:00
|
|
|
const struct bitcoin_signature *sig,
|
2019-06-07 11:38:20 +02:00
|
|
|
enum wallet_tx_type type);
|
2018-02-12 11:13:04 +01:00
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
static inline bool channel_can_add_htlc(const struct channel *channel)
|
|
|
|
{
|
|
|
|
return channel->state == CHANNELD_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool channel_fees_can_change(const struct channel *channel)
|
|
|
|
{
|
|
|
|
return channel->state == CHANNELD_NORMAL
|
|
|
|
|| channel->state == CHANNELD_SHUTTING_DOWN;
|
|
|
|
}
|
|
|
|
|
2018-02-19 02:06:14 +01:00
|
|
|
static inline bool channel_state_on_chain(enum channel_state state)
|
2018-02-12 11:10:46 +01:00
|
|
|
{
|
2018-02-23 07:23:51 +01:00
|
|
|
return state == ONCHAIN;
|
2018-02-12 11:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool channel_on_chain(const struct channel *channel)
|
|
|
|
{
|
|
|
|
return channel_state_on_chain(channel->state);
|
|
|
|
}
|
|
|
|
|
2021-01-20 02:07:04 +01:00
|
|
|
static inline bool channel_unsaved(const struct channel *channel)
|
|
|
|
{
|
|
|
|
return channel->state == DUALOPEND_OPEN_INIT
|
|
|
|
&& channel->dbid == 0;
|
|
|
|
}
|
|
|
|
|
2018-02-12 11:10:46 +01:00
|
|
|
static inline bool channel_active(const struct channel *channel)
|
|
|
|
{
|
|
|
|
return channel->state != FUNDING_SPEND_SEEN
|
|
|
|
&& channel->state != CLOSINGD_COMPLETE
|
2021-01-20 02:07:04 +01:00
|
|
|
&& !channel_unsaved(channel)
|
2018-02-12 11:10:46 +01:00
|
|
|
&& !channel_on_chain(channel);
|
|
|
|
}
|
|
|
|
|
2021-06-14 23:09:51 +02:00
|
|
|
static inline bool channel_closed(const struct channel *channel)
|
|
|
|
{
|
|
|
|
return channel->state == CLOSINGD_COMPLETE
|
|
|
|
|| channel->state == AWAITING_UNILATERAL
|
|
|
|
|| channel->state == FUNDING_SPEND_SEEN
|
|
|
|
|| channel->state == ONCHAIN
|
|
|
|
|| channel->state == CLOSED;
|
|
|
|
}
|
|
|
|
|
2021-09-09 07:29:35 +02:00
|
|
|
static inline bool channel_has(const struct channel *channel, int f)
|
|
|
|
{
|
|
|
|
return channel_type_has(channel->type, f);
|
|
|
|
}
|
|
|
|
|
2022-05-06 15:38:34 +02:00
|
|
|
/**
|
|
|
|
* Either returns the short_channel_id if it is known or the local alias.
|
|
|
|
*
|
|
|
|
* This is used to refer to a channel by its scid. But sometimes we
|
|
|
|
* don't have a scid yet, e.g., for `zeroconf` channels, so we resort
|
|
|
|
* to referencing it by the local alias, which we have in that case.
|
|
|
|
*/
|
|
|
|
const struct short_channel_id *
|
|
|
|
channel_scid_or_local_alias(const struct channel *chan);
|
|
|
|
|
2018-07-23 04:23:03 +02:00
|
|
|
void get_channel_basepoints(struct lightningd *ld,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *peer_id,
|
2018-07-23 04:23:03 +02:00
|
|
|
const u64 dbid,
|
|
|
|
struct basepoints *local_basepoints,
|
|
|
|
struct pubkey *local_funding_pubkey);
|
2018-02-23 06:53:44 +01:00
|
|
|
|
|
|
|
void channel_set_billboard(struct channel *channel, bool perm,
|
|
|
|
const char *str TAKES);
|
2018-02-28 23:23:45 +01:00
|
|
|
|
|
|
|
struct htlc_in *channel_has_htlc_in(struct channel *channel);
|
|
|
|
struct htlc_out *channel_has_htlc_out(struct channel *channel);
|
|
|
|
|
2022-01-24 21:00:52 +01:00
|
|
|
const u8 *get_channel_update(struct channel *channel);
|
|
|
|
|
2022-03-21 01:58:27 +01:00
|
|
|
struct amount_msat htlc_max_possible_send(const struct channel *channel);
|
2018-02-12 11:10:46 +01:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_H */
|