diff --git a/HACKING.md b/HACKING.md index 956a4eebf..34039421d 100644 --- a/HACKING.md +++ b/HACKING.md @@ -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. diff --git a/daemon/Makefile b/daemon/Makefile index 5ca771b48..3f3582255 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -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 \ diff --git a/daemon/controlled_time.c b/daemon/controlled_time.c deleted file mode 100644 index 5bf80917b..000000000 --- a/daemon/controlled_time.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "controlled_time.h" -#include "jsonrpc.h" -#include "lightningd.h" -#include "log.h" -#include "opt_time.h" -#include -#include -#include - -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" -}; diff --git a/daemon/controlled_time.h b/daemon/controlled_time.h deleted file mode 100644 index 2c74dd5c2..000000000 --- a/daemon/controlled_time.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LIGHTNING_DAEMON_CONTROLLED_TIME_H -#define LIGHTNING_DAEMON_CONTROLLED_TIME_H -#include "config.h" -#include -#include -#include - -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 */ diff --git a/daemon/jsonrpc.c b/daemon/jsonrpc.c index 6980da296..d6cb9c2f8 100644 --- a/daemon/jsonrpc.c +++ b/daemon/jsonrpc.c @@ -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, diff --git a/daemon/jsonrpc.h b/daemon/jsonrpc.h index 9d4eb5faa..b22d2d2c4 100644 --- a/daemon/jsonrpc.h +++ b/daemon/jsonrpc.h @@ -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; diff --git a/daemon/lightning-cli.c b/daemon/lightning-cli.c index a9f58f97d..0df904e3a 100644 --- a/daemon/lightning-cli.c +++ b/daemon/lightning-cli.c @@ -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 @@ -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) diff --git a/daemon/lightningd.c b/daemon/lightningd.c index 419b6c264..3889083fa 100644 --- a/daemon/lightningd.c +++ b/daemon/lightningd.c @@ -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); diff --git a/daemon/log.c b/daemon/log.c index 6d8159500..0e74c9b3e 100644 --- a/daemon/log.c +++ b/daemon/log.c @@ -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" diff --git a/daemon/packets.c b/daemon/packets.c index 28d3cd50a..11d66e64f 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -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" diff --git a/daemon/peer.c b/daemon/peer.c index ea3eb36ea..2a54ae6fb 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -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" diff --git a/daemon/timeout.c b/daemon/timeout.c index 57624d648..47fe29ab1 100644 --- a/daemon/timeout.c +++ b/daemon/timeout.c @@ -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;