From f6df38d97551e0df0c6ddfe3a02be2c26f09b83f Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 15 Oct 2014 17:08:01 +1100 Subject: [PATCH] Retry submitting a block up to 5 times if we fail to get a proper response --- src/bitcoin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bitcoin.c b/src/bitcoin.c index 9ba9a024..5812b994 100644 --- a/src/bitcoin.c +++ b/src/bitcoin.c @@ -379,23 +379,30 @@ out: bool submit_block(connsock_t *cs, char *params) { json_t *val, *res_val; + int len, retries = 0; const char *res_ret; bool ret = false; char *rpc_req; - int len; - len = strlen(params) + 50; + len = strlen(params) + 64; +retry: rpc_req = ckalloc(len); sprintf(rpc_req, "{\"method\": \"submitblock\", \"params\": [\"%s\"]}\n", params); val = json_rpc_call(cs, rpc_req); dealloc(rpc_req); if (!val) { LOGWARNING("Failed to get valid json response to submitblock"); + if (++retries < 5) + goto retry; return ret; } res_val = json_object_get(val, "result"); if (!res_val) { LOGWARNING("Failed to get result in json response to submitblock"); + if (++retries < 5) { + json_decref(val); + goto retry; + } goto out; } if (!json_is_true(res_val)) {