2017-01-10 06:07:51 +01:00
|
|
|
#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 06:52:56 +01:00
|
|
|
#include <bitcoin/privkey.h>
|
2017-01-10 06:08:33 +01:00
|
|
|
#include <ccan/container_of/container_of.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <ccan/time/time.h>
|
|
|
|
#include <ccan/timer/timer.h>
|
2017-04-01 13:01:13 +02:00
|
|
|
#include <lightningd/htlc_end.h>
|
2017-11-27 16:20:10 +01:00
|
|
|
#include <lightningd/txfilter.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <stdio.h>
|
2017-05-23 22:07:20 +02:00
|
|
|
#include <wallet/wallet.h>
|
2017-01-10 06:07:51 +01:00
|
|
|
|
|
|
|
/* BOLT #1:
|
|
|
|
*
|
|
|
|
* The default TCP port is 9735. This corresponds to hexadecimal
|
2017-06-06 01:48:10 +02:00
|
|
|
* `0x2607`, the Unicode code point for LIGHTNING.
|
2017-01-10 06:07:51 +01:00
|
|
|
*/
|
2017-10-11 12:06:50 +02:00
|
|
|
#define DEFAULT_PORT 9735
|
2017-01-10 06:07:51 +01:00
|
|
|
|
2017-08-28 18:04:01 +02:00
|
|
|
/* 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 blocks before we expect to see anchor?. */
|
|
|
|
u32 anchor_onchain_wait;
|
|
|
|
|
|
|
|
/* How many confirms until we consider an anchor "settled". */
|
|
|
|
u32 anchor_confirms;
|
|
|
|
|
|
|
|
/* How long will we accept them waiting? */
|
|
|
|
u32 anchor_confirms_max;
|
|
|
|
|
|
|
|
/* 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 06:16:57 +02:00
|
|
|
/* Minimum CLTV to subtract from incoming HTLCs to outgoing */
|
|
|
|
u32 cltv_expiry_delta;
|
|
|
|
|
|
|
|
/* Minimum CLTV if we're the final hop.*/
|
|
|
|
u32 cltv_final;
|
|
|
|
|
|
|
|
/* Maximum time for an expiring HTLC (blocks). */
|
|
|
|
u32 max_htlc_expiry;
|
2017-08-28 18:04:01 +02:00
|
|
|
|
|
|
|
/* Fee rates. */
|
|
|
|
u32 fee_base;
|
|
|
|
s32 fee_per_satoshi;
|
|
|
|
|
|
|
|
/* How long between polling bitcoind. */
|
|
|
|
struct timerel poll_time;
|
|
|
|
|
|
|
|
/* How long between changing commit and sending COMMIT message. */
|
|
|
|
struct timerel commit_time;
|
|
|
|
|
2018-01-10 03:43:23 +01:00
|
|
|
/* How often to broadcast gossip (msec) */
|
|
|
|
u32 broadcast_interval;
|
|
|
|
|
2018-01-09 15:45:07 +01:00
|
|
|
/* Channel update interval */
|
|
|
|
u32 channel_update_interval;
|
2018-01-16 10:24:46 +01:00
|
|
|
|
|
|
|
/* Do we let the funder set any fee rate they want */
|
|
|
|
bool ignore_fee_limits;
|
2017-08-28 18:04:01 +02:00
|
|
|
};
|
|
|
|
|
2017-08-28 18:09:01 +02:00
|
|
|
struct lightningd {
|
|
|
|
/* The directory to find all the subdaemons. */
|
|
|
|
const char *daemon_dir;
|
2017-08-28 18:04:01 +02:00
|
|
|
|
|
|
|
/* Our config dir, and rpc file */
|
|
|
|
char *config_dir;
|
|
|
|
char *rpc_filename;
|
|
|
|
|
|
|
|
/* Configuration settings. */
|
|
|
|
struct config config;
|
|
|
|
|
2017-08-28 18:09:01 +02:00
|
|
|
/* Log for general stuff. */
|
|
|
|
struct log_book *log_book;
|
|
|
|
struct log *log;
|
2018-01-29 01:30:15 +01:00
|
|
|
const char *logfile;
|
2017-08-28 18:04:01 +02:00
|
|
|
|
|
|
|
/* This is us. */
|
|
|
|
struct pubkey id;
|
|
|
|
|
2017-10-23 07:05:28 +02:00
|
|
|
/* 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 07:05:28 +02:00
|
|
|
u8 *rgb; /* tal_len() == 3. */
|
|
|
|
|
2017-08-28 18:09:01 +02:00
|
|
|
/* Any pending timers. */
|
|
|
|
struct timers timers;
|
2017-01-10 06:07:51 +01:00
|
|
|
|
2017-08-28 18:09:01 +02:00
|
|
|
/* Port we're listening on */
|
|
|
|
u16 portnum;
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2017-10-23 06:15:38 +02:00
|
|
|
/* Addresses to announce to the network (tal_count()) */
|
2017-10-23 06:17:38 +02:00
|
|
|
struct wireaddr *wireaddrs;
|
2017-10-23 06:15:38 +02:00
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
/* Bearer of all my secrets. */
|
2017-06-24 08:50:23 +02:00
|
|
|
int hsm_fd;
|
2018-02-05 05:09:27 +01:00
|
|
|
struct log *hsm_log;
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
/* Daemon looking after peers during init / before channel. */
|
2017-03-10 11:50:43 +01:00
|
|
|
struct subd *gossip;
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2017-01-10 06:08:33 +01:00
|
|
|
/* All peers we're tracking. */
|
|
|
|
struct list_head peers;
|
2017-02-24 06:52:56 +01:00
|
|
|
/* FIXME: This should stay in HSM */
|
2017-05-06 04:19:44 +02:00
|
|
|
struct secret peer_seed;
|
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 12:09:49 +02:00
|
|
|
|
|
|
|
/* Outstanding connect commands. */
|
|
|
|
struct list_head connects;
|
2017-02-21 05:45:29 +01:00
|
|
|
|
2017-03-07 01:56:38 +01:00
|
|
|
/* Our chain topology. */
|
|
|
|
struct chain_topology *topology;
|
|
|
|
|
2017-04-01 13:01:13 +02:00
|
|
|
/* HTLCs in flight. */
|
2017-06-20 07:53:03 +02:00
|
|
|
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-02-02 01:55:06 +01:00
|
|
|
/* Outstanding sendpay/pay commands. */
|
|
|
|
struct list_head pay_commands;
|
|
|
|
|
2017-08-28 18:09:01 +02:00
|
|
|
/* 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-05 05:09:28 +01:00
|
|
|
/* May be useful for non-developers debugging in the field */
|
|
|
|
char *debug_subdaemon_io;
|
|
|
|
|
2017-10-24 04:06:14 +02:00
|
|
|
#if DEVELOPER
|
|
|
|
/* If we want to debug a subdaemon. */
|
|
|
|
const char *dev_debug_subdaemon;
|
|
|
|
|
|
|
|
/* If we want to set a specific non-random HSM seed. */
|
|
|
|
const u8 *dev_hsm_seed;
|
|
|
|
|
|
|
|
/* 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 11:17:54 +01:00
|
|
|
|
|
|
|
/* Things we've marked as not leaking. */
|
|
|
|
const void **notleaks;
|
2018-01-29 01:30:15 +01:00
|
|
|
|
|
|
|
/* Disable automatic reconnects */
|
|
|
|
bool no_reconnect;
|
2017-10-24 04:06:14 +02:00
|
|
|
#endif /* DEVELOPER */
|
2017-01-10 06:07:51 +01:00
|
|
|
};
|
2017-01-10 06:08:33 +01:00
|
|
|
|
2017-08-28 18:09:01 +02:00
|
|
|
struct chainparams *get_chainparams(const struct lightningd *ld);
|
2017-12-15 11:18:54 +01:00
|
|
|
|
|
|
|
/* State for performing backtraces. */
|
|
|
|
struct backtrace_state *backtrace_state;
|
|
|
|
|
2018-01-03 12:05:44 +01:00
|
|
|
/* Check we can run subdaemons, and check their versions */
|
|
|
|
void test_daemons(const struct lightningd *ld);
|
|
|
|
|
2017-01-10 06:07:51 +01:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_LIGHTNINGD_H */
|