2015-09-25 04:21:18 +02:00
|
|
|
#ifndef LIGHTNING_STATE_H
|
|
|
|
#define LIGHTNING_STATE_H
|
2016-01-21 21:08:08 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <ccan/tal/tal.h>
|
2015-09-25 04:21:18 +02:00
|
|
|
#include <state_types.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the core state machine.
|
|
|
|
*
|
2016-01-21 21:11:47 +01:00
|
|
|
* Calling the state machine updates updates peer->state, and may call
|
|
|
|
* various peer_ callbacks. It also returns the status of the current
|
|
|
|
* command.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static inline bool state_is_error(enum state s)
|
|
|
|
{
|
|
|
|
return s >= STATE_ERR_ANCHOR_TIMEOUT && s <= STATE_ERR_INTERNAL;
|
|
|
|
}
|
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
struct peer;
|
2016-01-21 21:11:47 +01:00
|
|
|
struct bitcoin_tx;
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:46 +01:00
|
|
|
static inline bool input_is_pkt(enum state_input input)
|
2015-09-25 04:21:18 +02:00
|
|
|
{
|
|
|
|
return input <= PKT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
union input {
|
|
|
|
Pkt *pkt;
|
|
|
|
struct command *cmd;
|
|
|
|
struct bitcoin_event *btc;
|
2015-09-25 04:21:18 +02:00
|
|
|
struct htlc *htlc;
|
|
|
|
struct htlc_progress *htlc_prog;
|
2015-09-25 04:21:18 +02:00
|
|
|
};
|
|
|
|
|
2016-01-21 21:11:46 +01:00
|
|
|
enum command_status state(const tal_t *ctx,
|
|
|
|
struct peer *peer,
|
|
|
|
const enum state_input input,
|
|
|
|
const union input *idata,
|
2016-01-21 21:11:47 +01:00
|
|
|
Pkt **out,
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx **broadcast);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/* Any CMD_SEND_HTLC_* */
|
2015-09-25 04:21:18 +02:00
|
|
|
#define CMD_SEND_UPDATE_ANY INPUT_MAX
|
|
|
|
|
|
|
|
/* a == b? (or one of several for CMD_SEND_UPDATE_ANY) */
|
|
|
|
static inline bool input_is(enum state_input a, enum state_input b)
|
|
|
|
{
|
|
|
|
if (b == CMD_SEND_UPDATE_ANY) {
|
|
|
|
/* Single | here, we want to record all. */
|
2016-03-08 01:12:15 +01:00
|
|
|
return input_is(a, CMD_SEND_HTLC_ADD)
|
2015-09-25 04:21:18 +02:00
|
|
|
| input_is(a, CMD_SEND_HTLC_FULFILL)
|
2016-03-08 01:11:15 +01:00
|
|
|
| input_is(a, CMD_SEND_HTLC_FAIL);
|
2015-09-25 04:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For test_state_coverate to make the states. */
|
|
|
|
#ifdef MAPPING_INPUTS
|
|
|
|
MAPPING_INPUTS(b);
|
|
|
|
#endif
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
struct signature;
|
|
|
|
|
2016-01-21 21:11:46 +01:00
|
|
|
/* Inform peer have an unexpected packet. */
|
|
|
|
void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt);
|
|
|
|
|
2016-01-21 21:11:46 +01:00
|
|
|
/* Current HTLC management.
|
|
|
|
* The "current" htlc is set before sending CMD_SEND_HTLC_*, or by
|
|
|
|
* accept_pkt_htlc_*.
|
|
|
|
*
|
|
|
|
* After that the state machine manages the current htlc, eventually giving one
|
|
|
|
* of the following calls (which should reset the current HTLC):
|
|
|
|
*
|
|
|
|
* - peer_htlc_declined: sent PKT_UPDATE_DECLINE_HTLC.
|
|
|
|
* - peer_htlc_ours_deferred: their update was higher priority, retry later.
|
|
|
|
* - peer_htlc_added: a new HTLC was added successfully.
|
|
|
|
* - peer_htlc_fulfilled: an existing HTLC was fulfilled successfully.
|
2016-03-15 07:37:12 +01:00
|
|
|
* - peer_htlc_fail: an existing HTLC failed to route/timedout/etc.
|
2016-01-21 21:11:46 +01:00
|
|
|
* - peer_htlc_aborted: eg. comms error
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Someone declined our HTLC: details in pkt (we will also get CMD_FAIL) */
|
|
|
|
void peer_htlc_declined(struct peer *peer, const Pkt *pkt);
|
|
|
|
/* Called when their update overrides our update cmd. */
|
|
|
|
void peer_htlc_ours_deferred(struct peer *peer);
|
2016-03-08 01:11:15 +01:00
|
|
|
/* Successfully added/fulfilled/timedout/fail an HTLC. */
|
2016-01-21 21:11:46 +01:00
|
|
|
void peer_htlc_done(struct peer *peer);
|
|
|
|
/* Someone aborted an existing HTLC. */
|
|
|
|
void peer_htlc_aborted(struct peer *peer);
|
|
|
|
|
|
|
|
/* An on-chain transaction revealed an R value. */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct htlc *peer_tx_revealed_r_value(struct peer *peer,
|
|
|
|
const struct bitcoin_event *btc);
|
2016-01-21 21:11:46 +01:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/* Create various kinds of packets, allocated off @ctx */
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *pkt_open(const tal_t *ctx, const struct peer *peer,
|
2016-01-21 21:11:45 +01:00
|
|
|
OpenChannel__AnchorOffer anchor);
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *pkt_anchor(const tal_t *ctx, const struct peer *peer);
|
|
|
|
Pkt *pkt_open_commit_sig(const tal_t *ctx, const struct peer *peer);
|
|
|
|
Pkt *pkt_open_complete(const tal_t *ctx, const struct peer *peer);
|
2016-03-08 01:12:15 +01:00
|
|
|
Pkt *pkt_htlc_add(const tal_t *ctx, const struct peer *peer,
|
|
|
|
const struct htlc_progress *htlc_prog);
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *pkt_htlc_fulfill(const tal_t *ctx, const struct peer *peer,
|
2015-09-25 04:21:18 +02:00
|
|
|
const struct htlc_progress *htlc_prog);
|
2016-03-08 01:11:15 +01:00
|
|
|
Pkt *pkt_htlc_fail(const tal_t *ctx, const struct peer *peer,
|
2015-09-25 04:21:18 +02:00
|
|
|
const struct htlc_progress *htlc_prog);
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer);
|
|
|
|
Pkt *pkt_update_signature(const tal_t *ctx, const struct peer *peer);
|
|
|
|
Pkt *pkt_update_complete(const tal_t *ctx, const struct peer *peer);
|
2016-01-21 21:11:47 +01:00
|
|
|
Pkt *pkt_err(const tal_t *ctx, const char *fmt, ...);
|
2016-03-24 02:39:41 +01:00
|
|
|
Pkt *pkt_close_clearing(const tal_t *ctx, const struct peer *peer);
|
|
|
|
Pkt *pkt_close_signature(const tal_t *ctx, const struct peer *peer);
|
2016-01-21 21:11:46 +01:00
|
|
|
Pkt *pkt_err_unexpected(const tal_t *ctx, const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Process various packets: return an error packet on failure. */
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_open(const tal_t *ctx,
|
2016-01-21 21:11:47 +01:00
|
|
|
struct peer *peer,
|
|
|
|
const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_anchor(const tal_t *ctx,
|
2016-01-21 21:11:47 +01:00
|
|
|
struct peer *peer,
|
|
|
|
const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_open_commit_sig(const tal_t *ctx,
|
2016-01-21 21:11:47 +01:00
|
|
|
struct peer *peer, const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-03-08 01:09:15 +01:00
|
|
|
Pkt *accept_pkt_open_complete(const tal_t *ctx,
|
|
|
|
struct peer *peer, const Pkt *pkt);
|
|
|
|
|
2016-03-08 01:12:15 +01:00
|
|
|
Pkt *accept_pkt_htlc_add(const tal_t *ctx,
|
|
|
|
struct peer *peer, const Pkt *pkt,
|
|
|
|
Pkt **decline);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-03-08 01:11:15 +01:00
|
|
|
Pkt *accept_pkt_htlc_fail(const tal_t *ctx,
|
|
|
|
struct peer *peer, const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_htlc_fulfill(const tal_t *ctx,
|
2016-01-21 21:11:46 +01:00
|
|
|
struct peer *peer, const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_update_accept(const tal_t *ctx,
|
2016-01-21 21:11:46 +01:00
|
|
|
struct peer *peer, const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_update_complete(const tal_t *ctx,
|
2016-01-21 21:11:46 +01:00
|
|
|
struct peer *peer, const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-01-21 21:11:45 +01:00
|
|
|
Pkt *accept_pkt_update_signature(const tal_t *ctx,
|
2016-01-21 21:11:46 +01:00
|
|
|
struct peer *peer,
|
2016-01-21 21:11:46 +01:00
|
|
|
const Pkt *pkt);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-03-24 02:39:41 +01:00
|
|
|
Pkt *accept_pkt_close_clearing(const tal_t *ctx, struct peer *peer, const Pkt *pkt);
|
|
|
|
Pkt *accept_pkt_close_sig(const tal_t *ctx, struct peer *peer, const Pkt *pkt,
|
|
|
|
bool *matches);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/**
|
|
|
|
* committed_to_htlcs: do we have any locked-in HTLCs?
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
*
|
|
|
|
* If we were to generate a commit tx now, would it have HTLCs in it?
|
|
|
|
*/
|
2016-01-21 21:11:45 +01:00
|
|
|
bool committed_to_htlcs(const struct peer *peer);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2016-03-24 02:39:41 +01:00
|
|
|
/**
|
|
|
|
* peer_has_close_sig: do we have a valid close_sig from them?
|
|
|
|
* @peer: the state data for this peer.
|
|
|
|
*
|
|
|
|
* We use any acceptable close tx, if we have one, in preference to a commit tx.
|
|
|
|
*/
|
|
|
|
bool peer_has_close_sig(const struct peer *peer);
|
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_anchor: create a watch for the anchor transaction.
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @depthok: the input to give when anchor reaches expected depth.
|
|
|
|
* @timeout: the input to give if anchor doesn't reach depth in time.
|
|
|
|
* @unspent: the input to give if anchor is unspent after @depthok.
|
|
|
|
* @theyspent: the input to give if they spend anchor with their commit tx.
|
|
|
|
* @otherspent: the input to give if they spend anchor otherwise.
|
|
|
|
*
|
|
|
|
* @depthok can be INPUT_NONE if it's our anchor (we don't time
|
|
|
|
* ourselves out).
|
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_watch_anchor(struct peer *peer,
|
|
|
|
enum state_input depthok,
|
|
|
|
enum state_input timeout,
|
|
|
|
enum state_input unspent,
|
|
|
|
enum state_input theyspent,
|
|
|
|
enum state_input otherspent);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_unwatch_anchor_depth: remove depth watch for the anchor.
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @depthok: the input to give when anchor reaches expected depth.
|
|
|
|
* @timeout: the input to give if anchor doesn't reach depth in time.
|
|
|
|
*
|
|
|
|
* @depthok and @timeout must match bitcoin_watch_anchor() call.
|
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_unwatch_anchor_depth(struct peer *peer,
|
|
|
|
enum state_input depthok,
|
|
|
|
enum state_input timeout);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_delayed: watch this (commit) tx, tell me when I can spend it
|
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @tx: the tx we're watching.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @canspend: the input to give when commit reaches spendable depth.
|
2015-09-25 04:21:18 +02:00
|
|
|
*
|
|
|
|
* Note that this tx may be malleated, as it's dual-signed.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_watch_delayed(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
enum state_input canspend);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_tx: watch this tx until it's "irreversible"
|
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @tx: the tx we're watching.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @done: the input to give when tx is completely buried.
|
|
|
|
*
|
2016-01-21 21:11:47 +01:00
|
|
|
* Once this fires we consider the channel completely closed and stop
|
|
|
|
* watching (eg 100 txs down).
|
|
|
|
*
|
|
|
|
* This is used for watching a transaction we sent (such as a steal,
|
|
|
|
* or spend of their close, etc).
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_watch_tx(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
enum state_input done);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_close: watch for close tx until it's "irreversible" (or timedout)
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @done: the input to give when tx is completely buried.
|
2016-01-21 21:11:47 +01:00
|
|
|
* @timedout: the input to give if we time out (they don't provide sig).
|
2015-09-25 04:21:18 +02:00
|
|
|
*
|
2016-01-21 21:11:47 +01:00
|
|
|
* Once this fires we consider the channel completely closed and stop
|
|
|
|
* watching (eg 100 txs down).
|
|
|
|
*
|
2016-01-21 21:11:47 +01:00
|
|
|
* This is used for watching a mutual close.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_watch_close(struct peer *peer,
|
|
|
|
enum state_input done, enum state_input timedout);
|
2016-01-21 21:11:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* peer_unwatch_close_timeout: remove timeout for the close transaction
|
|
|
|
* @peer: the state data for this peer.
|
|
|
|
* @timeout: the input to give if anchor doesn't reach depth in time.
|
|
|
|
*
|
|
|
|
* This is called once we have successfully received their signature.
|
|
|
|
*/
|
|
|
|
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* peer_watch_anchor: create a watch for the anchor transaction.
|
|
|
|
* @peer: the state data for this peer.
|
|
|
|
* @depthok: the input to give when anchor reaches expected depth.
|
|
|
|
* @timeout: the input to give if anchor doesn't reach depth in time.
|
|
|
|
* @unspent: the input to give if anchor is unspent after @depthok.
|
|
|
|
* @theyspent: the input to give if they spend anchor with their commit tx.
|
|
|
|
* @otherspent: the input to give if they spend anchor otherwise.
|
|
|
|
*
|
|
|
|
* @depthok can be INPUT_NONE if it's our anchor (we don't time
|
|
|
|
* ourselves out).
|
|
|
|
*/
|
|
|
|
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_our_htlc_outputs: HTLC outputs from our commit tx to watch.
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @tx: the commitment tx
|
|
|
|
* @tous_timeout: input to give when a HTLC output to us times out.
|
|
|
|
* @tothem_spent: input to give when a HTLC output to them is spent.
|
|
|
|
* @tothem_timeout: input to give when a HTLC output to them times out.
|
2016-01-21 21:11:47 +01:00
|
|
|
*
|
|
|
|
* Returns true if there were any htlc outputs to watch.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
bool peer_watch_our_htlc_outputs(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
enum state_input tous_timeout,
|
|
|
|
enum state_input tothem_spent,
|
|
|
|
enum state_input tothem_timeout);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_their_htlc_outputs: HTLC outputs from their commit tx to watch.
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @tx: the commitment tx
|
|
|
|
* @tous_timeout: input to give when a HTLC output to us times out.
|
|
|
|
* @tothem_spent: input to give when a HTLC output to them is spent.
|
|
|
|
* @tothem_timeout: input to give when a HTLC output to them times out.
|
2016-01-21 21:11:47 +01:00
|
|
|
*
|
|
|
|
* Returns true if there were any htlc outputs to watch.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
bool peer_watch_their_htlc_outputs(struct peer *peer,
|
|
|
|
const struct bitcoin_event *tx,
|
|
|
|
enum state_input tous_timeout,
|
|
|
|
enum state_input tothem_spent,
|
|
|
|
enum state_input tothem_timeout);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_unwatch_htlc_output: stop watching an HTLC
|
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @htlc: the htlc to stop watching
|
2016-01-21 21:11:47 +01:00
|
|
|
* @all_done: input to give if we're not watching any outputs anymore.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_unwatch_htlc_output(struct peer *peer,
|
|
|
|
const struct htlc *htlc,
|
|
|
|
enum state_input all_done);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_unwatch_all_htlc_outputs: stop watching all HTLCs
|
2016-01-21 21:11:45 +01:00
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_unwatch_all_htlc_outputs(struct peer *peer);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_watch_htlc_spend: watch our spend of an HTLC output
|
|
|
|
* @peer: the state data for this peer.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @tx: the commitment tx
|
2016-01-21 21:11:47 +01:00
|
|
|
* @htlc: the htlc the tx is spending an output of
|
2015-09-25 04:21:18 +02:00
|
|
|
* @done: input to give when it's completely buried.
|
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_watch_htlc_spend(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
const struct htlc *htlc,
|
|
|
|
enum state_input done);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/**
|
2016-01-21 21:11:47 +01:00
|
|
|
* peer_unwatch_htlc_spend: stop watching our HTLC spend
|
|
|
|
* @peer: the state data for this peer.
|
|
|
|
* @htlc: the htlc to stop watching the spend for.
|
2015-09-25 04:21:18 +02:00
|
|
|
* @all_done: input to give if we're not watching anything anymore.
|
|
|
|
*/
|
2016-01-21 21:11:47 +01:00
|
|
|
void peer_unwatch_htlc_spend(struct peer *peer,
|
|
|
|
const struct htlc *htlc,
|
|
|
|
enum state_input all_done);
|
|
|
|
|
2016-03-24 02:39:41 +01:00
|
|
|
/**
|
|
|
|
* peer_watch_htlcs_cleared: tell us when no HTLCs are in commit txs.
|
|
|
|
* @peer: the state data for this peer.
|
|
|
|
* @all_done: input to give when all HTLCs are done.
|
|
|
|
*/
|
|
|
|
void peer_watch_htlcs_cleared(struct peer *peer,
|
|
|
|
enum state_input all_done);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* peer_calculate_close_fee: figure out what the fee for closing is.
|
|
|
|
* @peer: the state data for this peer.
|
|
|
|
*/
|
|
|
|
void peer_calculate_close_fee(struct peer *peer);
|
|
|
|
|
2016-01-21 21:11:47 +01:00
|
|
|
/* Start creation of the bitcoin anchor tx. */
|
|
|
|
void bitcoin_create_anchor(struct peer *peer, enum state_input done);
|
|
|
|
|
|
|
|
/* We didn't end up broadcasting the anchor: release the utxos.
|
|
|
|
* If done != INPUT_NONE, remove existing create_anchor too. */
|
|
|
|
void bitcoin_release_anchor(struct peer *peer, enum state_input done);
|
|
|
|
|
|
|
|
/* Get the bitcoin anchor tx. */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Create a bitcoin close tx. */
|
2016-03-08 01:08:15 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_close(const tal_t *ctx, struct peer *peer);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Create a bitcoin spend tx (to spend our commit's outputs) */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_spend_ours(const tal_t *ctx,
|
|
|
|
const struct peer *peer);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Create a bitcoin spend tx (to spend their commit's outputs) */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_spend_theirs(const tal_t *ctx,
|
|
|
|
const struct peer *peer,
|
|
|
|
const struct bitcoin_event *btc);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Create a bitcoin steal tx (to steal all their commit's outputs) */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_steal(const tal_t *ctx,
|
|
|
|
const struct peer *peer,
|
|
|
|
struct bitcoin_event *btc);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Create our commit tx */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_commit(const tal_t *ctx, struct peer *peer);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
/* Create a HTLC refund collection */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_htlc_timeout(const tal_t *ctx,
|
|
|
|
const struct peer *peer,
|
|
|
|
const struct htlc *htlc);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
|
|
|
/* Create a HTLC collection */
|
2016-01-21 21:11:47 +01:00
|
|
|
const struct bitcoin_tx *bitcoin_htlc_spend(const tal_t *ctx,
|
|
|
|
const struct peer *peer,
|
|
|
|
const struct htlc *htlc);
|
2015-09-25 04:21:18 +02:00
|
|
|
|
2015-09-25 04:21:18 +02:00
|
|
|
#endif /* LIGHTNING_STATE_H */
|