mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +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/timer/timer.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -20,6 +21,93 @@
|
||||
#include <unistd.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)
|
||||
{
|
||||
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());
|
||||
state->secpctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN);
|
||||
default_config(&state->config);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -74,6 +163,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
configdir_register_opts(state,
|
||||
&state->config_dir, &state->rpc_filename);
|
||||
config_register_opts(state);
|
||||
|
||||
/* Get any configdir options first. */
|
||||
opt_early_parse(argc, argv, opt_log_stderr_exit);
|
||||
|
||||
Reference in New Issue
Block a user