2017-01-10 15:37:51 +10:30
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_LIGHTNINGD_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_LIGHTNINGD_H
|
|
|
|
#include "config.h"
|
2017-07-10 10:31:35 +02:00
|
|
|
#include <bitcoin/chainparams.h>
|
2017-02-24 16:22:56 +10:30
|
|
|
#include <bitcoin/privkey.h>
|
2017-01-10 15:38:33 +10:30
|
|
|
#include <ccan/container_of/container_of.h>
|
2017-08-29 01:34:01 +09:30
|
|
|
#include <ccan/time/time.h>
|
|
|
|
#include <ccan/timer/timer.h>
|
2017-04-01 21:31:13 +10:30
|
|
|
#include <lightningd/htlc_end.h>
|
2018-09-20 13:46:50 +02:00
|
|
|
#include <lightningd/plugin.h>
|
2017-08-29 01:34:01 +09:30
|
|
|
#include <stdio.h>
|
2018-03-02 14:56:39 +01:00
|
|
|
#include <wallet/txfilter.h>
|
2017-05-23 22:07:20 +02:00
|
|
|
#include <wallet/wallet.h>
|
2017-01-10 15:37:51 +10:30
|
|
|
|
2017-08-29 01:34:01 +09:30
|
|
|
/* Various adjustable things. */
|
|
|
|
struct config {
|
|
|
|
/* How long do we want them to lock up their funds? (blocks) */
|
|
|
|
u32 locktime_blocks;
|
|
|
|
|
|
|
|
/* How long do we let them lock up our funds? (blocks) */
|
|
|
|
u32 locktime_max;
|
|
|
|
|
|
|
|
/* How many confirms until we consider an anchor "settled". */
|
|
|
|
u32 anchor_confirms;
|
|
|
|
|
|
|
|
/* Maximum percent of fee rate we'll accept. */
|
|
|
|
u32 commitment_fee_max_percent;
|
|
|
|
|
|
|
|
/* Minimum percent of fee rate we'll accept. */
|
|
|
|
u32 commitment_fee_min_percent;
|
|
|
|
|
|
|
|
/* Percent of fee rate we'll use. */
|
|
|
|
u32 commitment_fee_percent;
|
|
|
|
|
2017-10-23 14:46:57 +10:30
|
|
|
/* Minimum CLTV to subtract from incoming HTLCs to outgoing */
|
|
|
|
u32 cltv_expiry_delta;
|
|
|
|
|
|
|
|
/* Minimum CLTV if we're the final hop.*/
|
|
|
|
u32 cltv_final;
|
|
|
|
|
2017-08-29 01:34:01 +09:30
|
|
|
/* Fee rates. */
|
|
|
|
u32 fee_base;
|
|
|
|
s32 fee_per_satoshi;
|
|
|
|
|
|
|
|
/* How long between changing commit and sending COMMIT message. */
|
2018-05-17 14:16:22 +09:30
|
|
|
u32 commit_time_ms;
|
2017-08-29 01:34:01 +09:30
|
|
|
|
2018-01-10 13:13:23 +10:30
|
|
|
/* How often to broadcast gossip (msec) */
|
2018-10-15 15:27:38 +10:30
|
|
|
u32 broadcast_interval_msec;
|
2018-01-10 13:13:23 +10:30
|
|
|
|
2018-01-09 15:45:07 +01:00
|
|
|
/* Channel update interval */
|
|
|
|
u32 channel_update_interval;
|
2018-01-16 19:54:46 +10:30
|
|
|
|
|
|
|
/* Do we let the funder set any fee rate they want */
|
|
|
|
bool ignore_fee_limits;
|
2018-04-18 15:23:15 +02:00
|
|
|
|
|
|
|
/* Number of blocks to rescan from the current head, or absolute
|
|
|
|
* blockheight if rescan >= 500'000 */
|
|
|
|
s32 rescan;
|
2018-05-10 08:48:19 +09:30
|
|
|
|
|
|
|
/* ipv6 bind disable */
|
|
|
|
bool no_ipv6_bind;
|
2018-06-11 19:50:37 +02:00
|
|
|
|
|
|
|
/* Accept fee changes only if they are in the range our_fee -
|
|
|
|
* our_fee*multiplier */
|
|
|
|
u32 max_fee_multiplier;
|
2018-06-20 13:11:25 +02:00
|
|
|
|
|
|
|
/* Are we allowed to use DNS lookup for peers. */
|
|
|
|
bool use_dns;
|
2017-08-29 01:34:01 +09:30
|
|
|
};
|
|
|
|
|
2017-08-29 01:39:01 +09:30
|
|
|
struct lightningd {
|
|
|
|
/* The directory to find all the subdaemons. */
|
|
|
|
const char *daemon_dir;
|
2017-08-29 01:34:01 +09:30
|
|
|
|
2018-02-16 12:30:41 +10:30
|
|
|
/* Are we told to run in the background. */
|
|
|
|
bool daemon;
|
|
|
|
|
2018-09-03 10:11:27 +09:30
|
|
|
int pid_fd;
|
|
|
|
|
2017-08-29 01:34:01 +09:30
|
|
|
/* Our config dir, and rpc file */
|
|
|
|
char *config_dir;
|
2018-07-24 22:32:58 +02:00
|
|
|
|
|
|
|
/* Location of the RPC socket. */
|
2017-08-29 01:34:01 +09:30
|
|
|
char *rpc_filename;
|
|
|
|
|
2018-11-14 08:12:03 +01:00
|
|
|
/* The root of the jsonrpc interface. Can be shut down
|
|
|
|
* separately from the rest of the daemon to allow a clean
|
|
|
|
* shutdown, which frees all pending cmds in a DB
|
|
|
|
* transaction. */
|
|
|
|
struct jsonrpc *jsonrpc;
|
2018-07-24 22:32:58 +02:00
|
|
|
|
2018-07-11 11:11:09 +08:00
|
|
|
/* Configuration file name */
|
|
|
|
char *config_filename;
|
2017-08-29 01:34:01 +09:30
|
|
|
/* Configuration settings. */
|
|
|
|
struct config config;
|
|
|
|
|
2018-02-18 23:26:46 +10:30
|
|
|
/* This log_book is owned by all the struct logs */
|
2017-08-29 01:39:01 +09:30
|
|
|
struct log_book *log_book;
|
2018-02-18 23:26:46 +10:30
|
|
|
/* Log for general stuff. */
|
2017-08-29 01:39:01 +09:30
|
|
|
struct log *log;
|
2018-01-29 11:00:15 +10:30
|
|
|
const char *logfile;
|
2017-08-29 01:34:01 +09:30
|
|
|
|
|
|
|
/* This is us. */
|
|
|
|
struct pubkey id;
|
|
|
|
|
2017-10-23 15:35:28 +10:30
|
|
|
/* My name is... my favorite color is... */
|
2017-11-24 14:43:31 +01:00
|
|
|
u8 *alias; /* At least 32 bytes (zero-filled) */
|
2017-10-23 15:35:28 +10:30
|
|
|
u8 *rgb; /* tal_len() == 3. */
|
|
|
|
|
2017-08-29 01:39:01 +09:30
|
|
|
/* Any pending timers. */
|
|
|
|
struct timers timers;
|
2017-01-10 15:37:51 +10:30
|
|
|
|
2017-08-29 01:39:01 +09:30
|
|
|
/* Port we're listening on */
|
|
|
|
u16 portnum;
|
2017-01-10 15:38:33 +10:30
|
|
|
|
2018-05-07 13:14:40 +09:30
|
|
|
/* Do we want to reconnect to other peers? */
|
|
|
|
bool reconnect;
|
|
|
|
|
|
|
|
/* Do we want to listen for other peers? */
|
|
|
|
bool listen;
|
|
|
|
|
2018-05-07 13:58:12 +09:30
|
|
|
/* Do we want to guess addresses to listen and announce? */
|
|
|
|
bool autolisten;
|
|
|
|
|
2018-05-07 13:59:22 +09:30
|
|
|
/* Setup: Addresses to bind/announce to the network (tal_count()) */
|
|
|
|
struct wireaddr_internal *proposed_wireaddr;
|
|
|
|
/* Setup: And the bitset for each, whether to listen, announce or both */
|
|
|
|
enum addr_listen_announce *proposed_listen_announce;
|
|
|
|
|
|
|
|
/* Actual bindings and announcables from gossipd */
|
|
|
|
struct wireaddr_internal *binding;
|
|
|
|
struct wireaddr *announcable;
|
2017-10-23 14:45:38 +10:30
|
|
|
|
2017-01-10 15:38:33 +10:30
|
|
|
/* Bearer of all my secrets. */
|
2017-06-24 16:20:23 +09:30
|
|
|
int hsm_fd;
|
2018-07-09 20:47:59 +09:30
|
|
|
struct subd *hsm;
|
2017-01-10 15:38:33 +10:30
|
|
|
|
2018-07-24 15:48:58 +09:30
|
|
|
/* Daemon for routing */
|
|
|
|
struct subd *gossip;
|
|
|
|
|
2017-01-10 15:38:33 +10:30
|
|
|
/* Daemon looking after peers during init / before channel. */
|
2018-07-24 15:48:58 +09:30
|
|
|
struct subd *connectd;
|
2017-01-10 15:38:33 +10:30
|
|
|
|
2017-01-10 15:38:33 +10:30
|
|
|
/* All peers we're tracking. */
|
|
|
|
struct list_head peers;
|
gossipd: rewrite to do the handshake internally.
Now the flow is much simpler from a lightningd POV:
1. If we want to connect to a peer, just send gossipd `gossipctl_reach_peer`.
2. Every new peer, gossipd hands up to lightningd, with global/local features
and the peer fd and a gossip fd using `gossip_peer_connected`
3. If lightningd doesn't want it, it just hands the peerfd and global/local
features back to gossipd using `gossipctl_handle_peer`
4. If a peer sends a non-gossip msg (eg `open_channel`) the gossipd sends
it up using `gossip_peer_nongossip`.
5. If lightningd wants to fund a channel, it simply calls `release_channel`.
Notes:
* There's no more "unique_id": we use the peer id.
* For the moment, we don't ask gossipd when we're told to list peers, so
connected peers without a channel don't appear in the JSON getpeers API.
* We add a `gossipctl_peer_addrhint` for the moment, so you can connect to
a specific ip/port, but using other sources is a TODO.
* We now (correctly) only give up on reaching a peer after we exchange init
messages, which changes the test_disconnect case.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-11 20:39:49 +10:30
|
|
|
|
|
|
|
/* Outstanding connect commands. */
|
|
|
|
struct list_head connects;
|
2017-02-21 15:15:29 +10:30
|
|
|
|
2017-03-07 11:26:38 +10:30
|
|
|
/* Our chain topology. */
|
|
|
|
struct chain_topology *topology;
|
|
|
|
|
2017-04-01 21:31:13 +10:30
|
|
|
/* HTLCs in flight. */
|
2017-06-20 15:23:03 +09:30
|
|
|
struct htlc_in_map htlcs_in;
|
|
|
|
struct htlc_out_map htlcs_out;
|
2017-04-24 14:31:26 +02:00
|
|
|
|
2017-05-23 22:07:20 +02:00
|
|
|
struct wallet *wallet;
|
2017-07-10 10:31:35 +02:00
|
|
|
|
2018-03-10 06:41:45 +00:00
|
|
|
/* Outstanding waitsendpay commands. */
|
|
|
|
struct list_head waitsendpay_commands;
|
2018-03-10 07:44:28 +00:00
|
|
|
/* Outstanding sendpay commands. */
|
|
|
|
struct list_head sendpay_commands;
|
2018-04-10 06:03:15 +00:00
|
|
|
/* Outstanding close commands. */
|
|
|
|
struct list_head close_commands;
|
2018-09-12 05:27:11 +09:30
|
|
|
/* Outstanding ping commands. */
|
|
|
|
struct list_head ping_commands;
|
2018-02-02 11:25:06 +10:30
|
|
|
|
2017-08-29 01:39:01 +09:30
|
|
|
/* Maintained by invoices.c */
|
|
|
|
struct invoices *invoices;
|
|
|
|
|
2017-11-27 16:20:10 +01:00
|
|
|
/* Transaction filter matching what we're interested in */
|
|
|
|
struct txfilter *owned_txfilter;
|
|
|
|
|
2018-02-19 23:00:09 +00:00
|
|
|
/* PID file */
|
|
|
|
char *pidfile;
|
|
|
|
|
2018-03-18 12:22:21 +00:00
|
|
|
/* Initial autocleaninvoice settings. */
|
|
|
|
u64 ini_autocleaninvoice_cycle;
|
|
|
|
u64 ini_autocleaninvoice_expiredby;
|
|
|
|
|
2018-05-06 23:01:49 +00:00
|
|
|
/* Number of blocks we wait for a channel to get funded
|
|
|
|
* if we are the fundee. */
|
|
|
|
u32 max_funding_unconfirmed;
|
|
|
|
|
2018-12-08 11:00:56 +10:30
|
|
|
/* If we want to debug a subdaemon/plugin. */
|
|
|
|
const char *dev_debug_subprocess;
|
2017-10-24 12:36:14 +10:30
|
|
|
|
2018-12-08 11:00:56 +10:30
|
|
|
#if DEVELOPER
|
2017-10-24 12:36:14 +10:30
|
|
|
/* If we have a --dev-disconnect file */
|
|
|
|
int dev_disconnect_fd;
|
|
|
|
|
|
|
|
/* If we have --dev-fail-on-subdaemon-fail */
|
|
|
|
bool dev_subdaemon_fail;
|
2017-12-15 20:47:54 +10:30
|
|
|
|
2018-05-07 13:59:22 +09:30
|
|
|
/* Allow and accept localhost node_announcement addresses */
|
|
|
|
bool dev_allow_localhost;
|
|
|
|
|
2017-12-15 20:47:54 +10:30
|
|
|
/* Things we've marked as not leaking. */
|
|
|
|
const void **notleaks;
|
2017-10-24 12:36:14 +10:30
|
|
|
#endif /* DEVELOPER */
|
2018-05-10 08:48:19 +09:30
|
|
|
|
|
|
|
/* tor support */
|
2018-05-10 08:48:24 +09:30
|
|
|
struct wireaddr *proxyaddr;
|
|
|
|
bool use_proxy_always;
|
2018-05-10 08:48:19 +09:30
|
|
|
char *tor_service_password;
|
2018-05-10 08:48:24 +09:30
|
|
|
bool pure_tor_setup;
|
2018-09-20 13:46:50 +02:00
|
|
|
|
|
|
|
struct plugins *plugins;
|
2017-01-10 15:37:51 +10:30
|
|
|
};
|
2017-01-10 15:38:33 +10:30
|
|
|
|
2018-03-07 04:57:21 +10:30
|
|
|
const struct chainparams *get_chainparams(const struct lightningd *ld);
|
2017-12-15 20:48:54 +10:30
|
|
|
|
2018-01-03 11:05:44 +00:00
|
|
|
/* Check we can run subdaemons, and check their versions */
|
2018-09-03 10:12:27 +09:30
|
|
|
void test_subdaemons(const struct lightningd *ld);
|
2018-01-03 11:05:44 +00:00
|
|
|
|
2018-05-06 13:32:01 +00:00
|
|
|
/* Notify lightningd about new blocks. */
|
|
|
|
void notify_new_block(struct lightningd *ld, u32 block_height);
|
|
|
|
|
2017-01-10 15:37:51 +10:30
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_LIGHTNINGD_H */
|