Skip to content

Commit

Permalink
stratum: show url and height on new blocks
Browse files Browse the repository at this point in the history
and fix qubit difficulty
  • Loading branch information
tpruvot committed Nov 2, 2014
1 parent 9f3083c commit 7e4b0ea
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 25 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Version 1.0.7 (Tanguy Pruvot)
- Add NIST5 and QUBIT algos
- Show current stratum bloc height

Version 1.0.6 (Tanguy Pruvot)
- Fix scrypt algo
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Algorithms
*__cryptonight__ (Bytecoin [BCN], Monero)
*__fresh__ (FreshCoin)
*__neoscrypt__ (Feathercoin)
*__nist5__
*__nist5__ (TalkCoin [TAC], [UPM])
*__pentablake__ (Joincoin)
*__qubit__
*__qubit__ (MyriadCoin [MYR])
*__s3__ (OneCoin)
*__x11__ (Darkcoin [DRK], Hirocoin, Limecoin)
*__x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..)
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AC_CHECK_HEADERS([sys/sysctl.h], [], [],
#endif
])

AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc], [], [],
AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc, le16dec, le16enc], [], [],
[AC_INCLUDES_DEFAULT
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
Expand Down
43 changes: 21 additions & 22 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static int num_processors;
static char *rpc_url;
static char *rpc_userpass;
static char *rpc_user, *rpc_pass;
static char *short_url = NULL;
static int pk_script_size;
static unsigned char pk_script[25];
static char coinbase_sig[101] = "";
Expand Down Expand Up @@ -1555,6 +1556,9 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
case ALGO_NEOSCRYPT:
diff_to_target(work->target, sctx->job.diff / (65536.0 * opt_diff_factor));
break;
case ALGO_QUBIT:
diff_to_target(work->target, sctx->job.diff / (256.0 * opt_diff_factor));
break;
default:
diff_to_target(work->target, sctx->job.diff / opt_diff_factor);
}
Expand Down Expand Up @@ -2064,29 +2068,22 @@ static void *stratum_thread(void *userdata)
}
}

if (jsonrpc_2) {
if (stratum.work.job_id
&& (!g_work_time
|| strcmp(stratum.work.job_id, g_work.job_id))) {
pthread_mutex_lock(&g_work_lock);
stratum_gen_work(&stratum, &g_work);
time(&g_work_time);
pthread_mutex_unlock(&g_work_lock);
applog(LOG_BLUE, "Stratum requested work restart");
if (stratum.job.job_id &&
(!g_work_time || strcmp(stratum.job.job_id, g_work.job_id)) )
{
pthread_mutex_lock(&g_work_lock);
stratum_gen_work(&stratum, &g_work);
time(&g_work_time);
pthread_mutex_unlock(&g_work_lock);

if (stratum.job.clean || jsonrpc_2) {
if (!opt_quiet)
applog(LOG_BLUE, "%s sent %s block %d", short_url, algo_names[opt_algo],
stratum.bloc_height);
restart_threads();
}
} else {
if (stratum.job.job_id
&& (!g_work_time
|| strcmp(stratum.job.job_id, g_work.job_id))) {
pthread_mutex_lock(&g_work_lock);
stratum_gen_work(&stratum, &g_work);
time(&g_work_time);
pthread_mutex_unlock(&g_work_lock);
if (stratum.job.clean) {
applog(LOG_BLUE, "Stratum requested work restart");
restart_threads();
}
} else if (opt_debug && !opt_quiet) {
applog(LOG_BLUE, "%s asks job %d for block %d", short_url,
strtoul(stratum.job.job_id, NULL, 16), stratum.bloc_height);
}
}

Expand Down Expand Up @@ -2339,6 +2336,7 @@ static void parse_arg(int key, char *arg, char *pname)
free(rpc_url);
rpc_url = strdup(arg);
strcpy(rpc_url + (ap - arg), hp);
short_url = &rpc_url[(ap - arg) + 3];
} else {
if (*hp == '\0' || *hp == '/') {
fprintf(stderr, "%s: invalid URL -- '%s'\n",
Expand All @@ -2348,6 +2346,7 @@ static void parse_arg(int key, char *arg, char *pname)
free(rpc_url);
rpc_url = (char*) malloc(strlen(hp) + 8);
sprintf(rpc_url, "http://%s", hp);
short_url = &rpc_url[sizeof("http://")-1];
}
have_stratum = !opt_benchmark && !strncasecmp(rpc_url, "stratum", 7);
break;
Expand Down
19 changes: 19 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ static inline void le32enc(void *pp, uint32_t x)
}
#endif

#if !HAVE_DECL_LE16DEC
static inline uint16_t le16dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint16_t)(p[0]) + ((uint16_t)(p[1]) << 8));
}
#endif

#if !HAVE_DECL_LE16ENC
static inline void le16enc(void *pp, uint16_t x)
{
uint8_t *p = (uint8_t *)pp;
p[0] = x & 0xff;
p[1] = (x >> 8) & 0xff;
}
#endif

#if JANSSON_MAJOR_VERSION >= 2
#define JSON_LOADS(str, err_ptr) json_loads(str, 0, err_ptr)
#define JSON_LOAD_FILE(path, err_ptr) json_load_file(path, 0, err_ptr)
Expand Down Expand Up @@ -375,6 +392,8 @@ struct stratum_ctx {
struct stratum_job job;
struct work work;
pthread_mutex_t work_lock;

int bloc_height;
};

bool stratum_socket_full(struct stratum_ctx *sctx, int timeout);
Expand Down
32 changes: 32 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,36 @@ static bool stratum_2_job(struct stratum_ctx *sctx, json_t *params)
return ret;
}

/**
* Extract bloc height L H... here len=3, height=0x1333e8
* "...0000000000ffffffff2703e83313062f503253482f043d61105408"
*/
static uint32_t getblocheight(struct stratum_ctx *sctx)
{
uint32_t height = 0;
uint8_t hlen = 0, *p, *m;

// find 0xffff tag
p = (uint8_t*) sctx->job.coinbase + 32;
m = p + 128;
while (*p != 0xff && p < m) p++;
while (*p == 0xff && p < m) p++;
if (*(p-1) == 0xff && *(p-2) == 0xff) {
p++; hlen = *p;
p++; height = le16dec(p);
p += 2;
switch (hlen) {
case 4:
height += 0x10000UL * le16dec(p);
break;
case 3:
height += 0x10000UL * (*p);
break;
}
}
return height;
}

static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
{
const char *job_id, *prevhash, *coinb1, *coinb2, *version, *nbits, *ntime;
Expand Down Expand Up @@ -1290,6 +1320,8 @@ static bool stratum_notify(struct stratum_ctx *sctx, json_t *params)
sctx->job.job_id = strdup(job_id);
hex2bin(sctx->job.prevhash, prevhash, 32);

sctx->bloc_height = getblocheight(sctx);

for (i = 0; i < sctx->job.merkle_count; i++)
free(sctx->job.merkle[i]);
free(sctx->job.merkle);
Expand Down

0 comments on commit 7e4b0ea

Please sign in to comment.