Browse Source

lightningd: make --commit-time in milliseconds.

It was the only place we used opt_time, so cuts out much code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
babfddeb3e
  1. 2
      doc/lightningd-config.5
  2. 2
      doc/lightningd-config.5.txt
  3. 1
      lightningd/Makefile
  4. 2
      lightningd/channel_control.c
  5. 2
      lightningd/lightningd.h
  6. 82
      lightningd/opt_time.c
  7. 10
      lightningd/opt_time.h
  8. 10
      lightningd/options.c

2
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\&. 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 .RE
.PP .PP
\fBcommit\-time\fR=\fITIME\fR \fBcommit\-time\fR=\*(AqMILLISECONDS
.RS 4 .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\&. 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 .RE

2
doc/lightningd-config.5.txt

@ -143,7 +143,7 @@ Lightning node customization options:
fees increase, but make channels far more reliable since we never fees increase, but make channels far more reliable since we never
close it due to unreasonable fees. close it due to unreasonable fees.
*commit-time*='TIME':: *commit-time*='MILLISECONDS::
How long to wait before sending commitment messages to the peer: in 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 theory increasing this would reduce load, but your node would have to be
extremely busy node for you to even notice. extremely busy node for you to even notice.

1
lightningd/Makefile

@ -69,7 +69,6 @@ LIGHTNINGD_SRC := \
lightningd/log_status.c \ lightningd/log_status.c \
lightningd/onchain_control.c \ lightningd/onchain_control.c \
lightningd/opening_control.c \ lightningd/opening_control.c \
lightningd/opt_time.c \
lightningd/options.c \ lightningd/options.c \
lightningd/pay.c \ lightningd/pay.c \
lightningd/payalgo.c \ lightningd/payalgo.c \

2
lightningd/channel_control.c

@ -268,7 +268,7 @@ bool peer_start_channeld(struct channel *channel,
&channel->seed, &channel->seed,
&ld->id, &ld->id,
&channel->peer->id, &channel->peer->id,
time_to_msec(cfg->commit_time), cfg->commit_time_ms,
cfg->cltv_expiry_delta, cfg->cltv_expiry_delta,
channel->last_was_revoke, channel->last_was_revoke,
channel->last_sent_commit, channel->last_sent_commit,

2
lightningd/lightningd.h

@ -43,7 +43,7 @@ struct config {
s32 fee_per_satoshi; s32 fee_per_satoshi;
/* How long between changing commit and sending COMMIT message. */ /* How long between changing commit and sending COMMIT message. */
struct timerel commit_time; u32 commit_time_ms;
/* How often to broadcast gossip (msec) */ /* How often to broadcast gossip (msec) */
u32 broadcast_interval; u32 broadcast_interval;

82
lightningd/opt_time.c

@ -1,82 +0,0 @@
#include "opt_time.h"
#include <assert.h>
#include <ccan/str/str.h>
#include <ccan/tal/str/str.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
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);
}

10
lightningd/opt_time.h

@ -1,10 +0,0 @@
#ifndef LIGHTNING_LIGHTNINGD_OPT_TIME_H
#define LIGHTNING_LIGHTNINGD_OPT_TIME_H
#include "config.h"
#include <ccan/opt/opt.h>
#include <ccan/time/time.h>
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 */

10
lightningd/options.c

@ -22,7 +22,6 @@
#include <lightningd/jsonrpc.h> #include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h> #include <lightningd/lightningd.h>
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/opt_time.h>
#include <lightningd/options.h> #include <lightningd/options.h>
#include <lightningd/subd.h> #include <lightningd/subd.h>
#include <stdio.h> #include <stdio.h>
@ -335,8 +334,9 @@ static void config_register_opts(struct lightningd *ld)
opt_register_arg("--cltv-final", opt_set_u32, opt_show_u32, opt_register_arg("--cltv-final", opt_set_u32, opt_show_u32,
&ld->config.cltv_final, &ld->config.cltv_final,
"Number of blocks for final ctlv_expiry"); "Number of blocks for final ctlv_expiry");
opt_register_arg("--commit-time", opt_set_time, opt_show_time, opt_register_arg("--commit-time=<millseconds>",
&ld->config.commit_time, opt_set_u32, opt_show_u32,
&ld->config.commit_time_ms,
"Time after changes before sending out COMMIT"); "Time after changes before sending out COMMIT");
opt_register_arg("--fee-base", opt_set_u32, opt_show_u32, opt_register_arg("--fee-base", opt_set_u32, opt_show_u32,
&ld->config.fee_base, &ld->config.fee_base,
@ -475,7 +475,7 @@ static const struct config testnet_config = {
.cltv_final = 6, .cltv_final = 6,
/* Send commit 10msec after receiving; almost immediately. */ /* Send commit 10msec after receiving; almost immediately. */
.commit_time = TIME_FROM_MSEC(10), .commit_time_ms = 10,
/* Allow dust payments */ /* Allow dust payments */
.fee_base = 1, .fee_base = 1,
@ -527,7 +527,7 @@ static const struct config mainnet_config = {
.cltv_final = 8, .cltv_final = 8,
/* Send commit 10msec after receiving; almost immediately. */ /* Send commit 10msec after receiving; almost immediately. */
.commit_time = TIME_FROM_MSEC(10), .commit_time_ms = 10,
/* Discourage dust payments */ /* Discourage dust payments */
.fee_base = 1000, .fee_base = 1000,

Loading…
Cancel
Save