|
|
@@ -131,6 +131,7 @@ static bool want_getwork = true;
|
|
|
#if BLKMAKER_VERSION > 1
|
|
|
static bool have_at_least_one_getcbaddr;
|
|
|
static bytes_t opt_coinbase_script = BYTES_INIT;
|
|
|
+static uint32_t coinbase_script_block_id;
|
|
|
static uint32_t template_nonce;
|
|
|
#endif
|
|
|
#if BLKMAKER_VERSION > 0
|
|
|
@@ -2865,11 +2866,19 @@ void refresh_bitcoind_address(const bool fresh)
|
|
|
}
|
|
|
}
|
|
|
json = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, getcbaddr_req, false, false, NULL, pool, true);
|
|
|
- j2 = json_object_get(json, "error");
|
|
|
- if (unlikely(!json_is_null(j2)))
|
|
|
+ if (unlikely((!json) || !json_is_null( (j2 = json_object_get(json, "error")) )))
|
|
|
{
|
|
|
+ const char *estrc;
|
|
|
char *estr = NULL;
|
|
|
- applog(LOG_WARNING, "Error %cetting coinbase address from pool %d: %s", 'g', pool->pool_no, json_string_value(j2) ?: (estr = json_dumps_ANY(j2, JSON_ENSURE_ASCII | JSON_SORT_KEYS)));
|
|
|
+ if (!(json && j2))
|
|
|
+ estrc = NULL;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ estrc = json_string_value(j2);
|
|
|
+ if (!estrc)
|
|
|
+ estrc = estr = json_dumps_ANY(j2, JSON_ENSURE_ASCII | JSON_SORT_KEYS);
|
|
|
+ }
|
|
|
+ applog(LOG_WARNING, "Error %cetting coinbase address from pool %d: %s", 'g', pool->pool_no, estrc);
|
|
|
free(estr);
|
|
|
continue;
|
|
|
}
|
|
|
@@ -2891,6 +2900,7 @@ void refresh_bitcoind_address(const bool fresh)
|
|
|
break;
|
|
|
}
|
|
|
bytes_assimilate(&opt_coinbase_script, &newscript);
|
|
|
+ coinbase_script_block_id = current_block_id;
|
|
|
applog(LOG_NOTICE, "Now using coinbase address %s, provided by pool %d", s, pool->pool_no);
|
|
|
break;
|
|
|
}
|
|
|
@@ -2935,12 +2945,8 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
|
|
|
}
|
|
|
work->rolltime = blkmk_time_left(tmpl, tv_now.tv_sec);
|
|
|
#if BLKMAKER_VERSION > 1
|
|
|
- if ((!tmpl->cbtxn) && !bytes_len(&opt_coinbase_script))
|
|
|
- {
|
|
|
- // We are about to fail here because we lack a coinbase transaction
|
|
|
- // Try to get an address from bitcoind to use to avoid this
|
|
|
+ if ((!tmpl->cbtxn) && coinbase_script_block_id != current_block_id)
|
|
|
refresh_bitcoind_address(false);
|
|
|
- }
|
|
|
if (bytes_len(&opt_coinbase_script))
|
|
|
{
|
|
|
bool newcb;
|
|
|
@@ -5798,7 +5804,6 @@ void work_check_for_block(struct work * const work)
|
|
|
found_blocks++;
|
|
|
work->mandatory = true;
|
|
|
applog(LOG_NOTICE, "Found block for pool %d!", work->pool->pool_no);
|
|
|
- refresh_bitcoind_address(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -10999,9 +11004,11 @@ err:
|
|
|
if (rpcssl == -101)
|
|
|
rpcssl = 0;
|
|
|
|
|
|
+ const bool have_cbaddr = bytes_len(&opt_coinbase_script);
|
|
|
+
|
|
|
const int uri_sz = 0x30;
|
|
|
char * const uri = malloc(uri_sz);
|
|
|
- snprintf(uri, uri_sz, "http%s://localhost:%d/#getcbaddr#allblocks", rpcssl ? "s" : "", rpcport);
|
|
|
+ snprintf(uri, uri_sz, "http%s://localhost:%d/%s#allblocks", rpcssl ? "s" : "", rpcport, have_cbaddr ? "" : "#getcbaddr");
|
|
|
|
|
|
applog(LOG_DEBUG, "Local bitcoin RPC server on port %d found in %s", rpcport, filepath);
|
|
|
|