core-lightning/lightningd/lightningd.h

174 lines
4.1 KiB
C
Raw Normal View History

#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>
#include <bitcoin/privkey.h>
#include <ccan/container_of/container_of.h>
#include <ccan/time/time.h>
#include <ccan/timer/timer.h>
#include <lightningd/htlc_end.h>
#include <lightningd/txfilter.h>
#include <stdio.h>
#include <wallet/wallet.h>
/* BOLT #1:
*
* The default TCP port is 9735. This corresponds to hexadecimal
* `0x2607`, the Unicode code point for LIGHTNING.
*/
#define DEFAULT_PORT 9735
/* 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;
/* 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;
/* 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;
/* 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;
};
struct lightningd {
/* The directory to find all the subdaemons. */
const char *daemon_dir;
/* Our config dir, and rpc file */
char *config_dir;
char *rpc_filename;
/* Configuration settings. */
struct config config;
/* Log for general stuff. */
struct log_book *log_book;
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;
/* Addresses to announce to the network (tal_count()) */
struct wireaddr *wireaddrs;
/* Bearer of all my secrets. */
int hsm_fd;
struct log *hsm_log;
/* Daemon looking after peers during init / before channel. */
struct subd *gossip;
/* All peers we're tracking. */
struct list_head peers;
/* FIXME: This should stay in HSM */
struct secret peer_seed;
/* 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;
2017-07-10 10:31:35 +02:00
pay: remove cmd pointer from htlc_out. Maintaining it was always fraught, since the command could go away if the JSON RPC died. Most recently, it was broken again on shutdown (see below). In future we may allow pay commands to block on previous payments, so it won't even be a 1:1 mapping. Generalize it: keep commands in a simple list and do a lookup when a payment fails/succeeds. Valgrind error file: valgrind-errors.5732 ==5732== Invalid read of size 8 ==5732== at 0x4149FD: remove_cmd_from_hout (pay.c:292) ==5732== by 0x468BAB: notify (tal.c:237) ==5732== by 0x469077: del_tree (tal.c:400) ==5732== by 0x4690C7: del_tree (tal.c:410) ==5732== by 0x46948A: tal_free (tal.c:509) ==5732== by 0x40F1EA: main (lightningd.c:362) ==5732== Address 0x69df148 is 1,512 bytes inside a block of size 1,544 free'd ==5732== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5732== by 0x469150: del_tree (tal.c:421) ==5732== by 0x46948A: tal_free (tal.c:509) ==5732== by 0x4198F2: free_htlcs (peer_control.c:1281) ==5732== by 0x40EBA9: shutdown_subdaemons (lightningd.c:209) ==5732== by 0x40F1DE: main (lightningd.c:360) ==5732== Block was alloc'd at ==5732== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5732== by 0x468C30: allocate (tal.c:250) ==5732== by 0x4691F7: tal_alloc_ (tal.c:448) ==5732== by 0x40A279: new_htlc_out (htlc_end.c:143) ==5732== by 0x41FD64: send_htlc_out (peer_htlcs.c:397) ==5732== by 0x41511C: send_payment (pay.c:388) ==5732== by 0x41589E: json_sendpay (pay.c:513) ==5732== by 0x40D9B1: parse_request (jsonrpc.c:600) ==5732== by 0x40DCAC: read_json (jsonrpc.c:667) ==5732== by 0x45C706: next_plan (io.c:59) ==5732== by 0x45D1DD: do_plan (io.c:387) ==5732== by 0x45D21B: io_ready (io.c:397) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 01:55:06 +01:00
/* Outstanding sendpay/pay commands. */
struct list_head pay_commands;
/* Maintained by invoices.c */
struct invoices *invoices;
/* Transaction filter matching what we're interested in */
struct txfilter *owned_txfilter;
/* May be useful for non-developers debugging in the field */
char *debug_subdaemon_io;
#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;
/* Things we've marked as not leaking. */
const void **notleaks;
/* Disable automatic reconnects */
bool no_reconnect;
#endif /* DEVELOPER */
};
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);
#endif /* LIGHTNING_LIGHTNINGD_LIGHTNINGD_H */