From f4f0c1aa18f68291bd56e4ed53227bcc7cc8cf9d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 30 Jun 2016 09:08:10 +0930 Subject: [PATCH] daemon: add dev-routefail command. We're about to change the code so that if it can't route, it will fail the HTLC. The current low-level tests will hate this, so have a dev switch to turn that off. Signed-off-by: Rusty Russell --- daemon/jsonrpc.c | 1 + daemon/jsonrpc.h | 1 + daemon/lightningd.c | 1 + daemon/lightningd.h | 3 +++ daemon/routing.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/daemon/jsonrpc.c b/daemon/jsonrpc.c index ece03117b..9d3fb09aa 100644 --- a/daemon/jsonrpc.c +++ b/daemon/jsonrpc.c @@ -265,6 +265,7 @@ static const struct json_command *cmdlist[] = { &signcommit_command, &output_command, &add_route_command, + &routefail_command, }; static void json_help(struct command *cmd, diff --git a/daemon/jsonrpc.h b/daemon/jsonrpc.h index 7214665e1..aa37bf9dc 100644 --- a/daemon/jsonrpc.h +++ b/daemon/jsonrpc.h @@ -71,4 +71,5 @@ extern const struct json_command signcommit_command; extern const struct json_command output_command; extern const struct json_command accept_payment_command; extern const struct json_command add_route_command; +extern const struct json_command routefail_command; #endif /* LIGHTNING_DAEMON_JSONRPC_H */ diff --git a/daemon/lightningd.c b/daemon/lightningd.c index 076320a5e..5bba5da82 100644 --- a/daemon/lightningd.c +++ b/daemon/lightningd.c @@ -204,6 +204,7 @@ static struct lightningd_state *lightningd_state(void) list_head_init(&dstate->bitcoin_req); list_head_init(&dstate->wallet); list_head_init(&dstate->payments); + dstate->dev_never_routefail = false; dstate->bitcoin_req_running = false; dstate->nodes = empty_node_map(dstate); return dstate; diff --git a/daemon/lightningd.h b/daemon/lightningd.h index aa7e768e3..09b86e26f 100644 --- a/daemon/lightningd.h +++ b/daemon/lightningd.h @@ -96,5 +96,8 @@ struct lightningd_state { /* All known nodes. */ struct node_map *nodes; + + /* For testing: don't fail if we can't route. */ + bool dev_never_routefail; }; #endif /* LIGHTNING_DAEMON_LIGHTNING_H */ diff --git a/daemon/routing.c b/daemon/routing.c index 79e3a49fd..16b702dbe 100644 --- a/daemon/routing.c +++ b/daemon/routing.c @@ -299,3 +299,35 @@ const struct json_command add_route_command = { "Returns an empty result on success" }; +static void json_routefail(struct command *cmd, + const char *buffer, const jsmntok_t *params) +{ + jsmntok_t *enabletok; + bool enable; + + if (!json_get_params(buffer, params, + "enable", &enabletok, + NULL)) { + command_fail(cmd, "Need enable"); + return; + } + + if (!json_tok_bool(buffer, enabletok, &enable)) { + command_fail(cmd, "enable must be true or false"); + return; + } + + log_debug(cmd->dstate->base_log, "dev-routefail: routefail %s", + enable ? "enabled" : "disabled"); + cmd->dstate->dev_never_routefail = !enable; + + command_success(cmd, null_response(cmd)); +} +const struct json_command routefail_command = { + "dev-routefail", + json_routefail, + "FAIL htlcs that we can't route if {enable}", + "Returns an empty result on success" +}; + +