From 0d1b45dfccfb6f522e5569919ceef4476299c4dd Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 6 Jan 2021 16:22:34 +0100 Subject: [PATCH] json-rpc: Give `waitblockheight` an error code for timeouts We need to differentiate timeouts from other results, so make it recognizable. --- common/jsonrpc_errors.h | 3 +++ doc/lightning-waitblockheight.7 | 4 ++-- doc/lightning-waitblockheight.7.md | 2 +- lightningd/peer_control.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/common/jsonrpc_errors.h b/common/jsonrpc_errors.h index c4647b589..781781831 100644 --- a/common/jsonrpc_errors.h +++ b/common/jsonrpc_errors.h @@ -84,4 +84,7 @@ static const errcode_t OFFER_EXPIRED = 1002; static const errcode_t OFFER_ROUTE_NOT_FOUND = 1003; static const errcode_t OFFER_BAD_INVREQ_REPLY = 1004; +/* Errors from wait* commands */ +static const errcode_t WAIT_TIMEOUT = 2000; + #endif /* LIGHTNING_COMMON_JSONRPC_ERRORS_H */ diff --git a/doc/lightning-waitblockheight.7 b/doc/lightning-waitblockheight.7 index 31cc0e465..87b169099 100644 --- a/doc/lightning-waitblockheight.7 +++ b/doc/lightning-waitblockheight.7 @@ -23,7 +23,7 @@ the block height at the time the command returns\. If \fItimeout\fR seconds is reached without the specified blockheight -being reached, this command will fail\. +being reached, this command will fail with a code of \fB2000\fR\. .SH AUTHOR @@ -33,4 +33,4 @@ ZmnSCPxj \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:5714e6333e5ba57cc00de425e6dc411f2c30812bbc8d95d01d50c460ee002e29 +\" SHA256STAMP:ac3320b4b9e679d8c407e42c9663540e2fc2aca75143d192f58ce255ca9b3700 diff --git a/doc/lightning-waitblockheight.7.md b/doc/lightning-waitblockheight.7.md index e51dddf88..8ca4c4aad 100644 --- a/doc/lightning-waitblockheight.7.md +++ b/doc/lightning-waitblockheight.7.md @@ -24,7 +24,7 @@ an object with the single field *blockheight* is returned, which is the block height at the time the command returns. If *timeout* seconds is reached without the specified blockheight -being reached, this command will fail. +being reached, this command will fail with a code of `2000`. AUTHOR ------ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 3205527d5..525d0c8b3 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1850,7 +1850,7 @@ timeout_waitblockheight_waiter(struct waitblockheight_waiter *w) list_del(&w->list); w->removed = true; tal_steal(tmpctx, w); - was_pending(command_fail(w->cmd, LIGHTNINGD, + was_pending(command_fail(w->cmd, WAIT_TIMEOUT, "Timed out.")); } /* Called by lightningd at each new block. */