2020-08-21 17:31:33 +08:00
|
|
|
#ifndef LIGHTNING_PLUGINS_SPENDER_MULTIFUNDCHANNEL_H
|
|
|
|
#define LIGHTNING_PLUGINS_SPENDER_MULTIFUNDCHANNEL_H
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-10-20 20:18:19 -05:00
|
|
|
#include <ccan/ccan/list/list.h>
|
|
|
|
#include <common/channel_id.h>
|
2020-08-21 17:31:33 +08:00
|
|
|
#include <plugins/libplugin.h>
|
|
|
|
|
|
|
|
extern const struct plugin_command multifundchannel_commands[];
|
|
|
|
extern const size_t num_multifundchannel_commands;
|
|
|
|
|
2020-10-22 13:47:48 -05:00
|
|
|
/* Which protocol this channel open is using.
|
|
|
|
* OPEN_CHANNEL implies opt_dual_fund */
|
|
|
|
enum channel_protocol {
|
|
|
|
FUND_CHANNEL,
|
|
|
|
OPEN_CHANNEL,
|
|
|
|
};
|
|
|
|
|
2020-10-20 20:18:19 -05:00
|
|
|
/* Current state of the funding process. */
|
|
|
|
enum multifundchannel_state {
|
|
|
|
/* We have not yet performed `fundchannel_start`. */
|
|
|
|
MULTIFUNDCHANNEL_START_NOT_YET = 0,
|
2020-10-22 13:56:25 -05:00
|
|
|
/* The `connect` command succeeded. `*/
|
|
|
|
MULTIFUNDCHANNEL_CONNECTED,
|
|
|
|
|
|
|
|
/* The `fundchannel_start` or `openchannel_init` command
|
|
|
|
* succeeded. */
|
2020-10-20 20:18:19 -05:00
|
|
|
MULTIFUNDCHANNEL_STARTED,
|
|
|
|
|
2020-10-22 13:56:25 -05:00
|
|
|
/* V1 states */
|
|
|
|
/* The `fundchannel_complete` command succeeded. */
|
|
|
|
MULTIFUNDCHANNEL_COMPLETED,
|
|
|
|
|
|
|
|
/* V2 states */
|
|
|
|
/* The `openchannel_update` command succeeded. */
|
2020-10-20 20:18:19 -05:00
|
|
|
MULTIFUNDCHANNEL_UPDATED,
|
2020-10-22 13:56:25 -05:00
|
|
|
/* The commitments for this destinations have been secured */
|
2020-10-20 20:18:19 -05:00
|
|
|
MULTIFUNDCHANNEL_SECURED,
|
2020-10-22 13:56:25 -05:00
|
|
|
/* We've recieved the peer sigs for this destination */
|
2020-10-20 20:18:19 -05:00
|
|
|
MULTIFUNDCHANNEL_SIGNED,
|
2021-03-26 17:50:56 -05:00
|
|
|
/* We've gotten their sigs, but still waiting for their commit sigs */
|
|
|
|
MULTIFUNDCHANNEL_SIGNED_NOT_SECURED,
|
2020-10-22 13:56:25 -05:00
|
|
|
|
|
|
|
/* The transaction might now be broadcasted. */
|
|
|
|
MULTIFUNDCHANNEL_DONE,
|
|
|
|
/* Global fail state. Oops */
|
2020-10-20 20:18:19 -05:00
|
|
|
MULTIFUNDCHANNEL_FAILED,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Stores a destination that was removed due to some failure. */
|
|
|
|
struct multifundchannel_removed {
|
|
|
|
/* The destination we removed. */
|
|
|
|
struct node_id id;
|
|
|
|
/* The method that failed:
|
|
|
|
connect, fundchannel_start, fundchannel_complete.
|
|
|
|
*/
|
|
|
|
const char *method;
|
2021-03-11 20:46:33 -06:00
|
|
|
const char *error_message;
|
2022-09-18 09:50:50 +09:30
|
|
|
enum jsonrpc_errcode error_code;
|
2021-03-11 20:46:33 -06:00
|
|
|
/* Optional JSON object containing extra data */
|
|
|
|
const char *error_data;
|
2020-10-20 20:18:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* the object for a single destination. */
|
|
|
|
struct multifundchannel_destination {
|
|
|
|
/* the overall multifundchannel command object. */
|
|
|
|
struct multifundchannel_command *mfc;
|
|
|
|
|
|
|
|
/* the overall multifundchannel_command contains an
|
|
|
|
array of multifundchannel_destinations.
|
|
|
|
this provides the index within the array.
|
|
|
|
|
|
|
|
this is used in debug printing.
|
|
|
|
*/
|
|
|
|
unsigned int index;
|
|
|
|
|
|
|
|
/* id for this destination. */
|
|
|
|
struct node_id id;
|
|
|
|
/* address hint for this destination, null if not
|
|
|
|
specified.
|
|
|
|
*/
|
|
|
|
const char *addrhint;
|
|
|
|
/* the features this destination has. */
|
|
|
|
const u8 *their_features;
|
|
|
|
|
|
|
|
/* whether we have `fundchannel_start`, failed `connect` or
|
|
|
|
`fundchannel_complete`, etc.
|
|
|
|
*/
|
|
|
|
enum multifundchannel_state state;
|
|
|
|
|
2020-10-22 13:45:55 -05:00
|
|
|
/* Last known state before failure */
|
|
|
|
enum multifundchannel_state fail_state;
|
|
|
|
|
2020-10-20 20:18:19 -05:00
|
|
|
/* the actual target script and address. */
|
|
|
|
const u8 *funding_script;
|
|
|
|
const char *funding_addr;
|
|
|
|
|
|
|
|
/* the upfront shutdown script for this channel */
|
|
|
|
const char *close_to_str;
|
|
|
|
|
|
|
|
/* The scriptpubkey we will close to. Only set if
|
|
|
|
* peer supports opt_upfront_shutdownscript and
|
|
|
|
* we passsed in a valid close_to_str */
|
|
|
|
const u8 *close_to_script;
|
|
|
|
|
|
|
|
/* the amount to be funded for this destination.
|
|
|
|
if the specified amount is "all" then the `all`
|
|
|
|
flag is set, and the amount is initially 0 until
|
|
|
|
we have figured out how much exactly "all" is,
|
|
|
|
after the dryrun stage.
|
|
|
|
*/
|
|
|
|
bool all;
|
|
|
|
struct amount_sat amount;
|
|
|
|
|
2022-06-08 11:05:10 +02:00
|
|
|
struct amount_sat *reserve;
|
|
|
|
|
2020-10-20 20:18:19 -05:00
|
|
|
/* the output index for this destination. */
|
|
|
|
unsigned int outnum;
|
|
|
|
|
|
|
|
/* whether the channel to this destination will
|
|
|
|
be announced.
|
|
|
|
*/
|
|
|
|
bool announce;
|
|
|
|
/* how much of the initial funding to push to
|
|
|
|
the destination.
|
|
|
|
*/
|
|
|
|
struct amount_msat push_msat;
|
|
|
|
|
|
|
|
/* the actual channel_id. */
|
|
|
|
struct channel_id channel_id;
|
|
|
|
|
2021-03-11 20:46:33 -06:00
|
|
|
const char *error_message;
|
2022-09-18 09:50:50 +09:30
|
|
|
enum jsonrpc_errcode error_code;
|
2021-03-11 20:46:33 -06:00
|
|
|
/* Optional JSON object containing extra data */
|
|
|
|
const char *error_data;
|
2020-10-20 20:18:19 -05:00
|
|
|
|
2020-10-22 13:47:48 -05:00
|
|
|
/* what channel protocol this destination is using */
|
|
|
|
enum channel_protocol protocol;
|
|
|
|
|
|
|
|
/* PSBT for the inflight channel open (OPEN_CHANNEL) */
|
2020-10-20 20:18:19 -05:00
|
|
|
struct wally_psbt *psbt;
|
2020-10-22 13:47:48 -05:00
|
|
|
|
|
|
|
/* PSBT for the inflight channel open, updated (OPEN_CHANNEL) */
|
2020-10-20 20:18:19 -05:00
|
|
|
struct wally_psbt *updated_psbt;
|
2020-10-22 13:47:48 -05:00
|
|
|
|
|
|
|
/* serial of the funding output for this channel (OPEN_CHANNEL) */
|
2020-10-20 20:18:19 -05:00
|
|
|
u64 funding_serial;
|
2021-06-08 16:55:06 -05:00
|
|
|
|
|
|
|
/* amount to request peer to lease (OPEN_CHANNEL) */
|
|
|
|
struct amount_sat request_amt;
|
2021-07-02 16:19:47 -05:00
|
|
|
|
|
|
|
/* Channel lease rates that we expect the peer to respond with */
|
|
|
|
struct lease_rates *rates;
|
2022-05-20 11:45:26 +02:00
|
|
|
|
|
|
|
/* Number of blocks to wait before sending `channel_ready`. */
|
|
|
|
u32 *mindepth;
|
2020-10-20 20:18:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The object for a single multifundchannel command. */
|
|
|
|
struct multifundchannel_command {
|
|
|
|
/* A unique numeric identifier for this particular
|
|
|
|
multifundchannel execution.
|
|
|
|
|
|
|
|
This is used for debug logs; we want to be able to
|
|
|
|
identify *which* multifundchannel is being described
|
|
|
|
in the debug logs, especially if the user runs
|
|
|
|
multiple `multifundchannel` commands in parallel, or
|
|
|
|
in very close sequence, which might confuse us with
|
|
|
|
*which* debug message belongs with *which* command.
|
|
|
|
|
|
|
|
We actually just reuse the id from the cmd.
|
|
|
|
Store it here for easier access.
|
|
|
|
*/
|
|
|
|
u64 id;
|
|
|
|
|
|
|
|
/* The plugin-level command. */
|
|
|
|
struct command *cmd;
|
|
|
|
/* An array of destinations. */
|
|
|
|
struct multifundchannel_destination *destinations;
|
|
|
|
/* Number of pending parallel fundchannel_start or
|
|
|
|
fundchannel_complete.
|
|
|
|
*/
|
|
|
|
size_t pending;
|
|
|
|
|
|
|
|
/* The feerate desired by the user. */
|
|
|
|
const char *feerate_str;
|
|
|
|
|
|
|
|
/* If specified, the feerate to be used for channel commitment
|
|
|
|
* transactions. Defaults to the `feerate_str` if not provided. */
|
|
|
|
const char *cmtmt_feerate_str;
|
|
|
|
|
|
|
|
/* The minimum number of confirmations for owned
|
|
|
|
UTXOs to be selected.
|
|
|
|
*/
|
|
|
|
u32 minconf;
|
|
|
|
/* The set of utxos to be used. */
|
|
|
|
const char *utxos_str;
|
|
|
|
/* How long should we keep going if things fail. */
|
|
|
|
size_t minchannels;
|
|
|
|
/* Array of destinations that were removed in a best-effort
|
|
|
|
attempt to fund as many channels as possible.
|
|
|
|
*/
|
|
|
|
struct multifundchannel_removed *removeds;
|
|
|
|
|
|
|
|
/* The PSBT of the funding transaction we are building.
|
|
|
|
Prior to `fundchannel_start` completing for all destinations,
|
|
|
|
this contains an unsigned incomplete transaction that is just a
|
|
|
|
reservation of the inputs.
|
|
|
|
After `fundchannel_start`, this contains an unsigned transaction
|
|
|
|
with complete outputs.
|
|
|
|
After `fundchannel_complete`, this contains a signed, finalized
|
|
|
|
transaction.
|
|
|
|
*/
|
|
|
|
struct wally_psbt *psbt;
|
|
|
|
/* The actual feerate of the PSBT. */
|
|
|
|
u32 feerate_per_kw;
|
|
|
|
/* The expected weight of the PSBT after adding in all the outputs.
|
|
|
|
* In weight units (sipa). */
|
|
|
|
u32 estimated_final_weight;
|
|
|
|
/* The txid of the final funding transaction. */
|
|
|
|
struct bitcoin_txid *txid;
|
|
|
|
|
|
|
|
/* The actual tx of the actual final funding transaction
|
|
|
|
that was broadcast.
|
|
|
|
*/
|
|
|
|
const char *final_tx;
|
|
|
|
const char *final_txid;
|
|
|
|
|
|
|
|
/* V2 things */
|
|
|
|
struct list_node list;
|
2020-10-22 14:29:28 -05:00
|
|
|
|
|
|
|
/* V2 channel opens use this flag to gate PSBT signing */
|
|
|
|
bool sigs_collected;
|
2020-10-20 20:18:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Use this instead of forward_error. */
|
|
|
|
struct command_result *
|
|
|
|
mfc_forward_error(struct command *cmd,
|
|
|
|
const char *buf, const jsmntok_t *error,
|
|
|
|
struct multifundchannel_command *);
|
|
|
|
|
2021-03-11 20:46:33 -06:00
|
|
|
/* When a destination fails, record the furthest state reached, and the
|
|
|
|
* error message for the failure */
|
|
|
|
void fail_destination_tok(struct multifundchannel_destination *dest,
|
|
|
|
const char *buf,
|
|
|
|
const jsmntok_t *error);
|
|
|
|
void fail_destination_msg(struct multifundchannel_destination *dest,
|
fix: build with gcc 13 with enum and int mismatch
gcc 13 add an extra check for the enum in the definition
of a method. In our case the code was failing with the
following error, and the compiler is right, our definition
is different from the implementation.
```
$ make
CC: cc -DBINTOPKGLIBEXECDIR="../libexec/c-lightning" -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror -Wno-maybe-uninitialized -Wshadow=local -std=gnu11 -g -fstack-protector-strong -Og -I ccan -I external/libwally-core/include/ -I external/libwally-core/src/secp256k1/include/ -I external/jsmn/ -I external/libbacktrace/ -I external/gheap/ -I external/x86_64-redhat-linux/libbacktrace-build -I external/libsodium/src/libsodium/include -I external/libsodium/src/libsodium/include/sodium -I external/x86_64-redhat-linux/libsodium-build/src/libsodium/include -I . -I/usr/local/include -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS -DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1 -DCOMPAT_V072=1 -DCOMPAT_V073=1 -DCOMPAT_V080=1 -DCOMPAT_V081=1 -DCOMPAT_V082=1 -DCOMPAT_V090=1 -DCOMPAT_V0100=1 -DCOMPAT_V0121=1 -DBUILD_ELEMENTS=1 -c -o
LD: cc -Og config.vars -Lexternal/x86_64-redhat-linux -lwallycore -lsecp256k1 -ljsmn -lbacktrace -lsodium -L/usr/local/include -lm -lgmp -lsqlite3 -lz -o
cc plugins/spender/multifundchannel.c
plugins/spender/multifundchannel.c:71:6: error: conflicting types for ‘fail_destination_msg’ due to enum/integer mismatch; have ‘void(struct multifundchannel_destination *, enum jsonrpc_errcode, const char *)’ [-Werror=enum-int-mismatch]
71 | void fail_destination_msg(struct multifundchannel_destination *dest,
| ^~~~~~~~~~~~~~~~~~~~
In file included from plugins/spender/multifundchannel.c:13:
./plugins/spender/multifundchannel.h:263:6: note: previous declaration of ‘fail_destination_msg’ with type ‘void(struct multifundchannel_destination *, int, const char *)’
263 | void fail_destination_msg(struct multifundchannel_destination *dest,
| ^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:307: plugins/spender/multifundchannel.o] Error 1
```
The gcc 13 is not released yet, but fedora beta is out for public testing,
so it is useful fix this error in this release candidate cycle.
Changelog-Fixed: Build: Compilation with upcoming gcc 13
Reported-by: @grubles
Link: https://github.com/ElementsProject/lightning/issues/6175
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-04-16 17:35:22 +02:00
|
|
|
enum jsonrpc_errcode error_code,
|
2021-03-11 20:46:33 -06:00
|
|
|
const char *err_str TAKES);
|
2020-10-22 13:45:55 -05:00
|
|
|
|
2020-10-22 13:47:48 -05:00
|
|
|
/* dest_count - Returns count of destinations using given protocol version */
|
|
|
|
size_t dest_count(const struct multifundchannel_command *mfc,
|
|
|
|
enum channel_protocol);
|
|
|
|
|
2021-03-10 20:20:21 -06:00
|
|
|
/* Is this destination using the v2/OPEN_CHANNEL protocol? */
|
|
|
|
bool is_v2(const struct multifundchannel_destination *dest);
|
|
|
|
|
2020-10-20 20:18:19 -05:00
|
|
|
/* Use this instead of command_finished. */
|
|
|
|
struct command_result *
|
|
|
|
mfc_finished(struct multifundchannel_command *, struct json_stream *response);
|
|
|
|
|
2020-10-22 14:07:33 -05:00
|
|
|
struct command_result *
|
|
|
|
after_channel_start(struct multifundchannel_command *mfc);
|
|
|
|
|
2020-10-22 14:17:11 -05:00
|
|
|
struct command_result *
|
|
|
|
perform_fundchannel_complete(struct multifundchannel_command *mfc);
|
|
|
|
|
2020-10-22 14:29:28 -05:00
|
|
|
struct command_result *
|
|
|
|
perform_signpsbt(struct multifundchannel_command *mfc);
|
|
|
|
|
2020-10-22 14:32:45 -05:00
|
|
|
struct command_result *
|
|
|
|
multifundchannel_finished(struct multifundchannel_command *mfc);
|
|
|
|
|
2020-10-22 14:01:23 -05:00
|
|
|
struct command_result *
|
|
|
|
redo_multifundchannel(struct multifundchannel_command *mfc,
|
2021-03-10 20:22:03 -06:00
|
|
|
const char *failing_method,
|
|
|
|
const char *why);
|
2020-08-21 17:31:33 +08:00
|
|
|
#endif /* LIGHTNING_PLUGINS_SPENDER_MULTIFUNDCHANNEL_H */
|