mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
50f5eb34b4
Prior to this, lightningd would hand uninteresting peers back to connectd, which would then return it to lightningd if it sent a non-gossip msg, or if lightningd asked it to release the peer. Now connectd hands the peer to lightningd once we've done the init handshake, which hands it off to openingd. This is a deep structural change, so we do the minimum here and cleanup in the following patches. Lightningd: 1. Remove peer_nongossip handling from connect_control and peer_control. 2. Remove list of outstanding fundchannel command; it was only needed to find the race between us asking connectd to release the peer and it reconnecting. 3. We can no longer tell if the remote end has started trying to fund a channel (until it has succeeded): it's very transitory anyway so not worth fixing. 4. We now always have a struct peer, and allocate an uncommitted_channel for it, though it may never be used if neither end funds a channel. 5. We start funding on messages for openingd: we can get a funder_reply or a fundee, or an error in response to our request to fund a channel. so we handle all of them. 6. A new peer_start_openingd() is called after connectd hands us a peer. 7. json_fund_channel just looks through local peers; there are none hidden in connectd any more. 8. We sometimes start a new openingd just to send an error message. Openingd: 1. We always have information we need to accept them funding a channel (in the init message). 2. We have to listen for three fds: peer, gossip and master, so we opencode the poll. 3. We have an explicit message to start trying to fund a channel. 4. We can be told to send a message in our init message. Testing: 1. We don't handle some things gracefully yet, so two tests are disabled. 2. 'hand_back_peer .*: now local again' from connectd is no longer a message, openingd says 'Handed peer, entering loop' once its managing it. 3. peer['state'] used to be set to 'GOSSIPING' (otherwise this field doesn't exist; 'state' is now per-channel. It doesn't exist at all now. 4. Some tests now need to turn on IO logging in openingd, not connectd. 5. There's a gap between connecting on one node and having connectd on the peer hand over the connection to openingd. Our tests sometimes checked getpeers() on the peer, and didn't see anything, so line_graph needed updating. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
217 lines
5.4 KiB
C
217 lines
5.4 KiB
C
#ifndef LIGHTNING_LIGHTNINGD_LIGHTNINGD_H
|
|
#define LIGHTNING_LIGHTNINGD_LIGHTNINGD_H
|
|
#include "config.h"
|
|
#include <bitcoin/chainparams.h>
|
|
#include <bitcoin/privkey.h>
|
|
#include <ccan/container_of/container_of.h>
|
|
#include <ccan/time/time.h>
|
|
#include <ccan/timer/timer.h>
|
|
#include <common/json_escaped.h>
|
|
#include <lightningd/htlc_end.h>
|
|
#include <stdio.h>
|
|
#include <wallet/txfilter.h>
|
|
#include <wallet/wallet.h>
|
|
|
|
/* 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;
|
|
|
|
/* Minimum CLTV to subtract from incoming HTLCs to outgoing */
|
|
u32 cltv_expiry_delta;
|
|
|
|
/* Minimum CLTV if we're the final hop.*/
|
|
u32 cltv_final;
|
|
|
|
/* Fee rates. */
|
|
u32 fee_base;
|
|
s32 fee_per_satoshi;
|
|
|
|
/* How long between changing commit and sending COMMIT message. */
|
|
u32 commit_time_ms;
|
|
|
|
/* How often to broadcast gossip (msec) */
|
|
u32 broadcast_interval;
|
|
|
|
/* Channel update interval */
|
|
u32 channel_update_interval;
|
|
|
|
/* Do we let the funder set any fee rate they want */
|
|
bool ignore_fee_limits;
|
|
|
|
/* Number of blocks to rescan from the current head, or absolute
|
|
* blockheight if rescan >= 500'000 */
|
|
s32 rescan;
|
|
|
|
/* ipv6 bind disable */
|
|
bool no_ipv6_bind;
|
|
|
|
/* Accept fee changes only if they are in the range our_fee -
|
|
* our_fee*multiplier */
|
|
u32 max_fee_multiplier;
|
|
|
|
/* Are we allowed to use DNS lookup for peers. */
|
|
bool use_dns;
|
|
};
|
|
|
|
struct lightningd {
|
|
/* The directory to find all the subdaemons. */
|
|
const char *daemon_dir;
|
|
|
|
/* Are we told to run in the background. */
|
|
bool daemon;
|
|
|
|
/* Our config dir, and rpc file */
|
|
char *config_dir;
|
|
|
|
/* Location of the RPC socket. */
|
|
char *rpc_filename;
|
|
|
|
/* The listener for the RPC socket. 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 io_listener *rpc_listener;
|
|
|
|
/* Configuration file name */
|
|
char *config_filename;
|
|
/* Configuration settings. */
|
|
struct config config;
|
|
|
|
/* This log_book is owned by all the struct logs */
|
|
struct log_book *log_book;
|
|
/* Log for general stuff. */
|
|
struct log *log;
|
|
const char *logfile;
|
|
|
|
/* This is us. */
|
|
struct pubkey id;
|
|
|
|
/* My name is... my favorite color is... */
|
|
u8 *alias; /* At least 32 bytes (zero-filled) */
|
|
u8 *rgb; /* tal_len() == 3. */
|
|
|
|
/* Any pending timers. */
|
|
struct timers timers;
|
|
|
|
/* Port we're listening on */
|
|
u16 portnum;
|
|
|
|
/* Do we want to reconnect to other peers? */
|
|
bool reconnect;
|
|
|
|
/* Do we want to listen for other peers? */
|
|
bool listen;
|
|
|
|
/* Do we want to guess addresses to listen and announce? */
|
|
bool autolisten;
|
|
|
|
/* 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;
|
|
|
|
/* Bearer of all my secrets. */
|
|
int hsm_fd;
|
|
struct subd *hsm;
|
|
|
|
/* Daemon for routing */
|
|
struct subd *gossip;
|
|
|
|
/* Daemon looking after peers during init / before channel. */
|
|
struct subd *connectd;
|
|
|
|
/* All peers we're tracking. */
|
|
struct list_head peers;
|
|
|
|
/* Outstanding connect commands. */
|
|
struct list_head connects;
|
|
|
|
/* Our chain topology. */
|
|
struct chain_topology *topology;
|
|
|
|
/* HTLCs in flight. */
|
|
struct htlc_in_map htlcs_in;
|
|
struct htlc_out_map htlcs_out;
|
|
|
|
struct wallet *wallet;
|
|
|
|
/* Outstanding waitsendpay commands. */
|
|
struct list_head waitsendpay_commands;
|
|
/* Outstanding sendpay commands. */
|
|
struct list_head sendpay_commands;
|
|
/* Outstanding close commands. */
|
|
struct list_head close_commands;
|
|
|
|
/* Maintained by invoices.c */
|
|
struct invoices *invoices;
|
|
|
|
/* Transaction filter matching what we're interested in */
|
|
struct txfilter *owned_txfilter;
|
|
|
|
/* PID file */
|
|
char *pidfile;
|
|
|
|
/* Initial autocleaninvoice settings. */
|
|
u64 ini_autocleaninvoice_cycle;
|
|
u64 ini_autocleaninvoice_expiredby;
|
|
|
|
/* Number of blocks we wait for a channel to get funded
|
|
* if we are the fundee. */
|
|
u32 max_funding_unconfirmed;
|
|
|
|
#if DEVELOPER
|
|
/* If we want to debug a subdaemon. */
|
|
const char *dev_debug_subdaemon;
|
|
|
|
/* If we have a --dev-disconnect file */
|
|
int dev_disconnect_fd;
|
|
|
|
/* If we have --dev-fail-on-subdaemon-fail */
|
|
bool dev_subdaemon_fail;
|
|
|
|
/* Allow and accept localhost node_announcement addresses */
|
|
bool dev_allow_localhost;
|
|
|
|
/* Things we've marked as not leaking. */
|
|
const void **notleaks;
|
|
#endif /* DEVELOPER */
|
|
|
|
/* tor support */
|
|
struct wireaddr *proxyaddr;
|
|
bool use_proxy_always;
|
|
char *tor_service_password;
|
|
bool pure_tor_setup;
|
|
};
|
|
|
|
const struct chainparams *get_chainparams(const struct lightningd *ld);
|
|
|
|
/* State for performing backtraces. */
|
|
struct backtrace_state *backtrace_state;
|
|
|
|
/* Check we can run subdaemons, and check their versions */
|
|
void test_daemons(const struct lightningd *ld);
|
|
|
|
/* Notify lightningd about new blocks. */
|
|
void notify_new_block(struct lightningd *ld, u32 block_height);
|
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_LIGHTNINGD_H */
|