mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
daemon: config file support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
#include <ccan/timer/timer.h>
|
#include <ccan/timer/timer.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -20,6 +21,93 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
|
static char *opt_set_u64(const char *arg, u64 *u)
|
||||||
|
{
|
||||||
|
char *endp;
|
||||||
|
unsigned long long l;
|
||||||
|
|
||||||
|
/* This is how the manpage says to do it. Yech. */
|
||||||
|
errno = 0;
|
||||||
|
l = strtoull(arg, &endp, 0);
|
||||||
|
if (*endp || !arg[0])
|
||||||
|
return tal_fmt(NULL, "'%s' is not a number", arg);
|
||||||
|
*u = l;
|
||||||
|
if (errno || *u != l)
|
||||||
|
return tal_fmt(NULL, "'%s' is out of range", arg);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *opt_set_u32(const char *arg, u32 *u)
|
||||||
|
{
|
||||||
|
char *endp;
|
||||||
|
unsigned long l;
|
||||||
|
|
||||||
|
/* This is how the manpage says to do it. Yech. */
|
||||||
|
errno = 0;
|
||||||
|
l = strtoul(arg, &endp, 0);
|
||||||
|
if (*endp || !arg[0])
|
||||||
|
return tal_fmt(NULL, "'%s' is not a number", arg);
|
||||||
|
*u = l;
|
||||||
|
if (errno || *u != l)
|
||||||
|
return tal_fmt(NULL, "'%s' is out of range", arg);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u)
|
||||||
|
{
|
||||||
|
snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void opt_show_u32(char buf[OPT_SHOW_LEN], const u32 *u)
|
||||||
|
{
|
||||||
|
snprintf(buf, OPT_SHOW_LEN, "%"PRIu32, *u);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void config_register_opts(struct lightningd_state *state)
|
||||||
|
{
|
||||||
|
opt_register_arg("--locktime", opt_set_u32, opt_show_u32,
|
||||||
|
&state->config.rel_locktime,
|
||||||
|
"Seconds before peer can unilaterally spend funds");
|
||||||
|
opt_register_arg("--max-locktime", opt_set_u32, opt_show_u32,
|
||||||
|
&state->config.rel_locktime_max,
|
||||||
|
"Maximum seconds peer can lock up our funds");
|
||||||
|
opt_register_arg("--anchor-confirms", opt_set_u32, opt_show_u32,
|
||||||
|
&state->config.anchor_confirms,
|
||||||
|
"Confirmations required for anchor transaction");
|
||||||
|
opt_register_arg("--max-anchor-confirms", opt_set_u32, opt_show_u32,
|
||||||
|
&state->config.anchor_confirms_max,
|
||||||
|
"Maximum confirmations other side can wait for anchor transaction");
|
||||||
|
opt_register_arg("--commit-fee", opt_set_u64, opt_show_u64,
|
||||||
|
&state->config.commitment_fee,
|
||||||
|
"Satoshis to offer for commitment transaction fee");
|
||||||
|
opt_register_arg("--min-commit-fee", opt_set_u64, opt_show_u64,
|
||||||
|
&state->config.commitment_fee_min,
|
||||||
|
"Minimum satoshis to accept for commitment transaction fee");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void default_config(struct config *config)
|
||||||
|
{
|
||||||
|
/* One day to catch cheating attempts. */
|
||||||
|
config->rel_locktime = 60 * 60 * 24;
|
||||||
|
|
||||||
|
/* They can have up to 3 days. */
|
||||||
|
config->rel_locktime_max = 60 * 60 * 24 * 3;
|
||||||
|
|
||||||
|
/* We're fairly trusting, under normal circumstances. */
|
||||||
|
config->anchor_confirms = 3;
|
||||||
|
|
||||||
|
/* More than 10 confirms seems overkill. */
|
||||||
|
config->anchor_confirms_max = 10;
|
||||||
|
|
||||||
|
/* FIXME: These should float with bitcoind's recommendations! */
|
||||||
|
|
||||||
|
/* Pay hefty fee (10x current suggested minimum). */
|
||||||
|
config->commitment_fee = 50000;
|
||||||
|
|
||||||
|
/* Don't accept less than double the current standard fee. */
|
||||||
|
config->commitment_fee_min = 10000;
|
||||||
|
}
|
||||||
|
|
||||||
static struct lightningd_state *lightningd_state(void)
|
static struct lightningd_state *lightningd_state(void)
|
||||||
{
|
{
|
||||||
struct lightningd_state *state = tal(NULL, struct lightningd_state);
|
struct lightningd_state *state = tal(NULL, struct lightningd_state);
|
||||||
@@ -32,6 +120,7 @@ static struct lightningd_state *lightningd_state(void)
|
|||||||
timers_init(&state->timers, time_now());
|
timers_init(&state->timers, time_now());
|
||||||
state->secpctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
state->secpctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
default_config(&state->config);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +163,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
configdir_register_opts(state,
|
configdir_register_opts(state,
|
||||||
&state->config_dir, &state->rpc_filename);
|
&state->config_dir, &state->rpc_filename);
|
||||||
|
config_register_opts(state);
|
||||||
|
|
||||||
/* Get any configdir options first. */
|
/* Get any configdir options first. */
|
||||||
opt_early_parse(argc, argv, opt_log_stderr_exit);
|
opt_early_parse(argc, argv, opt_log_stderr_exit);
|
||||||
|
|||||||
@@ -3,10 +3,32 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "bitcoin/pubkey.h"
|
#include "bitcoin/pubkey.h"
|
||||||
#include <ccan/list/list.h>
|
#include <ccan/list/list.h>
|
||||||
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <ccan/timer/timer.h>
|
#include <ccan/timer/timer.h>
|
||||||
#include <secp256k1.h>
|
#include <secp256k1.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Various adjustable things. */
|
||||||
|
struct config {
|
||||||
|
/* How long do we want them to lock up their funds? (seconds) */
|
||||||
|
u32 rel_locktime;
|
||||||
|
|
||||||
|
/* How long do we let them lock up our funds? (seconds) */
|
||||||
|
u32 rel_locktime_max;
|
||||||
|
|
||||||
|
/* How many confirms until we consider an anchor "settled". */
|
||||||
|
u32 anchor_confirms;
|
||||||
|
|
||||||
|
/* How long will we accept them waiting? */
|
||||||
|
u32 anchor_confirms_max;
|
||||||
|
|
||||||
|
/* What are we prepared to pay in commitment fee (satoshis). */
|
||||||
|
u64 commitment_fee;
|
||||||
|
|
||||||
|
/* How little are we prepared to have them pay? */
|
||||||
|
u64 commitment_fee_min;
|
||||||
|
};
|
||||||
|
|
||||||
/* Here's where the global variables hide! */
|
/* Here's where the global variables hide! */
|
||||||
struct lightningd_state {
|
struct lightningd_state {
|
||||||
/* Where all our logging goes. */
|
/* Where all our logging goes. */
|
||||||
@@ -18,6 +40,9 @@ struct lightningd_state {
|
|||||||
char *config_dir;
|
char *config_dir;
|
||||||
char *rpc_filename;
|
char *rpc_filename;
|
||||||
|
|
||||||
|
/* Configuration settings. */
|
||||||
|
struct config config;
|
||||||
|
|
||||||
/* Any pending timers. */
|
/* Any pending timers. */
|
||||||
struct timers timers;
|
struct timers timers;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user