diff --git a/doc/lightningd-config.5 b/doc/lightningd-config.5 index 21f413f58..26a63b934 100644 --- a/doc/lightningd-config.5 +++ b/doc/lightningd-config.5 @@ -196,7 +196,7 @@ This is the proportional fee to charge for every payment which passes through\&. Allow nodes which establish channels to us to set any fee they want\&. This may result in a channel which cannot be closed, should fees increase, but make channels far more reliable since we never close it due to unreasonable fees\&. .RE .PP -\fBcommit\-time\fR=\fITIME\fR +\fBcommit\-time\fR=\*(AqMILLISECONDS .RS 4 How long to wait before sending commitment messages to the peer: in theory increasing this would reduce load, but your node would have to be extremely busy node for you to even notice\&. .RE diff --git a/doc/lightningd-config.5.txt b/doc/lightningd-config.5.txt index 6fb574df1..fea93b9ed 100644 --- a/doc/lightningd-config.5.txt +++ b/doc/lightningd-config.5.txt @@ -143,7 +143,7 @@ Lightning node customization options: fees increase, but make channels far more reliable since we never close it due to unreasonable fees. -*commit-time*='TIME':: +*commit-time*='MILLISECONDS:: How long to wait before sending commitment messages to the peer: in theory increasing this would reduce load, but your node would have to be extremely busy node for you to even notice. diff --git a/lightningd/Makefile b/lightningd/Makefile index 101d906f7..193c2d177 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -69,7 +69,6 @@ LIGHTNINGD_SRC := \ lightningd/log_status.c \ lightningd/onchain_control.c \ lightningd/opening_control.c \ - lightningd/opt_time.c \ lightningd/options.c \ lightningd/pay.c \ lightningd/payalgo.c \ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 1fe983d82..380d4b76c 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -268,7 +268,7 @@ bool peer_start_channeld(struct channel *channel, &channel->seed, &ld->id, &channel->peer->id, - time_to_msec(cfg->commit_time), + cfg->commit_time_ms, cfg->cltv_expiry_delta, channel->last_was_revoke, channel->last_sent_commit, diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 741b35cfd..5069dd95d 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -43,7 +43,7 @@ struct config { s32 fee_per_satoshi; /* How long between changing commit and sending COMMIT message. */ - struct timerel commit_time; + u32 commit_time_ms; /* How often to broadcast gossip (msec) */ u32 broadcast_interval; diff --git a/lightningd/opt_time.c b/lightningd/opt_time.c deleted file mode 100644 index 1efbbb9de..000000000 --- a/lightningd/opt_time.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "opt_time.h" -#include -#include -#include -#include -#include -#include - -static bool match(const char *str, const char *abbrev, const char *full) -{ - if (streq(str, abbrev)) - return true; - - if (streq(str, full)) - return true; - - /* Allow "seconds" */ - if (memcmp(str, full, strlen(full)) == 0 - && streq(str + strlen(full), "s")) - return true; - - return false; -} - -char *opt_set_time(const char *arg, struct timerel *t) -{ - char *endp; - unsigned long int l; - - assert(arg != NULL); - - /* This is how the manpage says to do it. Yech. */ - errno = 0; - l = strtol(arg, &endp, 0); - if (endp == arg) - return tal_fmt(NULL, "'%s' is not a number", arg); - if (errno) - return tal_fmt(NULL, "'%s' is out of range", arg); - - while (isspace(*endp)) - endp++; - - if (match(endp, "s", "second")) - *t = time_from_sec(l); - else if (match(endp, "m", "minute")) - *t = time_from_sec(l * 60); - else if (match(endp, "h", "hour")) - *t = time_from_sec(l * 60 * 60); - else if (match(endp, "d", "day")) - *t = time_from_sec(l * 60 * 60 * 24); - else if (match(endp, "ms", "millisecond")) - *t = time_from_msec(l); - else if (match(endp, "us", "microsecond")) - *t = time_from_usec(l); - else if (match(endp, "ns", "nanosecond")) - *t = time_from_nsec(l); - else - return tal_fmt(NULL, "Unknown time unit %s", endp); - return NULL; -} - -void opt_show_time(char buf[OPT_SHOW_LEN], const struct timerel *t) -{ - if (t->ts.tv_nsec) { - if (t->ts.tv_nsec % 1000) - sprintf(buf, "%"PRIu64"ns", time_to_nsec(*t)); - else if (t->ts.tv_nsec % 1000000) - sprintf(buf, "%"PRIu64"us", time_to_usec(*t)); - else - sprintf(buf, "%"PRIu64"ms", time_to_msec(*t)); - } else if (t->ts.tv_sec) { - if (t->ts.tv_sec % (60 * 60 * 24) == 0) - sprintf(buf, "%lud", t->ts.tv_sec / (60 * 60 * 24)); - else if (t->ts.tv_sec % (60 * 60) == 0) - sprintf(buf, "%luh", t->ts.tv_sec / (60 * 60)); - else if (t->ts.tv_sec % 60 == 0) - sprintf(buf, "%lum", t->ts.tv_sec / 60); - else - sprintf(buf, "%lus", t->ts.tv_sec); - } else - sprintf(buf, "%lus", t->ts.tv_sec); -} diff --git a/lightningd/opt_time.h b/lightningd/opt_time.h deleted file mode 100644 index 980030463..000000000 --- a/lightningd/opt_time.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LIGHTNING_LIGHTNINGD_OPT_TIME_H -#define LIGHTNING_LIGHTNINGD_OPT_TIME_H -#include "config.h" -#include -#include - -char *opt_set_time(const char *arg, struct timerel *t); -void opt_show_time(char buf[OPT_SHOW_LEN], const struct timerel *t); - -#endif /* LIGHTNING_LIGHTNINGD_OPT_TIME_H */ diff --git a/lightningd/options.c b/lightningd/options.c index affea615e..6128b9b58 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -335,8 +334,9 @@ static void config_register_opts(struct lightningd *ld) opt_register_arg("--cltv-final", opt_set_u32, opt_show_u32, &ld->config.cltv_final, "Number of blocks for final ctlv_expiry"); - opt_register_arg("--commit-time", opt_set_time, opt_show_time, - &ld->config.commit_time, + opt_register_arg("--commit-time=", + opt_set_u32, opt_show_u32, + &ld->config.commit_time_ms, "Time after changes before sending out COMMIT"); opt_register_arg("--fee-base", opt_set_u32, opt_show_u32, &ld->config.fee_base, @@ -475,7 +475,7 @@ static const struct config testnet_config = { .cltv_final = 6, /* Send commit 10msec after receiving; almost immediately. */ - .commit_time = TIME_FROM_MSEC(10), + .commit_time_ms = 10, /* Allow dust payments */ .fee_base = 1, @@ -527,7 +527,7 @@ static const struct config mainnet_config = { .cltv_final = 8, /* Send commit 10msec after receiving; almost immediately. */ - .commit_time = TIME_FROM_MSEC(10), + .commit_time_ms = 10, /* Discourage dust payments */ .fee_base = 1000,