Browse Source

Retry submitting a block up to 5 times if we fail to get a proper response

master
ckolivas 10 years ago
parent
commit
f6df38d975
  1. 11
      src/bitcoin.c

11
src/bitcoin.c

@ -379,23 +379,30 @@ out:
bool submit_block(connsock_t *cs, char *params) bool submit_block(connsock_t *cs, char *params)
{ {
json_t *val, *res_val; json_t *val, *res_val;
int len, retries = 0;
const char *res_ret; const char *res_ret;
bool ret = false; bool ret = false;
char *rpc_req; char *rpc_req;
int len;
len = strlen(params) + 50; len = strlen(params) + 64;
retry:
rpc_req = ckalloc(len); rpc_req = ckalloc(len);
sprintf(rpc_req, "{\"method\": \"submitblock\", \"params\": [\"%s\"]}\n", params); sprintf(rpc_req, "{\"method\": \"submitblock\", \"params\": [\"%s\"]}\n", params);
val = json_rpc_call(cs, rpc_req); val = json_rpc_call(cs, rpc_req);
dealloc(rpc_req); dealloc(rpc_req);
if (!val) { if (!val) {
LOGWARNING("Failed to get valid json response to submitblock"); LOGWARNING("Failed to get valid json response to submitblock");
if (++retries < 5)
goto retry;
return ret; return ret;
} }
res_val = json_object_get(val, "result"); res_val = json_object_get(val, "result");
if (!res_val) { if (!res_val) {
LOGWARNING("Failed to get result in json response to submitblock"); LOGWARNING("Failed to get result in json response to submitblock");
if (++retries < 5) {
json_decref(val);
goto retry;
}
goto out; goto out;
} }
if (!json_is_true(res_val)) { if (!json_is_true(res_val)) {

Loading…
Cancel
Save