controlled_time: remove

We don't need it for testing at the moment, and if we do it'll have
to change to relative anyway now we're going to use time_mono().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-11-09 18:54:15 +10:30
parent c5de5d4c39
commit 4bed6c8c67
12 changed files with 2 additions and 116 deletions

View File

@ -50,7 +50,6 @@ Here's a list of parts, with notes:
- Misc:
- configdir: support for ~/.lightning/config
- controlled_time: support for dev-mocktime to alter time.
- log: logging routines
- pseudorand: pseudorandom wrapper
- secrets: routines for using secret keys.

View File

@ -18,7 +18,6 @@ DAEMON_SRC := \
daemon/chaintopology.c \
daemon/channel.c \
daemon/commit_tx.c \
daemon/controlled_time.c \
daemon/cryptopkt.c \
daemon/db.c \
daemon/dns.c \
@ -64,7 +63,6 @@ DAEMON_HEADERS := \
daemon/channel.h \
daemon/commit_tx.h \
daemon/configdir.h \
daemon/controlled_time.h \
daemon/cryptopkt.h \
daemon/db.h \
daemon/dns.h \

View File

@ -1,73 +0,0 @@
#include "controlled_time.h"
#include "jsonrpc.h"
#include "lightningd.h"
#include "log.h"
#include "opt_time.h"
#include <ccan/tal/str/str.h>
#include <inttypes.h>
#include <stdio.h>
static struct timeabs mock_time;
struct timeabs controlled_time(void)
{
if (mock_time.ts.tv_sec)
return mock_time;
return time_now();
}
void controlled_time_register_opts(void)
{
opt_register_arg("--mocktime", opt_set_timeabs, opt_show_timeabs,
&mock_time, opt_hidden);
}
char *controlled_time_arg(const tal_t *ctx)
{
char buf[sizeof("--mocktime=") + OPT_SHOW_LEN] = "--mocktime=";
if (!mock_time.ts.tv_sec)
return NULL;
opt_show_timeabs(buf + strlen(buf), &mock_time);
return tal_strdup(ctx, buf);
}
static void json_mocktime(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
struct json_result *response = new_json_result(cmd);
jsmntok_t *mocktimetok;
u64 prev_time, mocktime;
char mocktimestr[STR_MAX_CHARS(int64_t)];
if (!json_get_params(buffer, params,
"mocktime", &mocktimetok,
NULL)) {
command_fail(cmd, "Need mocktime");
return;
}
if (!json_tok_u64(buffer, mocktimetok, &mocktime)) {
command_fail(cmd, "Need valid mocktime");
return;
}
prev_time = controlled_time().ts.tv_sec;
mock_time.ts.tv_sec = mocktime;
json_object_start(response, NULL);
sprintf(mocktimestr, "%"PRIi64,
(s64)controlled_time().ts.tv_sec - prev_time);
json_add_string(response, "offset", mocktimestr);
json_object_end(response);
log_unusual(cmd->dstate->base_log,
"mocktime set to %"PRIu64, (u64)mock_time.ts.tv_sec);
command_success(cmd, response);
}
const struct json_command dev_mocktime_command = {
"dev-mocktime",
json_mocktime,
"Set current time to {mocktime} seconds (0 to return to normal)",
"Returns the offset on success"
};

View File

@ -1,12 +0,0 @@
#ifndef LIGHTNING_DAEMON_CONTROLLED_TIME_H
#define LIGHTNING_DAEMON_CONTROLLED_TIME_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <ccan/time/time.h>
struct timeabs controlled_time(void);
void controlled_time_register_opts(void);
char *controlled_time_arg(const tal_t *ctx);
#endif /* LIGHTNING_DAEMON_CONTROLLED_TIME_H */

View File

@ -1,7 +1,6 @@
/* Code for JSON_RPC API */
/* eg: { "method" : "dev-echo", "params" : [ "hello", "Arabella!" ], "id" : "1" } */
#include "chaintopology.h"
#include "controlled_time.h"
#include "json.h"
#include "jsonrpc.h"
#include "lightningd.h"
@ -307,7 +306,6 @@ static const struct json_command *cmdlist[] = {
&dev_commit_command,
&dev_feerate_command,
&dev_rhash_command,
&dev_mocktime_command,
&dev_crash_command,
&dev_restart_command,
&dev_disconnect_command,

View File

@ -83,7 +83,6 @@ extern const struct json_command dev_newhtlc_command;
extern const struct json_command dev_fulfillhtlc_command;
extern const struct json_command dev_failhtlc_command;
extern const struct json_command dev_commit_command;
extern const struct json_command dev_mocktime_command;
extern const struct json_command dev_reconnect_command;
extern const struct json_command dev_disconnect_command;
extern const struct json_command dev_signcommit_command;

View File

@ -2,7 +2,6 @@
* Helper to submit via JSON-RPC and get back response.
*/
#include "configdir.h"
#include "controlled_time.h"
#include "json.h"
#include "version.h"
#include <ccan/err/err.h>
@ -40,11 +39,6 @@ static void tal_freefn(void *ptr)
tal_free(ptr);
}
struct timeabs controlled_time(void)
{
return time_now();
}
struct netaddr;
char *netaddr_name(const tal_t *ctx, const struct netaddr *a);
char *netaddr_name(const tal_t *ctx, const struct netaddr *a)

View File

@ -1,7 +1,6 @@
#include "bitcoind.h"
#include "chaintopology.h"
#include "configdir.h"
#include "controlled_time.h"
#include "db.h"
#include "irc_announce.h"
#include "jsonrpc.h"
@ -172,7 +171,6 @@ static void config_register_opts(struct lightningd_state *dstate)
static void dev_register_opts(struct lightningd_state *dstate)
{
controlled_time_register_opts();
opt_register_noarg("--dev-no-routefail", opt_set_bool,
&dstate->dev_never_routefail, opt_hidden);
opt_register_noarg("--dev-no-broadcast", opt_set_bool,
@ -353,7 +351,7 @@ static struct lightningd_state *lightningd_state(void)
list_head_init(&dstate->pay_commands);
dstate->portnum = 0;
dstate->testnet = true;
timers_init(&dstate->timers, controlled_time());
timers_init(&dstate->timers, time_now());
txwatch_hash_init(&dstate->txwatches);
txowatch_hash_init(&dstate->txowatches);
dstate->secpctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
@ -547,9 +545,6 @@ int main(int argc, char *argv[])
if (dstate->config.use_irc)
setup_irc_connection(dstate);
/* Make sure we use the artificially-controlled time for timers */
io_time_override(controlled_time);
log_info(dstate->base_log, "Hello world!");
/* If we loaded peers from database, reconnect now. */
@ -574,7 +569,6 @@ int main(int argc, char *argv[])
if (dstate->reexec) {
int fd;
char *mocktimearg;
log_unusual(dstate->base_log, "Restart at user request");
fflush(stdout);
@ -584,13 +578,6 @@ int main(int argc, char *argv[])
for (fd = 3; fd < 1024; fd++)
close(fd);
/* Maybe append mocktime arg. */
mocktimearg = controlled_time_arg(dstate->reexec);
if (mocktimearg) {
size_t n = tal_count(dstate->reexec);
tal_resizez(&dstate->reexec, n+1);
dstate->reexec[n-1] = mocktimearg;
}
if (dstate->dev_never_routefail) {
size_t n = tal_count(dstate->reexec);
tal_resizez(&dstate->reexec, n+1);

View File

@ -2,7 +2,6 @@
#include "bitcoin/pubkey.h"
#include "bitcoin/tx.h"
#include "channel.h"
#include "controlled_time.h"
#include "htlc.h"
#include "lightningd.h"
#include "log.h"

View File

@ -3,7 +3,6 @@
#include "chaintopology.h"
#include "close_tx.h"
#include "commit_tx.h"
#include "controlled_time.h"
#include "cryptopkt.h"
#include "htlc.h"
#include "lightningd.h"

View File

@ -2,7 +2,6 @@
#include "chaintopology.h"
#include "close_tx.h"
#include "commit_tx.h"
#include "controlled_time.h"
#include "cryptopkt.h"
#include "db.h"
#include "dns.h"

View File

@ -1,4 +1,3 @@
#include "controlled_time.h"
#include "lightningd.h"
#include "timeout.h"
#include "utils.h"
@ -21,7 +20,7 @@ struct oneshot *new_reltimer_(struct lightningd_state *dstate,
void (*cb)(void *), void *arg)
{
struct oneshot *t = tal(ctx, struct oneshot);
struct timeabs expiry = timeabs_add(controlled_time(), relexpiry);
struct timeabs expiry = timeabs_add(time_now(), relexpiry);
t->cb = cb;
t->arg = arg;